diff --git a/bin/now-deploy.js b/bin/now-deploy.js index df30ab7..e5f424c 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -12,6 +12,7 @@ const minimist = require('minimist'); const ms = require('ms'); const flatten = require('arr-flatten'); const dotenv = require('dotenv'); +const { eraseLines } = require('ansi-escapes'); // Ours const copy = require('../lib/copy'); @@ -30,6 +31,10 @@ const { reAlias, assignAlias } = require('../lib/re-alias'); const exit = require('../lib/utils/exit'); const logo = require('../lib/utils/output/logo'); 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), { string: ['config', 'token', 'name', 'alias'], @@ -229,6 +234,8 @@ async function sync(token) { const start = Date.now(); const rawPath = argv._[0]; + const planPromise = new NowPlans(apiUrl, token, { debug }).getCurrent(); + const stopDeployment = msg => { error(msg); process.exit(1); @@ -597,6 +604,35 @@ async function sync(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) { const bar = new Progress('> Upload [:bar] :percent :etas', { width: 20, diff --git a/lib/utils/input/prompt-bool.js b/lib/utils/input/prompt-bool.js index 7f5d5e1..224525a 100644 --- a/lib/utils/input/prompt-bool.js +++ b/lib/utils/input/prompt-bool.js @@ -1,5 +1,7 @@ const chalk = require('chalk'); +const info = require('../output/info'); + module.exports = ( label, { @@ -10,7 +12,7 @@ module.exports = ( noChar = 'n', stdin = process.stdin, stdout = process.stdout, - trailing = '\n' + trailing = '' } = {} ) => { return new Promise((resolve, reject) => { @@ -20,7 +22,7 @@ module.exports = ( stdin.resume(); function restore() { - console.log(trailing); + stdout.write(trailing); stdin.setRawMode(isRaw); stdin.pause(); stdin.removeListener('data', onData); @@ -53,7 +55,7 @@ module.exports = ( : defaultValue ? `[${chalk.bold(yesChar.toUpperCase())}|${noChar}]` : `[${yesChar}|${chalk.bold(noChar.toUpperCase())}]`; - stdout.write(`${chalk.gray('-')} ${label} ${chalk.gray(defaultText)} `); + info(`${label} ${chalk.gray(defaultText)} `); stdin.on('data', onData); }); };