|
|
@ -1,27 +1,34 @@ |
|
|
|
#!/usr/bin/env node |
|
|
|
import program from 'commander'; |
|
|
|
import Progress from 'progress'; |
|
|
|
import copy from '../lib/copy'; |
|
|
|
import * as cfg from '../lib/cfg'; |
|
|
|
import { resolve } from 'path'; |
|
|
|
import login from '../lib/login'; |
|
|
|
import * as cfg from '../lib/cfg'; |
|
|
|
import { version } from '../../package'; |
|
|
|
import checkUpdate from '../lib/check-update'; |
|
|
|
import bytes from 'bytes'; |
|
|
|
import chalk from 'chalk'; |
|
|
|
import minimist from 'minimist'; |
|
|
|
import Now from '../lib'; |
|
|
|
import ms from 'ms'; |
|
|
|
|
|
|
|
program |
|
|
|
.usage('[options]') |
|
|
|
.version(require('../../package').version) |
|
|
|
.option('-d, --debug', 'Debug mode [off]', false) |
|
|
|
.option('-f, --force', 'Force a new deployment even if nothing has changed', false) |
|
|
|
.option('-F, --forceSync', 'Force a new deployment even if nothing has changed and force syncing of all files', false) |
|
|
|
.option('-L, --login', 'Configure login') |
|
|
|
.option('-C, --no-clipboard', 'Do not attempt to copy URL to clipboard') |
|
|
|
.parse(process.argv); |
|
|
|
const argv = minimist(process.argv.slice(2)); |
|
|
|
const help = () => { |
|
|
|
console.log(` |
|
|
|
𝚫 now [options] <path> |
|
|
|
|
|
|
|
Options: |
|
|
|
|
|
|
|
let path = program.args[program.args.length - 1]; |
|
|
|
-h, --help output usage information |
|
|
|
-v, --version output the version number |
|
|
|
-d, --debug Debug mode [off] |
|
|
|
-f, --force Force a new deployment even if nothing has changed |
|
|
|
-L, --login Configure login |
|
|
|
-C, --no-clipboard Do not attempt to copy URL to clipboard |
|
|
|
`); |
|
|
|
}; |
|
|
|
|
|
|
|
let path = argv._[0]; |
|
|
|
|
|
|
|
if (path) { |
|
|
|
if ('/' !== path[0]) { |
|
|
@ -31,8 +38,14 @@ if (path) { |
|
|
|
path = process.cwd(); |
|
|
|
} |
|
|
|
|
|
|
|
const debug = !!program.debug; |
|
|
|
const clipboard = !program.noClipboard; |
|
|
|
// options |
|
|
|
const debug = argv.debug || argv.d; |
|
|
|
const clipboard = !(argv.noClipboard || argv.C); |
|
|
|
const force = argv.f || argv.force; |
|
|
|
const forceSync = argv.F || argv.forceSync; |
|
|
|
const shouldLogin = argv.L || argv.login; |
|
|
|
|
|
|
|
// auto-update checking |
|
|
|
const config = cfg.read(); |
|
|
|
const update = checkUpdate({ debug }); |
|
|
|
const exit = (code) => { |
|
|
@ -42,10 +55,16 @@ const exit = (code) => { |
|
|
|
setTimeout(() => process.exit(code), 1000); |
|
|
|
}; |
|
|
|
|
|
|
|
if (!config.token || program.login) { |
|
|
|
if (argv.h || argv.help) { |
|
|
|
help(); |
|
|
|
exit(0); |
|
|
|
} else if (argv.v || argv.version) { |
|
|
|
console.log(chalk.bold('𝚫 now'), version); |
|
|
|
exit(0); |
|
|
|
} else if (!config.token || shouldLogin) { |
|
|
|
login() |
|
|
|
.then((token) => { |
|
|
|
if (program.login) { |
|
|
|
if (shouldLogin) { |
|
|
|
console.log('> Logged in successfully. Token saved in ~/.now.json'); |
|
|
|
exit(0); |
|
|
|
} else { |
|
|
@ -74,7 +93,7 @@ async function sync (token) { |
|
|
|
const now = new Now(token, { debug }); |
|
|
|
|
|
|
|
try { |
|
|
|
await now.create(path, { forceNew: program.force, forceSync: program.forceSync }); |
|
|
|
await now.create(path, { forceNew: force, forceSync: forceSync }); |
|
|
|
} catch (err) { |
|
|
|
handleError(err); |
|
|
|
return; |
|
|
|