Skip to content

Instantly share code, notes, and snippets.

@bfcoder
Forked from blaise-io/prepend-use-strict.js
Last active August 29, 2015 14:25
Show Gist options
  • Save bfcoder/ca88c00724c27895b77e to your computer and use it in GitHub Desktop.
Save bfcoder/ca88c00724c27895b77e to your computer and use it in GitHub Desktop.
Prepend all JavaScript files with "use strict"; that don't have it yet
// To run:
// npm install globby
// node prepend-use-strict.js
var globby = require('globby');
var fs = require('fs');
globby('**/*.js', function(err, files) {
for (var i = 0, m = files.length; i < m; i++) {
var fileContent = fs.readFileSync(files[i]).toString();
if (!fileContent.match("use strict")) {
fileContent = "\"use strict\";\n\n" + fileContent;
fs.writeFileSync(files[i], fileContent);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment