Verbatim code moves; drops dead WORKFLOW_STATE_DIR const that was declared but never read. No behavior change: tsc clean, 316 tests pass.
153 lines
4.9 KiB
TypeScript
153 lines
4.9 KiB
TypeScript
import {
|
|
findWorkflowsByTaskType,
|
|
getWorkflowDetail,
|
|
listAllWorkflows,
|
|
} from "../../../domains/platform/services.js";
|
|
import { stringOption, numberOption, booleanOption } from "../../parser.js";
|
|
import { createClientsForCorp } from "../../helpers.js";
|
|
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
|
import { PLATFORM_ID_OPTION_KEYS, createWorkflowDetailClient } from "./shared.js";
|
|
|
|
export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
|
const page = numberOption(parsed.options, ["page"]) || 1;
|
|
const pageSize = numberOption(parsed.options, ["pageSize", "size"]) || 50;
|
|
const filterPlatformId = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
|
|
|
const rawResult = await listAllWorkflows(clients, { page, pageSize });
|
|
const workflows = filterPlatformId
|
|
? rawResult.workflows.filter(
|
|
(wf) => wf.platformId === filterPlatformId || wf.platformName === filterPlatformId
|
|
)
|
|
: rawResult.workflows;
|
|
const result = filterPlatformId
|
|
? { ...rawResult, workflows, totalWorkflows: workflows.length }
|
|
: rawResult;
|
|
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
if (result.workflows.length === 0) {
|
|
return {
|
|
stdout: `企业 [${runtime.selectedCorp!.name}] 下暂无工作流\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const rows = result.workflows.map((wf, i) => [
|
|
i + 1,
|
|
wf.id,
|
|
wf.pipelineName,
|
|
wf.platformName || wf.platformId || "-",
|
|
wf.state === 1 ? "🟢 启用" : "⚪ 停用",
|
|
wf.tasks?.length ?? "-",
|
|
]);
|
|
|
|
const table = printTable(
|
|
["#", "工作流 ID", "工作流名称", "所属自建应用", "状态", "节点数"],
|
|
rows
|
|
);
|
|
|
|
return {
|
|
stdout: `====== [${runtime.selectedCorp!.name}] 工作流列表 (共 ${result.workflows.length} 条) ======\n${table}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
export async function handleGet(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
|
if (!pipelineId) {
|
|
return { stdout: "", stderr: "用法: hose-use workflow get <pipelineId>\n", exitCode: 1 };
|
|
}
|
|
|
|
const { client } = await createWorkflowDetailClient(parsed, runtime, pipelineId);
|
|
const detail = await getWorkflowDetail(client, pipelineId);
|
|
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(detail, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
const summary = printKeyValue({
|
|
"工作流 ID": detail.id,
|
|
"工作流名称": detail.label,
|
|
"状态": detail.state === 1 ? "🟢 启用" : "⚪ 停用",
|
|
"版本号": detail.version || "-",
|
|
"节点总数": detail.tasks?.length ?? 0,
|
|
});
|
|
|
|
let taskList = "";
|
|
if (detail.tasks && detail.tasks.length > 0) {
|
|
const taskRows = detail.tasks.map((t, i) => [
|
|
i + 1,
|
|
t.name || "-",
|
|
t.label || "-",
|
|
t.type,
|
|
t.groupName || "-",
|
|
]);
|
|
taskList = `\n 节点结构:\n` + printTable(["#", "节点标识", "节点名称", "类型", "分组"], taskRows);
|
|
}
|
|
|
|
return {
|
|
stdout: `====== 工作流详情 ======\n${summary}\n${taskList}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
export async function handleFind(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const taskType = stringOption(parsed.options, ["task", "taskType", "type"]) || parsed.args[0];
|
|
if (!taskType) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "用法: hose-use workflow find --task=<节点类型> (如 code-js2, http, condition)\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
|
const includeDetail = booleanOption(parsed.options, ["includeDetail", "detail"]);
|
|
const page = numberOption(parsed.options, ["page"]) || 1;
|
|
const pageSize = numberOption(parsed.options, ["pageSize", "size"]) || 50;
|
|
|
|
const result = await findWorkflowsByTaskType(clients, taskType, {
|
|
page,
|
|
pageSize,
|
|
includeDetail,
|
|
});
|
|
|
|
if (runtime.jsonMode) {
|
|
return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
}
|
|
|
|
if (result.workflows.length === 0) {
|
|
return {
|
|
stdout: `未找到包含节点类型 [${taskType}] 的工作流\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const rows = result.workflows.map((wf, i) => [
|
|
i + 1,
|
|
wf.id,
|
|
wf.pipelineName,
|
|
wf.platformName || wf.platformId || "-",
|
|
wf.state === 1 ? "🟢 启用" : "⚪ 停用",
|
|
]);
|
|
|
|
const table = printTable(
|
|
["#", "工作流 ID", "工作流名称", "所属自建应用", "状态"],
|
|
rows
|
|
);
|
|
|
|
return {
|
|
stdout: `====== 匹配节点类型 [${taskType}] 的工作流 (共 ${result.workflows.length} 条) ======\n${table}\n`,
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|