diff --git a/src/commands/fetch-build-index.ts b/src/commands/fetch-build-index.ts new file mode 100644 index 0000000..887a6e3 --- /dev/null +++ b/src/commands/fetch-build-index.ts @@ -0,0 +1,33 @@ +import { Command, flags } from '@oclif/command' +import { YAMLMap } from 'yaml/types' + +import { DEVICE_CONFIG_FLAGS, loadDeviceConfigs } from '../config/device' +import { fetchBetaBuildIndex, fetchBuildIndex } from '../images/build-index' +import { yamlStringifyNoFold } from '../util/yaml' + +export default class FetchBuildIndex extends Command { + description = 'fetch main or beta build index and print it out as YAML' + + static flags = { + ...DEVICE_CONFIG_FLAGS, + beta: flags.string({ + char: 'b', + description: 'Fetch index of beta builds for the specified major OS version (e.g. -b 14)', + }), + } + + async run() { + let { flags } = this.parse(FetchBuildIndex) + let devices = await loadDeviceConfigs(flags.devices) + + let index: YAMLMap + if (flags.beta === undefined) { + index = await fetchBuildIndex(devices) + } else { + index = await fetchBetaBuildIndex(devices, flags.beta) + } + + let yaml = yamlStringifyNoFold(index) + this.log(yaml) + } +} diff --git a/src/util/yaml.ts b/src/util/yaml.ts new file mode 100644 index 0000000..fce2012 --- /dev/null +++ b/src/util/yaml.ts @@ -0,0 +1,11 @@ +import YAML, { Options } from 'yaml' + +export function yamlStringifyNoFold(value: any, options?: Options) { + let orig = YAML.scalarOptions.str.fold.lineWidth + YAML.scalarOptions.str.fold.lineWidth = 0 + try { + return YAML.stringify(value, options) + } finally { + YAML.scalarOptions.str.fold.lineWidth = orig + } +}