add update-build-index command
See its description.
This commit is contained in:
parent
a4d615c057
commit
e29dbb7aea
2 changed files with 47 additions and 1 deletions
33
src/commands/update-build-index.ts
Normal file
33
src/commands/update-build-index.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { Command } from '@oclif/command'
|
||||||
|
import { readFileSync } from 'fs'
|
||||||
|
import { writeFile } from 'fs/promises'
|
||||||
|
import { YAMLMap } from 'yaml/types'
|
||||||
|
|
||||||
|
import { DEVICE_CONFIG_FLAGS, loadDeviceConfigs } from '../config/device'
|
||||||
|
import { ADEVTOOL_DIR, MAIN_BUILD_INDEX_PART } from '../config/paths'
|
||||||
|
import { fetchBuildIndex } from '../images/build-index'
|
||||||
|
import { showGitDiff } from '../util/cli'
|
||||||
|
import { yamlStringifyNoFold } from '../util/yaml'
|
||||||
|
|
||||||
|
export default class UpdateBuildIndex extends Command {
|
||||||
|
static description = 'fetch main (non-beta) build index and if it has changed, update build-index-main.yml file in-place and show git diff'
|
||||||
|
|
||||||
|
static flags = DEVICE_CONFIG_FLAGS
|
||||||
|
|
||||||
|
async run() {
|
||||||
|
let { flags } = this.parse(UpdateBuildIndex)
|
||||||
|
let devices = await loadDeviceConfigs(flags.devices)
|
||||||
|
|
||||||
|
let index: YAMLMap = await fetchBuildIndex(devices)
|
||||||
|
|
||||||
|
let yaml = yamlStringifyNoFold(index)
|
||||||
|
|
||||||
|
if (readFileSync(MAIN_BUILD_INDEX_PART).toString() === yaml) {
|
||||||
|
this.log('main build index is up-to-date')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
await writeFile(MAIN_BUILD_INDEX_PART, yaml)
|
||||||
|
showGitDiff(ADEVTOOL_DIR, MAIN_BUILD_INDEX_PART)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
import ora from 'ora'
|
import assert from 'assert'
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
import child_proc from 'child_process'
|
||||||
|
import ora from 'ora'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
export type ProgressCallback = (progress: string) => void
|
export type ProgressCallback = (progress: string) => void
|
||||||
|
|
||||||
|
@ -25,3 +28,13 @@ export async function withSpinner<Return>(action: string, callback: (spinner: or
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showGitDiff(repoPath: string, filePath?: string) {
|
||||||
|
let args = ['-C', repoPath, `diff`]
|
||||||
|
if (filePath !== undefined) {
|
||||||
|
args.push(path.relative(repoPath, filePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
let ret = child_proc.spawnSync('git', args, { stdio: 'inherit' })
|
||||||
|
assert(ret.status === 0)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue