Permalink
Browse files

Merge branch 'feature/formatting' into develop

  • Loading branch information...
brolund committed Sep 2, 2012
2 parents 3935f01 + 6ca0783 commit 10c77ffeb290afd65411b7dc10b5f1a77c8aa2fd
Showing with 35 additions and 1 deletion.
  1. +33 −0 format.js
  2. +2 −1 package.json
View
@@ -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);
+ });
+});
View
@@ -9,7 +9,8 @@
"webdriverjs": "~0.6.9",
"soda": "~0.2.5",
"when": "~1.4.2",
- "request": "~2.11.0"
+ "request": "~2.11.0",
+ "node-js-beautify": "~0.1.0"
},
"repository": {
"type": "git",

0 comments on commit 10c77ff

Please sign in to comment.