Skip to content

Commit

Permalink
Merge pull request #22 from johny-gog/better_logs_less_writing
Browse files Browse the repository at this point in the history
Less spam in logs & less writing to disk
  • Loading branch information
nuzzio committed Mar 23, 2019
2 parents 4a84e8b + 87fc8e1 commit 80991ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion 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",
Expand Down
20 changes: 13 additions & 7 deletions tasks/strip_code.js
Expand Up @@ -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.",
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -387,24 +390,27 @@ 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);
}

/**
* 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));
});
};

0 comments on commit 80991ed

Please sign in to comment.