diff --git a/bin/jsbin b/bin/jsbin new file mode 100755 index 00000000..308ab704 --- /dev/null +++ b/bin/jsbin @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +var cmd = require('commander'), + path = require('path'), + fs = require('fs'), + app; + +function error(msg) { + console.error('\n error: ' + msg + '\n'); + process.exit(1); +} + +cmd.version(require('../package.json').version); + +cmd.option('-p --port ', 'port to run on', function (port) { + port = parseInt(port, 10); + if (port) { + process.env.PORT = port; + } else { + error('-p port must be numeric'); + } +}); + +cmd.option('-c --config ', 'path to config file', function (file) { + file = path.resolve(process.cwd(), file); + + if ((path.existsSync || fs.existsSync)(file)) { + process.env.JSBIN_CONFIG = file; + } else { + error('-c config must be path to a valid config file'); + } +}); + +cmd.option('-e --env ', 'deployment environment', function (env) { + process.env.ENV = env; +}); + +cmd.parse(process.argv); + +app = require('../lib/app.js'); +app.connect(function (err) { + if (err) { + throw err; + } + + process.stdout.write('JSBin is up and running. Now point your browser at ' + app.set('url full') + '\n'); + app.listen(app.set('url port')); +});