diff --git a/README.md b/README.md index 388f361..1400308 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,11 @@ In lieu of a formal styleguide, take care to maintain the existing coding style. ## Release History +#### 1.0.7 + +* Log only number of changed files, you have to use grunt verbose to get verbose logs. +* Write to disk only if the file contents changed, or the destination changed. + #### 1.0.6 * Added Windows tests on AppVeyor. diff --git a/package.json b/package.json index 4470663..5e6b8e7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-strip-code", "description": "Remove dev and test only code in production builds", - "version": "1.0.6", + "version": "1.0.7", "homepage": "https://github.com/nuzzio/grunt-strip-code", "author": { "name": "Rene Cabral", diff --git a/tasks/strip_code.js b/tasks/strip_code.js index 19e1499..bd2a899 100644 --- a/tasks/strip_code.js +++ b/tasks/strip_code.js @@ -24,6 +24,7 @@ module.exports = function (grunt) { var fileStartDelimiters = []; var fileEndDelimiters = []; var strings = {}; + var strippedCount = 0; strings.en_us = { "missing.end.block": "Missing end block: in file `%f` for start block `%p` at line %n.", @@ -37,7 +38,8 @@ module.exports = function (grunt) { "translate.param.missing": "translate() function must have at least a string key parameter.", "striped.file.saved.file": "Stripped code from file: `%1`, and saved it to: `%2`.", "nothing.striped.file.saved.file": "No code was stripped from file: `%1`,it was saved to: `%2`.", - "string.key.missing": "String key not found" + "string.key.missing": "String key not found", + "stripped.summary": "Stripped %1 files." }; var errors = []; @@ -101,7 +103,7 @@ module.exports = function (grunt) { return string; }; - + // Legacy Checks // Respecting legacy code by taking pattern, if defined, // over start_comment & end_comment @@ -345,6 +347,7 @@ module.exports = function (grunt) { this.files.forEach(function (f) { f.src.forEach(function (filepath) { var message = null; + var isFileStripped = false; fileStartDelimiters = []; fileEndDelimiters = []; @@ -387,6 +390,8 @@ module.exports = function (grunt) { if (contents !== replacement) { message = translate('striped.file.saved.file', filepath, destination); + isFileStripped = true; + strippedCount++; } else { message = translate('nothing.striped.file.saved.file', filepath, destination); } @@ -394,17 +399,18 @@ module.exports = function (grunt) { /** * Write file to its destination. */ - grunt.file.write(destination, replacement); + if (isFileStripped || filepath !== destination) { + grunt.file.write(destination, replacement); + } /** * Log file strip status and write destination. */ - grunt.log.writeln(message); - + grunt.verbose.writeln(message); }); }); - + grunt.verbose.writeln(''); + grunt.log.writeln(translate('stripped.summary', strippedCount)); }); }; -