-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathnow.js
executable file
·91 lines (74 loc) · 1.73 KB
/
now.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
#!/usr/bin/env node
// Native
const {resolve} = require('path')
// Packages
const nodeVersion = require('node-version')
const updateNotifier = require('update-notifier')
// Ours
const {error} = require('../lib/error')
const pkg = require('../package')
// Support for keywords "async" and "await"
require('async-to-gen/register')({
excludes: null
})
// Throw an error if node version is too low
if (nodeVersion.major < 6) {
error('Now requires at least version 6 of Node. Please upgrade!')
process.exit(1)
}
// Only check for updates in the npm version
if (!process.pkg) {
updateNotifier({pkg}).notify()
}
// This command will be run if no other sub command is specified
const defaultCommand = 'deploy'
const commands = new Set([
defaultCommand,
'help',
'list',
'ls',
'rm',
'remove',
'alias',
'aliases',
'ln',
'domain',
'domains',
'dns',
'cert',
'certs',
'secret',
'secrets'
])
const aliases = new Map([
['ls', 'list'],
['rm', 'remove'],
['ln', 'alias'],
['aliases', 'alias'],
['domain', 'domains'],
['cert', 'certs'],
['secret', 'secrets']
])
let cmd = defaultCommand
const args = process.argv.slice(2)
const index = args.findIndex(a => commands.has(a))
if (index > -1) {
cmd = args[index]
args.splice(index, 1)
if (cmd === 'help') {
if (index < args.length && commands.has(args[index])) {
cmd = args[index]
args.splice(index, 1)
} else {
cmd = defaultCommand
}
args.unshift('--help')
}
cmd = aliases.get(cmd) || cmd
}
const bin = resolve(__dirname, 'now-' + cmd + '.js')
// Prepare process.argv for subcommand
process.argv = process.argv.slice(0, 2).concat(args)
// Load sub command
// With custom parameter to make "pkg" happy
require(bin, 'may-exclude')