Repair command-line handling
This commit is contained in:
parent
3d1b151462
commit
a98aa357d4
|
@ -12,8 +12,7 @@ import { changeExt, Diagnostic, expandInputGlob, formatFailures } from './cli-ut
|
||||||
export type CommandLineArguments = {
|
export type CommandLineArguments = {
|
||||||
inputs: string[];
|
inputs: string[];
|
||||||
xrefs: string[];
|
xrefs: string[];
|
||||||
base: string | undefined;
|
output: string | undefined;
|
||||||
output: string;
|
|
||||||
stdout: boolean;
|
stdout: boolean;
|
||||||
core: string;
|
core: string;
|
||||||
watch: boolean;
|
watch: boolean;
|
||||||
|
@ -116,7 +115,7 @@ export function runOnce(options: CommandLineArguments): CompilationResult {
|
||||||
|
|
||||||
const inputFiles: Array<TranslatedFile> = inputFiles0.map(i => {
|
const inputFiles: Array<TranslatedFile> = inputFiles0.map(i => {
|
||||||
const { inputBaseDir, inputFilePath, baseRelPath, modulePath, schema } = 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 };
|
return { inputBaseDir, inputFilePath, outputFilePath, schemaPath: modulePath, schema };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,14 +173,13 @@ export function main(argv: Array<string>) {
|
||||||
new Command()
|
new Command()
|
||||||
.arguments('[input...]')
|
.arguments('[input...]')
|
||||||
.description('Compile Preserves schema definitions to TypeScript', {
|
.description('Compile Preserves schema definitions to TypeScript', {
|
||||||
input: 'Input filename or glob',
|
input: 'Input directory, optionally with :<glob> on the end',
|
||||||
})
|
})
|
||||||
.option('--xref <glob>', 'Cross-reference other textual Preserves schema definitions',
|
.option('--xref <glob>', 'Cross-reference other textual Preserves schema definitions',
|
||||||
(glob, prev: string[]) => [... prev, glob], [])
|
(glob, prev: string[]) => [... prev, glob], [])
|
||||||
.option('--output <directory>', 'Output directory for modules (default: next to sources)')
|
.option('--output <directory>', 'Output directory for modules')
|
||||||
.option('--stdout', 'Prints each module to stdout one after the other instead ' +
|
.option('--stdout', 'Prints each module to stdout one after the other instead ' +
|
||||||
'of writing them to files in the `--output` directory')
|
'of writing them to files in the `--output` directory')
|
||||||
.option('--base <directory>', 'Base directory for sources (default: common prefix)')
|
|
||||||
.option('--core <path>', 'Import path for @preserves/core', '@preserves/core')
|
.option('--core <path>', 'Import path for @preserves/core', '@preserves/core')
|
||||||
.option('--watch', 'Watch base directory for changes')
|
.option('--watch', 'Watch base directory for changes')
|
||||||
.option('--traceback', 'Include stack traces in compiler errors')
|
.option('--traceback', 'Include stack traces in compiler errors')
|
||||||
|
@ -189,10 +187,14 @@ export function main(argv: Array<string>) {
|
||||||
(nsPath: string, previous: string[]): string[] => [... previous, nsPath],
|
(nsPath: string, previous: string[]): string[] => [... previous, nsPath],
|
||||||
[])
|
[])
|
||||||
.action((inputs: string[], rawOptions) => {
|
.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 = {
|
const options: CommandLineArguments = {
|
||||||
inputs: inputs.map(i => path.normalize(i)),
|
inputs: inputs.map(i => path.normalize(i)),
|
||||||
xrefs: rawOptions.xref.map((x: string) => path.normalize(x)),
|
xrefs: rawOptions.xref.map((x: string) => path.normalize(x)),
|
||||||
base: rawOptions.base,
|
|
||||||
output: rawOptions.output,
|
output: rawOptions.output,
|
||||||
stdout: rawOptions.stdout,
|
stdout: rawOptions.stdout,
|
||||||
core: rawOptions.core,
|
core: rawOptions.core,
|
||||||
|
|
Loading…
Reference in New Issue