diff --git a/ts2panda/package.json b/ts2panda/package.json index 4d2d5abd58136b94ed80b3cb96ef613a0f689281..beb9979c7db1ec10e1540b79cc9959bd706712b3 100644 --- a/ts2panda/package.json +++ b/ts2panda/package.json @@ -46,6 +46,7 @@ "rxjs": "^6.6.3", "test262-stream": "^1.3.0", "unique-temp-dir": "^1.0.0", - "yargs": "^16.2.0" + "yargs": "^16.2.0", + "commander": "9.4.0" } } diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 9844d6bd9424752c77b22189de518346f0ca3ccb..ea10cef54987f47d49a9913955b3563e7c03bb01 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -13,89 +13,87 @@ * limitations under the License. */ -// singleton to parse commandLine infos -import commandLineArgs from "command-line-args"; -import commandLineUsage from "command-line-usage"; +import { Command, ParseOptionsResult } from "commander"; +import * as path from "path"; import * as ts from "typescript"; import { LOGE } from "./log"; -import * as path from "path"; import { execute } from "./base/util"; -const ts2pandaOptions = [ - { name: 'modules', alias: 'm', type: Boolean, defaultValue: false, description: "compile as module." }, - { name: 'debug-log', alias: 'l', type: Boolean, defaultValue: false, description: "show info debug log and generate the json file."}, - { name: 'dump-assembly', alias: 'a', type: Boolean, defaultValue: false, description: "dump assembly to file." }, - { name: 'debug', alias: 'd', type: Boolean, defaultValue: false, description: "compile with debug info." }, - { name: 'debug-add-watch', alias: 'w', type: String, lazyMultiple: true, defaultValue: [], description: "watch expression and abc file path in debug mode." }, - { name: 'keep-persistent-watch', alias: 'k', type: String, lazyMultiple: true, defaultValue: [], description: "keep persistent watch on js file with watched expression." }, - { name: 'show-statistics', alias: 's', type: String, lazyMultiple: true, defaultValue: "", description: "show compile statistics(ast, histogram, hoisting, all)." }, - { name: 'output', alias: 'o', type: String, defaultValue: "", description: "set output file." }, - { name: 'timeout', alias: 't', type: Number, defaultValue: 0, description: "js to abc timeout threshold(unit: seconds)." }, - { name: 'opt-log-level', type: String, defaultValue: "error", description: "specifie optimizer log level. Possible values: ['debug', 'info', 'error', 'fatal']" }, - { - name: 'opt-level', type: Number, defaultValue: 1, description: "Optimization level. Possible values: [0, 1, 2]. Default: 0\n 0: no optimizations\n \ - 1: basic bytecode optimizations, including valueNumber, lowering, constantResolver, regAccAllocator\n \ - 2: other bytecode optimizations, unimplemented yet"}, - { name: 'help', alias: 'h', type: Boolean, description: "Show usage guide." }, - { name: 'bc-version', alias: 'v', type: Boolean, defaultValue: false, description: "Print ark bytecode version" }, - { name: 'bc-min-version', type: Boolean, defaultValue: false, description: "Print ark bytecode minimum supported version" }, - { name: 'included-files', alias: 'i', type: String, lazyMultiple: true, defaultValue: [], description: "The list of dependent files." }, - { name: 'record-type', alias: 'p', type: Boolean, defaultValue: false, description: "Record type info. Default: true" }, - { name: 'dts-type-record', alias: 'q', type: Boolean, defaultValue: false, description: "Record type info for .d.ts files. Default: false" }, - { name: 'debug-type', alias: 'g', type: Boolean, defaultValue: false, description: "Print type-related log. Default: false" }, - { name: 'output-type', type: Boolean, defaultValue: false, description: "set output type."} -] - - - export class CmdOptions { - private static parsedResult: ts.ParsedCommandLine; - private static options: commandLineArgs.CommandLineOptions; + private static cmd: Command = new Command(); + private static parsedResult: ParseOptionsResult; + private static unknownOpts: ts.ParsedCommandLine; + + static initOptions(): void { + this.cmd + .option('-m, --module', 'compile as module.', false) + .option('-l, --debug-log', 'show info debug log and generate the json file.', false) + .option('-a, --dump-assembly', 'dump assembly to file.', false) + .option('-d, --debug', 'compile with debug info.', false) + .option('-w, --debug-add-watch ', 'watch expression and abc file path in debug mode.', []) + .option('-k, --keep-persistent-watch ', + 'keep persistent watch on js file with watched expression.', []) + .option('-s, --show-statistics', 'show compile statistics(ast, histogram, hoisting, all).', '') + .option('-o, --output', 'set output file.', '') + .option('-t, --timeout