Support writing to stdout
This commit is contained in:
parent
bacf310648
commit
306c7c2cae
|
@ -13,6 +13,7 @@ export type CommandLineArguments = {
|
||||||
input: string;
|
input: string;
|
||||||
base: string | undefined;
|
base: string | undefined;
|
||||||
output: string | undefined;
|
output: string | undefined;
|
||||||
|
stdout: boolean;
|
||||||
core: string;
|
core: string;
|
||||||
watch: boolean;
|
watch: boolean;
|
||||||
traceback: boolean;
|
traceback: boolean;
|
||||||
|
@ -167,15 +168,26 @@ export function runOnce(options: CommandLineArguments): CompilationResult {
|
||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
fs.mkdirSync(path.dirname(c.outputFilePath), { recursive: true });
|
fs.mkdirSync(path.dirname(c.outputFilePath), { recursive: true });
|
||||||
|
let compiledModule;
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(c.outputFilePath, compile(env, c.schema, {
|
compiledModule = compile(env, c.schema, {
|
||||||
preservesModule: options.core,
|
preservesModule: options.core,
|
||||||
warn: (message: string, pos: Position | null) =>
|
warn: (message: string, pos: Position | null) =>
|
||||||
failures.push({ type: 'warn', file: c.inputFilePath, detail: { message, pos } }),
|
failures.push({ type: 'warn', file: c.inputFilePath, detail: { message, pos } }),
|
||||||
}), 'utf-8');
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
failures.push({ type: 'error', file: c.inputFilePath, detail: e });
|
failures.push({ type: 'error', file: c.inputFilePath, detail: e });
|
||||||
}
|
}
|
||||||
|
if (compiledModule !== void 0) {
|
||||||
|
if (options.stdout) {
|
||||||
|
console.log('////------------------------------------------------------------');
|
||||||
|
console.log('//// ' + c.outputFilePath);
|
||||||
|
console.log();
|
||||||
|
console.log(compiledModule);
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(c.outputFilePath, compiledModule, 'utf-8');
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const d of failures) {
|
for (const d of failures) {
|
||||||
|
@ -208,7 +220,13 @@ export function main(argv: Array<string>) {
|
||||||
})
|
})
|
||||||
.option('output', {
|
.option('output', {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Output directory for sources (default: next to sources)',
|
description: 'Output directory for modules (default: next to sources)',
|
||||||
|
})
|
||||||
|
.option('stdout', {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Prints each module to stdout one after the other instead ' +
|
||||||
|
'of writing them to files in the `--output` directory',
|
||||||
|
default: false,
|
||||||
})
|
})
|
||||||
.option('base', {
|
.option('base', {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
|
Loading…
Reference in New Issue