Browse Source

Merge branch 'master' of github.com:zeithq/now into add/registration

Conflicts:
	lib/login.js
master
Tony Kovanen 9 years ago
parent
commit
9f5aacded5
  1. 66
      bin/now
  2. 1
      package.json

66
bin/now

@ -2,11 +2,15 @@
import program from 'commander';
import { resolve } from 'path';
import { copy } from 'copy-paste';
import login from '../lib/login';
import now from '../lib';
import fs from 'fs';
import ms from 'ms';
import os from 'os';
program
.option('-d, --debug', 'Debug mode [off]', false)
.option('-L, --login', 'Configure login')
.option('-C, --no-clipboard', 'Do not attempt to copy URL to clipboard')
.parse(process.argv);
@ -20,25 +24,53 @@ if (path) {
path = process.cwd();
}
const debug = !!program.debug;
const clipboard = !program.noClipboard;
const start = Date.now();
let config;
console.log(`> Deploying ${path}`);
try {
config = fs.readFileSync(resolve(os.homedir(), '.now.json'), 'utf8');
config = JSON.parse(config);
} catch (err) {
login()
.then(() => {
if (program.L) {
console.log('> Logged in successfully. Token saved in ~/.now.json');
process.exit(0);
} else {
sync();
}
})
.catch((e) => {
error(`Authentication error – ${e.message}`);
});
}
now(path, { debug }).then((url) => {
const elapsed = ms(new Date() - start);
if (clipboard) {
copy(url, (err) => {
console.log(`> ${url} ${!err ? '(copied to clipboard)' : ''} [${elapsed}]`);
});
} else {
console.log(`> ${url} [${elapsed}]`);
}
}, (err) => {
error(err.message);
process.exit(1);
});
const sync = () => {
const debug = !!program.debug;
const clipboard = !program.noClipboard;
const start = Date.now();
console.log(`> Deploying ${path}`);
now(path, { debug })
.then((url) => {
const elapsed = ms(new Date() - start);
if (clipboard) {
copy(url, (err) => {
console.log(`> ${url} ${!err ? '(copied to clipboard)' : ''} [${elapsed}]`);
});
} else {
console.log(`> ${url} [${elapsed}]`);
}
}, (err) => {
if (403 === err.statusCode) {
error('Authorization error. Run `now -L` to log-in again.');
} else {
error(err.message);
}
process.exit(1);
});
};
function error (err) {
console.error(`> \u001b[31mError!\u001b[39m ${err}.`);

1
package.json

@ -19,6 +19,7 @@
"commander": "2.9.0",
"copy-paste": "1.1.4",
"fs-promise": "0.4.1",
"inquirer": "0.12.0",
"ms": "0.7.1",
"node-fetch": "1.3.3",
"spdy": "3.2.0"

Loading…
Cancel
Save