You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.1 KiB
109 lines
2.1 KiB
#!/bin/bash
|
|
// >&/dev/null; exec node $(node -p "process.version[1] >= 7 ? '--harmony-async-await' : '--lazy'") $0 $@
|
|
|
|
// Native
|
|
const {resolve} = require('path')
|
|
|
|
// Packages
|
|
const minimist = require('minimist')
|
|
const {spawn} = require('cross-spawn')
|
|
const nodeVersion = require('node-version')
|
|
const isAsyncSupported = require('is-async-supported')
|
|
|
|
if (!isAsyncSupported()) {
|
|
require('async-to-gen/register')
|
|
}
|
|
|
|
// Ours
|
|
const checkUpdate = require('../lib/check-update')
|
|
const {error} = require('../lib/error')
|
|
|
|
|
|
if (nodeVersion.major < 6) {
|
|
error('Now requires at least version 6 of Node. Please upgrade!')
|
|
process.exit(1)
|
|
}
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
|
|
|
// options
|
|
const debug = argv.debug || argv.d
|
|
|
|
// Disable updates by default
|
|
let update = false
|
|
|
|
// auto-update checking
|
|
// only for the npm version, not the enclosed one
|
|
if (!process.pkg) {
|
|
update = checkUpdate({debug})
|
|
}
|
|
|
|
const exit = code => {
|
|
if (update) {
|
|
update.then(() => process.exit(code))
|
|
}
|
|
// don't wait for updates more than a second
|
|
// when the process really wants to exit
|
|
setTimeout(() => process.exit(code), 1000)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
let bin = resolve(__dirname, 'now-' + cmd)
|
|
|
|
// Prepare process.argv for subcommand
|
|
process.argv = process.argv.slice(0, 2).concat(args);
|
|
require(bin)
|
|
|
|
// vi:syntax=javascript
|
|
|