Start the React rebuild of the DWG/DXF viewer (#1). - HMDesign is a git submodule (vendor/HMDesign, main) and its packages/ui is an npm workspace, so @hm-design/ui resolves to the submodule and shares this repo's node_modules. - scripts/setup-hmdesign.mjs (postinstall) builds the package dist and points vendor/HMDesign/node_modules at ours with a junction, because HMDesign's build script reads typescript/shadcn from its own root. Nothing inside the submodule is modified. - Versions follow HMDesign (react 19.3.0, vite 8.3.0, tailwindcss 4.3.3, typescript 7.0.2) and the sample (three 0.185.1, dxf-parser 1.1.2, opentype.js 2.0.0). - CSS entry: tailwindcss + @hm-design/ui/tailwind.css (index.css). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.5 KiB
JavaScript
49 lines
2.5 KiB
JavaScript
/**
|
|
* Prepare the HMDesign submodule for this app (runs as `postinstall`, or `npm run hm:build`).
|
|
*
|
|
* HMDesign is consumed as a git submodule (vendor/HMDesign) whose `packages/ui` is an npm workspace of this
|
|
* repo, so `@hm-design/ui` resolves to vendor/HMDesign/packages/ui and its dependencies are installed into
|
|
* this repo's node_modules. The package exports compiled `dist/` (JS, types, theme CSS, fonts), which Git
|
|
* does not carry, so it has to be built once after install.
|
|
*
|
|
* HMDesign's own package build (vendor/HMDesign/scripts/build-package.mjs) reads TypeScript and shadcn from
|
|
* `<HMDesign root>/node_modules/...` by absolute path. Instead of a second full `npm ci` inside the submodule
|
|
* (Storybook and friends), point that folder at this repo's node_modules with a directory junction. The
|
|
* submodule's .gitignore already ignores node_modules/, so its working tree stays clean.
|
|
*
|
|
* Nothing inside the submodule is edited.
|
|
*/
|
|
import { existsSync, lstatSync, symlinkSync, statSync } from "node:fs"
|
|
import path from "node:path"
|
|
import { fileURLToPath } from "node:url"
|
|
import { execFileSync } from "node:child_process"
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
const hm = path.join(root, "vendor", "HMDesign")
|
|
const uiPkg = path.join(hm, "packages", "ui")
|
|
const force = process.argv.includes("--force")
|
|
|
|
if (!existsSync(path.join(uiPkg, "package.json"))) {
|
|
console.error("[setup-hmdesign] vendor/HMDesign is empty. Run: git submodule update --init --recursive")
|
|
process.exit(1)
|
|
}
|
|
|
|
const hmNodeModules = path.join(hm, "node_modules")
|
|
const rootNodeModules = path.join(root, "node_modules")
|
|
if (!existsSync(hmNodeModules)) {
|
|
symlinkSync(rootNodeModules, hmNodeModules, "junction")
|
|
console.log("[setup-hmdesign] linked vendor/HMDesign/node_modules -> node_modules")
|
|
} else if (!lstatSync(hmNodeModules).isSymbolicLink()) {
|
|
console.log("[setup-hmdesign] vendor/HMDesign/node_modules is a real folder; using it as is")
|
|
}
|
|
|
|
const distEntry = path.join(uiPkg, "dist", "index.js")
|
|
const srcIndex = path.join(uiPkg, "src", "index.ts")
|
|
const stale = !existsSync(distEntry) || statSync(srcIndex).mtimeMs > statSync(distEntry).mtimeMs
|
|
if (force || stale) {
|
|
console.log("[setup-hmdesign] building @hm-design/ui (vendor/HMDesign/packages/ui/dist)")
|
|
execFileSync(process.execPath, [path.join(hm, "scripts", "build-package.mjs"), "ui"], { cwd: uiPkg, stdio: "inherit" })
|
|
} else {
|
|
console.log("[setup-hmdesign] @hm-design/ui dist is up to date")
|
|
}
|