@lark-apaas/fullstack-cli 1.1.45-alpha.6 → 1.1.45-beta.0
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 +184 -181
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2365,8 +2365,8 @@ var genDbSchemaCommand = {
|
|
|
2365
2365
|
};
|
|
2366
2366
|
|
|
2367
2367
|
// src/commands/sync/run.handler.ts
|
|
2368
|
-
import
|
|
2369
|
-
import
|
|
2368
|
+
import path5 from "path";
|
|
2369
|
+
import fs7 from "fs";
|
|
2370
2370
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2371
2371
|
|
|
2372
2372
|
// src/config/sync.ts
|
|
@@ -2395,7 +2395,7 @@ var syncConfig = {
|
|
|
2395
2395
|
command: "chmod +x .githooks/pre-commit 2>/dev/null; git config core.hooksPath .githooks 2>/dev/null || true",
|
|
2396
2396
|
overwrite: false
|
|
2397
2397
|
},
|
|
2398
|
-
// 1c. scripts.precommit = pre-commit
|
|
2398
|
+
// 1c. scripts.precommit = pre-commit 真正的执行体(跑 npm run lint)
|
|
2399
2399
|
{
|
|
2400
2400
|
type: "add-script",
|
|
2401
2401
|
name: "precommit",
|
|
@@ -2462,6 +2462,14 @@ var syncConfig = {
|
|
|
2462
2462
|
to: ".spark_project",
|
|
2463
2463
|
type: "file",
|
|
2464
2464
|
overwrite: true
|
|
2465
|
+
},
|
|
2466
|
+
// 9. 把模板版本的 lint 脚本替换为支持 --files 的 runner
|
|
2467
|
+
// 只识别平台模板生成的 `concurrently ...` 形态,用户真正改写过的脚本保持原样
|
|
2468
|
+
{
|
|
2469
|
+
type: "patch-script",
|
|
2470
|
+
name: "lint",
|
|
2471
|
+
to: "node ./scripts/lint.js",
|
|
2472
|
+
ifStartsWith: "concurrently "
|
|
2465
2473
|
}
|
|
2466
2474
|
],
|
|
2467
2475
|
// 文件权限设置
|
|
@@ -2549,97 +2557,22 @@ function deepMergeJson(user, template, arrayMerge = {}, currentPath = "") {
|
|
|
2549
2557
|
return result;
|
|
2550
2558
|
}
|
|
2551
2559
|
|
|
2552
|
-
// src/
|
|
2560
|
+
// src/commands/sync/activate-hooks.ts
|
|
2553
2561
|
import fs6 from "fs";
|
|
2554
2562
|
import path4 from "path";
|
|
2555
|
-
var LEGACY_LINT_SCRIPT = 'concurrently "npm run eslint" "npm run type:check" "npm run stylelint"';
|
|
2556
|
-
var PATCHED_LINT_SCRIPT = "node ./scripts/lint.js";
|
|
2557
|
-
function readPackageJson(cwd = process.cwd()) {
|
|
2558
|
-
const pkgPath = path4.join(cwd, "package.json");
|
|
2559
|
-
if (!fs6.existsSync(pkgPath)) {
|
|
2560
|
-
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2561
|
-
}
|
|
2562
|
-
const content = fs6.readFileSync(pkgPath, "utf-8");
|
|
2563
|
-
return JSON.parse(content);
|
|
2564
|
-
}
|
|
2565
|
-
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2566
|
-
const pkgPath = path4.join(cwd, "package.json");
|
|
2567
|
-
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
2568
|
-
fs6.writeFileSync(pkgPath, content, "utf-8");
|
|
2569
|
-
}
|
|
2570
|
-
function patchLintScriptForFilesSupport(pkg2) {
|
|
2571
|
-
const currentLint = pkg2.scripts?.lint;
|
|
2572
|
-
if (!currentLint) {
|
|
2573
|
-
return "skipped-missing";
|
|
2574
|
-
}
|
|
2575
|
-
if (currentLint === PATCHED_LINT_SCRIPT || currentLint === "node scripts/lint.js") {
|
|
2576
|
-
return "already-patched";
|
|
2577
|
-
}
|
|
2578
|
-
if (currentLint !== LEGACY_LINT_SCRIPT) {
|
|
2579
|
-
return "skipped-custom";
|
|
2580
|
-
}
|
|
2581
|
-
pkg2.scripts = pkg2.scripts || {};
|
|
2582
|
-
pkg2.scripts.lint = PATCHED_LINT_SCRIPT;
|
|
2583
|
-
return "patched";
|
|
2584
|
-
}
|
|
2585
|
-
function removeUpgradeScript(pkg2) {
|
|
2586
|
-
if (!pkg2.scripts?.upgrade) {
|
|
2587
|
-
return false;
|
|
2588
|
-
}
|
|
2589
|
-
delete pkg2.scripts.upgrade;
|
|
2590
|
-
return true;
|
|
2591
|
-
}
|
|
2592
|
-
function cleanDevScript(pkg2) {
|
|
2593
|
-
if (!pkg2.scripts?.dev) {
|
|
2594
|
-
return false;
|
|
2595
|
-
}
|
|
2596
|
-
const originalDev = pkg2.scripts.dev;
|
|
2597
|
-
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
2598
|
-
if (cleanedDev !== originalDev) {
|
|
2599
|
-
pkg2.scripts.dev = cleanedDev;
|
|
2600
|
-
return true;
|
|
2601
|
-
}
|
|
2602
|
-
return false;
|
|
2603
|
-
}
|
|
2604
|
-
function cleanupPackageJson(cwd = process.cwd()) {
|
|
2605
|
-
try {
|
|
2606
|
-
const pkg2 = readPackageJson(cwd);
|
|
2607
|
-
let changed = false;
|
|
2608
|
-
if (removeUpgradeScript(pkg2)) {
|
|
2609
|
-
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
2610
|
-
changed = true;
|
|
2611
|
-
}
|
|
2612
|
-
if (cleanDevScript(pkg2)) {
|
|
2613
|
-
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
2614
|
-
changed = true;
|
|
2615
|
-
}
|
|
2616
|
-
if (changed) {
|
|
2617
|
-
writePackageJson(pkg2, cwd);
|
|
2618
|
-
}
|
|
2619
|
-
return changed;
|
|
2620
|
-
} catch (error) {
|
|
2621
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2622
|
-
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
2623
|
-
return false;
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
// src/commands/sync/activate-hooks.ts
|
|
2628
|
-
import fs7 from "fs";
|
|
2629
|
-
import path5 from "path";
|
|
2630
2563
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
2631
2564
|
function activateGitHooks(userProjectRoot) {
|
|
2632
|
-
if (!
|
|
2565
|
+
if (!fs6.existsSync(path4.join(userProjectRoot, ".git"))) {
|
|
2633
2566
|
return { action: "skipped-no-git" };
|
|
2634
2567
|
}
|
|
2635
|
-
const hookFile =
|
|
2636
|
-
if (!
|
|
2568
|
+
const hookFile = path4.join(userProjectRoot, ".githooks", "pre-commit");
|
|
2569
|
+
if (!fs6.existsSync(hookFile)) {
|
|
2637
2570
|
return { action: "skipped-no-hook-file" };
|
|
2638
2571
|
}
|
|
2639
2572
|
let changed = false;
|
|
2640
|
-
const currentMode =
|
|
2573
|
+
const currentMode = fs6.statSync(hookFile).mode & 511;
|
|
2641
2574
|
if ((currentMode & 73) !== 73) {
|
|
2642
|
-
|
|
2575
|
+
fs6.chmodSync(hookFile, 493);
|
|
2643
2576
|
changed = true;
|
|
2644
2577
|
}
|
|
2645
2578
|
const probe = spawnSync2("git", ["config", "--get", "core.hooksPath"], {
|
|
@@ -2668,14 +2601,14 @@ function activateGitHooks(userProjectRoot) {
|
|
|
2668
2601
|
async function run2(options) {
|
|
2669
2602
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2670
2603
|
const __filename = fileURLToPath3(import.meta.url);
|
|
2671
|
-
const __dirname2 =
|
|
2672
|
-
const pluginRoot =
|
|
2604
|
+
const __dirname2 = path5.dirname(__filename);
|
|
2605
|
+
const pluginRoot = path5.resolve(__dirname2, "..");
|
|
2673
2606
|
if (userProjectRoot === pluginRoot) {
|
|
2674
2607
|
console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
|
|
2675
2608
|
process.exit(0);
|
|
2676
2609
|
}
|
|
2677
|
-
const userPackageJson =
|
|
2678
|
-
if (!
|
|
2610
|
+
const userPackageJson = path5.join(userProjectRoot, "package.json");
|
|
2611
|
+
if (!fs7.existsSync(userPackageJson)) {
|
|
2679
2612
|
console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
|
|
2680
2613
|
process.exit(0);
|
|
2681
2614
|
}
|
|
@@ -2691,7 +2624,6 @@ async function run2(options) {
|
|
|
2691
2624
|
for (const rule of config.sync) {
|
|
2692
2625
|
await syncRule(rule, pluginRoot, userProjectRoot);
|
|
2693
2626
|
}
|
|
2694
|
-
patchUserPackageJson(userProjectRoot);
|
|
2695
2627
|
if (config.permissions) {
|
|
2696
2628
|
setPermissions(config.permissions, userProjectRoot);
|
|
2697
2629
|
}
|
|
@@ -2708,32 +2640,9 @@ async function run2(options) {
|
|
|
2708
2640
|
process.exit(1);
|
|
2709
2641
|
}
|
|
2710
2642
|
}
|
|
2711
|
-
function patchUserPackageJson(userProjectRoot) {
|
|
2712
|
-
try {
|
|
2713
|
-
const pkg2 = readPackageJson(userProjectRoot);
|
|
2714
|
-
const lintPatchResult = patchLintScriptForFilesSupport(pkg2);
|
|
2715
|
-
if (lintPatchResult === "patched") {
|
|
2716
|
-
writePackageJson(pkg2, userProjectRoot);
|
|
2717
|
-
console.log("[fullstack-cli] \u2713 Patched scripts.lint to support --files");
|
|
2718
|
-
return;
|
|
2719
|
-
}
|
|
2720
|
-
if (lintPatchResult === "already-patched") {
|
|
2721
|
-
console.log("[fullstack-cli] \u25CB scripts.lint already supports --files");
|
|
2722
|
-
return;
|
|
2723
|
-
}
|
|
2724
|
-
if (lintPatchResult === "skipped-custom") {
|
|
2725
|
-
console.warn(
|
|
2726
|
-
"[fullstack-cli] \u26A0 Skipped patching scripts.lint because it has been customized"
|
|
2727
|
-
);
|
|
2728
|
-
}
|
|
2729
|
-
} catch (error) {
|
|
2730
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2731
|
-
console.warn(`[fullstack-cli] \u26A0 Could not patch package.json: ${message}`);
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
2643
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2735
2644
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2736
|
-
const destPath2 =
|
|
2645
|
+
const destPath2 = path5.join(userProjectRoot, rule.to);
|
|
2737
2646
|
if (rule.type === "delete-file") {
|
|
2738
2647
|
deleteFile(destPath2);
|
|
2739
2648
|
} else {
|
|
@@ -2742,32 +2651,37 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2742
2651
|
return;
|
|
2743
2652
|
}
|
|
2744
2653
|
if (rule.type === "remove-line") {
|
|
2745
|
-
const destPath2 =
|
|
2654
|
+
const destPath2 = path5.join(userProjectRoot, rule.to);
|
|
2746
2655
|
removeLineFromFile(destPath2, rule.pattern);
|
|
2747
2656
|
return;
|
|
2748
2657
|
}
|
|
2749
2658
|
if (rule.type === "add-script") {
|
|
2750
|
-
const packageJsonPath =
|
|
2659
|
+
const packageJsonPath = path5.join(userProjectRoot, "package.json");
|
|
2751
2660
|
addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
|
|
2752
2661
|
return;
|
|
2753
2662
|
}
|
|
2663
|
+
if (rule.type === "patch-script") {
|
|
2664
|
+
const packageJsonPath = path5.join(userProjectRoot, "package.json");
|
|
2665
|
+
patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2754
2668
|
if (rule.type === "add-line") {
|
|
2755
|
-
const destPath2 =
|
|
2669
|
+
const destPath2 = path5.join(userProjectRoot, rule.to);
|
|
2756
2670
|
addLineToFile(destPath2, rule.line);
|
|
2757
2671
|
return;
|
|
2758
2672
|
}
|
|
2759
2673
|
if (rule.type === "merge-json") {
|
|
2760
|
-
const srcPath2 =
|
|
2761
|
-
const destPath2 =
|
|
2674
|
+
const srcPath2 = path5.join(pluginRoot, rule.from);
|
|
2675
|
+
const destPath2 = path5.join(userProjectRoot, rule.to);
|
|
2762
2676
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2763
2677
|
return;
|
|
2764
2678
|
}
|
|
2765
2679
|
if (!("from" in rule)) {
|
|
2766
2680
|
return;
|
|
2767
2681
|
}
|
|
2768
|
-
const srcPath =
|
|
2769
|
-
const destPath =
|
|
2770
|
-
if (!
|
|
2682
|
+
const srcPath = path5.join(pluginRoot, rule.from);
|
|
2683
|
+
const destPath = path5.join(userProjectRoot, rule.to);
|
|
2684
|
+
if (!fs7.existsSync(srcPath)) {
|
|
2771
2685
|
console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
|
|
2772
2686
|
return;
|
|
2773
2687
|
}
|
|
@@ -2784,68 +2698,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2784
2698
|
}
|
|
2785
2699
|
}
|
|
2786
2700
|
function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
|
|
2787
|
-
if (onlyIfExists && !
|
|
2788
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2701
|
+
if (onlyIfExists && !fs7.existsSync(dest)) {
|
|
2702
|
+
console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (skipped, target not exists)`);
|
|
2789
2703
|
return;
|
|
2790
2704
|
}
|
|
2791
|
-
const destDir =
|
|
2792
|
-
if (!
|
|
2793
|
-
|
|
2705
|
+
const destDir = path5.dirname(dest);
|
|
2706
|
+
if (!fs7.existsSync(destDir)) {
|
|
2707
|
+
fs7.mkdirSync(destDir, { recursive: true });
|
|
2794
2708
|
}
|
|
2795
|
-
if (
|
|
2796
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2709
|
+
if (fs7.existsSync(dest) && !overwrite) {
|
|
2710
|
+
console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (skipped, already exists)`);
|
|
2797
2711
|
return;
|
|
2798
2712
|
}
|
|
2799
|
-
|
|
2800
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2713
|
+
fs7.copyFileSync(src, dest);
|
|
2714
|
+
console.log(`[fullstack-cli] \u2713 ${path5.basename(dest)}`);
|
|
2801
2715
|
}
|
|
2802
2716
|
function syncDirectory(src, dest, overwrite = true) {
|
|
2803
|
-
if (!
|
|
2804
|
-
|
|
2717
|
+
if (!fs7.existsSync(dest)) {
|
|
2718
|
+
fs7.mkdirSync(dest, { recursive: true });
|
|
2805
2719
|
}
|
|
2806
|
-
const files =
|
|
2720
|
+
const files = fs7.readdirSync(src);
|
|
2807
2721
|
let count = 0;
|
|
2808
2722
|
files.forEach((file) => {
|
|
2809
|
-
const srcFile =
|
|
2810
|
-
const destFile =
|
|
2811
|
-
const stats =
|
|
2723
|
+
const srcFile = path5.join(src, file);
|
|
2724
|
+
const destFile = path5.join(dest, file);
|
|
2725
|
+
const stats = fs7.statSync(srcFile);
|
|
2812
2726
|
if (stats.isDirectory()) {
|
|
2813
2727
|
syncDirectory(srcFile, destFile, overwrite);
|
|
2814
2728
|
} else {
|
|
2815
|
-
if (overwrite || !
|
|
2816
|
-
|
|
2817
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2729
|
+
if (overwrite || !fs7.existsSync(destFile)) {
|
|
2730
|
+
fs7.copyFileSync(srcFile, destFile);
|
|
2731
|
+
console.log(`[fullstack-cli] \u2713 ${path5.relative(dest, destFile)}`);
|
|
2818
2732
|
count++;
|
|
2819
2733
|
}
|
|
2820
2734
|
}
|
|
2821
2735
|
});
|
|
2822
2736
|
if (count > 0) {
|
|
2823
|
-
console.log(`[fullstack-cli] Synced ${count} files to ${
|
|
2737
|
+
console.log(`[fullstack-cli] Synced ${count} files to ${path5.basename(dest)}/`);
|
|
2824
2738
|
}
|
|
2825
2739
|
}
|
|
2826
2740
|
function appendToFile(src, dest) {
|
|
2827
|
-
const content =
|
|
2741
|
+
const content = fs7.readFileSync(src, "utf-8");
|
|
2828
2742
|
let existingContent = "";
|
|
2829
|
-
if (
|
|
2830
|
-
existingContent =
|
|
2743
|
+
if (fs7.existsSync(dest)) {
|
|
2744
|
+
existingContent = fs7.readFileSync(dest, "utf-8");
|
|
2831
2745
|
}
|
|
2832
2746
|
if (existingContent.includes(content.trim())) {
|
|
2833
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2747
|
+
console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (already contains content)`);
|
|
2834
2748
|
return;
|
|
2835
2749
|
}
|
|
2836
|
-
|
|
2837
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2750
|
+
fs7.appendFileSync(dest, content);
|
|
2751
|
+
console.log(`[fullstack-cli] \u2713 ${path5.basename(dest)} (appended)`);
|
|
2838
2752
|
}
|
|
2839
2753
|
function setPermissions(permissions, projectRoot) {
|
|
2840
2754
|
for (const [pattern, mode] of Object.entries(permissions)) {
|
|
2841
2755
|
if (pattern === "**/*.sh") {
|
|
2842
|
-
const scriptsDir =
|
|
2843
|
-
if (
|
|
2844
|
-
const files =
|
|
2756
|
+
const scriptsDir = path5.join(projectRoot, "scripts");
|
|
2757
|
+
if (fs7.existsSync(scriptsDir)) {
|
|
2758
|
+
const files = fs7.readdirSync(scriptsDir);
|
|
2845
2759
|
files.forEach((file) => {
|
|
2846
2760
|
if (file.endsWith(".sh")) {
|
|
2847
|
-
const filePath =
|
|
2848
|
-
|
|
2761
|
+
const filePath = path5.join(scriptsDir, file);
|
|
2762
|
+
fs7.chmodSync(filePath, mode);
|
|
2849
2763
|
}
|
|
2850
2764
|
});
|
|
2851
2765
|
}
|
|
@@ -2853,27 +2767,27 @@ function setPermissions(permissions, projectRoot) {
|
|
|
2853
2767
|
}
|
|
2854
2768
|
}
|
|
2855
2769
|
function deleteFile(filePath) {
|
|
2856
|
-
if (
|
|
2857
|
-
|
|
2858
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2770
|
+
if (fs7.existsSync(filePath)) {
|
|
2771
|
+
fs7.unlinkSync(filePath);
|
|
2772
|
+
console.log(`[fullstack-cli] \u2713 ${path5.basename(filePath)} (deleted)`);
|
|
2859
2773
|
} else {
|
|
2860
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2774
|
+
console.log(`[fullstack-cli] \u25CB ${path5.basename(filePath)} (not found)`);
|
|
2861
2775
|
}
|
|
2862
2776
|
}
|
|
2863
2777
|
function deleteDirectory(dirPath) {
|
|
2864
|
-
if (
|
|
2865
|
-
|
|
2866
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2778
|
+
if (fs7.existsSync(dirPath)) {
|
|
2779
|
+
fs7.rmSync(dirPath, { recursive: true });
|
|
2780
|
+
console.log(`[fullstack-cli] \u2713 ${path5.basename(dirPath)} (deleted)`);
|
|
2867
2781
|
} else {
|
|
2868
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2782
|
+
console.log(`[fullstack-cli] \u25CB ${path5.basename(dirPath)} (not found)`);
|
|
2869
2783
|
}
|
|
2870
2784
|
}
|
|
2871
2785
|
function addScript(packageJsonPath, name, command, overwrite) {
|
|
2872
|
-
if (!
|
|
2786
|
+
if (!fs7.existsSync(packageJsonPath)) {
|
|
2873
2787
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2874
2788
|
return;
|
|
2875
2789
|
}
|
|
2876
|
-
const content =
|
|
2790
|
+
const content = fs7.readFileSync(packageJsonPath, "utf-8");
|
|
2877
2791
|
const pkg2 = JSON.parse(content);
|
|
2878
2792
|
if (!pkg2.scripts) {
|
|
2879
2793
|
pkg2.scripts = {};
|
|
@@ -2885,42 +2799,73 @@ function addScript(packageJsonPath, name, command, overwrite) {
|
|
|
2885
2799
|
}
|
|
2886
2800
|
}
|
|
2887
2801
|
pkg2.scripts[name] = command;
|
|
2888
|
-
|
|
2802
|
+
fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2889
2803
|
console.log(`[fullstack-cli] \u2713 scripts.${name}`);
|
|
2890
2804
|
}
|
|
2805
|
+
function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
2806
|
+
if (!fs7.existsSync(packageJsonPath)) {
|
|
2807
|
+
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
try {
|
|
2811
|
+
const content = fs7.readFileSync(packageJsonPath, "utf-8");
|
|
2812
|
+
const pkg2 = JSON.parse(content);
|
|
2813
|
+
const current = pkg2.scripts?.[name];
|
|
2814
|
+
if (!current) {
|
|
2815
|
+
console.log(`[fullstack-cli] \u25CB scripts.${name} (not present, skipped)`);
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
if (current === to) {
|
|
2819
|
+
console.log(`[fullstack-cli] \u25CB scripts.${name} (already patched)`);
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
if (!current.startsWith(ifStartsWith)) {
|
|
2823
|
+
console.warn(
|
|
2824
|
+
`[fullstack-cli] \u26A0 Skipped patching scripts.${name} because it has been customized`
|
|
2825
|
+
);
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
pkg2.scripts[name] = to;
|
|
2829
|
+
fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2830
|
+
console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2833
|
+
console.warn(`[fullstack-cli] \u26A0 Could not patch scripts.${name}: ${message}`);
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2891
2836
|
function addLineToFile(filePath, line) {
|
|
2892
|
-
const fileName =
|
|
2893
|
-
if (!
|
|
2837
|
+
const fileName = path5.basename(filePath);
|
|
2838
|
+
if (!fs7.existsSync(filePath)) {
|
|
2894
2839
|
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
2895
2840
|
return;
|
|
2896
2841
|
}
|
|
2897
|
-
const content =
|
|
2842
|
+
const content = fs7.readFileSync(filePath, "utf-8");
|
|
2898
2843
|
const lines = content.split("\n").map((l) => l.trim());
|
|
2899
2844
|
if (lines.includes(line)) {
|
|
2900
2845
|
console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
|
|
2901
2846
|
return;
|
|
2902
2847
|
}
|
|
2903
2848
|
const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
|
|
2904
|
-
|
|
2849
|
+
fs7.appendFileSync(filePath, appendContent);
|
|
2905
2850
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
2906
2851
|
}
|
|
2907
2852
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
2908
|
-
const fileName =
|
|
2909
|
-
if (!
|
|
2853
|
+
const fileName = path5.basename(dest);
|
|
2854
|
+
if (!fs7.existsSync(src)) {
|
|
2910
2855
|
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
2911
2856
|
return;
|
|
2912
2857
|
}
|
|
2913
|
-
const templateContent = JSON.parse(
|
|
2914
|
-
if (!
|
|
2915
|
-
const destDir =
|
|
2916
|
-
if (!
|
|
2917
|
-
|
|
2858
|
+
const templateContent = JSON.parse(fs7.readFileSync(src, "utf-8"));
|
|
2859
|
+
if (!fs7.existsSync(dest)) {
|
|
2860
|
+
const destDir = path5.dirname(dest);
|
|
2861
|
+
if (!fs7.existsSync(destDir)) {
|
|
2862
|
+
fs7.mkdirSync(destDir, { recursive: true });
|
|
2918
2863
|
}
|
|
2919
|
-
|
|
2864
|
+
fs7.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
2920
2865
|
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
2921
2866
|
return;
|
|
2922
2867
|
}
|
|
2923
|
-
const userContent = JSON.parse(
|
|
2868
|
+
const userContent = JSON.parse(fs7.readFileSync(dest, "utf-8"));
|
|
2924
2869
|
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
2925
2870
|
const userStr = JSON.stringify(userContent, null, 2);
|
|
2926
2871
|
const mergedStr = JSON.stringify(merged, null, 2);
|
|
@@ -2928,7 +2873,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
|
|
|
2928
2873
|
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
2929
2874
|
return;
|
|
2930
2875
|
}
|
|
2931
|
-
|
|
2876
|
+
fs7.writeFileSync(dest, mergedStr + "\n");
|
|
2932
2877
|
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
2933
2878
|
}
|
|
2934
2879
|
|
|
@@ -2989,12 +2934,12 @@ async function reportCreateInstanceEvent(pluginKey, version) {
|
|
|
2989
2934
|
|
|
2990
2935
|
// src/utils/git.ts
|
|
2991
2936
|
import { execSync, spawnSync as spawnSync3 } from "child_process";
|
|
2992
|
-
import
|
|
2993
|
-
import
|
|
2937
|
+
import fs8 from "fs";
|
|
2938
|
+
import path6 from "path";
|
|
2994
2939
|
function isGitRepository(cwd = process.cwd()) {
|
|
2995
2940
|
try {
|
|
2996
|
-
const gitDir =
|
|
2997
|
-
if (
|
|
2941
|
+
const gitDir = path6.join(cwd, ".git");
|
|
2942
|
+
if (fs8.existsSync(gitDir)) {
|
|
2998
2943
|
return true;
|
|
2999
2944
|
}
|
|
3000
2945
|
const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
|
|
@@ -3023,7 +2968,7 @@ function getChangedFiles(cwd = process.cwd()) {
|
|
|
3023
2968
|
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
3024
2969
|
const filteredFiles = [];
|
|
3025
2970
|
for (const filePath of filesToStage) {
|
|
3026
|
-
if (
|
|
2971
|
+
if (fs8.existsSync(path6.join(cwd, filePath))) {
|
|
3027
2972
|
filteredFiles.push(filePath);
|
|
3028
2973
|
continue;
|
|
3029
2974
|
}
|
|
@@ -3107,6 +3052,64 @@ Auto-committed by fullstack-cli`;
|
|
|
3107
3052
|
}
|
|
3108
3053
|
}
|
|
3109
3054
|
|
|
3055
|
+
// src/utils/package-json.ts
|
|
3056
|
+
import fs9 from "fs";
|
|
3057
|
+
import path7 from "path";
|
|
3058
|
+
function readPackageJson(cwd = process.cwd()) {
|
|
3059
|
+
const pkgPath = path7.join(cwd, "package.json");
|
|
3060
|
+
if (!fs9.existsSync(pkgPath)) {
|
|
3061
|
+
throw new Error(`package.json not found at ${pkgPath}`);
|
|
3062
|
+
}
|
|
3063
|
+
const content = fs9.readFileSync(pkgPath, "utf-8");
|
|
3064
|
+
return JSON.parse(content);
|
|
3065
|
+
}
|
|
3066
|
+
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
3067
|
+
const pkgPath = path7.join(cwd, "package.json");
|
|
3068
|
+
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
3069
|
+
fs9.writeFileSync(pkgPath, content, "utf-8");
|
|
3070
|
+
}
|
|
3071
|
+
function removeUpgradeScript(pkg2) {
|
|
3072
|
+
if (!pkg2.scripts?.upgrade) {
|
|
3073
|
+
return false;
|
|
3074
|
+
}
|
|
3075
|
+
delete pkg2.scripts.upgrade;
|
|
3076
|
+
return true;
|
|
3077
|
+
}
|
|
3078
|
+
function cleanDevScript(pkg2) {
|
|
3079
|
+
if (!pkg2.scripts?.dev) {
|
|
3080
|
+
return false;
|
|
3081
|
+
}
|
|
3082
|
+
const originalDev = pkg2.scripts.dev;
|
|
3083
|
+
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
3084
|
+
if (cleanedDev !== originalDev) {
|
|
3085
|
+
pkg2.scripts.dev = cleanedDev;
|
|
3086
|
+
return true;
|
|
3087
|
+
}
|
|
3088
|
+
return false;
|
|
3089
|
+
}
|
|
3090
|
+
function cleanupPackageJson(cwd = process.cwd()) {
|
|
3091
|
+
try {
|
|
3092
|
+
const pkg2 = readPackageJson(cwd);
|
|
3093
|
+
let changed = false;
|
|
3094
|
+
if (removeUpgradeScript(pkg2)) {
|
|
3095
|
+
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
3096
|
+
changed = true;
|
|
3097
|
+
}
|
|
3098
|
+
if (cleanDevScript(pkg2)) {
|
|
3099
|
+
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
3100
|
+
changed = true;
|
|
3101
|
+
}
|
|
3102
|
+
if (changed) {
|
|
3103
|
+
writePackageJson(pkg2, cwd);
|
|
3104
|
+
}
|
|
3105
|
+
return changed;
|
|
3106
|
+
} catch (error) {
|
|
3107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3108
|
+
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
3109
|
+
return false;
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3110
3113
|
// src/commands/upgrade/shared/utils.ts
|
|
3111
3114
|
import path8 from "path";
|
|
3112
3115
|
import fs10 from "fs";
|