feat: restore isolated HiCAD engineering tools
This commit is contained in:
parent
4c21fd4844
commit
9c9e462682
@ -5,7 +5,7 @@ import { redirect } from "next/navigation";
|
||||
import { auth } from "@/app/(auth)/auth";
|
||||
|
||||
const ZOO_MODELING_APP_SRC =
|
||||
"/vendor/zoo-modeling-app/index.html?v=f2b345db";
|
||||
"/vendor/zoo-modeling-app/index.html?v=f2b345db-eng1";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = {
|
||||
|
||||
@ -149,6 +149,10 @@ function patchOfficialSource() {
|
||||
path.join(customizationDir, "HicadManufacturingLauncher.tsx.template"),
|
||||
path.join(sourceDir, "src/components/HicadManufacturingLauncher.tsx")
|
||||
);
|
||||
copyFileSync(
|
||||
path.join(customizationDir, "HicadManufacturingSlot.tsx.template"),
|
||||
path.join(sourceDir, "src/components/HicadManufacturingSlot.tsx")
|
||||
);
|
||||
}
|
||||
copyFileSync(
|
||||
path.join(customizationDir, "localization.ts"),
|
||||
@ -215,26 +219,36 @@ function patchOfficialSource() {
|
||||
" <HicadManufacturingPanel projectName={projectName ?? 'HiCAD 模型'} />\n",
|
||||
""
|
||||
);
|
||||
replaceSource(
|
||||
"src/components/OpenedProject.tsx",
|
||||
"import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n",
|
||||
""
|
||||
);
|
||||
replaceSource(
|
||||
"src/components/OpenedProject.tsx",
|
||||
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\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"
|
||||
"import { AppHeader } from '@src/components/AppHeader'\nimport { HicadManufacturingSlot } from '@src/components/HicadManufacturingSlot'\n"
|
||||
);
|
||||
replaceSource(
|
||||
"src/components/OpenedProject.tsx",
|
||||
" <StatusBar\n",
|
||||
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\n <StatusBar\n"
|
||||
" <HicadManufacturingSlot projectName={projectName ?? 'HiCAD 模型'} />\n <StatusBar\n"
|
||||
);
|
||||
} else {
|
||||
replaceSource(
|
||||
"src/components/OpenedProject.tsx",
|
||||
"import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n",
|
||||
"import { HicadManufacturingSlot } from '@src/components/HicadManufacturingSlot'\n",
|
||||
""
|
||||
);
|
||||
replaceSource(
|
||||
"src/components/OpenedProject.tsx",
|
||||
" <HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />\n",
|
||||
" <HicadManufacturingSlot projectName={projectName ?? 'HiCAD 模型'} />\n",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@ -53,11 +53,20 @@ test.describe('HiCAD manufacturing extension', () => {
|
||||
.at(-1)
|
||||
)
|
||||
expect(vendorScript).toContain(
|
||||
"import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'"
|
||||
"import { HicadManufacturingSlot } from '@src/components/HicadManufacturingSlot'"
|
||||
)
|
||||
expect(vendorScript).toContain(
|
||||
"<HicadManufacturingLauncher projectName={projectName ?? 'HiCAD 模型'} />"
|
||||
"<HicadManufacturingSlot projectName={projectName ?? 'HiCAD 模型'} />"
|
||||
)
|
||||
const slot = fs.readFileSync(
|
||||
path.join(
|
||||
projectRoot,
|
||||
'vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template'
|
||||
),
|
||||
'utf8'
|
||||
)
|
||||
expect(slot).toContain('lazy(() =>')
|
||||
expect(slot).toContain('ManufacturingSlotBoundary')
|
||||
const launcher = fs.readFileSync(
|
||||
path.join(
|
||||
projectRoot,
|
||||
|
||||
40
vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template
vendored
Normal file
40
vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
import { Component, lazy, Suspense, type ErrorInfo, type ReactNode } from 'react'
|
||||
|
||||
const ManufacturingLauncher = lazy(() =>
|
||||
import('./HicadManufacturingLauncher').then((module) => ({
|
||||
default: module.HicadManufacturingLauncher,
|
||||
}))
|
||||
)
|
||||
|
||||
class ManufacturingSlotBoundary extends Component<
|
||||
{ children: ReactNode },
|
||||
{ failed: boolean }
|
||||
> {
|
||||
state = { failed: false }
|
||||
|
||||
static getDerivedStateFromError() {
|
||||
return { failed: true }
|
||||
}
|
||||
|
||||
componentDidCatch(error: unknown, info: ErrorInfo) {
|
||||
console.error('[HiCAD Manufacturing] Launcher failed safely', error, info)
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.failed ? null : this.props.children
|
||||
}
|
||||
}
|
||||
|
||||
export function HicadManufacturingSlot({
|
||||
projectName,
|
||||
}: {
|
||||
projectName: string
|
||||
}) {
|
||||
return (
|
||||
<ManufacturingSlotBoundary>
|
||||
<Suspense fallback={null}>
|
||||
<ManufacturingLauncher projectName={projectName} />
|
||||
</Suspense>
|
||||
</ManufacturingSlotBoundary>
|
||||
)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user