UNPKG

bute

Version:

The complete distribution solution for NodeJS

60 lines (51 loc) 1.26 kB
#!/usr/bin/env node 'use strict'; process.title = 'bute'; var nopt = require("nopt"); var fs = require('fs'); var path = require("path"); var colors = require('colors/safe'); colors.setTheme({ dim: 'grey', info: 'cyan', success: 'green', error: 'red', warn: 'yellow', debug: 'grey', help: 'cyan', bold: 'bold' }); var options = { "allow": [String, Array], "deny": [String, Array], "list": [Boolean], "mode": ["development", "production"], "init": path, "start": path } var short = { "a": ["--allow"], "d": ["--deny"], "l": ["--list"], "m": ["--mode"], "i": ["--init"], "s": ["--start"] } var config = { name: "", allow: [], deny: [] }; var parsed = nopt(options, short, process.argv, 2); fs.readFile('./butefile.json', 'utf8', function (err, data) { if (err) { if(err.code === "ENOENT") fs.open('./butefile.json', 'w', function(err, fd) { if(err) console.log(colors.error(err)); fs.writeSync(fd, JSON.stringify(config, null, 4)); }) else console.log(err); config = new Object; }else bute.config = JSON.parse(data); }); console.log(colors.info(parsed)); console.log(colors.debug(config));