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