Skip to content

Commit

Permalink
Add a jsbin binary for the npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jul 6, 2012
1 parent c06a477 commit 142f9fb
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions bin/jsbin
Original file line number Diff line number Diff line change
@@ -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>', '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 <config.json>', '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 <development>', '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'));
});

0 comments on commit 142f9fb

Please sign in to comment.