diff --git a/Gruntfile.js b/Gruntfile.js index 08cff05..5756f9d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -150,6 +150,36 @@ module.exports = function(grunt) { 'test/fixtures/css2.css' ] } + }, + create_empty_files_option_one: { + options: { + createEmptyFiles: true + }, + files: { + 'tmp/create_empty_files_option_one.js': [ + 'test/fixtures/not_available.js' + ] + } + }, + create_empty_files_option_two: { + options: { + createEmptyFiles: false + }, + files: { + 'tmp/create_empty_files_option_two.js': [ + 'test/fixtures/not_available.js' + ] + } + }, + create_empty_files_option_three: { + options: { + createEmptyFiles: false + }, + files: { + 'tmp/create_empty_files_option_three.js': [ + 'test/fixtures/empty.js' + ] + } } }, diff --git a/tasks/concat.js b/tasks/concat.js index 81fd862..ca3a0b5 100644 --- a/tasks/concat.js +++ b/tasks/concat.js @@ -25,7 +25,8 @@ module.exports = function(grunt) { process: false, sourceMap: false, sourceMapName: undefined, - sourceMapStyle: 'embed' + sourceMapStyle: 'embed', + createEmptyFiles: true }); // Normalize boolean options that accept options objects. @@ -110,11 +111,15 @@ module.exports = function(grunt) { src += sourceMapHelper.url(); } - // Write the destination file. - grunt.file.write(f.dest, src); + if (!options.createEmptyFiles && /^\s*$/.test(src)) { + grunt.verbose.write('No content available.'); + } else { + // Write the destination file. + grunt.file.write(f.dest, src); - // Print a success message. - grunt.verbose.write('File ' + chalk.cyan(f.dest) + ' created.'); + // Print a success message. + grunt.verbose.write('File ' + chalk.cyan(f.dest) + ' created.'); + } }); }); diff --git a/test/concat_test.js b/test/concat_test.js index 3de58d6..b8391ba 100644 --- a/test/concat_test.js +++ b/test/concat_test.js @@ -105,6 +105,21 @@ exports.concat = { expected = getNormalizedFile('test/expected/sourcemap_css.css.map'); test.equal(actual, expected, 'should output the css map.'); + test.done(); + }, + create_empty_files_option: function(test) { + test.expect(3); + + var actual = getNormalizedFile('tmp/create_empty_files_option_one.js'); + var expected = ''; + test.equal(actual, expected, 'should create empty file.'); + + actual = grunt.file.exists('tmp/create_empty_files_option_two.js'); + test.ok(!actual, 'should not create file.'); + + actual = grunt.file.exists('tmp/create_empty_files_option_three.js'); + test.ok(!actual, 'should not create file.'); + test.done(); } }; diff --git a/test/fixtures/empty.js b/test/fixtures/empty.js new file mode 100644 index 0000000..b6f99d1 --- /dev/null +++ b/test/fixtures/empty.js @@ -0,0 +1,4 @@ + + + +