Browse Source

Prompt the user before uploading OSS code (#435)

* Make `promptBool` print nothing as trailing by default

* Prompt OSS users before uploading the code

* Fetch the plan as soon as possible

* Use `info` on `prompt-bool`

* Fix trailing print on `prompt-bool`

* Better wording for the message

* Erease the prompt after receivng an answer
master
Matheus Fernandes 8 years ago
committed by GitHub
parent
commit
9717d06a55
  1. 36
      bin/now-deploy.js
  2. 8
      lib/utils/input/prompt-bool.js

36
bin/now-deploy.js

@ -12,6 +12,7 @@ const minimist = require('minimist');
const ms = require('ms'); const ms = require('ms');
const flatten = require('arr-flatten'); const flatten = require('arr-flatten');
const dotenv = require('dotenv'); const dotenv = require('dotenv');
const { eraseLines } = require('ansi-escapes');
// Ours // Ours
const copy = require('../lib/copy'); const copy = require('../lib/copy');
@ -30,6 +31,10 @@ const { reAlias, assignAlias } = require('../lib/re-alias');
const exit = require('../lib/utils/exit'); const exit = require('../lib/utils/exit');
const logo = require('../lib/utils/output/logo'); const logo = require('../lib/utils/output/logo');
const cmd = require('../lib/utils/output/cmd'); const cmd = require('../lib/utils/output/cmd');
const info = require('../lib/utils/output/info');
const wait = require('../lib/utils/output/wait');
const NowPlans = require('../lib/plans');
const promptBool = require('../lib/utils/input/prompt-bool');
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token', 'name', 'alias'], string: ['config', 'token', 'name', 'alias'],
@ -229,6 +234,8 @@ async function sync(token) {
const start = Date.now(); const start = Date.now();
const rawPath = argv._[0]; const rawPath = argv._[0];
const planPromise = new NowPlans(apiUrl, token, { debug }).getCurrent();
const stopDeployment = msg => { const stopDeployment = msg => {
error(msg); error(msg);
process.exit(1); process.exit(1);
@ -597,6 +604,35 @@ async function sync(token) {
printLogs(now.host, token); printLogs(now.host, token);
}; };
const plan = await planPromise;
if (plan.id === 'oss') {
info(
`You are on the OSS plan. Your code will be made ${chalk.bold('public')}.`
);
let proceed;
try {
const label = 'Are you sure you want to proceed with the deployment?';
proceed = await promptBool(label, { trailing: eraseLines(2) });
} catch (err) {
if (err.message === 'USER_ABORT') {
proceed = false;
} else {
throw err;
}
}
if (!proceed) {
const stopSpinner = wait('Canceling deployment');
now.remove(now.id, { hard: true });
stopSpinner();
info('Deployment aborted. No files were synced.');
info(`You can upgrade by running ${cmd('now upgrade')}.`);
return exit();
}
}
if (now.syncAmount) { if (now.syncAmount) {
const bar = new Progress('> Upload [:bar] :percent :etas', { const bar = new Progress('> Upload [:bar] :percent :etas', {
width: 20, width: 20,

8
lib/utils/input/prompt-bool.js

@ -1,5 +1,7 @@
const chalk = require('chalk'); const chalk = require('chalk');
const info = require('../output/info');
module.exports = ( module.exports = (
label, label,
{ {
@ -10,7 +12,7 @@ module.exports = (
noChar = 'n', noChar = 'n',
stdin = process.stdin, stdin = process.stdin,
stdout = process.stdout, stdout = process.stdout,
trailing = '\n' trailing = ''
} = {} } = {}
) => { ) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -20,7 +22,7 @@ module.exports = (
stdin.resume(); stdin.resume();
function restore() { function restore() {
console.log(trailing); stdout.write(trailing);
stdin.setRawMode(isRaw); stdin.setRawMode(isRaw);
stdin.pause(); stdin.pause();
stdin.removeListener('data', onData); stdin.removeListener('data', onData);
@ -53,7 +55,7 @@ module.exports = (
: defaultValue : defaultValue
? `[${chalk.bold(yesChar.toUpperCase())}|${noChar}]` ? `[${chalk.bold(yesChar.toUpperCase())}|${noChar}]`
: `[${yesChar}|${chalk.bold(noChar.toUpperCase())}]`; : `[${yesChar}|${chalk.bold(noChar.toUpperCase())}]`;
stdout.write(`${chalk.gray('-')} ${label} ${chalk.gray(defaultText)} `); info(`${label} ${chalk.gray(defaultText)} `);
stdin.on('data', onData); stdin.on('data', onData);
}); });
}; };

Loading…
Cancel
Save