1 const {resolve, relative, join} = require('path')
2 const {spawnSync} = require('child_process')
3 const build = require('../lib/build.js')
4 const {nwo} = require('../lib/gh')
5
6 // check only build with the current versions instead of checking the registry
7 // and also fails if any changes are detected. this is used in CI to make sure
8 // edits to the CLI content are made in the CLI repo
9 const checkOnly = process.argv.includes('--check-only')
10
11 const ROOT = resolve(__dirname, '../..')
12 const contentPath = join(ROOT, 'content/cli')
13 const navPath = join(ROOT, 'content/nav.yml')
14
15 const checkContent = () => {
16 const status = spawnSync('git', ['status', '--porcelain', contentPath], {encoding: 'utf-8'})
17 if (status.stdout) {
18 const msg = [
19 `The following untracked changes to ${relative(process.cwd(), contentPath)} were found:`,
20 status.stdout,
21 `These files are generated and changes might need to be made in the ${nwo} repository.`,
22 ]
23 throw new Error(msg.join('\n'))
24 }
25 }
26
27 build({
28 releases: require('../releases.json'),
29 loglevel: process.argv.includes('--debug') || process.env.CI ? 'verbose' : 'info',
30 prerelease: false,
31 useCurrent: checkOnly,
32 contentPath,
33 navPath,
34 })
35 .then(() => {
36 if (checkOnly) {
37 checkContent()
38 }
39 return console.log('DONE')
40 })
41 .catch(e => {
42 console.error(e)
43 process.exit(1)
44 })