|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const yargs = require('yargs'); |
| 4 | + |
| 5 | +const CLI = require('../../lib/cli'); |
| 6 | +const ReleasePreparation = require('../../lib/prepare_release'); |
| 7 | +const { runPromise } = require('../../lib/run'); |
| 8 | + |
| 9 | +const PREPARE = 'prepare'; |
| 10 | +const PROMOTE = 'promote'; |
| 11 | + |
| 12 | +const releaseOptions = { |
| 13 | + prepare: { |
| 14 | + describe: 'Prepare a new release of Node.js', |
| 15 | + type: 'boolean' |
| 16 | + }, |
| 17 | + promote: { |
| 18 | + describe: 'Promote new release of Node.js', |
| 19 | + type: 'boolean' |
| 20 | + }, |
| 21 | + security: { |
| 22 | + describe: 'Demarcate the new security release as a security release', |
| 23 | + type: 'boolean' |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +function builder(yargs) { |
| 28 | + return yargs |
| 29 | + .options(releaseOptions).positional('newVersion', { |
| 30 | + describe: 'Version number of the release to be prepared or promoted' |
| 31 | + }) |
| 32 | + .example('git node release --prepare 1.2.3', |
| 33 | + 'Prepare a new release of Node.js tagged v1.2.3'); |
| 34 | +} |
| 35 | + |
| 36 | +function handler(argv) { |
| 37 | + if (argv.prepare) { |
| 38 | + return release(PREPARE, argv); |
| 39 | + } else if (argv.promote) { |
| 40 | + return release(PROMOTE, argv); |
| 41 | + } |
| 42 | + |
| 43 | + // If more than one action is provided or no valid action |
| 44 | + // is provided, show help. |
| 45 | + yargs.showHelp(); |
| 46 | +} |
| 47 | + |
| 48 | +function release(state, argv) { |
| 49 | + const logStream = process.stdout.isTTY ? process.stdout : process.stderr; |
| 50 | + const cli = new CLI(logStream); |
| 51 | + const dir = process.cwd(); |
| 52 | + |
| 53 | + return runPromise(main(state, argv, cli, dir)).catch((err) => { |
| 54 | + if (cli.spinner.enabled) { |
| 55 | + cli.spinner.fail(); |
| 56 | + } |
| 57 | + throw err; |
| 58 | + }); |
| 59 | +} |
| 60 | + |
| 61 | +module.exports = { |
| 62 | + command: 'release [newVersion|options]', |
| 63 | + describe: |
| 64 | + 'Manage an in-progress release or start a new one.', |
| 65 | + builder, |
| 66 | + handler |
| 67 | +}; |
| 68 | + |
| 69 | +async function main(state, argv, cli, dir) { |
| 70 | + if (state === PREPARE) { |
| 71 | + const prep = new ReleasePreparation(argv, cli, dir); |
| 72 | + |
| 73 | + if (prep.warnForWrongBranch()) return; |
| 74 | + |
| 75 | + // If the new version was automatically calculated, confirm it. |
| 76 | + if (!argv.newVersion) { |
| 77 | + const create = await cli.prompt( |
| 78 | + `Create release with new version ${prep.newVersion}?`, |
| 79 | + { defaultAnswer: true }); |
| 80 | + |
| 81 | + if (!create) { |
| 82 | + cli.error('Aborting release preparation process'); |
| 83 | + return; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return prep.prepare(); |
| 88 | + } else if (state === PROMOTE) { |
| 89 | + // TODO(codebytere): implement release promotion. |
| 90 | + } |
| 91 | +} |
0 commit comments