From 38f5ad12c4d5f9d0508c2a3a1417cdc8155edd64 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Tue, 5 Jul 2022 16:18:33 +0800 Subject: [PATCH] Set default timeout and enable self-defined timeout for watch 1. Set the default time out for watch as 10s; 2. Enable IDE to use the commandline for self-defining the time out value Signed-off-by: gavin1012_hw Change-Id: I528d8deabc8f095a283320422a388361238ad7dc --- ts2panda/src/cmdOptions.ts | 2 +- ts2panda/src/index.ts | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 4e108670db..79f4d92665 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 866827b25d..3861368b12 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; } -- Gitee