generator/cmd/combine-batches.ts (34 lines of code) (raw):

// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import path from 'path'; import { SchemaConfiguration, saveAutoGeneratedSchemaRefs } from '../generate'; import { executeSynchronous, readJsonFile, } from '../utils'; import yargs from 'yargs'; import { flatten, uniq } from 'lodash'; import { cp } from 'fs/promises'; import { schemasBasePath } from '../constants'; const argsConfig = yargs .strict() .option('input-path', { type: 'string', desc: 'The path to find batch results' }) .option('batch-count', { type: 'number', desc: 'The total number of batches' }); executeSynchronous(async () => { const args = await argsConfig.parseAsync(); const inputPath = args['input-path']; const batchCount = args['batch-count']; if (!inputPath || !batchCount) { throw 'Bad input'; } let schemaConfigs: SchemaConfiguration[] = []; for (let i = 0; i < batchCount; i++) { const schemasPath = path.join(inputPath, `batch-${i}-schemas`); const batchSchemaConfigs: SchemaConfiguration[] = await readJsonFile(`${schemasPath}/schemaconfig.json`); const relativePaths = uniq(batchSchemaConfigs.map(x => x.relativePath)); for (const relativePath of relativePaths) { const source = path.join(schemasPath, relativePath); const dest = path.join(schemasBasePath, relativePath); console.log(`copying ${source} to ${dest}`); await cp(source, dest, { force: true }); } console.log(`schema config for batch ${i}: ${JSON.stringify(batchSchemaConfigs, null, 2)}`); schemaConfigs = [...schemaConfigs, ...batchSchemaConfigs]; } await saveAutoGeneratedSchemaRefs(flatten(schemaConfigs), true); });