-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.ts
60 lines (47 loc) · 1.51 KB
/
update.ts
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
import { flags } from '@oclif/command'
import { Codex } from '../services/codex'
import ui from '../services/ui'
import BaseCommand from '../base/base-command'
import state, { Mode } from '../services/state'
export default class Update extends BaseCommand {
static description = 'update baseline from vdc'
static EXIT_CODE_ON_UPDATES = 2
static flags = {
...BaseCommand.flags,
check: flags.boolean({
char: 'c',
description: 'check if there\'s an update without actually performing the update',
default: false
}),
yes: flags.boolean({
char: 'y',
description: 'answer yes to all questions; useful in CI automation',
default: false
}),
output: flags.string({
char: 'o',
required: true
})
}
async run() {
const codex = new Codex()
await codex.load()
const update = await codex.updateCheck()
if (update === undefined) {
ui.info('no upstream api spec updates found')
process.exit()
}
ui.warning('updates found in upstream api spec')
if (state.mode === Mode.EDIT) {
throw new Error('you are currently in edit mode and cannot update the baseline')
}
codex.createNewUpstreamUpdate(update?.patch, this.flags.output)
ui.info(`upstream update saved to ${this.flags.output}`)
if (this.flags.check) {
process.exit(Update.EXIT_CODE_ON_UPDATES)
}
ui.info('performing baseline update')
await codex.updateBaseline(update?.content)
ui.info('baseline updated successfully')
}
}