1
0
mirror of synced 2025-12-17 03:57:28 +08:00

command line interface and updates for npm

This commit is contained in:
Zach Carter
2011-05-01 17:36:27 -04:00
parent ac7b47930b
commit 9c1023cfb1
12 changed files with 486 additions and 357 deletions

33
lib/cli.js Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env node
var sys = require("sys");
var parser = require("./jsonlint").parser;
function parse (source) {
try {
sys.puts(JSON.stringify(parser.parse(source),null," "));
} catch (e) {
sys.puts(e);
process.exit(1);
}
}
function main (args) {
var source = '';
if (args[1]) {
source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
parse(source);
} else {
var stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function (chunk) {
source += chunk.toString('utf8');
});
stdin.on('end', function () {
parse(source);
});
}
}
main(process.argv.slice(1));