|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs') |
| 4 | +const path = require('path') |
| 5 | +const program = require('commander') |
| 6 | +const yaml = require('js-yaml') |
| 7 | +const allVersions = require('../lib/all-versions') |
| 8 | +const releaseCandidateFile = 'data/variables/release_candidate.yml' |
| 9 | +const releaseCandidateYaml = path.join(process.cwd(), releaseCandidateFile) |
| 10 | + |
| 11 | +const allowedActions = ['create', 'remove'] |
| 12 | + |
| 13 | +// [start-readme] |
| 14 | +// |
| 15 | +// This script creates or removes a release candidate banner for a specified version. |
| 16 | +// |
| 17 | +// [end-readme] |
| 18 | + |
| 19 | +program |
| 20 | + .description('Create or remove a release candidate banner for the provided docs version.') |
| 21 | + // The following two settings let us use `version` as a flag without clashing with reserved opts |
| 22 | + .storeOptionsAsProperties(false) |
| 23 | + .passCommandToAction(false) |
| 24 | + .option(`-a, --action <${allowedActions.join(' or ')}>`, 'Create or remove the banner.') |
| 25 | + .option('-v, --version <version>', 'The version the banner applies to. Must be in <plan@release> format.') |
| 26 | + .parse(process.argv) |
| 27 | + |
| 28 | +const options = program.opts() |
| 29 | + |
| 30 | +if (!allowedActions.includes(options.action)) { |
| 31 | + console.log(`Error! You must specify --action <${allowedActions.join(' or ')}>.`) |
| 32 | + process.exit(1) |
| 33 | +} |
| 34 | + |
| 35 | +if (!(Object.keys(allVersions).includes(options.version))) { |
| 36 | + console.log('Error! You must specify --version with the full name of a supported version, e.g., enterprise-server@2.22.') |
| 37 | + process.exit(1) |
| 38 | +} |
| 39 | + |
| 40 | +// Load the release candidate variable |
| 41 | +const releaseCandidateData = yaml.safeLoad(fs.readFileSync(releaseCandidateYaml, 'utf8')) |
| 42 | + |
| 43 | +// Create or remove the variable |
| 44 | +if (options.action === 'create') { |
| 45 | + releaseCandidateData.version = options.version |
| 46 | +} |
| 47 | + |
| 48 | +if (options.action === 'remove') { |
| 49 | + releaseCandidateData.version = '' |
| 50 | +} |
| 51 | + |
| 52 | +// Update the file |
| 53 | +fs.writeFileSync(releaseCandidateYaml, yaml.safeDump(releaseCandidateData)) |
| 54 | + |
| 55 | +// Display next steps |
| 56 | +console.log(`\nDone! Commit the update to ${releaseCandidateFile}. This ${options.action}s the banner for ${options.version}. |
| 57 | +
|
| 58 | +- To change the banner text, you can edit header.notices.release_candidate in data/ui.yml. |
| 59 | +- To change the banner styling, you can edit includes/header-notification.html. |
| 60 | +`) |
0 commit comments