From a98aa357d4275e236fc45841544cd09f82dddc6b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 22 Jan 2022 23:20:35 +0100 Subject: [PATCH] Repair command-line handling --- .../schema/src/bin/preserves-schema-ts.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/implementations/javascript/packages/schema/src/bin/preserves-schema-ts.ts b/implementations/javascript/packages/schema/src/bin/preserves-schema-ts.ts index 8289e83..26c2c65 100644 --- a/implementations/javascript/packages/schema/src/bin/preserves-schema-ts.ts +++ b/implementations/javascript/packages/schema/src/bin/preserves-schema-ts.ts @@ -12,8 +12,7 @@ import { changeExt, Diagnostic, expandInputGlob, formatFailures } from './cli-ut export type CommandLineArguments = { inputs: string[]; xrefs: string[]; - base: string | undefined; - output: string; + output: string | undefined; stdout: boolean; core: string; watch: boolean; @@ -116,7 +115,7 @@ export function runOnce(options: CommandLineArguments): CompilationResult { const inputFiles: Array = inputFiles0.map(i => { const { inputBaseDir, inputFilePath, baseRelPath, modulePath, schema } = i; - const outputFilePath = path.join(options.output, changeExt(baseRelPath, '.ts')); + const outputFilePath = path.join(options.output ?? '.', changeExt(baseRelPath, '.ts')); return { inputBaseDir, inputFilePath, outputFilePath, schemaPath: modulePath, schema }; }); @@ -174,14 +173,13 @@ export function main(argv: Array) { new Command() .arguments('[input...]') .description('Compile Preserves schema definitions to TypeScript', { - input: 'Input filename or glob', + input: 'Input directory, optionally with : on the end', }) .option('--xref ', 'Cross-reference other textual Preserves schema definitions', (glob, prev: string[]) => [... prev, glob], []) - .option('--output ', 'Output directory for modules (default: next to sources)') + .option('--output ', 'Output directory for modules') .option('--stdout', 'Prints each module to stdout one after the other instead ' + 'of writing them to files in the `--output` directory') - .option('--base ', 'Base directory for sources (default: common prefix)') .option('--core ', 'Import path for @preserves/core', '@preserves/core') .option('--watch', 'Watch base directory for changes') .option('--traceback', 'Include stack traces in compiler errors') @@ -189,10 +187,14 @@ export function main(argv: Array) { (nsPath: string, previous: string[]): string[] => [... previous, nsPath], []) .action((inputs: string[], rawOptions) => { + if ((rawOptions.output === void 0 && !rawOptions.stdout) || + (rawOptions.output !== void 0 && rawOptions.stdout)) + { + throw new Error("Either --output or --stdout (but not both) must be supplied."); + } const options: CommandLineArguments = { inputs: inputs.map(i => path.normalize(i)), xrefs: rawOptions.xref.map((x: string) => path.normalize(x)), - base: rawOptions.base, output: rawOptions.output, stdout: rawOptions.stdout, core: rawOptions.core,