diff --git a/public/locales/en.json b/public/locales/en.json index 58b64aa..875c59a 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -4,6 +4,7 @@ "build": "Build", "batch": "Batch Script", "buildCompleted": "Build completed", + "buildFailed": "Build failed, more information can be found in the console.", "cancel": "Cancel", "copy": "Copy", "createProject": "Create Project", diff --git a/public/locales/zh.json b/public/locales/zh.json index 760f788..1251db0 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -4,6 +4,7 @@ "build": "构建", "batch": "批处理脚本", "buildCompleted": "构建完成", + "buildFailed": "构建出现错误,详情请查看控制台!", "cancel": "取消", "copy": "复制", "createProject": "新建项目", diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index ce4597b..f810c9e 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -195,7 +195,9 @@ export const useWorkspace = create((set, get) => ({ useSetting.getState().appendRecent(path); } catch (error) { console.error(error); - useSetting.getState().removeRecent(path); + if (!fs.existsSync(path)) { + useSetting.getState().removeRecent(path); + } message.error(`load workspace error: ${path}`); } } @@ -242,14 +244,22 @@ export const useWorkspace = create((set, get) => ({ editor.dispatch?.("save"); } try { + let hasError = false; for (const path of workspace.allFiles) { const buildpath = buildDir + "/" + Path.relative(workspace.workdir, path); console.log("build:", buildpath); const treeModel = b3util.createBuildData(path); + if (!b3util.checkNodeData(treeModel?.root)) { + hasError = true; + } fs.mkdirSync(Path.dirname(buildpath), { recursive: true }); fs.writeFileSync(buildpath, JSON.stringify(treeModel, null, 2)); } - message.success(i18n.t("buildCompleted")); + if (hasError) { + message.error(i18n.t("buildFailed")); + } else { + message.success(i18n.t("buildCompleted")); + } } catch (error) { console.error(error); } diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index bcd43a3..1df09ba 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -66,6 +66,78 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => { return false; }; +export const checkNodeData = (data: NodeModel | null | undefined) => { + if (!data) { + return false; + } + let hasError = false; + const conf = useWorkspace.getState().getNodeDef(data.name); + if (conf.input) { + for (let i = 0; i < conf.input.length; i++) { + if (conf.input[i].indexOf("?") === -1 && !data.input?.[i]) { + console.error(`check ${data.id}|${data.name}: intput field '${conf.input[i]}' is required`); + hasError = true; + } + } + } + if (conf.output) { + for (let i = 0; i < conf.output.length; i++) { + if (conf.output[i].indexOf("?") === -1 && !data.output?.[i]) { + console.error( + `check ${data.id}|${data.name}: output field '${conf.output[i]}' is required` + ); + hasError = true; + } + } + } + if (conf.args) { + for (let i = 0; i < conf.args.length; i++) { + const arg = conf.args[i]; + if (arg.type.indexOf("?") === -1) { + const value = data.args?.[arg.name]; + if (arg.type === "float") { + if (typeof value !== "number") { + console.error(`check ${data.id}|${data.name}: '${arg.name}' must be a number`); + hasError = true; + } + } else if (arg.type === "int") { + if (typeof value !== "number" || value !== Math.floor(value)) { + console.error(`check ${data.id}|${data.name}: '${arg.name}' must be a int`); + hasError = true; + } + } else if (arg.type === "string") { + if (!value || typeof value !== "string") { + console.error(`check ${data.id}|${data.name}: '${arg.name}' must be a string`); + hasError = true; + } + } else if (arg.type === "enum") { + if (!arg.options?.find((option) => option.value === value)) { + console.error( + `check ${data.id}|${data.name}: '${arg.name}' must be one of option value` + ); + hasError = true; + } + } else if (arg.type == "code") { + if (!value || typeof value !== "string") { + console.error(`check ${data.id}|${data.name}: '${arg.name}' must be a string`); + hasError = true; + } + } + } + } + } + + if (data.children) { + for (const child of data.children) { + if (!checkNodeData(child)) { + hasError = true; + } + } + } + + return !hasError; +}; + export const copyFromNode = (data: TreeGraphData, node: NodeModel) => { data.name = node.name; data.debug = node.debug; @@ -192,6 +264,7 @@ export const checkTreeData = (data: TreeGraphData) => { } } } + return true; }; @@ -253,7 +326,7 @@ export const createBuildData = (path: string) => { const data = createTreeData(treeModel.root); refreshTreeDataId(data); treeModel.root = createFileData(data, true); - return treeModel as NodeModel; + return treeModel as TreeModel; } catch (error) { console.log("build error:", path, error); }