master
James Long 2016-11-29 12:14:10 -05:00
commit 29627ee520
3 changed files with 52 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

42
bin/jscodefmt Executable file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env node
const fs = require("fs");
const argv = require("minimist")(process.argv.slice(2));
const recast = require("recast");
const babylon = require("babylon");
const filename = argv["_"][0];
const printWidth = argv['print-width'] || 80;
const tabWidth = argv['tab-width'] || 2;
var babylonOptions = {
sourceType: 'module',
allowImportExportEverywhere: false,
allowReturnOutsideFunction: false,
plugins: [
'asyncFunctions',
'asyncGenerators',
'classConstructorCall',
'classProperties',
'decorators',
'doExpressions',
'exponentiationOperator',
'exportExtensions',
'flow',
'functionSent',
'functionBind',
'jsx',
'objectRestSpread',
'trailingFunctionCommas'
]
};
const ast = recast.parse(fs.readFileSync(filename, "utf8"), {
parser: {
parse: function(source) {
return babylon.parse(source, babylonOptions);
}
}
});
console.log(recast.prettyPrint(ast, { tabWidth, wrapColumn: printWidth }).code);

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"title": "jscodefmt",
"bin": { "jscodefmt": "./bin/jscodefmt" },
"dependencies": {
"babylon": "^6.14.1",
"minimist": "^1.2.0",
"recast": "git+https://github.com/jlongster/recast.git#print-all!"
}
}