check tree data when build
This commit is contained in:
1 parent
7ceaf45971
commit
2f4adf6a5a
4 files changed
+88
-3
No files matched your search
@@ -4,6 +4,7 @@
|
|||||||
"build": "Build",
|
"build": "Build",
|
||||||
"batch": "Batch Script",
|
"batch": "Batch Script",
|
||||||
"buildCompleted": "Build completed",
|
"buildCompleted": "Build completed",
|
||||||
|
"buildFailed": "Build failed, more information can be found in the console.",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"copy": "Copy",
|
"copy": "Copy",
|
||||||
"createProject": "Create Project",
|
"createProject": "Create Project",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"build": "构建",
|
"build": "构建",
|
||||||
"batch": "批处理脚本",
|
"batch": "批处理脚本",
|
||||||
"buildCompleted": "构建完成",
|
"buildCompleted": "构建完成",
|
||||||
|
"buildFailed": "构建出现错误,详情请查看控制台!",
|
||||||
"cancel": "取消",
|
"cancel": "取消",
|
||||||
"copy": "复制",
|
"copy": "复制",
|
||||||
"createProject": "新建项目",
|
"createProject": "新建项目",
|
||||||
|
|||||||
@@ -195,7 +195,9 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
useSetting.getState().appendRecent(path);
|
useSetting.getState().appendRecent(path);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
useSetting.getState().removeRecent(path);
|
if (!fs.existsSync(path)) {
|
||||||
|
useSetting.getState().removeRecent(path);
|
||||||
|
}
|
||||||
message.error(`load workspace error: ${path}`);
|
message.error(`load workspace error: ${path}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,14 +244,22 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
editor.dispatch?.("save");
|
editor.dispatch?.("save");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
let hasError = false;
|
||||||
for (const path of workspace.allFiles) {
|
for (const path of workspace.allFiles) {
|
||||||
const buildpath = buildDir + "/" + Path.relative(workspace.workdir, path);
|
const buildpath = buildDir + "/" + Path.relative(workspace.workdir, path);
|
||||||
console.log("build:", buildpath);
|
console.log("build:", buildpath);
|
||||||
const treeModel = b3util.createBuildData(path);
|
const treeModel = b3util.createBuildData(path);
|
||||||
|
if (!b3util.checkNodeData(treeModel?.root)) {
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
fs.mkdirSync(Path.dirname(buildpath), { recursive: true });
|
fs.mkdirSync(Path.dirname(buildpath), { recursive: true });
|
||||||
fs.writeFileSync(buildpath, JSON.stringify(treeModel, null, 2));
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
+74
-1
@@ -66,6 +66,78 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => {
|
|||||||
return false;
|
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) => {
|
export const copyFromNode = (data: TreeGraphData, node: NodeModel) => {
|
||||||
data.name = node.name;
|
data.name = node.name;
|
||||||
data.debug = node.debug;
|
data.debug = node.debug;
|
||||||
@@ -192,6 +264,7 @@ export const checkTreeData = (data: TreeGraphData) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -253,7 +326,7 @@ export const createBuildData = (path: string) => {
|
|||||||
const data = createTreeData(treeModel.root);
|
const data = createTreeData(treeModel.root);
|
||||||
refreshTreeDataId(data);
|
refreshTreeDataId(data);
|
||||||
treeModel.root = createFileData(data, true);
|
treeModel.root = createFileData(data, true);
|
||||||
return treeModel as NodeModel;
|
return treeModel as TreeModel;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("build error:", path, error);
|
console.log("build error:", path, error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user