From 07ece78cd6ee7442655ad8751045f639f507561d Mon Sep 17 00:00:00 2001 From: "pakintada@gmail.com" Date: Fri, 15 Mar 2024 10:59:56 +0700 Subject: [PATCH] feat(misc): :sparkles: add commands - add help, declaration for long script instead of prefix --- client/src/app/shared/helpers/debugger.ts | 38 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/client/src/app/shared/helpers/debugger.ts b/client/src/app/shared/helpers/debugger.ts index 582d1f5..12bda80 100644 --- a/client/src/app/shared/helpers/debugger.ts +++ b/client/src/app/shared/helpers/debugger.ts @@ -20,6 +20,21 @@ // export class Debugger { public output: any[] = []; + public commandList: string[] = [ + "** any js code can be used here! **", + "external commands: ", + "", + "use tb; - start the tb script until `tbs` is found.", + "tbs; - stop the tb scipt, the next line may execute in js or others.", + "!tb - prefix for execute commands from angular", + "!tb proto - list all functions and variables in this component", + "!tb clear - clear output", + "!tb store - collect and store previous line output as variable. This can be used to interact with function", + "!tb vars - view all stored variables", + "!tb var:: - get variable value by stored name", + "!tb get:: - get value of variable in angular", + "!tb fn:: <...args> - execute the function with args", + ]; // evaluate eval(comp: any) { let enableCommand = document.getElementById('command-enable') as any; @@ -30,12 +45,26 @@ export class Debugger { let holdon:any = {}; // split line let lines = command.value.split('\n'); + let declPrefixFlag = false; lines.forEach((line: string, index: number) => { + + if(line == "use tb;") { + declPrefixFlag = true; + } else if(line == "tbs;"){ + declPrefixFlag = false; + } + // this.output.push(line); // escape line, exec function of class - if(line.startsWith("!tb")){ - let cmd = line.substring(3).trim(); + if(line.startsWith("!tb") || declPrefixFlag){ + let cmd = ""; + if(line.includes("!tb")){ + cmd = line.substring(3).trim(); + } else { + cmd = line; + } + switch(cmd){ case "proto": this.output.push(Object.keys(comp)); @@ -54,6 +83,9 @@ export class Debugger { case "vars": this.output.push(JSON.stringify(holdon)); break; + case "help": + this.output.push(this.commandList.join("\n")); + break; default: @@ -93,7 +125,7 @@ export class Debugger { break; } - } else if (!line.startsWith("//")){ + } else if (!line.startsWith("//") && line != ""){ if(!line.startsWith("window") && !line.startsWith("let") && !line.startsWith("var")){ line = "window."+line;