Skip to content

Commit

Permalink
Add code format tool (not finished yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sannis committed Dec 19, 2015
1 parent 7cd5281 commit d76a3e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"lodash": "^3.3.1",
"mocha": "^2.0.1",
"should": "^7.0.1",
"tiny-worker": "^1.1.1"
"tiny-worker": "^1.1.1",
"js-beautify": "^1.5.10"
}
}
47 changes: 47 additions & 0 deletions tools/codeformat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var _ = require('lodash');
var bluebird = require('bluebird');
var path = require('path');
var glob = bluebird.promisify(require('glob'));
var fs = require('fs');
var readFile = bluebird.promisify(fs.readFile);
var writeFile = bluebird.promisify(fs.writeFile);
var beautify = require('js-beautify').js_beautify;

var beautify_options = {
"indent_size": 2,
"indent_char": " ",
"eol": "\n",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 10,
"jslint_happy": false,
"space_after_anon_function": false,
"brace_style": "collapse",
"keep_array_indentation": false,
"keep_function_indentation": false,
"space_before_conditional": true,
"break_chained_methods": false,
"eval_code": false,
"end_with_newline": true
};

console.log("Starting formatting.");

var sources = path.join('src', 'languages', '*.js');

bluebird.map(glob(sources), function (name) {
var basename = path.basename(name, '.js');

return readFile(name).then(function (blob) {
return beautify(blob.toString(), beautify_options);
}).then(function (blob) {
return writeFile(name, blob).then(function () {
console.log(" ✓ " + basename);
});
});
}).then(function () {
console.log("Finished formatting.");
});

0 comments on commit d76a3e7

Please sign in to comment.