@lark-apaas/fullstack-cli 1.1.38 → 1.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -47
- package/package.json +2 -3
- package/templates/scripts/build.sh +50 -12
package/dist/index.js
CHANGED
|
@@ -2438,13 +2438,6 @@ var syncConfig = {
|
|
|
2438
2438
|
to: ".spark_project",
|
|
2439
2439
|
type: "file",
|
|
2440
2440
|
overwrite: true
|
|
2441
|
-
},
|
|
2442
|
-
// 9. 确保 tsconfig.app.json 排除 shared/static 目录(避免 TSC 严格校验 JSON 导致编译失败)
|
|
2443
|
-
{
|
|
2444
|
-
type: "ensure-json-array-item",
|
|
2445
|
-
to: "tsconfig.app.json",
|
|
2446
|
-
jsonPath: "exclude",
|
|
2447
|
-
items: ["shared/static"]
|
|
2448
2441
|
}
|
|
2449
2442
|
],
|
|
2450
2443
|
// 文件权限设置
|
|
@@ -2699,11 +2692,6 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2699
2692
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2700
2693
|
return;
|
|
2701
2694
|
}
|
|
2702
|
-
if (rule.type === "ensure-json-array-item") {
|
|
2703
|
-
const destPath2 = path5.join(userProjectRoot, rule.to);
|
|
2704
|
-
ensureJsonArrayItem(destPath2, rule.jsonPath, rule.items);
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2707
2695
|
if (!("from" in rule)) {
|
|
2708
2696
|
return;
|
|
2709
2697
|
}
|
|
@@ -2846,41 +2834,6 @@ function addLineToFile(filePath, line) {
|
|
|
2846
2834
|
fs7.appendFileSync(filePath, appendContent);
|
|
2847
2835
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
2848
2836
|
}
|
|
2849
|
-
function ensureJsonArrayItem(filePath, jsonPath, items) {
|
|
2850
|
-
const fileName = path5.basename(filePath);
|
|
2851
|
-
if (!fs7.existsSync(filePath)) {
|
|
2852
|
-
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
2853
|
-
return;
|
|
2854
|
-
}
|
|
2855
|
-
const content = JSON.parse(fs7.readFileSync(filePath, "utf-8"));
|
|
2856
|
-
const parts = jsonPath.split(".");
|
|
2857
|
-
let current = content;
|
|
2858
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
2859
|
-
const part = parts[i];
|
|
2860
|
-
if (current[part] == null || typeof current[part] !== "object") {
|
|
2861
|
-
current[part] = {};
|
|
2862
|
-
}
|
|
2863
|
-
current = current[part];
|
|
2864
|
-
}
|
|
2865
|
-
const lastKey = parts[parts.length - 1];
|
|
2866
|
-
if (!Array.isArray(current[lastKey])) {
|
|
2867
|
-
current[lastKey] = [];
|
|
2868
|
-
}
|
|
2869
|
-
const arr = current[lastKey];
|
|
2870
|
-
const added = [];
|
|
2871
|
-
for (const item of items) {
|
|
2872
|
-
if (!arr.includes(item)) {
|
|
2873
|
-
arr.push(item);
|
|
2874
|
-
added.push(item);
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
if (added.length === 0) {
|
|
2878
|
-
console.log(`[fullstack-cli] \u25CB ${fileName} ${jsonPath} (already contains all items)`);
|
|
2879
|
-
return;
|
|
2880
|
-
}
|
|
2881
|
-
fs7.writeFileSync(filePath, JSON.stringify(content, null, 2) + "\n");
|
|
2882
|
-
console.log(`[fullstack-cli] \u2713 ${fileName} ${jsonPath} (added: ${added.join(", ")})`);
|
|
2883
|
-
}
|
|
2884
2837
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
2885
2838
|
const fileName = path5.basename(dest);
|
|
2886
2839
|
if (!fs7.existsSync(src)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.39",
|
|
4
4
|
"description": "CLI tool for fullstack template management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -56,6 +56,5 @@
|
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"typescript": "^5.9.2"
|
|
59
|
-
}
|
|
60
|
-
"migrationVersion": 1
|
|
59
|
+
}
|
|
61
60
|
}
|
|
@@ -19,32 +19,69 @@ print_time() {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
# ==================== 步骤 0 ====================
|
|
22
|
-
echo "🗑️ [0/
|
|
22
|
+
echo "🗑️ [0/6] 安装插件"
|
|
23
23
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
24
24
|
npx fullstack-cli action-plugin init
|
|
25
25
|
print_time $STEP_START
|
|
26
26
|
echo ""
|
|
27
27
|
|
|
28
28
|
# ==================== 步骤 1 ====================
|
|
29
|
-
echo "📝 [1/
|
|
29
|
+
echo "📝 [1/6] 更新 openapi 代码"
|
|
30
30
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
31
31
|
npm run gen:openapi
|
|
32
32
|
print_time $STEP_START
|
|
33
33
|
echo ""
|
|
34
34
|
|
|
35
35
|
# ==================== 步骤 2 ====================
|
|
36
|
-
echo "🗑️ [2/
|
|
36
|
+
echo "🗑️ [2/6] 清理 dist 目录"
|
|
37
37
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
38
38
|
rm -rf "$ROOT_DIR/dist"
|
|
39
39
|
print_time $STEP_START
|
|
40
40
|
echo ""
|
|
41
41
|
|
|
42
42
|
# ==================== 步骤 3 ====================
|
|
43
|
+
echo "🗺️ [3/6] 生成路由定义"
|
|
44
|
+
STEP_START=$(node -e "console.log(Date.now())")
|
|
45
|
+
|
|
46
|
+
# 在 client/server 构建之前生成到 dist/,供 DefinePlugin 注入前端 bundle
|
|
47
|
+
# 注意:nest-cli.json 中 deleteOutDir 必须为 false(模板默认值),否则 nest build 会清掉 dist/
|
|
48
|
+
echo " ├─ 生成 API 路由定义..."
|
|
49
|
+
npx generate-api-routes --server-dir ./server --out-dir ./dist > /tmp/gen-api-routes.log 2>&1 &
|
|
50
|
+
API_ROUTES_PID=$!
|
|
51
|
+
|
|
52
|
+
echo " ├─ 生成页面路由定义..."
|
|
53
|
+
npx generate-page-routes --app-path ./client/src/app.tsx --out-dir ./dist > /tmp/gen-page-routes.log 2>&1 &
|
|
54
|
+
PAGE_ROUTES_PID=$!
|
|
55
|
+
|
|
56
|
+
API_ROUTES_EXIT=0
|
|
57
|
+
PAGE_ROUTES_EXIT=0
|
|
58
|
+
|
|
59
|
+
wait $API_ROUTES_PID || API_ROUTES_EXIT=$?
|
|
60
|
+
wait $PAGE_ROUTES_PID || PAGE_ROUTES_EXIT=$?
|
|
61
|
+
|
|
62
|
+
if [ $API_ROUTES_EXIT -ne 0 ]; then
|
|
63
|
+
echo " ⚠️ API 路由生成失败(不影响构建)"
|
|
64
|
+
cat /tmp/gen-api-routes.log
|
|
65
|
+
else
|
|
66
|
+
echo " ✅ API 路由生成完成"
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
if [ $PAGE_ROUTES_EXIT -ne 0 ]; then
|
|
70
|
+
echo " ⚠️ 页面路由生成失败(不影响构建)"
|
|
71
|
+
cat /tmp/gen-page-routes.log
|
|
72
|
+
else
|
|
73
|
+
echo " ✅ 页面路由生成完成"
|
|
74
|
+
fi
|
|
75
|
+
print_time $STEP_START
|
|
76
|
+
echo ""
|
|
77
|
+
|
|
78
|
+
# ==================== 步骤 4 ====================
|
|
79
|
+
echo "🔨 [4/6] 并行构建 server 和 client"
|
|
43
80
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
44
81
|
|
|
45
82
|
# 根据 only_frontend_change 决定是否构建 server
|
|
46
83
|
if [[ "${only_frontend_change:-false}" == "true" ]]; then
|
|
47
|
-
echo "🔨 [
|
|
84
|
+
echo "🔨 [4/6] 仅构建 client (only_frontend_change=true)"
|
|
48
85
|
|
|
49
86
|
echo " ├─ 启动 client 构建..."
|
|
50
87
|
npm run build:client > /tmp/build-client.log 2>&1
|
|
@@ -58,7 +95,7 @@ if [[ "${only_frontend_change:-false}" == "true" ]]; then
|
|
|
58
95
|
|
|
59
96
|
echo " ✅ Client 构建完成"
|
|
60
97
|
else
|
|
61
|
-
echo "🔨 [
|
|
98
|
+
echo "🔨 [4/6] 并行构建 server 和 client"
|
|
62
99
|
|
|
63
100
|
# 并行构建
|
|
64
101
|
echo " ├─ 启动 server 构建..."
|
|
@@ -96,15 +133,15 @@ fi
|
|
|
96
133
|
print_time $STEP_START
|
|
97
134
|
echo ""
|
|
98
135
|
|
|
99
|
-
# ==================== 步骤
|
|
100
|
-
echo "📦 [
|
|
136
|
+
# ==================== 步骤 5 ====================
|
|
137
|
+
echo "📦 [5/6] 准备产物"
|
|
101
138
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
102
139
|
|
|
103
140
|
# 移动 client 下的 HTML 文件到 dist/dist/client,保证 views 路径在 dev/prod 下一致
|
|
104
|
-
# HTML
|
|
141
|
+
# 使用 mv 而非 cp:HTML 不能上传到公网 CDN,移走后 dist/client 中不再包含 HTML
|
|
105
142
|
if [ -d "$DIST_DIR/client" ]; then
|
|
106
143
|
mkdir -p "$DIST_DIR/dist/client"
|
|
107
|
-
find "$DIST_DIR/client" -maxdepth 1 -name "*.html" -exec
|
|
144
|
+
find "$DIST_DIR/client" -maxdepth 1 -name "*.html" -exec mv {} "$DIST_DIR/dist/client/" \;
|
|
108
145
|
fi
|
|
109
146
|
|
|
110
147
|
# server 相关产物准备(only_frontend_change=true 时跳过)
|
|
@@ -127,14 +164,15 @@ rm -rf "$DIST_DIR/tsconfig.node.tsbuildinfo"
|
|
|
127
164
|
print_time $STEP_START
|
|
128
165
|
echo ""
|
|
129
166
|
|
|
130
|
-
# ==================== 步骤
|
|
167
|
+
# ==================== 步骤 6 ====================
|
|
168
|
+
echo "✂️ [6/6] 智能依赖裁剪"
|
|
131
169
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
132
170
|
|
|
133
171
|
# 智能依赖裁剪(仅全量构建时执行,纯前端场景不打包 server,无需裁剪)
|
|
134
172
|
if [[ "${only_frontend_change:-false}" == "true" ]]; then
|
|
135
|
-
echo "✂️ [
|
|
173
|
+
echo "✂️ [6/6] 跳过智能依赖裁剪 (only_frontend_change=true)"
|
|
136
174
|
else
|
|
137
|
-
echo "✂️ [
|
|
175
|
+
echo "✂️ [6/6] 智能依赖裁剪"
|
|
138
176
|
|
|
139
177
|
# 分析实际依赖、复制并裁剪 node_modules、生成精简的 package.json
|
|
140
178
|
node "$ROOT_DIR/scripts/prune-smart.js"
|