Skip to content

Commit

Permalink
Merge branch 'feature/formatting' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
brolund committed Sep 2, 2012
2 parents 3935f01 + 6ca0783 commit 10c77ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions format.js
@@ -0,0 +1,33 @@
var jsb = require('node-js-beautify');
var _ = require('./site/js/underscore');
var when = require('when');
var fs = require('fs');

var arguments = process.argv.splice(2);

var files = arguments;
console.log(files);

function formatFile(file) {
var def = when.defer();

console.log("Formatting", file);
fs.readFile(file, 'UTF-8', function(err, data) {
if (err) def.reject(err);
var r = new jsb().beautify_js(data, {
'indent_size': 4,
'indent_char': ' '
});
fs.writeFile(file, r, function(err) {
if (err) def.reject(err);
def.resolve("File '" + file + "' reformatted");
});
});
return def.promise;
}

when.all(_.map(files, formatFile)).then(function(res) {
_.each(res, function(item) {
console.log(item);
});
});
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -9,7 +9,8 @@
"webdriverjs": "~0.6.9", "webdriverjs": "~0.6.9",
"soda": "~0.2.5", "soda": "~0.2.5",
"when": "~1.4.2", "when": "~1.4.2",
"request": "~2.11.0" "request": "~2.11.0",
"node-js-beautify": "~0.1.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down

0 comments on commit 10c77ff

Please sign in to comment.