11#! /bin/bash
2- rm -rf ../boot/src/main/resources/static/assets/*
32
4- mkdir -p ../boot/src/main/resources/static/assets/
5- cp dist/vite.svg ../boot/src/main/resources/static/
6- cp -R dist/assets/* ../boot/src/main/resources/static/assets/
3+ echo " Copy asserts into SpringBoot resources"
4+ # 定义目标路径
5+ BASE_DIR=" ../boot/src/main/resources"
6+ STATIC_DIR=" $BASE_DIR /static"
7+ ASSETS_DIR=" $STATIC_DIR /assets"
8+ TEMPLATES_DIR=" $BASE_DIR /templates"
9+ SRC_DIR=" dist"
710
8- mkdir -p ../boot/src/main/resources/templates
9- cp dist/index.html ../boot/src/main/resources/templates/index.html
11+ # 检查 dist 目录是否存在
12+ if [ ! -d " $SRC_DIR " ]; then
13+ echo " fail: $SRC_DIR not exists"
14+ exit 1
15+ fi
1016
11- echo " copy success"
17+ # 确定使用 sed 还是 gsed
18+ if [[ " $OSTYPE " == " darwin" * ]]; then
19+ SED_CMD=" gsed"
20+ if ! command -v gsed & > /dev/null; then
21+ echo " fail: macOS need install gsed (by 'brew install gnu-sed')"
22+ exit 1
23+ fi
24+ else
25+ SED_CMD=" sed"
26+ fi
27+
28+ # 创建目录(如果不存在)
29+ mkdir -p " $ASSETS_DIR " " $TEMPLATES_DIR "
30+
31+ # 检查并清理 assets 目录
32+ rm -rf " $ASSETS_DIR " /*
33+
34+ # 复制静态文件
35+ cp " $SRC_DIR /vite.svg" " $STATIC_DIR /"
36+ cp -R " $SRC_DIR /assets/" * " $ASSETS_DIR /"
37+
38+ # 处理 index.html
39+ INDEX_SRC=" $SRC_DIR /index.html"
40+ INDEX_DEST=" $TEMPLATES_DIR /index.html"
41+
42+ if [ ! -f " $INDEX_SRC " ]; then
43+ echo " fail: $INDEX_SRC not exists, make sure you had built frontend project with bun run build"
44+ exit 1
45+ fi
46+
47+ # 创建临时文件进行 thymeleaf 语法转换
48+ TEMP_FILE=$( mktemp)
49+ cp " $INDEX_SRC " " $TEMP_FILE "
50+
51+ " $SED_CMD " -i ' s/href="\([^"]*\)"/th:href="@{\1}"/g' " $TEMP_FILE "
52+ " $SED_CMD " -i ' s/src="\([^"]*\)"/th:src="@{\1}"/g' " $TEMP_FILE "
53+
54+ cp " $TEMP_FILE " " $INDEX_DEST "
55+ rm " $TEMP_FILE "
56+ echo " SpringBoot resources update successfully"
0 commit comments