feat(misc): add commands

- add help, declaration for long script instead of prefix
This commit is contained in:
pakintada@gmail.com 2024-03-15 10:59:56 +07:00
parent bdcc7d8d56
commit 07ece78cd6

View file

@ -20,6 +20,21 @@
// </div>
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::<name> - get variable value by stored name",
"!tb get::<name> - get value of variable in angular",
"!tb fn::<name> <...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;