mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-20 19:20:37 +08:00
新增子流程功能,可以添加子流程,方便后续作为函数调用
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
export function generateCode(commandFlow) {
|
||||
export function generateCode(commandFlow, functionName = null) {
|
||||
// 检查是否包含异步函数
|
||||
const hasAsyncFunction = commandFlow.some((cmd) => cmd.isAsync);
|
||||
|
||||
let code = hasAsyncFunction ? ["async function run() {"] : [];
|
||||
const indent = hasAsyncFunction ? " " : "";
|
||||
let code = [];
|
||||
const funcName = functionName || "run";
|
||||
|
||||
// 生成函数声明
|
||||
code.push(`${hasAsyncFunction ? "async " : ""}function ${funcName}() {`);
|
||||
|
||||
const indent = " ";
|
||||
|
||||
commandFlow.forEach((cmd) => {
|
||||
// 跳过禁用的命令
|
||||
@@ -20,9 +25,11 @@ export function generateCode(commandFlow) {
|
||||
code.push(line);
|
||||
});
|
||||
|
||||
if (hasAsyncFunction) {
|
||||
code.push("}"); // Close the async function
|
||||
code.push("run();"); // Call the function
|
||||
code.push("}"); // Close the function
|
||||
|
||||
// 如果是主函数,则自动执行
|
||||
if (functionName === "main") {
|
||||
code.push("\nmain();"); // Call the main function
|
||||
}
|
||||
|
||||
return code.join("\n");
|
||||
|
||||
Reference in New Issue
Block a user