forked from coreh-deprecated/nide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·53 lines (46 loc) · 1.48 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
var program = require('commander');
var server = require('./server/server');
var project = require('./server/project');
var exec = require('child_process').exec
var fs = require('fs')
var packageJSON = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf-8'))
var checkForDependencies = function(callback) {
exec('which npm', function(err, stdout, stderr) {
if (err) {
console.error('Could not find `npm` command. Is npm installed?')
process.exit(-1)
} else {
callback()
}
})
}
program
.version(packageJSON.version)
.option('-p, --port <number>', 'use a custom http port')
program
.command('init [directory]')
.description('Initialize a new project and listen for connections.')
.action(function(dir){checkForDependencies(function(){
project.chdir(dir)
project.init()
project.start()
server.listen(program.port || process.env.PORT || 8123)
})})
program
.command('listen [directory]')
.description('Listen for connections.')
.action(function(dir){checkForDependencies(function(){
project.chdir(dir)
project.start()
server.listen(program.port || process.env.PORT || 8123)
})})
if (process.argv.length > 2) {
if (process.argv[2].charAt(0) == '-') {
process.argv.splice(2, 0, 'listen')
}
program.parse(process.argv);
} else {
process.argv.push('listen');
program.parse(process.argv);
}