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