collect errors in build

This commit is contained in:
codetypes committed 2025-08-31 16:47:50 +08:00
1 parent 53099d65f1
commit 7d0526b277
6 files changed
+29 -14

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "behavior3editor", "name": "behavior3editor",
"version": "1.8.4", "version": "1.8.5",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "behavior3editor", "name": "behavior3editor",
"version": "1.8.4", "version": "1.8.5",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "behavior3editor", "name": "behavior3editor",
"version": "1.8.4", "version": "1.8.5",
"main": "dist-electron/main/index.js", "main": "dist-electron/main/index.js",
"description": "行为树编辑器", "description": "行为树编辑器",
"author": "zhandouxiaojiji & codetypes", "author": "zhandouxiaojiji & codetypes",
+2 -2
View File
@@ -44,12 +44,12 @@ export const onSetup = (env) => {
console.log(env.fs.readFileSync("sample/scripts/build.js", "utf8")); console.log(env.fs.readFileSync("sample/scripts/build.js", "utf8"));
}; };
export const onProcessTree = (tree) => { export const onProcessTree = (tree, errors) => {
console.log(`processTree ${tree.name}`); console.log(`processTree ${tree.name}`);
return tree; return tree;
}; };
export const onProcessNode = (node, tree) => { export const onProcessNode = (node, tree, errors) => {
console.log(`processNode ${tree.name} ${node.name}#${node.id}`); console.log(`processNode ${tree.name} ${node.name}#${node.id}`);
return node; return node;
}; };
+6 -1
View File
@@ -426,7 +426,12 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
}); });
workspace.allFiles.forEach((file) => { workspace.allFiles.forEach((file) => {
let tree: TreeData | null = readTree(file.path); 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) { if (tree) {
batch.onWriteFile?.(file.path, tree); batch.onWriteFile?.(file.path, tree);
writeTree(file.path, tree); writeTree(file.path, tree);
+1 -1
View File
@@ -1,6 +1,6 @@
import { NodeDef } from "../behavior3/src/behavior3"; 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"]; export const keyWords = ["true", "false", "null", "undefined", "NaN", "Infinity"];
+17 -7
View File
@@ -37,8 +37,8 @@ type Env = {
export interface BatchScript { export interface BatchScript {
onSetup?(env: Env): void; onSetup?(env: Env): void;
onProcessTree?(tree: TreeData, path: string): TreeData | null; onProcessTree?(tree: TreeData, path: string, errors: string[]): TreeData | null;
onProcessNode?(node: NodeData): NodeData | null; onProcessNode?(node: NodeData, errors: string[]): NodeData | null;
onWriteFile?(path: string, tree: TreeData): void; onWriteFile?(path: string, tree: TreeData): void;
onComplete?(status: "success" | "failure"): void; onComplete?(status: "success" | "failure"): void;
} }
@@ -767,12 +767,17 @@ export const createBuildData = (path: string) => {
return null; 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) { if (!tree) {
return null; return null;
} }
if (batch.onProcessTree) { if (batch.onProcessTree) {
tree = batch.onProcessTree(tree, path); tree = batch.onProcessTree(tree, path, errors);
} }
if (!tree) { if (!tree) {
return null; return null;
@@ -789,7 +794,7 @@ export const processBatch = (tree: TreeData | null, path: string, batch: BatchSc
}); });
node.children = children; node.children = children;
} }
return batch.onProcessNode?.(node); return batch.onProcessNode?.(node, errors);
}; };
tree.root = processNode(tree.root) ?? ({} as NodeData); 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)) { for (const path of Path.ls(Path.dirname(project), true)) {
if (path.endsWith(".json")) { if (path.endsWith(".json")) {
const buildpath = buildDir + "/" + path.substring(workdir.length + 1); const buildpath = buildDir + "/" + path.substring(workdir.length + 1);
console.log("build:", buildpath);
let tree = createBuildData(path); let tree = createBuildData(path);
const errors: string[] = [];
if (buildScript) { if (buildScript) {
tree = processBatch(tree, path, buildScript); tree = processBatch(tree, path, buildScript, errors);
} }
if (!tree) { if (!tree) {
continue; continue;
@@ -835,6 +840,11 @@ export const buildProject = async (project: string, buildDir: string) => {
console.log("skip:", buildpath); console.log("skip:", buildpath);
continue; continue;
} }
console.log("build:", buildpath);
if (errors.length) {
errors.forEach((msg) => console.error(msg));
hasError = true;
}
const declare: FileVarDecl = { const declare: FileVarDecl = {
import: tree.import.map((v) => ({ path: v, vars: [], depends: [] })), import: tree.import.map((v) => ({ path: v, vars: [], depends: [] })),
vars: tree.vars.map((v) => ({ name: v.name, desc: v.desc })), vars: tree.vars.map((v) => ({ name: v.name, desc: v.desc })),