@lark-apaas/fullstack-cli 1.1.45-alpha.3 → 1.1.45-alpha.4
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 +31 -38
- package/package.json +1 -1
- package/templates/scripts/hooks/run-precommit.js +1 -50
package/dist/index.js
CHANGED
|
@@ -2636,16 +2636,32 @@ function activateGitHooks(userProjectRoot) {
|
|
|
2636
2636
|
if (!fs7.existsSync(hookFile)) {
|
|
2637
2637
|
return { action: "skipped-no-hook-file" };
|
|
2638
2638
|
}
|
|
2639
|
-
|
|
2640
|
-
const
|
|
2639
|
+
let changed = false;
|
|
2640
|
+
const currentMode = fs7.statSync(hookFile).mode & 511;
|
|
2641
|
+
if ((currentMode & 73) !== 73) {
|
|
2642
|
+
fs7.chmodSync(hookFile, 493);
|
|
2643
|
+
changed = true;
|
|
2644
|
+
}
|
|
2645
|
+
const probe = spawnSync2("git", ["config", "--get", "core.hooksPath"], {
|
|
2641
2646
|
cwd: userProjectRoot,
|
|
2642
|
-
stdio: ["ignore", "
|
|
2647
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
2643
2648
|
});
|
|
2644
|
-
|
|
2645
|
-
|
|
2649
|
+
const currentHooksPath = probe.stdout ? probe.stdout.toString().trim() : "";
|
|
2650
|
+
if (currentHooksPath !== ".husky") {
|
|
2651
|
+
const res = spawnSync2("git", ["config", "core.hooksPath", ".husky"], {
|
|
2652
|
+
cwd: userProjectRoot,
|
|
2653
|
+
stdio: ["ignore", "inherit", "inherit"]
|
|
2654
|
+
});
|
|
2655
|
+
if (res.status !== 0) {
|
|
2656
|
+
throw new Error(`git config core.hooksPath exited with ${String(res.status)}`);
|
|
2657
|
+
}
|
|
2658
|
+
changed = true;
|
|
2646
2659
|
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2660
|
+
if (changed) {
|
|
2661
|
+
console.log("[fullstack-cli] \u2713 git hooks activated (core.hooksPath -> .husky)");
|
|
2662
|
+
return { action: "activated" };
|
|
2663
|
+
}
|
|
2664
|
+
return { action: "already-active" };
|
|
2649
2665
|
}
|
|
2650
2666
|
|
|
2651
2667
|
// src/commands/sync/run.handler.ts
|
|
@@ -2696,48 +2712,25 @@ function patchUserPackageJson(userProjectRoot) {
|
|
|
2696
2712
|
try {
|
|
2697
2713
|
const pkg2 = readPackageJson(userProjectRoot);
|
|
2698
2714
|
const lintPatchResult = patchLintScriptForFilesSupport(pkg2);
|
|
2699
|
-
const huskyMigrated = migrateLegacyHuskySetup(pkg2);
|
|
2700
|
-
let needsWrite = false;
|
|
2701
|
-
let logMessage = "";
|
|
2702
2715
|
if (lintPatchResult === "patched") {
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2716
|
+
writePackageJson(pkg2, userProjectRoot);
|
|
2717
|
+
console.log("[fullstack-cli] \u2713 Patched scripts.lint to support --files");
|
|
2718
|
+
return;
|
|
2719
|
+
}
|
|
2720
|
+
if (lintPatchResult === "already-patched") {
|
|
2706
2721
|
console.log("[fullstack-cli] \u25CB scripts.lint already supports --files");
|
|
2707
|
-
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
if (lintPatchResult === "skipped-custom") {
|
|
2708
2725
|
console.warn(
|
|
2709
2726
|
"[fullstack-cli] \u26A0 Skipped patching scripts.lint because it has been customized"
|
|
2710
2727
|
);
|
|
2711
2728
|
}
|
|
2712
|
-
if (huskyMigrated) {
|
|
2713
|
-
needsWrite = true;
|
|
2714
|
-
}
|
|
2715
|
-
if (needsWrite) {
|
|
2716
|
-
writePackageJson(pkg2, userProjectRoot);
|
|
2717
|
-
if (logMessage) console.log(logMessage);
|
|
2718
|
-
}
|
|
2719
2729
|
} catch (error) {
|
|
2720
2730
|
const message = error instanceof Error ? error.message : String(error);
|
|
2721
2731
|
console.warn(`[fullstack-cli] \u26A0 Could not patch package.json: ${message}`);
|
|
2722
2732
|
}
|
|
2723
2733
|
}
|
|
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
|
-
}
|
|
2741
2734
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2742
2735
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2743
2736
|
const destPath2 = path6.join(userProjectRoot, rule.to);
|
package/package.json
CHANGED
|
@@ -3,26 +3,16 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
const { spawnSync } = require('node:child_process');
|
|
6
|
-
const path = require('node:path');
|
|
7
6
|
|
|
8
7
|
const SEP = ' ' + '─'.repeat(36);
|
|
9
|
-
const LOG_DIR = process.env.FULLSTACK_LOG_DIR || '/tmp';
|
|
10
|
-
const READ_LOG_TYPES = ['server-std', 'client-std'];
|
|
11
8
|
|
|
12
|
-
function
|
|
13
|
-
return type.endsWith('-std') ? type.slice(0, -4) + '.std.log' : type + '.log';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function failAndExit(step, body, extraTip) {
|
|
9
|
+
function failAndExit(step, body) {
|
|
17
10
|
process.stderr.write('\n✗ pre-commit failed: ' + step + '\n');
|
|
18
11
|
process.stderr.write(SEP + '\n');
|
|
19
12
|
if (body && body.length > 0) {
|
|
20
13
|
process.stderr.write(body.replace(/\s+$/, '') + '\n');
|
|
21
14
|
}
|
|
22
15
|
process.stderr.write(SEP + '\n');
|
|
23
|
-
if (extraTip) {
|
|
24
|
-
process.stderr.write(' tip: ' + extraTip + '\n');
|
|
25
|
-
}
|
|
26
16
|
process.stderr.write(' bypass: git commit --no-verify\n');
|
|
27
17
|
process.exit(1);
|
|
28
18
|
}
|
|
@@ -44,43 +34,4 @@ function runLint() {
|
|
|
44
34
|
}
|
|
45
35
|
}
|
|
46
36
|
|
|
47
|
-
function runReadLogsCheck() {
|
|
48
|
-
for (const type of READ_LOG_TYPES) {
|
|
49
|
-
const res = spawnSync(
|
|
50
|
-
'npx',
|
|
51
|
-
['--no-install', 'fullstack-cli', 'read-logs', '--dir', LOG_DIR, '--type', type, '--max-lines', '200'],
|
|
52
|
-
{ stdio: ['ignore', 'pipe', 'pipe'], env: process.env }
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// 读不到日志文件、CLI 不存在或其他执行错误都不阻断 commit
|
|
56
|
-
if (res.error) continue;
|
|
57
|
-
if (res.status !== 0) continue;
|
|
58
|
-
|
|
59
|
-
const stdout = res.stdout ? res.stdout.toString() : '';
|
|
60
|
-
const lines = stdout.split('\n').map((s) => s.trim()).filter(Boolean);
|
|
61
|
-
if (lines.length === 0) continue;
|
|
62
|
-
|
|
63
|
-
let parsed;
|
|
64
|
-
try {
|
|
65
|
-
parsed = JSON.parse(lines[lines.length - 1]);
|
|
66
|
-
} catch (_) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (parsed && parsed.hasError === true) {
|
|
71
|
-
const logs = Array.isArray(parsed.logs) ? parsed.logs : [];
|
|
72
|
-
const preview = logs
|
|
73
|
-
.slice(-10)
|
|
74
|
-
.map((entry) => (typeof entry === 'string' ? entry : JSON.stringify(entry)))
|
|
75
|
-
.join('\n');
|
|
76
|
-
failAndExit(
|
|
77
|
-
'read-logs[' + type + ']',
|
|
78
|
-
preview,
|
|
79
|
-
'若为历史 session 残留,可 rm ' + path.join(LOG_DIR, logFileFor(type)) + ' 后重试'
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
37
|
runLint();
|
|
86
|
-
runReadLogsCheck();
|