Skip to content

Commit 881587d

Browse files
committed
build(ui): enahnce cross-platform dx
1 parent e10673a commit 881587d

File tree

4 files changed

+78
-67
lines changed

4 files changed

+78
-67
lines changed

web/bun.lockb

19.4 KB
Binary file not shown.

web/copy-build.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2+
import { cp } from "node:fs/promises";
3+
import { join, resolve } from "node:path";
4+
5+
const BASE_DIR = resolve("../boot/src/main/resources");
6+
const STATIC_DIR = join(BASE_DIR, "static");
7+
const ASSETS_DIR = join(STATIC_DIR, "assets");
8+
const TEMPLATES_DIR = join(BASE_DIR, "templates");
9+
const SRC_DIR = resolve("dist");
10+
11+
async function main() {
12+
console.log("Copy assets into SpringBoot resources");
13+
14+
if (!existsSync(SRC_DIR)) {
15+
console.error(`Error: ${SRC_DIR} does not exist`);
16+
process.exit(1);
17+
}
18+
19+
mkdirSync(ASSETS_DIR, { recursive: true });
20+
mkdirSync(TEMPLATES_DIR, { recursive: true });
21+
22+
if (existsSync(ASSETS_DIR)) {
23+
const files = readdirSync(ASSETS_DIR);
24+
for (const file of files) {
25+
rmSync(join(ASSETS_DIR, file), { recursive: true, force: true });
26+
}
27+
}
28+
29+
try {
30+
if (existsSync(join(SRC_DIR, "vite.svg"))) {
31+
await cp(join(SRC_DIR, "vite.svg"), join(STATIC_DIR, "vite.svg"));
32+
}
33+
34+
const assetsSourceDir = join(SRC_DIR, "assets");
35+
if (existsSync(assetsSourceDir)) {
36+
await cp(assetsSourceDir, ASSETS_DIR, { recursive: true });
37+
}
38+
} catch (err) {
39+
console.error("Error copying assets:", err);
40+
process.exit(1);
41+
}
42+
43+
const INDEX_SRC = join(SRC_DIR, "index.html");
44+
const INDEX_DEST = join(TEMPLATES_DIR, "index.html");
45+
46+
if (!existsSync(INDEX_SRC)) {
47+
console.error(`Error: ${INDEX_SRC} does not exist. Make sure you built the frontend project first.`);
48+
process.exit(1);
49+
}
50+
51+
const htmlContent = readFileSync(INDEX_SRC, "utf8");
52+
const updatedHtml = htmlContent
53+
.replace(/href="([^"]*)"/g, 'th:href="@{$1}"')
54+
.replace(/src="([^"]*)"/g, 'th:src="@{$1}"');
55+
56+
writeFileSync(INDEX_DEST, updatedHtml);
57+
console.log("SpringBoot resources updated successfully");
58+
}
59+
60+
main().catch((err) => {
61+
console.error("Error:", err);
62+
process.exit(1);
63+
});

web/copy-build.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

web/package.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"typecheck": "tsc --noEmit",
7+
"typecheck": "tsc -b --noEmit",
88
"dev": "vite --port=3001",
9-
"build": "tsc -b && vite build --mode production && bash copy-build.sh",
10-
"serve": "vite preview",
11-
"check": "bunx @biomejs/biome check ./ --write",
12-
"start": "vite"
9+
"build": "tsc -b && vite build --mode production && bun run copy-build.js",
10+
"build:analyze": "vite build --mode production --outDir dist/analyze && npx vite-bundle-visualizer",
11+
"preview": "vite preview",
12+
"clean": "rimraf dist",
13+
"lint": "bunx @biomejs/biome check ./",
14+
"lint:fix": "bunx @biomejs/biome check ./ --write"
1315
},
1416
"devDependencies": {
1517
"@biomejs/biome": "1.9.4",
16-
"@tanstack/router-plugin": "^1.111.3",
18+
"@tanstack/router-plugin": "^1.111.7",
1719
"@types/node": "^22.13.5",
1820
"@types/react": "^19.0.10",
19-
"@types/react-dom": "^19.0.4",
20-
"@vitejs/plugin-react": "^4.3.4",
2121
"@types/react-copy-to-clipboard": "^5.0.7",
22+
"@types/react-dom": "^19.0.4",
2223
"@types/react-syntax-highlighter": "^15.5.13",
24+
"@vitejs/plugin-react": "^4.3.4",
25+
"rimraf": "^6.0.1",
2326
"tailwindcss": "^4.0.8",
2427
"typescript": "^5.7.3",
25-
"vite": "^6.1.1"
28+
"vite": "^6.2.0",
29+
"vite-bundle-visualizer": "^1.2.1"
2630
},
2731
"dependencies": {
2832
"@hookform/resolvers": "^4.1.2",
@@ -39,8 +43,8 @@
3943
"@radix-ui/react-tooltip": "^1.1.8",
4044
"@tailwindcss/vite": "^4.0.8",
4145
"@tanstack/react-query": "^5.66.9",
42-
"@tanstack/react-router": "^1.111.3",
43-
"@tanstack/router-devtools": "^1.111.3",
46+
"@tanstack/react-router": "^1.111.7",
47+
"@tanstack/router-devtools": "^1.111.7",
4448
"class-variance-authority": "^0.7.1",
4549
"clsx": "^2.1.1",
4650
"i18next": "^24.2.2",

0 commit comments

Comments
 (0)