mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
Add a jsbin binary for the npm package
This commit is contained in:
parent
c06a477052
commit
142f9fb82b
48
bin/jsbin
Executable file
48
bin/jsbin
Executable file
@ -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'));
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user