forked from alexanderGugel/ied
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.js
executable file
·100 lines (92 loc) · 2.11 KB
/
cmd.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
var fs = require('fs')
var path = require('path')
var minimist = require('minimist')
var config = require('../lib/config')
var installCmd = require('../lib/install_cmd')
var runCmd = require('../lib/run_cmd')
var shellCmd = require('../lib/shell_cmd')
var pingCmd = require('../lib/ping_cmd')
var lsCmd = require('../lib/ls_cmd')
var exposeCmd = require('../lib/expose_cmd')
var configCmd = require('../lib/config_cmd')
var initCmd = require('../lib/init_cmd')
var linkCmd = require('../lib/link_cmd')
var unlinkCmd = require('../lib/unlink_cmd')
function helpCmd () {
fs.ReadStream(path.join(__dirname, 'USAGE.txt')).pipe(process.stdout)
}
function versionCmd () {
console.log('ied version', require('../package.json').version)
}
var cwd = process.cwd()
var argv = minimist(process.argv.slice(2), {
alias: {
h: 'help',
v: 'version',
S: 'save',
D: 'save-dev',
o: 'only',
r: 'registry'
}
})
if (argv.registry) {
config.registry = argv.registry
}
// This doesn't have to be an IIFE, since Node wraps everything in a function
// anyways, but standard doesn't like return statements here.
(function () {
if (argv.help) {
return helpCmd()
}
if (argv.version) {
return versionCmd()
}
switch (argv._[0]) {
case 'i':
case 'install':
installCmd(cwd, argv)
break
case 'sh':
case 'shell':
shellCmd(cwd)
break
case 'r':
case 'run':
case 'run-script':
runCmd(cwd, argv)
break
case 't':
case 'test':
// The test command is simple a run command that executes the test script.
var _argv = Object.create(argv)
_argv._ = ['run'].concat(argv._)
runCmd(cwd, _argv)
break
case 'ls':
lsCmd(cwd)
break
case 'ping':
pingCmd()
break
case 'conf':
case 'config':
configCmd()
break
case 'expose':
case 'ex':
exposeCmd(cwd, argv)
break
case 'init':
initCmd(cwd, argv)
break
case 'link':
linkCmd(cwd, argv)
break
case 'unlink':
unlinkCmd(cwd, argv)
break
default:
helpCmd()
}
}())