From 7d0526b277d3aa7d2189bb137131b06bf00812af Mon Sep 17 00:00:00 2001 From: codetypes Date: Sun, 31 Aug 2025 16:47:50 +0800 Subject: [PATCH] collect errors in build --- package-lock.json | 4 ++-- package.json | 2 +- sample/scripts/build.js | 4 ++-- src/contexts/workspace-context.ts | 7 ++++++- src/misc/b3type.ts | 2 +- src/misc/b3util.ts | 24 +++++++++++++++++------- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9cce351..40471ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "behavior3editor", - "version": "1.8.4", + "version": "1.8.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "behavior3editor", - "version": "1.8.4", + "version": "1.8.5", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 67ba286..650ee7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "behavior3editor", - "version": "1.8.4", + "version": "1.8.5", "main": "dist-electron/main/index.js", "description": "行为树编辑器", "author": "zhandouxiaojiji & codetypes", diff --git a/sample/scripts/build.js b/sample/scripts/build.js index ca53901..2e61c73 100644 --- a/sample/scripts/build.js +++ b/sample/scripts/build.js @@ -44,12 +44,12 @@ export const onSetup = (env) => { console.log(env.fs.readFileSync("sample/scripts/build.js", "utf8")); }; -export const onProcessTree = (tree) => { +export const onProcessTree = (tree, errors) => { console.log(`processTree ${tree.name}`); return tree; }; -export const onProcessNode = (node, tree) => { +export const onProcessNode = (node, tree, errors) => { console.log(`processNode ${tree.name} ${node.name}#${node.id}`); return node; }; diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index 15b6db2..7abb8ea 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -426,7 +426,12 @@ export const useWorkspace = create((set, get) => ({ }); workspace.allFiles.forEach((file) => { let tree: TreeData | null = readTree(file.path); - tree = b3util.processBatch(tree, file.path, batch); + const errors: string[] = []; + tree = b3util.processBatch(tree, file.path, batch, errors); + if (errors.length) { + errors.forEach((error) => message.error(error)); + hasError = true; + } if (tree) { batch.onWriteFile?.(file.path, tree); writeTree(file.path, tree); diff --git a/src/misc/b3type.ts b/src/misc/b3type.ts index 70fd785..4753392 100644 --- a/src/misc/b3type.ts +++ b/src/misc/b3type.ts @@ -1,6 +1,6 @@ import { NodeDef } from "../behavior3/src/behavior3"; -export const VERSION = "1.8.4"; +export const VERSION = "1.8.5"; export const keyWords = ["true", "false", "null", "undefined", "NaN", "Infinity"]; diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index 3486dba..4f2d545 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -37,8 +37,8 @@ type Env = { export interface BatchScript { onSetup?(env: Env): void; - onProcessTree?(tree: TreeData, path: string): TreeData | null; - onProcessNode?(node: NodeData): NodeData | null; + onProcessTree?(tree: TreeData, path: string, errors: string[]): TreeData | null; + onProcessNode?(node: NodeData, errors: string[]): NodeData | null; onWriteFile?(path: string, tree: TreeData): void; onComplete?(status: "success" | "failure"): void; } @@ -767,12 +767,17 @@ export const createBuildData = (path: string) => { return null; }; -export const processBatch = (tree: TreeData | null, path: string, batch: BatchScript) => { +export const processBatch = ( + tree: TreeData | null, + path: string, + batch: BatchScript, + errors: string[] +) => { if (!tree) { return null; } if (batch.onProcessTree) { - tree = batch.onProcessTree(tree, path); + tree = batch.onProcessTree(tree, path, errors); } if (!tree) { return null; @@ -789,7 +794,7 @@ export const processBatch = (tree: TreeData | null, path: string, batch: BatchSc }); node.children = children; } - return batch.onProcessNode?.(node); + return batch.onProcessNode?.(node, errors); }; tree.root = processNode(tree.root) ?? ({} as NodeData); } @@ -823,10 +828,10 @@ export const buildProject = async (project: string, buildDir: string) => { for (const path of Path.ls(Path.dirname(project), true)) { if (path.endsWith(".json")) { const buildpath = buildDir + "/" + path.substring(workdir.length + 1); - console.log("build:", buildpath); let tree = createBuildData(path); + const errors: string[] = []; if (buildScript) { - tree = processBatch(tree, path, buildScript); + tree = processBatch(tree, path, buildScript, errors); } if (!tree) { continue; @@ -835,6 +840,11 @@ export const buildProject = async (project: string, buildDir: string) => { console.log("skip:", buildpath); continue; } + console.log("build:", buildpath); + if (errors.length) { + errors.forEach((msg) => console.error(msg)); + hasError = true; + } const declare: FileVarDecl = { import: tree.import.map((v) => ({ path: v, vars: [], depends: [] })), vars: tree.vars.map((v) => ({ name: v.name, desc: v.desc })),