Skip to content

Commit

Permalink
Fix a bug so it only overwrites a file is there was stripped code.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Jul 9, 2013
1 parent 4e199d7 commit 83b6290
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"grunt": "~0.4.1"
},
"keywords": [
"gruntplugin"
"gruntplugin",
"strip",
"unit",
"test",
"private",
"functions"
]
}
}
20 changes: 11 additions & 9 deletions tasks/strip_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ module.exports = function(grunt) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return;
}
// strip test blocks from the file
var contents = grunt.file.read(filepath).replace(pattern, "");
// save file and print a success message.
if (f.dest) {
grunt.file.write(f.dest, contents);
grunt.log.writeln("Stripped code from " + filepath + " and saved to " + f.dest);
} else {
grunt.file.write(filepath, contents);
grunt.log.writeln("Stripped code from " + filepath);
var contents = grunt.file.read(filepath)
, replacement = contents.replace(pattern, "");
// if replacement is different than contents, save file and print a success message.
if (contents != replacement) {
if (f.dest) {
grunt.file.write(f.dest, replacement);
grunt.log.writeln("Stripped code from " + filepath + " and saved to " + f.dest);
} else {
grunt.file.write(filepath, replacement);
grunt.log.writeln("Stripped code from " + filepath);
}
}
});
});
Expand Down

0 comments on commit 83b6290

Please sign in to comment.