JsonRPC/src/index.ts

78 lines
2.0 KiB
TypeScript
Raw Normal View History

#!/usr/bin/env node
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
2022-01-07 08:45:08 +00:00
import startCompile, { Target, Targets } from "./process";
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");
}
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);
});
}
)
.option("verbose", {
alias: "v",
type: "boolean",
describe: "Adds additional outputs",
})
.strictCommands()
.demandCommand()
.parse();