@lark-apaas/fullstack-cli 1.1.45-alpha.1 → 1.1.45-alpha.3
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
CHANGED
|
@@ -2380,27 +2380,22 @@ var syncConfig = {
|
|
|
2380
2380
|
type: "directory",
|
|
2381
2381
|
overwrite: true
|
|
2382
2382
|
},
|
|
2383
|
-
// 1a. 同步 .husky 目录(hook
|
|
2383
|
+
// 1a. 同步 .husky 目录(hook 入口,可执行 sh 脚本)
|
|
2384
2384
|
{
|
|
2385
2385
|
from: "templates/.husky",
|
|
2386
2386
|
to: ".husky",
|
|
2387
2387
|
type: "directory",
|
|
2388
2388
|
overwrite: true
|
|
2389
2389
|
},
|
|
2390
|
-
// 1b.
|
|
2391
|
-
|
|
2392
|
-
from: "templates/package.husky-patch.json",
|
|
2393
|
-
to: "package.json",
|
|
2394
|
-
type: "merge-json"
|
|
2395
|
-
},
|
|
2396
|
-
// 1c. scripts.prepare = husky(npm install 时自动跑,等价于 husky install)
|
|
2390
|
+
// 1b. scripts.prepare:npm install 后自动激活 git hooks(不依赖 husky 库)
|
|
2391
|
+
// 直接写 core.hooksPath,并保底给 pre-commit 加执行位;非 git 仓库下静默退出
|
|
2397
2392
|
{
|
|
2398
2393
|
type: "add-script",
|
|
2399
2394
|
name: "prepare",
|
|
2400
|
-
command: "husky",
|
|
2395
|
+
command: "chmod +x .husky/pre-commit 2>/dev/null; git config core.hooksPath .husky 2>/dev/null || true",
|
|
2401
2396
|
overwrite: false
|
|
2402
2397
|
},
|
|
2403
|
-
//
|
|
2398
|
+
// 1c. scripts.precommit = pre-commit 真正的执行体(npm run lint + read-logs ×5)
|
|
2404
2399
|
{
|
|
2405
2400
|
type: "add-script",
|
|
2406
2401
|
name: "precommit",
|
|
@@ -2633,28 +2628,24 @@ function cleanupPackageJson(cwd = process.cwd()) {
|
|
|
2633
2628
|
import fs7 from "fs";
|
|
2634
2629
|
import path5 from "path";
|
|
2635
2630
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
2636
|
-
function
|
|
2631
|
+
function activateGitHooks(userProjectRoot) {
|
|
2637
2632
|
if (!fs7.existsSync(path5.join(userProjectRoot, ".git"))) {
|
|
2638
2633
|
return { action: "skipped-no-git" };
|
|
2639
2634
|
}
|
|
2640
|
-
const
|
|
2641
|
-
if (!fs7.existsSync(
|
|
2642
|
-
|
|
2643
|
-
return { action: "skipped-no-husky" };
|
|
2635
|
+
const hookFile = path5.join(userProjectRoot, ".husky", "pre-commit");
|
|
2636
|
+
if (!fs7.existsSync(hookFile)) {
|
|
2637
|
+
return { action: "skipped-no-hook-file" };
|
|
2644
2638
|
}
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
return { action: "already-initialized" };
|
|
2648
|
-
}
|
|
2649
|
-
const res = spawnSync2("node", [huskyBin], {
|
|
2639
|
+
fs7.chmodSync(hookFile, 493);
|
|
2640
|
+
const res = spawnSync2("git", ["config", "core.hooksPath", ".husky"], {
|
|
2650
2641
|
cwd: userProjectRoot,
|
|
2651
2642
|
stdio: ["ignore", "inherit", "inherit"]
|
|
2652
2643
|
});
|
|
2653
2644
|
if (res.status !== 0) {
|
|
2654
|
-
throw new Error(`
|
|
2645
|
+
throw new Error(`git config core.hooksPath exited with ${String(res.status)}`);
|
|
2655
2646
|
}
|
|
2656
|
-
console.log("[fullstack-cli] \u2713
|
|
2657
|
-
return { action: "
|
|
2647
|
+
console.log("[fullstack-cli] \u2713 git hooks activated (core.hooksPath -> .husky)");
|
|
2648
|
+
return { action: "activated" };
|
|
2658
2649
|
}
|
|
2659
2650
|
|
|
2660
2651
|
// src/commands/sync/run.handler.ts
|
|
@@ -2689,10 +2680,10 @@ async function run2(options) {
|
|
|
2689
2680
|
setPermissions(config.permissions, userProjectRoot);
|
|
2690
2681
|
}
|
|
2691
2682
|
try {
|
|
2692
|
-
|
|
2683
|
+
activateGitHooks(userProjectRoot);
|
|
2693
2684
|
} catch (error) {
|
|
2694
2685
|
const message = error instanceof Error ? error.message : String(error);
|
|
2695
|
-
console.warn(`[fullstack-cli] \u26A0 Failed to
|
|
2686
|
+
console.warn(`[fullstack-cli] \u26A0 Failed to activate git hooks: ${message}`);
|
|
2696
2687
|
}
|
|
2697
2688
|
console.log("[fullstack-cli] Sync completed successfully \u2705");
|
|
2698
2689
|
} catch (error) {
|
|
@@ -2705,25 +2696,48 @@ function patchUserPackageJson(userProjectRoot) {
|
|
|
2705
2696
|
try {
|
|
2706
2697
|
const pkg2 = readPackageJson(userProjectRoot);
|
|
2707
2698
|
const lintPatchResult = patchLintScriptForFilesSupport(pkg2);
|
|
2699
|
+
const huskyMigrated = migrateLegacyHuskySetup(pkg2);
|
|
2700
|
+
let needsWrite = false;
|
|
2701
|
+
let logMessage = "";
|
|
2708
2702
|
if (lintPatchResult === "patched") {
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
}
|
|
2713
|
-
if (lintPatchResult === "already-patched") {
|
|
2703
|
+
needsWrite = true;
|
|
2704
|
+
logMessage = "[fullstack-cli] \u2713 Patched scripts.lint to support --files";
|
|
2705
|
+
} else if (lintPatchResult === "already-patched") {
|
|
2714
2706
|
console.log("[fullstack-cli] \u25CB scripts.lint already supports --files");
|
|
2715
|
-
|
|
2716
|
-
}
|
|
2717
|
-
if (lintPatchResult === "skipped-custom") {
|
|
2707
|
+
} else if (lintPatchResult === "skipped-custom") {
|
|
2718
2708
|
console.warn(
|
|
2719
2709
|
"[fullstack-cli] \u26A0 Skipped patching scripts.lint because it has been customized"
|
|
2720
2710
|
);
|
|
2721
2711
|
}
|
|
2712
|
+
if (huskyMigrated) {
|
|
2713
|
+
needsWrite = true;
|
|
2714
|
+
}
|
|
2715
|
+
if (needsWrite) {
|
|
2716
|
+
writePackageJson(pkg2, userProjectRoot);
|
|
2717
|
+
if (logMessage) console.log(logMessage);
|
|
2718
|
+
}
|
|
2722
2719
|
} catch (error) {
|
|
2723
2720
|
const message = error instanceof Error ? error.message : String(error);
|
|
2724
2721
|
console.warn(`[fullstack-cli] \u26A0 Could not patch package.json: ${message}`);
|
|
2725
2722
|
}
|
|
2726
2723
|
}
|
|
2724
|
+
function migrateLegacyHuskySetup(pkg2) {
|
|
2725
|
+
let changed = false;
|
|
2726
|
+
const newPrepare = "chmod +x .husky/pre-commit 2>/dev/null; git config core.hooksPath .husky 2>/dev/null || true";
|
|
2727
|
+
const scripts = pkg2.scripts;
|
|
2728
|
+
if (scripts && scripts.prepare === "husky") {
|
|
2729
|
+
scripts.prepare = newPrepare;
|
|
2730
|
+
console.log("[fullstack-cli] \u2713 Migrated scripts.prepare from husky to native git config");
|
|
2731
|
+
changed = true;
|
|
2732
|
+
}
|
|
2733
|
+
const devDeps = pkg2.devDependencies;
|
|
2734
|
+
if (devDeps && devDeps.husky) {
|
|
2735
|
+
delete devDeps.husky;
|
|
2736
|
+
console.log("[fullstack-cli] \u2713 Removed legacy husky devDependency");
|
|
2737
|
+
changed = true;
|
|
2738
|
+
}
|
|
2739
|
+
return changed;
|
|
2740
|
+
}
|
|
2727
2741
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2728
2742
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2729
2743
|
const destPath2 = path6.join(userProjectRoot, rule.to);
|
package/package.json
CHANGED