diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 4e108670db4789dfb4ba0e5bde0af7bc345a089b..79f4d926655bceea2895144483314a528247510e 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -27,7 +27,7 @@ const ts2pandaOptions = [ { 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: 'debug-add-watch', alias: 'w', type: String, lazyMultiple: true, defaultValue: [], description: "watch expression, abc file path and maybe watchTimeOut(in seconds) 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." }, diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 866827b25dd93dc2907a5b0c25728ea2c2624410..3861368b123dbd2b9b285f1e9febf8c1e25686b4 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -159,13 +159,13 @@ function getDtsFiles(libDir: string): string[] { } const stopWatchingStr = "####"; -const watchAbcFileTimeOut = 5000; +const watchAbcFileDefaultTimeOut = 10; const watchFileName = "watch_expressions"; -function updateWatchedFile() { +function updateWatchedFile(watchAbcFileTimeOut: number) { let watchArgs = CmdOptions.getAddWatchArgs(); let ideIputStr = watchArgs[0]; - if (watchArgs.length != 2 || !isBase64Str(ideIputStr)) { + if (watchArgs.length > 3 || !isBase64Str(ideIputStr)) { throw new Error("Incorrect args' format or not enter base64 string in watch mode"); } let fragmentSep = "\\n"; @@ -206,7 +206,7 @@ function updateWatchedFile() { fs.unlinkSync(jsFileName); fs.unlinkSync(abcFileName); throw new Error("watchFileServer has not been initialized"); - }, watchAbcFileTimeOut); + }, watchAbcFileTimeOut*1000); } function convertWatchExpression(jsfileName: string, parsed: ts.ParsedCommandLine | undefined) { @@ -220,7 +220,7 @@ function keepWatchingFiles(filePath: string, parsed: ts.ParsedCommandLine | unde let jsFileName = filePath + path.sep + watchFileName + ".js"; let abcFileName = filePath + path.sep + watchFileName + ".abc"; if (fs.existsSync(jsFileName)) { - console.log("watchFileServer has been initialized"); + console.log("watchFileServer has been initialized supportTimeout"); return; } fs.writeFileSync(jsFileName, "initJsFile\n"); @@ -237,7 +237,7 @@ function keepWatchingFiles(filePath: string, parsed: ts.ParsedCommandLine | unde } convertWatchExpression(jsFileName, parsed); }); - console.log("startWatchingSuccess"); + console.log("startWatchingSuccess supportTimeout"); process.on("exit", () => { fs.unlinkSync(jsFileName); @@ -286,7 +286,15 @@ function run(args: string[], options?: ts.CompilerOptions): void { return; } if (CmdOptions.isWatchMode()) { - updateWatchedFile(); + if (CmdOptions.getAddWatchArgs().length == 3) { + let watchAbcFileTimeOut = Number(CmdOptions.getAddWatchArgs()[2]); + if (watchAbcFileTimeOut.toString() == "NaN") { + throw new Error("Incorrect args' format for watch out time in watch mode"); + } + updateWatchedFile(watchAbcFileTimeOut); + return; + } + updateWatchedFile(watchAbcFileDefaultTimeOut); return; }