forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-banner.js
executable file
·62 lines (49 loc) · 1.93 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
61
62
#!/usr/bin/env node
// [start-readme]
//
// This script creates or removes a release candidate banner for a specified version.
//
// [end-readme]
import fs from 'fs/promises'
import path from 'path'
import program from 'commander'
import yaml from 'js-yaml'
import { allVersions } from '../../lib/all-versions.js'
const releaseCandidateFile = 'data/variables/release_candidate.yml'
const releaseCandidateYaml = path.join(process.cwd(), releaseCandidateFile)
const allowedActions = ['create', 'remove']
program
.description('Create or remove a release candidate banner for the provided docs version.')
.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.load(await fs.readFile(releaseCandidateYaml, 'utf8'))
// Create or remove the variable
if (options.action === 'create') {
releaseCandidateData.version = options.version
}
if (options.action === 'remove') {
releaseCandidateData.version = ''
}
// Update the file
await fs.writeFile(releaseCandidateYaml, yaml.dump(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.
`)