fix: isolate latest HiCAD startup

This commit is contained in:
134 2026-07-27 20:22:30 +08:00 committed by root
parent bbe27bd555
commit 623ab0f8b5
3 changed files with 44 additions and 23 deletions

View File

@ -4,7 +4,8 @@ import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { auth } from "@/app/(auth)/auth";
const ZOO_MODELING_APP_SRC = "/vendor/zoo-modeling-app/index.html";
const ZOO_MODELING_APP_SRC =
"/vendor/zoo-modeling-app/index.html?v=f2b345db";
export const dynamic = "force-dynamic";
export const metadata: Metadata = {

View File

@ -31,6 +31,8 @@ const outputDir = path.join(root, "public/vendor/zoo-modeling-app");
const customizationDir = path.join(root, "vendor/zoo-modeling-app");
const proxyToken = "hicad-session";
const brandedFaviconUrl = "/api/favicon?surface=hicad";
const enableManufacturingExtension =
process.env.HICAD_MANUFACTURING_EXTENSION === "1";
function run(command, args, options = {}) {
const result = spawnSync(command, args, {
@ -134,18 +136,20 @@ function patchOfficialSource() {
path.join(customizationDir, "Logo.tsx"),
path.join(sourceDir, "src/components/Logo.tsx")
);
copyFileSync(
path.join(customizationDir, "manufacturing.ts"),
path.join(sourceDir, "src/components/manufacturing.ts")
);
copyFileSync(
path.join(customizationDir, "HicadManufacturingPanel.tsx"),
path.join(sourceDir, "src/components/HicadManufacturingPanel.tsx")
);
copyFileSync(
path.join(customizationDir, "HicadManufacturingLauncher.tsx"),
path.join(sourceDir, "src/components/HicadManufacturingLauncher.tsx")
);
if (enableManufacturingExtension) {
copyFileSync(
path.join(customizationDir, "manufacturing.ts"),
path.join(sourceDir, "src/components/manufacturing.ts")
);
copyFileSync(
path.join(customizationDir, "HicadManufacturingPanel.tsx"),
path.join(sourceDir, "src/components/HicadManufacturingPanel.tsx")
);
copyFileSync(
path.join(customizationDir, "HicadManufacturingLauncher.tsx"),
path.join(sourceDir, "src/components/HicadManufacturingLauncher.tsx")
);
}
copyFileSync(
path.join(customizationDir, "localization.ts"),
path.join(sourceDir, "src/lib/hicadLocalization.ts")
@ -211,16 +215,29 @@ function patchOfficialSource() {
" <HicadManufacturingPanel projectName={projectName ?? 'HiCAD 模型'} />\n",
""
);
replaceSource(
"src/components/OpenedProject.tsx",
"import { AppHeader } from '@src/components/AppHeader'\n",
"import { AppHeader } from '@src/components/AppHeader'\nimport { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n"
);
replaceSource(
"src/components/OpenedProject.tsx",
" <StatusBar\n",
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\n <StatusBar\n"
);
if (enableManufacturingExtension) {
replaceSource(
"src/components/OpenedProject.tsx",
"import { AppHeader } from '@src/components/AppHeader'\n",
"import { AppHeader } from '@src/components/AppHeader'\nimport { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n"
);
replaceSource(
"src/components/OpenedProject.tsx",
" <StatusBar\n",
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\n <StatusBar\n"
);
} else {
replaceSource(
"src/components/OpenedProject.tsx",
"import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n",
""
);
replaceSource(
"src/components/OpenedProject.tsx",
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\n",
""
);
}
replaceSource(
"src/lib/socket.ts",
` ws.addEventListener('open', () => {\n ws.send(\n JSON.stringify({\n type: 'headers',\n headers: {\n Authorization: 'Bearer ' + token,\n },\n })\n )\n resolve(ws)\n })`,

View File

@ -44,6 +44,9 @@ test.describe('HiCAD manufacturing extension', () => {
'utf8'
)
expect(vendorScript).toContain(
'process.env.HICAD_MANUFACTURING_EXTENSION === "1"'
)
expect(vendorScript).toContain(
'vendor/zoo-modeling-app/HicadManufacturingLauncher.tsx'
.split('/')