Skip to content

Loading…

No longer re-writes unchanged files. #10

Merged
merged 1 commit into from

2 participants

@davdiv

This pull request prevents files to be written if they did not change, and displays how many files changed.

This is especially useful when using this plugin with grunt-contrib-watch, to avoid infinite loops.

@vkadam vkadam merged commit 3b5970a into vkadam:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @davdiv
Showing with 8 additions and 4 deletions.
  1. +8 −4 tasks/jsbeautifier.js
View
12 tasks/jsbeautifier.js
@@ -10,6 +10,7 @@ module.exports = function(grunt) {
var beautify = require('js-beautify').js_beautify;
var params = this.options();
var fileCount = 0;
+ var changedFileCount = 0;
if (this.filesSrc) {
grunt.verbose.writeln('Beautifing using filesSrc with ' + this.filesSrc.length.toString().cyan + ' files...');
@@ -18,16 +19,19 @@ module.exports = function(grunt) {
return;
}
- var result = grunt.file.read(src);
+ var original = grunt.file.read(src);
grunt.verbose.write('Beautifing ' + src.cyan + '...');
- result = beautify(result, params);
+ var result = beautify(original, params);
result += '\n';
grunt.verbose.ok();
- grunt.file.write(src, result);
+ if (original !== result) {
+ grunt.file.write(src, result);
+ changedFileCount++;
+ }
fileCount++;
});
}
- grunt.log.write('Beautified ' + fileCount.toString().cyan + ' files...');
+ grunt.log.write('Beautified ' + fileCount.toString().cyan + ' files, changed ' + changedFileCount.toString().cyan + ' files...');
grunt.log.ok();
});
};
Something went wrong with that request. Please try again.