#!/usr/bin/env node
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
|
|
var docopt = require('docopt');
|
|
var jsnice = require('../');
|
|
|
|
var doc = [
|
|
'Usage:',
|
|
' jsnice <file>',
|
|
' jsnice [--no-pretty] [--no-rename] [--no-types] <file>',
|
|
' jsnice (--help | --version)',
|
|
'',
|
|
'Options:',
|
|
' --help Show this text',
|
|
' --version Show jsnice version info',
|
|
' --no-pretty Dont prettify the script',
|
|
' --no-rename Dont rename variables',
|
|
' --no-types Dont add doc strings for params/returns',
|
|
].join('\r\n');
|
|
|
|
var args = docopt.docopt(doc, {
|
|
help: true,
|
|
version: 'jsnice ' + require('../package.json').version,
|
|
});
|
|
|
|
// Resolve file path
|
|
var filePath = args['<file>'];
|
|
var js = fs.readFileSync(filePath);
|
|
var options = {
|
|
pretty: !args['--no-pretty'],
|
|
types: !args['--no-types'],
|
|
rename: !args['--no-rename'],
|
|
};
|
|
jsnice.nicify(js, options, function(err, data) {
|
|
if (err) {
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
console.log(data.js);
|
|
});
|