@lark-apaas/fullstack-cli 1.1.30 → 1.1.31
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 +86 -4
- package/package.json +1 -1
- package/templates/scripts/build.sh +15 -14
- package/templates/scripts/prune-smart.js +4 -6
- package/templates/scripts/run.sh +4 -1
package/dist/index.js
CHANGED
|
@@ -2377,12 +2377,15 @@ var syncConfig = {
|
|
|
2377
2377
|
type: "directory",
|
|
2378
2378
|
overwrite: true
|
|
2379
2379
|
},
|
|
2380
|
-
// 2.
|
|
2380
|
+
// 2. 智能合并 nest-cli.json 配置(保留用户自定义的 assets、plugins 等)
|
|
2381
2381
|
{
|
|
2382
2382
|
from: "templates/nest-cli.json",
|
|
2383
2383
|
to: "nest-cli.json",
|
|
2384
|
-
type: "
|
|
2385
|
-
|
|
2384
|
+
type: "merge-json",
|
|
2385
|
+
arrayMerge: {
|
|
2386
|
+
"compilerOptions.assets": { key: "include" },
|
|
2387
|
+
"compilerOptions.plugins": { key: "name" }
|
|
2388
|
+
}
|
|
2386
2389
|
},
|
|
2387
2390
|
// // 2. 追加内容到 .gitignore
|
|
2388
2391
|
// {
|
|
@@ -2475,6 +2478,52 @@ function removeLineFromFile(filePath, pattern) {
|
|
|
2475
2478
|
return true;
|
|
2476
2479
|
}
|
|
2477
2480
|
|
|
2481
|
+
// src/utils/merge-json.ts
|
|
2482
|
+
function isPlainObject(value) {
|
|
2483
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2484
|
+
}
|
|
2485
|
+
function mergeArrayByKey(userArr, templateArr, key) {
|
|
2486
|
+
const result = [...userArr];
|
|
2487
|
+
for (const templateItem of templateArr) {
|
|
2488
|
+
if (!isPlainObject(templateItem)) continue;
|
|
2489
|
+
const templateKey = templateItem[key];
|
|
2490
|
+
const existingIndex = result.findIndex(
|
|
2491
|
+
(item) => isPlainObject(item) && item[key] === templateKey
|
|
2492
|
+
);
|
|
2493
|
+
if (existingIndex >= 0) {
|
|
2494
|
+
result[existingIndex] = templateItem;
|
|
2495
|
+
} else {
|
|
2496
|
+
result.push(templateItem);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
return result;
|
|
2500
|
+
}
|
|
2501
|
+
function deepMergeJson(user, template, arrayMerge = {}, currentPath = "") {
|
|
2502
|
+
const result = { ...user };
|
|
2503
|
+
for (const key of Object.keys(template)) {
|
|
2504
|
+
const fullPath = currentPath ? `${currentPath}.${key}` : key;
|
|
2505
|
+
const templateValue = template[key];
|
|
2506
|
+
const userValue = user[key];
|
|
2507
|
+
if (Array.isArray(templateValue)) {
|
|
2508
|
+
const mergeConfig = arrayMerge[fullPath];
|
|
2509
|
+
if (mergeConfig && Array.isArray(userValue)) {
|
|
2510
|
+
result[key] = mergeArrayByKey(userValue, templateValue, mergeConfig.key);
|
|
2511
|
+
} else {
|
|
2512
|
+
result[key] = templateValue;
|
|
2513
|
+
}
|
|
2514
|
+
} else if (isPlainObject(templateValue)) {
|
|
2515
|
+
if (isPlainObject(userValue)) {
|
|
2516
|
+
result[key] = deepMergeJson(userValue, templateValue, arrayMerge, fullPath);
|
|
2517
|
+
} else {
|
|
2518
|
+
result[key] = templateValue;
|
|
2519
|
+
}
|
|
2520
|
+
} else {
|
|
2521
|
+
result[key] = templateValue;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
return result;
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2478
2527
|
// src/commands/sync/run.handler.ts
|
|
2479
2528
|
async function run2(options) {
|
|
2480
2529
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
@@ -2537,6 +2586,12 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2537
2586
|
addLineToFile(destPath2, rule.line);
|
|
2538
2587
|
return;
|
|
2539
2588
|
}
|
|
2589
|
+
if (rule.type === "merge-json") {
|
|
2590
|
+
const srcPath2 = path4.join(pluginRoot, rule.from);
|
|
2591
|
+
const destPath2 = path4.join(userProjectRoot, rule.to);
|
|
2592
|
+
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2593
|
+
return;
|
|
2594
|
+
}
|
|
2540
2595
|
if (!("from" in rule)) {
|
|
2541
2596
|
return;
|
|
2542
2597
|
}
|
|
@@ -2679,6 +2734,33 @@ function addLineToFile(filePath, line) {
|
|
|
2679
2734
|
fs6.appendFileSync(filePath, appendContent);
|
|
2680
2735
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
2681
2736
|
}
|
|
2737
|
+
function mergeJsonFile(src, dest, arrayMerge) {
|
|
2738
|
+
const fileName = path4.basename(dest);
|
|
2739
|
+
if (!fs6.existsSync(src)) {
|
|
2740
|
+
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
2741
|
+
return;
|
|
2742
|
+
}
|
|
2743
|
+
const templateContent = JSON.parse(fs6.readFileSync(src, "utf-8"));
|
|
2744
|
+
if (!fs6.existsSync(dest)) {
|
|
2745
|
+
const destDir = path4.dirname(dest);
|
|
2746
|
+
if (!fs6.existsSync(destDir)) {
|
|
2747
|
+
fs6.mkdirSync(destDir, { recursive: true });
|
|
2748
|
+
}
|
|
2749
|
+
fs6.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
2750
|
+
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
2751
|
+
return;
|
|
2752
|
+
}
|
|
2753
|
+
const userContent = JSON.parse(fs6.readFileSync(dest, "utf-8"));
|
|
2754
|
+
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
2755
|
+
const userStr = JSON.stringify(userContent, null, 2);
|
|
2756
|
+
const mergedStr = JSON.stringify(merged, null, 2);
|
|
2757
|
+
if (userStr === mergedStr) {
|
|
2758
|
+
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
fs6.writeFileSync(dest, mergedStr + "\n");
|
|
2762
|
+
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
2763
|
+
}
|
|
2682
2764
|
|
|
2683
2765
|
// src/commands/sync/index.ts
|
|
2684
2766
|
var syncCommand = {
|
|
@@ -2935,7 +3017,7 @@ function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
|
2935
3017
|
const syncConfig2 = genSyncConfig({ disableGenOpenapi });
|
|
2936
3018
|
const filesToStage = /* @__PURE__ */ new Set();
|
|
2937
3019
|
syncConfig2.sync.forEach((rule) => {
|
|
2938
|
-
if (rule.type === "file" || rule.type === "directory") {
|
|
3020
|
+
if (rule.type === "file" || rule.type === "directory" || rule.type === "merge-json") {
|
|
2939
3021
|
filesToStage.add(rule.to);
|
|
2940
3022
|
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
2941
3023
|
filesToStage.add(rule.to);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
set -euo pipefail
|
|
4
4
|
|
|
5
5
|
ROOT_DIR="$(pwd)"
|
|
6
|
-
|
|
6
|
+
DIST_DIR="$ROOT_DIR/dist"
|
|
7
7
|
|
|
8
8
|
# 记录总开始时间
|
|
9
9
|
TOTAL_START=$(node -e "console.log(Date.now())")
|
|
@@ -78,25 +78,26 @@ print_time $STEP_START
|
|
|
78
78
|
echo ""
|
|
79
79
|
|
|
80
80
|
# ==================== 步骤 4 ====================
|
|
81
|
-
echo "📦 [4/5]
|
|
81
|
+
echo "📦 [4/5] 准备产物"
|
|
82
82
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# 移动 HTML(从 dist/client 移走,避免残留)
|
|
87
|
-
mv "$ROOT_DIR/dist/client/"*.html "$OUT_DIR/dist/client/" || true
|
|
88
|
-
|
|
89
|
-
# 拷贝 run.sh 文件
|
|
90
|
-
cp "$ROOT_DIR/scripts/run.sh" "$OUT_DIR/"
|
|
84
|
+
# 拷贝 run.sh 到 dist/(prod 从 dist/ 启动,确保 cwd 一致性)
|
|
85
|
+
cp "$ROOT_DIR/scripts/run.sh" "$DIST_DIR/"
|
|
91
86
|
|
|
92
87
|
# 拷贝 .env 文件(如果存在)
|
|
93
88
|
if [ -f "$ROOT_DIR/.env" ]; then
|
|
94
|
-
cp "$ROOT_DIR/.env" "$
|
|
89
|
+
cp "$ROOT_DIR/.env" "$DIST_DIR/"
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
# 移动 client 下的 HTML 文件到 dist/dist/client,保证 views 路径在 dev/prod 下一致
|
|
93
|
+
if [ -d "$DIST_DIR/client" ]; then
|
|
94
|
+
mkdir -p "$DIST_DIR/dist/client"
|
|
95
|
+
find "$DIST_DIR/client" -maxdepth 1 -name "*.html" -exec mv {} "$DIST_DIR/dist/client/" \;
|
|
95
96
|
fi
|
|
96
97
|
|
|
97
98
|
# 清理无用文件
|
|
98
|
-
rm -rf "$
|
|
99
|
-
rm -rf "$
|
|
99
|
+
rm -rf "$DIST_DIR/scripts"
|
|
100
|
+
rm -rf "$DIST_DIR/tsconfig.node.tsbuildinfo"
|
|
100
101
|
|
|
101
102
|
print_time $STEP_START
|
|
102
103
|
echo ""
|
|
@@ -116,8 +117,8 @@ echo "构建完成"
|
|
|
116
117
|
print_time $TOTAL_START
|
|
117
118
|
|
|
118
119
|
# 输出产物信息
|
|
119
|
-
DIST_SIZE=$(du -sh "$
|
|
120
|
-
NODE_MODULES_SIZE=$(du -sh "$
|
|
120
|
+
DIST_SIZE=$(du -sh "$DIST_DIR" | cut -f1)
|
|
121
|
+
NODE_MODULES_SIZE=$(du -sh "$DIST_DIR/node_modules" | cut -f1)
|
|
121
122
|
echo ""
|
|
122
123
|
echo "📊 构建产物统计:"
|
|
123
124
|
echo " 产物大小: $DIST_SIZE"
|
|
@@ -6,11 +6,12 @@ const fs = require('fs');
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
|
|
8
8
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
|
9
|
-
const
|
|
9
|
+
const DIST_DIR = path.join(ROOT_DIR, 'dist');
|
|
10
|
+
const DIST_SERVER_DIR = path.join(DIST_DIR, 'server');
|
|
10
11
|
const ROOT_PACKAGE_JSON = path.join(ROOT_DIR, 'package.json');
|
|
11
12
|
const ROOT_NODE_MODULES = path.join(ROOT_DIR, 'node_modules');
|
|
12
|
-
const OUT_NODE_MODULES = path.join(
|
|
13
|
-
const OUT_PACKAGE_JSON = path.join(
|
|
13
|
+
const OUT_NODE_MODULES = path.join(DIST_DIR, 'node_modules');
|
|
14
|
+
const OUT_PACKAGE_JSON = path.join(DIST_DIR, 'package.json');
|
|
14
15
|
|
|
15
16
|
// Server 入口文件
|
|
16
17
|
const SERVER_ENTRY = path.join(DIST_SERVER_DIR, 'main.js');
|
|
@@ -294,9 +295,6 @@ async function smartPrune() {
|
|
|
294
295
|
version: originalPackage.version,
|
|
295
296
|
private: true,
|
|
296
297
|
dependencies: prunedDependencies,
|
|
297
|
-
scripts: {
|
|
298
|
-
start: originalPackage.scripts?.start || 'node main.js'
|
|
299
|
-
},
|
|
300
298
|
engines: originalPackage.engines
|
|
301
299
|
};
|
|
302
300
|
|
package/templates/scripts/run.sh
CHANGED