2022-01-01 01:08:05 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2021-12-31 21:38:26 +00:00
|
|
|
import yargs from "yargs";
|
|
|
|
import { hideBin } from "yargs/helpers";
|
2022-01-07 08:45:08 +00:00
|
|
|
import startCompile, { Target, Targets } from "./process";
|
2021-12-31 21:38:26 +00:00
|
|
|
|
|
|
|
import dbg from "debug";
|
|
|
|
const log = dbg("app");
|
|
|
|
|
|
|
|
dbg.disable();
|
|
|
|
|
|
|
|
yargs(hideBin(process.argv))
|
|
|
|
.version("1.0.0")
|
|
|
|
.command(
|
|
|
|
"compile <input>",
|
|
|
|
"Compile source",
|
|
|
|
(yargs) => {
|
|
|
|
return yargs
|
|
|
|
.positional("input", {
|
|
|
|
describe: "Input file",
|
|
|
|
type: "string",
|
|
|
|
demandOption: true,
|
|
|
|
})
|
|
|
|
.option("definition", {
|
|
|
|
type: "string",
|
|
|
|
describe: "Emit definition json at specified location",
|
|
|
|
})
|
|
|
|
.option("output", {
|
|
|
|
type: "string",
|
|
|
|
describe: "Output lang and location 'ts:out/' 'c:/test'",
|
|
|
|
alias: "o",
|
|
|
|
coerce: (arg: string | string[] | undefined) => {
|
|
|
|
if (!arg) return [];
|
|
|
|
if (!Array.isArray(arg)) arg = [arg];
|
|
|
|
return arg.map((input) => {
|
|
|
|
const [type, output] = input.split(":", 2);
|
|
|
|
return {
|
|
|
|
type,
|
|
|
|
output,
|
|
|
|
} as Target;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
array: true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
(argv) => {
|
2022-07-16 21:03:27 +00:00
|
|
|
if (argv.verbose) {
|
|
|
|
dbg.enable("app");
|
|
|
|
}
|
2021-12-31 21:38:26 +00:00
|
|
|
log("Received compile command with args", argv);
|
|
|
|
|
|
|
|
startCompile({
|
|
|
|
input: argv.input,
|
|
|
|
targets: argv.output as any,
|
2022-07-16 21:03:27 +00:00
|
|
|
emitDefinitions: argv.definition,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.command(
|
|
|
|
"targets",
|
|
|
|
"List all targets",
|
|
|
|
(yargs) => yargs,
|
|
|
|
() => {
|
|
|
|
console.log("Targets:");
|
|
|
|
Targets.forEach((__dirname, target) => {
|
|
|
|
console.log(" " + target);
|
|
|
|
});
|
2021-12-31 21:38:26 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.option("verbose", {
|
|
|
|
alias: "v",
|
|
|
|
type: "boolean",
|
|
|
|
describe: "Adds additional outputs",
|
|
|
|
})
|
|
|
|
.strictCommands()
|
|
|
|
.demandCommand()
|
|
|
|
.parse();
|