@lark-apaas/fullstack-cli 1.1.45-alpha.5 → 1.1.45-alpha.6
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 +460 -395
- package/package.json +1 -1
- package/templates/.githooks/pre-commit +4 -0
- package/templates/scripts/hooks/run-precommit.js +37 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs29 from "fs";
|
|
3
|
+
import path25 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -2365,21 +2365,43 @@ var genDbSchemaCommand = {
|
|
|
2365
2365
|
};
|
|
2366
2366
|
|
|
2367
2367
|
// src/commands/sync/run.handler.ts
|
|
2368
|
-
import
|
|
2369
|
-
import
|
|
2368
|
+
import path6 from "path";
|
|
2369
|
+
import fs8 from "fs";
|
|
2370
2370
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2371
2371
|
|
|
2372
2372
|
// src/config/sync.ts
|
|
2373
2373
|
var syncConfig = {
|
|
2374
2374
|
// 派生规则
|
|
2375
2375
|
sync: [
|
|
2376
|
-
// 1. 派生 scripts
|
|
2376
|
+
// 1. 派生 scripts 目录(总是覆盖;递归同步,包含 scripts/hooks/run-precommit.js)
|
|
2377
2377
|
{
|
|
2378
2378
|
from: "templates/scripts",
|
|
2379
2379
|
to: "scripts",
|
|
2380
2380
|
type: "directory",
|
|
2381
2381
|
overwrite: true
|
|
2382
2382
|
},
|
|
2383
|
+
// 1a. 同步 .githooks 目录(hook 入口,可执行 sh 脚本)
|
|
2384
|
+
{
|
|
2385
|
+
from: "templates/.githooks",
|
|
2386
|
+
to: ".githooks",
|
|
2387
|
+
type: "directory",
|
|
2388
|
+
overwrite: true
|
|
2389
|
+
},
|
|
2390
|
+
// 1b. scripts.prepare:npm install 后自动激活 git hooks(原生 git,无第三方依赖)
|
|
2391
|
+
// 直接写 core.hooksPath,并保底给 pre-commit 加执行位;非 git 仓库下静默退出
|
|
2392
|
+
{
|
|
2393
|
+
type: "add-script",
|
|
2394
|
+
name: "prepare",
|
|
2395
|
+
command: "chmod +x .githooks/pre-commit 2>/dev/null; git config core.hooksPath .githooks 2>/dev/null || true",
|
|
2396
|
+
overwrite: false
|
|
2397
|
+
},
|
|
2398
|
+
// 1c. scripts.precommit = pre-commit 真正的执行体(npm run lint + read-logs ×5)
|
|
2399
|
+
{
|
|
2400
|
+
type: "add-script",
|
|
2401
|
+
name: "precommit",
|
|
2402
|
+
command: "node scripts/hooks/run-precommit.js",
|
|
2403
|
+
overwrite: false
|
|
2404
|
+
},
|
|
2383
2405
|
// 2. 智能合并 nest-cli.json 配置(保留用户自定义的 assets、plugins 等)
|
|
2384
2406
|
{
|
|
2385
2407
|
from: "templates/nest-cli.json",
|
|
@@ -2440,14 +2462,6 @@ var syncConfig = {
|
|
|
2440
2462
|
to: ".spark_project",
|
|
2441
2463
|
type: "file",
|
|
2442
2464
|
overwrite: true
|
|
2443
|
-
},
|
|
2444
|
-
// 9. 把模板版本的 lint 脚本替换为支持 --files 的 runner
|
|
2445
|
-
// 只识别平台模板生成的 `concurrently ...` 形态,用户真正改写过的脚本保持原样
|
|
2446
|
-
{
|
|
2447
|
-
type: "patch-script",
|
|
2448
|
-
name: "lint",
|
|
2449
|
-
to: "node ./scripts/lint.js",
|
|
2450
|
-
ifStartsWith: "concurrently "
|
|
2451
2465
|
}
|
|
2452
2466
|
],
|
|
2453
2467
|
// 文件权限设置
|
|
@@ -2535,18 +2549,133 @@ function deepMergeJson(user, template, arrayMerge = {}, currentPath = "") {
|
|
|
2535
2549
|
return result;
|
|
2536
2550
|
}
|
|
2537
2551
|
|
|
2552
|
+
// src/utils/package-json.ts
|
|
2553
|
+
import fs6 from "fs";
|
|
2554
|
+
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
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
2631
|
+
function activateGitHooks(userProjectRoot) {
|
|
2632
|
+
if (!fs7.existsSync(path5.join(userProjectRoot, ".git"))) {
|
|
2633
|
+
return { action: "skipped-no-git" };
|
|
2634
|
+
}
|
|
2635
|
+
const hookFile = path5.join(userProjectRoot, ".githooks", "pre-commit");
|
|
2636
|
+
if (!fs7.existsSync(hookFile)) {
|
|
2637
|
+
return { action: "skipped-no-hook-file" };
|
|
2638
|
+
}
|
|
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"], {
|
|
2646
|
+
cwd: userProjectRoot,
|
|
2647
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
2648
|
+
});
|
|
2649
|
+
const currentHooksPath = probe.stdout ? probe.stdout.toString().trim() : "";
|
|
2650
|
+
if (currentHooksPath !== ".githooks") {
|
|
2651
|
+
const res = spawnSync2("git", ["config", "core.hooksPath", ".githooks"], {
|
|
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;
|
|
2659
|
+
}
|
|
2660
|
+
if (changed) {
|
|
2661
|
+
console.log("[fullstack-cli] \u2713 git hooks activated (core.hooksPath -> .githooks)");
|
|
2662
|
+
return { action: "activated" };
|
|
2663
|
+
}
|
|
2664
|
+
return { action: "already-active" };
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2538
2667
|
// src/commands/sync/run.handler.ts
|
|
2539
2668
|
async function run2(options) {
|
|
2540
2669
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2541
2670
|
const __filename = fileURLToPath3(import.meta.url);
|
|
2542
|
-
const __dirname2 =
|
|
2543
|
-
const pluginRoot =
|
|
2671
|
+
const __dirname2 = path6.dirname(__filename);
|
|
2672
|
+
const pluginRoot = path6.resolve(__dirname2, "..");
|
|
2544
2673
|
if (userProjectRoot === pluginRoot) {
|
|
2545
2674
|
console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
|
|
2546
2675
|
process.exit(0);
|
|
2547
2676
|
}
|
|
2548
|
-
const userPackageJson =
|
|
2549
|
-
if (!
|
|
2677
|
+
const userPackageJson = path6.join(userProjectRoot, "package.json");
|
|
2678
|
+
if (!fs8.existsSync(userPackageJson)) {
|
|
2550
2679
|
console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
|
|
2551
2680
|
process.exit(0);
|
|
2552
2681
|
}
|
|
@@ -2562,9 +2691,16 @@ async function run2(options) {
|
|
|
2562
2691
|
for (const rule of config.sync) {
|
|
2563
2692
|
await syncRule(rule, pluginRoot, userProjectRoot);
|
|
2564
2693
|
}
|
|
2694
|
+
patchUserPackageJson(userProjectRoot);
|
|
2565
2695
|
if (config.permissions) {
|
|
2566
2696
|
setPermissions(config.permissions, userProjectRoot);
|
|
2567
2697
|
}
|
|
2698
|
+
try {
|
|
2699
|
+
activateGitHooks(userProjectRoot);
|
|
2700
|
+
} catch (error) {
|
|
2701
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2702
|
+
console.warn(`[fullstack-cli] \u26A0 Failed to activate git hooks: ${message}`);
|
|
2703
|
+
}
|
|
2568
2704
|
console.log("[fullstack-cli] Sync completed successfully \u2705");
|
|
2569
2705
|
} catch (error) {
|
|
2570
2706
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2572,9 +2708,32 @@ async function run2(options) {
|
|
|
2572
2708
|
process.exit(1);
|
|
2573
2709
|
}
|
|
2574
2710
|
}
|
|
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
|
+
}
|
|
2575
2734
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2576
2735
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2577
|
-
const destPath2 =
|
|
2736
|
+
const destPath2 = path6.join(userProjectRoot, rule.to);
|
|
2578
2737
|
if (rule.type === "delete-file") {
|
|
2579
2738
|
deleteFile(destPath2);
|
|
2580
2739
|
} else {
|
|
@@ -2583,37 +2742,32 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2583
2742
|
return;
|
|
2584
2743
|
}
|
|
2585
2744
|
if (rule.type === "remove-line") {
|
|
2586
|
-
const destPath2 =
|
|
2745
|
+
const destPath2 = path6.join(userProjectRoot, rule.to);
|
|
2587
2746
|
removeLineFromFile(destPath2, rule.pattern);
|
|
2588
2747
|
return;
|
|
2589
2748
|
}
|
|
2590
2749
|
if (rule.type === "add-script") {
|
|
2591
|
-
const packageJsonPath =
|
|
2750
|
+
const packageJsonPath = path6.join(userProjectRoot, "package.json");
|
|
2592
2751
|
addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
|
|
2593
2752
|
return;
|
|
2594
2753
|
}
|
|
2595
|
-
if (rule.type === "patch-script") {
|
|
2596
|
-
const packageJsonPath = path4.join(userProjectRoot, "package.json");
|
|
2597
|
-
patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
|
|
2598
|
-
return;
|
|
2599
|
-
}
|
|
2600
2754
|
if (rule.type === "add-line") {
|
|
2601
|
-
const destPath2 =
|
|
2755
|
+
const destPath2 = path6.join(userProjectRoot, rule.to);
|
|
2602
2756
|
addLineToFile(destPath2, rule.line);
|
|
2603
2757
|
return;
|
|
2604
2758
|
}
|
|
2605
2759
|
if (rule.type === "merge-json") {
|
|
2606
|
-
const srcPath2 =
|
|
2607
|
-
const destPath2 =
|
|
2760
|
+
const srcPath2 = path6.join(pluginRoot, rule.from);
|
|
2761
|
+
const destPath2 = path6.join(userProjectRoot, rule.to);
|
|
2608
2762
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2609
2763
|
return;
|
|
2610
2764
|
}
|
|
2611
2765
|
if (!("from" in rule)) {
|
|
2612
2766
|
return;
|
|
2613
2767
|
}
|
|
2614
|
-
const srcPath =
|
|
2615
|
-
const destPath =
|
|
2616
|
-
if (!
|
|
2768
|
+
const srcPath = path6.join(pluginRoot, rule.from);
|
|
2769
|
+
const destPath = path6.join(userProjectRoot, rule.to);
|
|
2770
|
+
if (!fs8.existsSync(srcPath)) {
|
|
2617
2771
|
console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
|
|
2618
2772
|
return;
|
|
2619
2773
|
}
|
|
@@ -2630,68 +2784,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2630
2784
|
}
|
|
2631
2785
|
}
|
|
2632
2786
|
function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
|
|
2633
|
-
if (onlyIfExists && !
|
|
2634
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2787
|
+
if (onlyIfExists && !fs8.existsSync(dest)) {
|
|
2788
|
+
console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (skipped, target not exists)`);
|
|
2635
2789
|
return;
|
|
2636
2790
|
}
|
|
2637
|
-
const destDir =
|
|
2638
|
-
if (!
|
|
2639
|
-
|
|
2791
|
+
const destDir = path6.dirname(dest);
|
|
2792
|
+
if (!fs8.existsSync(destDir)) {
|
|
2793
|
+
fs8.mkdirSync(destDir, { recursive: true });
|
|
2640
2794
|
}
|
|
2641
|
-
if (
|
|
2642
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2795
|
+
if (fs8.existsSync(dest) && !overwrite) {
|
|
2796
|
+
console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (skipped, already exists)`);
|
|
2643
2797
|
return;
|
|
2644
2798
|
}
|
|
2645
|
-
|
|
2646
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2799
|
+
fs8.copyFileSync(src, dest);
|
|
2800
|
+
console.log(`[fullstack-cli] \u2713 ${path6.basename(dest)}`);
|
|
2647
2801
|
}
|
|
2648
2802
|
function syncDirectory(src, dest, overwrite = true) {
|
|
2649
|
-
if (!
|
|
2650
|
-
|
|
2803
|
+
if (!fs8.existsSync(dest)) {
|
|
2804
|
+
fs8.mkdirSync(dest, { recursive: true });
|
|
2651
2805
|
}
|
|
2652
|
-
const files =
|
|
2806
|
+
const files = fs8.readdirSync(src);
|
|
2653
2807
|
let count = 0;
|
|
2654
2808
|
files.forEach((file) => {
|
|
2655
|
-
const srcFile =
|
|
2656
|
-
const destFile =
|
|
2657
|
-
const stats =
|
|
2809
|
+
const srcFile = path6.join(src, file);
|
|
2810
|
+
const destFile = path6.join(dest, file);
|
|
2811
|
+
const stats = fs8.statSync(srcFile);
|
|
2658
2812
|
if (stats.isDirectory()) {
|
|
2659
2813
|
syncDirectory(srcFile, destFile, overwrite);
|
|
2660
2814
|
} else {
|
|
2661
|
-
if (overwrite || !
|
|
2662
|
-
|
|
2663
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2815
|
+
if (overwrite || !fs8.existsSync(destFile)) {
|
|
2816
|
+
fs8.copyFileSync(srcFile, destFile);
|
|
2817
|
+
console.log(`[fullstack-cli] \u2713 ${path6.relative(dest, destFile)}`);
|
|
2664
2818
|
count++;
|
|
2665
2819
|
}
|
|
2666
2820
|
}
|
|
2667
2821
|
});
|
|
2668
2822
|
if (count > 0) {
|
|
2669
|
-
console.log(`[fullstack-cli] Synced ${count} files to ${
|
|
2823
|
+
console.log(`[fullstack-cli] Synced ${count} files to ${path6.basename(dest)}/`);
|
|
2670
2824
|
}
|
|
2671
2825
|
}
|
|
2672
2826
|
function appendToFile(src, dest) {
|
|
2673
|
-
const content =
|
|
2827
|
+
const content = fs8.readFileSync(src, "utf-8");
|
|
2674
2828
|
let existingContent = "";
|
|
2675
|
-
if (
|
|
2676
|
-
existingContent =
|
|
2829
|
+
if (fs8.existsSync(dest)) {
|
|
2830
|
+
existingContent = fs8.readFileSync(dest, "utf-8");
|
|
2677
2831
|
}
|
|
2678
2832
|
if (existingContent.includes(content.trim())) {
|
|
2679
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2833
|
+
console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (already contains content)`);
|
|
2680
2834
|
return;
|
|
2681
2835
|
}
|
|
2682
|
-
|
|
2683
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2836
|
+
fs8.appendFileSync(dest, content);
|
|
2837
|
+
console.log(`[fullstack-cli] \u2713 ${path6.basename(dest)} (appended)`);
|
|
2684
2838
|
}
|
|
2685
2839
|
function setPermissions(permissions, projectRoot) {
|
|
2686
2840
|
for (const [pattern, mode] of Object.entries(permissions)) {
|
|
2687
2841
|
if (pattern === "**/*.sh") {
|
|
2688
|
-
const scriptsDir =
|
|
2689
|
-
if (
|
|
2690
|
-
const files =
|
|
2842
|
+
const scriptsDir = path6.join(projectRoot, "scripts");
|
|
2843
|
+
if (fs8.existsSync(scriptsDir)) {
|
|
2844
|
+
const files = fs8.readdirSync(scriptsDir);
|
|
2691
2845
|
files.forEach((file) => {
|
|
2692
2846
|
if (file.endsWith(".sh")) {
|
|
2693
|
-
const filePath =
|
|
2694
|
-
|
|
2847
|
+
const filePath = path6.join(scriptsDir, file);
|
|
2848
|
+
fs8.chmodSync(filePath, mode);
|
|
2695
2849
|
}
|
|
2696
2850
|
});
|
|
2697
2851
|
}
|
|
@@ -2699,27 +2853,27 @@ function setPermissions(permissions, projectRoot) {
|
|
|
2699
2853
|
}
|
|
2700
2854
|
}
|
|
2701
2855
|
function deleteFile(filePath) {
|
|
2702
|
-
if (
|
|
2703
|
-
|
|
2704
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2856
|
+
if (fs8.existsSync(filePath)) {
|
|
2857
|
+
fs8.unlinkSync(filePath);
|
|
2858
|
+
console.log(`[fullstack-cli] \u2713 ${path6.basename(filePath)} (deleted)`);
|
|
2705
2859
|
} else {
|
|
2706
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2860
|
+
console.log(`[fullstack-cli] \u25CB ${path6.basename(filePath)} (not found)`);
|
|
2707
2861
|
}
|
|
2708
2862
|
}
|
|
2709
2863
|
function deleteDirectory(dirPath) {
|
|
2710
|
-
if (
|
|
2711
|
-
|
|
2712
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2864
|
+
if (fs8.existsSync(dirPath)) {
|
|
2865
|
+
fs8.rmSync(dirPath, { recursive: true });
|
|
2866
|
+
console.log(`[fullstack-cli] \u2713 ${path6.basename(dirPath)} (deleted)`);
|
|
2713
2867
|
} else {
|
|
2714
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2868
|
+
console.log(`[fullstack-cli] \u25CB ${path6.basename(dirPath)} (not found)`);
|
|
2715
2869
|
}
|
|
2716
2870
|
}
|
|
2717
2871
|
function addScript(packageJsonPath, name, command, overwrite) {
|
|
2718
|
-
if (!
|
|
2872
|
+
if (!fs8.existsSync(packageJsonPath)) {
|
|
2719
2873
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2720
2874
|
return;
|
|
2721
2875
|
}
|
|
2722
|
-
const content =
|
|
2876
|
+
const content = fs8.readFileSync(packageJsonPath, "utf-8");
|
|
2723
2877
|
const pkg2 = JSON.parse(content);
|
|
2724
2878
|
if (!pkg2.scripts) {
|
|
2725
2879
|
pkg2.scripts = {};
|
|
@@ -2731,73 +2885,42 @@ function addScript(packageJsonPath, name, command, overwrite) {
|
|
|
2731
2885
|
}
|
|
2732
2886
|
}
|
|
2733
2887
|
pkg2.scripts[name] = command;
|
|
2734
|
-
|
|
2888
|
+
fs8.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2735
2889
|
console.log(`[fullstack-cli] \u2713 scripts.${name}`);
|
|
2736
2890
|
}
|
|
2737
|
-
function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
2738
|
-
if (!fs6.existsSync(packageJsonPath)) {
|
|
2739
|
-
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2740
|
-
return;
|
|
2741
|
-
}
|
|
2742
|
-
try {
|
|
2743
|
-
const content = fs6.readFileSync(packageJsonPath, "utf-8");
|
|
2744
|
-
const pkg2 = JSON.parse(content);
|
|
2745
|
-
const current = pkg2.scripts?.[name];
|
|
2746
|
-
if (!current) {
|
|
2747
|
-
console.log(`[fullstack-cli] \u25CB scripts.${name} (not present, skipped)`);
|
|
2748
|
-
return;
|
|
2749
|
-
}
|
|
2750
|
-
if (current === to) {
|
|
2751
|
-
console.log(`[fullstack-cli] \u25CB scripts.${name} (already patched)`);
|
|
2752
|
-
return;
|
|
2753
|
-
}
|
|
2754
|
-
if (!current.startsWith(ifStartsWith)) {
|
|
2755
|
-
console.warn(
|
|
2756
|
-
`[fullstack-cli] \u26A0 Skipped patching scripts.${name} because it has been customized`
|
|
2757
|
-
);
|
|
2758
|
-
return;
|
|
2759
|
-
}
|
|
2760
|
-
pkg2.scripts[name] = to;
|
|
2761
|
-
fs6.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2762
|
-
console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
|
|
2763
|
-
} catch (error) {
|
|
2764
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2765
|
-
console.warn(`[fullstack-cli] \u26A0 Could not patch scripts.${name}: ${message}`);
|
|
2766
|
-
}
|
|
2767
|
-
}
|
|
2768
2891
|
function addLineToFile(filePath, line) {
|
|
2769
|
-
const fileName =
|
|
2770
|
-
if (!
|
|
2892
|
+
const fileName = path6.basename(filePath);
|
|
2893
|
+
if (!fs8.existsSync(filePath)) {
|
|
2771
2894
|
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
2772
2895
|
return;
|
|
2773
2896
|
}
|
|
2774
|
-
const content =
|
|
2897
|
+
const content = fs8.readFileSync(filePath, "utf-8");
|
|
2775
2898
|
const lines = content.split("\n").map((l) => l.trim());
|
|
2776
2899
|
if (lines.includes(line)) {
|
|
2777
2900
|
console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
|
|
2778
2901
|
return;
|
|
2779
2902
|
}
|
|
2780
2903
|
const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
|
|
2781
|
-
|
|
2904
|
+
fs8.appendFileSync(filePath, appendContent);
|
|
2782
2905
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
2783
2906
|
}
|
|
2784
2907
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
2785
|
-
const fileName =
|
|
2786
|
-
if (!
|
|
2908
|
+
const fileName = path6.basename(dest);
|
|
2909
|
+
if (!fs8.existsSync(src)) {
|
|
2787
2910
|
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
2788
2911
|
return;
|
|
2789
2912
|
}
|
|
2790
|
-
const templateContent = JSON.parse(
|
|
2791
|
-
if (!
|
|
2792
|
-
const destDir =
|
|
2793
|
-
if (!
|
|
2794
|
-
|
|
2913
|
+
const templateContent = JSON.parse(fs8.readFileSync(src, "utf-8"));
|
|
2914
|
+
if (!fs8.existsSync(dest)) {
|
|
2915
|
+
const destDir = path6.dirname(dest);
|
|
2916
|
+
if (!fs8.existsSync(destDir)) {
|
|
2917
|
+
fs8.mkdirSync(destDir, { recursive: true });
|
|
2795
2918
|
}
|
|
2796
|
-
|
|
2919
|
+
fs8.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
2797
2920
|
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
2798
2921
|
return;
|
|
2799
2922
|
}
|
|
2800
|
-
const userContent = JSON.parse(
|
|
2923
|
+
const userContent = JSON.parse(fs8.readFileSync(dest, "utf-8"));
|
|
2801
2924
|
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
2802
2925
|
const userStr = JSON.stringify(userContent, null, 2);
|
|
2803
2926
|
const mergedStr = JSON.stringify(merged, null, 2);
|
|
@@ -2805,7 +2928,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
|
|
|
2805
2928
|
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
2806
2929
|
return;
|
|
2807
2930
|
}
|
|
2808
|
-
|
|
2931
|
+
fs8.writeFileSync(dest, mergedStr + "\n");
|
|
2809
2932
|
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
2810
2933
|
}
|
|
2811
2934
|
|
|
@@ -2865,16 +2988,16 @@ async function reportCreateInstanceEvent(pluginKey, version) {
|
|
|
2865
2988
|
}
|
|
2866
2989
|
|
|
2867
2990
|
// src/utils/git.ts
|
|
2868
|
-
import { execSync, spawnSync as
|
|
2869
|
-
import
|
|
2870
|
-
import
|
|
2991
|
+
import { execSync, spawnSync as spawnSync3 } from "child_process";
|
|
2992
|
+
import fs9 from "fs";
|
|
2993
|
+
import path7 from "path";
|
|
2871
2994
|
function isGitRepository(cwd = process.cwd()) {
|
|
2872
2995
|
try {
|
|
2873
|
-
const gitDir =
|
|
2874
|
-
if (
|
|
2996
|
+
const gitDir = path7.join(cwd, ".git");
|
|
2997
|
+
if (fs9.existsSync(gitDir)) {
|
|
2875
2998
|
return true;
|
|
2876
2999
|
}
|
|
2877
|
-
const result =
|
|
3000
|
+
const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
|
|
2878
3001
|
cwd,
|
|
2879
3002
|
stdio: "pipe",
|
|
2880
3003
|
encoding: "utf-8"
|
|
@@ -2900,11 +3023,11 @@ function getChangedFiles(cwd = process.cwd()) {
|
|
|
2900
3023
|
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
2901
3024
|
const filteredFiles = [];
|
|
2902
3025
|
for (const filePath of filesToStage) {
|
|
2903
|
-
if (
|
|
3026
|
+
if (fs9.existsSync(path7.join(cwd, filePath))) {
|
|
2904
3027
|
filteredFiles.push(filePath);
|
|
2905
3028
|
continue;
|
|
2906
3029
|
}
|
|
2907
|
-
const tracked =
|
|
3030
|
+
const tracked = spawnSync3("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
2908
3031
|
cwd,
|
|
2909
3032
|
stdio: "pipe",
|
|
2910
3033
|
encoding: "utf-8"
|
|
@@ -2916,7 +3039,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
|
2916
3039
|
if (filteredFiles.length === 0) {
|
|
2917
3040
|
return;
|
|
2918
3041
|
}
|
|
2919
|
-
const result =
|
|
3042
|
+
const result = spawnSync3("git", ["add", "--", ...filteredFiles], {
|
|
2920
3043
|
cwd,
|
|
2921
3044
|
stdio: "pipe",
|
|
2922
3045
|
encoding: "utf-8"
|
|
@@ -2927,7 +3050,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
|
2927
3050
|
}
|
|
2928
3051
|
}
|
|
2929
3052
|
function hasStagedChanges(cwd = process.cwd()) {
|
|
2930
|
-
const result =
|
|
3053
|
+
const result = spawnSync3("git", ["diff", "--cached", "--quiet"], {
|
|
2931
3054
|
cwd,
|
|
2932
3055
|
stdio: "pipe",
|
|
2933
3056
|
encoding: "utf-8"
|
|
@@ -2942,7 +3065,7 @@ function hasStagedChanges(cwd = process.cwd()) {
|
|
|
2942
3065
|
throw new Error(`Failed to check staged changes: ${errorMsg}`);
|
|
2943
3066
|
}
|
|
2944
3067
|
function gitCommit(message, cwd = process.cwd()) {
|
|
2945
|
-
const result =
|
|
3068
|
+
const result = spawnSync3("git", ["commit", "-m", message], {
|
|
2946
3069
|
cwd,
|
|
2947
3070
|
stdio: "pipe",
|
|
2948
3071
|
encoding: "utf-8"
|
|
@@ -2984,74 +3107,16 @@ Auto-committed by fullstack-cli`;
|
|
|
2984
3107
|
}
|
|
2985
3108
|
}
|
|
2986
3109
|
|
|
2987
|
-
// src/utils/package-json.ts
|
|
2988
|
-
import fs8 from "fs";
|
|
2989
|
-
import path6 from "path";
|
|
2990
|
-
function readPackageJson(cwd = process.cwd()) {
|
|
2991
|
-
const pkgPath = path6.join(cwd, "package.json");
|
|
2992
|
-
if (!fs8.existsSync(pkgPath)) {
|
|
2993
|
-
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2994
|
-
}
|
|
2995
|
-
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
2996
|
-
return JSON.parse(content);
|
|
2997
|
-
}
|
|
2998
|
-
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2999
|
-
const pkgPath = path6.join(cwd, "package.json");
|
|
3000
|
-
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
3001
|
-
fs8.writeFileSync(pkgPath, content, "utf-8");
|
|
3002
|
-
}
|
|
3003
|
-
function removeUpgradeScript(pkg2) {
|
|
3004
|
-
if (!pkg2.scripts?.upgrade) {
|
|
3005
|
-
return false;
|
|
3006
|
-
}
|
|
3007
|
-
delete pkg2.scripts.upgrade;
|
|
3008
|
-
return true;
|
|
3009
|
-
}
|
|
3010
|
-
function cleanDevScript(pkg2) {
|
|
3011
|
-
if (!pkg2.scripts?.dev) {
|
|
3012
|
-
return false;
|
|
3013
|
-
}
|
|
3014
|
-
const originalDev = pkg2.scripts.dev;
|
|
3015
|
-
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
3016
|
-
if (cleanedDev !== originalDev) {
|
|
3017
|
-
pkg2.scripts.dev = cleanedDev;
|
|
3018
|
-
return true;
|
|
3019
|
-
}
|
|
3020
|
-
return false;
|
|
3021
|
-
}
|
|
3022
|
-
function cleanupPackageJson(cwd = process.cwd()) {
|
|
3023
|
-
try {
|
|
3024
|
-
const pkg2 = readPackageJson(cwd);
|
|
3025
|
-
let changed = false;
|
|
3026
|
-
if (removeUpgradeScript(pkg2)) {
|
|
3027
|
-
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
3028
|
-
changed = true;
|
|
3029
|
-
}
|
|
3030
|
-
if (cleanDevScript(pkg2)) {
|
|
3031
|
-
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
3032
|
-
changed = true;
|
|
3033
|
-
}
|
|
3034
|
-
if (changed) {
|
|
3035
|
-
writePackageJson(pkg2, cwd);
|
|
3036
|
-
}
|
|
3037
|
-
return changed;
|
|
3038
|
-
} catch (error) {
|
|
3039
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
3040
|
-
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
3041
|
-
return false;
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
3110
|
// src/commands/upgrade/shared/utils.ts
|
|
3046
|
-
import
|
|
3047
|
-
import
|
|
3111
|
+
import path8 from "path";
|
|
3112
|
+
import fs10 from "fs";
|
|
3048
3113
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3049
3114
|
function getCliVersion() {
|
|
3050
3115
|
try {
|
|
3051
3116
|
const __filename = fileURLToPath4(import.meta.url);
|
|
3052
|
-
const __dirname2 =
|
|
3053
|
-
const pkgPath =
|
|
3054
|
-
const pkgContent =
|
|
3117
|
+
const __dirname2 = path8.dirname(__filename);
|
|
3118
|
+
const pkgPath = path8.resolve(__dirname2, "../../../package.json");
|
|
3119
|
+
const pkgContent = fs10.readFileSync(pkgPath, "utf-8");
|
|
3055
3120
|
const pkg2 = JSON.parse(pkgContent);
|
|
3056
3121
|
return pkg2.version || "unknown";
|
|
3057
3122
|
} catch {
|
|
@@ -3109,9 +3174,9 @@ async function run3(options = {}) {
|
|
|
3109
3174
|
}
|
|
3110
3175
|
|
|
3111
3176
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3112
|
-
import { spawnSync as
|
|
3113
|
-
import
|
|
3114
|
-
import
|
|
3177
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
3178
|
+
import fs11 from "fs";
|
|
3179
|
+
import path9 from "path";
|
|
3115
3180
|
|
|
3116
3181
|
// src/utils/grayscale/config.ts
|
|
3117
3182
|
function getGrayscaleConfig(configJson) {
|
|
@@ -3330,7 +3395,7 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3330
3395
|
packages.forEach((pkg2) => {
|
|
3331
3396
|
const target = `${pkg2}@${version}`;
|
|
3332
3397
|
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
3333
|
-
const result =
|
|
3398
|
+
const result = spawnSync4("npm", ["install", target], {
|
|
3334
3399
|
cwd,
|
|
3335
3400
|
stdio: "inherit"
|
|
3336
3401
|
});
|
|
@@ -3342,7 +3407,7 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3342
3407
|
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
3343
3408
|
packages.forEach((pkg2) => {
|
|
3344
3409
|
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
3345
|
-
const result =
|
|
3410
|
+
const result = spawnSync4("npm", ["update", pkg2], {
|
|
3346
3411
|
cwd,
|
|
3347
3412
|
stdio: "inherit"
|
|
3348
3413
|
});
|
|
@@ -3359,8 +3424,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3359
3424
|
if (version) {
|
|
3360
3425
|
let current = "";
|
|
3361
3426
|
try {
|
|
3362
|
-
const installedPkgPath =
|
|
3363
|
-
const installedPkg = JSON.parse(
|
|
3427
|
+
const installedPkgPath = path9.join(cwd, "node_modules", pkg2, "package.json");
|
|
3428
|
+
const installedPkg = JSON.parse(fs11.readFileSync(installedPkgPath, "utf-8"));
|
|
3364
3429
|
current = installedPkg.version || "";
|
|
3365
3430
|
} catch (err) {
|
|
3366
3431
|
const code = err?.code;
|
|
@@ -3403,7 +3468,7 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3403
3468
|
}
|
|
3404
3469
|
const targets = upgradePlan.map(({ pkg: pkg2, version }) => `${pkg2}@${version}`);
|
|
3405
3470
|
console.log(`[fullstack-cli] Installing ${targets.join(" ")}...`);
|
|
3406
|
-
const result =
|
|
3471
|
+
const result = spawnSync4("npm", ["install", ...targets], {
|
|
3407
3472
|
cwd,
|
|
3408
3473
|
stdio: "inherit"
|
|
3409
3474
|
});
|
|
@@ -3477,9 +3542,9 @@ var depsCommand = {
|
|
|
3477
3542
|
};
|
|
3478
3543
|
|
|
3479
3544
|
// src/commands/upgrade/global-deps/run.handler.ts
|
|
3480
|
-
import { spawnSync as
|
|
3481
|
-
import
|
|
3482
|
-
import
|
|
3545
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
3546
|
+
import fs12 from "fs";
|
|
3547
|
+
import path10 from "path";
|
|
3483
3548
|
var MANAGED_GLOBAL_CLIS = [
|
|
3484
3549
|
"@lark-apaas/fullstack-cli",
|
|
3485
3550
|
"@lark-apaas/miaoda-cli"
|
|
@@ -3490,15 +3555,15 @@ function readGlobalInstalledVersion(pkg2) {
|
|
|
3490
3555
|
if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
|
|
3491
3556
|
candidates.push("/usr");
|
|
3492
3557
|
candidates.push("/usr/local");
|
|
3493
|
-
if (process.env.HOME) candidates.push(
|
|
3558
|
+
if (process.env.HOME) candidates.push(path10.join(process.env.HOME, ".npm-global"));
|
|
3494
3559
|
const seen = /* @__PURE__ */ new Set();
|
|
3495
3560
|
for (const prefix of candidates) {
|
|
3496
3561
|
if (seen.has(prefix)) continue;
|
|
3497
3562
|
seen.add(prefix);
|
|
3498
3563
|
try {
|
|
3499
|
-
const pkgPath =
|
|
3500
|
-
if (
|
|
3501
|
-
const meta = JSON.parse(
|
|
3564
|
+
const pkgPath = path10.join(prefix, "lib", "node_modules", pkg2, "package.json");
|
|
3565
|
+
if (fs12.existsSync(pkgPath)) {
|
|
3566
|
+
const meta = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
|
|
3502
3567
|
if (meta && typeof meta.version === "string") return meta.version;
|
|
3503
3568
|
}
|
|
3504
3569
|
} catch (err) {
|
|
@@ -3556,7 +3621,7 @@ async function run5(options = {}) {
|
|
|
3556
3621
|
npmArgs.push("--registry", options.registry);
|
|
3557
3622
|
}
|
|
3558
3623
|
console.log(`[fullstack-cli] Running: npm ${npmArgs.join(" ")}`);
|
|
3559
|
-
const result =
|
|
3624
|
+
const result = spawnSync5("npm", npmArgs, { stdio: "inherit" });
|
|
3560
3625
|
if (result.error || result.status !== 0) {
|
|
3561
3626
|
console.warn(
|
|
3562
3627
|
`[fullstack-cli] npm install -g failed: ${result.error?.message ?? `exit ${result.status}`}`
|
|
@@ -3595,9 +3660,9 @@ var upgradeCommand = {
|
|
|
3595
3660
|
};
|
|
3596
3661
|
|
|
3597
3662
|
// src/commands/action-plugin/utils.ts
|
|
3598
|
-
import
|
|
3599
|
-
import
|
|
3600
|
-
import { spawnSync as
|
|
3663
|
+
import fs13 from "fs";
|
|
3664
|
+
import path11 from "path";
|
|
3665
|
+
import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
|
|
3601
3666
|
function parsePluginName(input) {
|
|
3602
3667
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
3603
3668
|
if (!match) {
|
|
@@ -3614,18 +3679,18 @@ function getProjectRoot() {
|
|
|
3614
3679
|
return process.cwd();
|
|
3615
3680
|
}
|
|
3616
3681
|
function getPackageJsonPath() {
|
|
3617
|
-
return
|
|
3682
|
+
return path11.join(getProjectRoot(), "package.json");
|
|
3618
3683
|
}
|
|
3619
3684
|
function getPluginPath(pluginName) {
|
|
3620
|
-
return
|
|
3685
|
+
return path11.join(getProjectRoot(), "node_modules", pluginName);
|
|
3621
3686
|
}
|
|
3622
3687
|
function readPackageJson2() {
|
|
3623
3688
|
const pkgPath = getPackageJsonPath();
|
|
3624
|
-
if (!
|
|
3689
|
+
if (!fs13.existsSync(pkgPath)) {
|
|
3625
3690
|
throw new Error("package.json not found in current directory");
|
|
3626
3691
|
}
|
|
3627
3692
|
try {
|
|
3628
|
-
const content =
|
|
3693
|
+
const content = fs13.readFileSync(pkgPath, "utf-8");
|
|
3629
3694
|
return JSON.parse(content);
|
|
3630
3695
|
} catch {
|
|
3631
3696
|
throw new Error("Failed to parse package.json");
|
|
@@ -3633,7 +3698,7 @@ function readPackageJson2() {
|
|
|
3633
3698
|
}
|
|
3634
3699
|
function writePackageJson2(pkg2) {
|
|
3635
3700
|
const pkgPath = getPackageJsonPath();
|
|
3636
|
-
|
|
3701
|
+
fs13.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3637
3702
|
}
|
|
3638
3703
|
function readActionPlugins() {
|
|
3639
3704
|
const pkg2 = readPackageJson2();
|
|
@@ -3654,7 +3719,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
3654
3719
|
}
|
|
3655
3720
|
function npmInstall(tgzPath) {
|
|
3656
3721
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
3657
|
-
const result =
|
|
3722
|
+
const result = spawnSync6("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
3658
3723
|
cwd: getProjectRoot(),
|
|
3659
3724
|
stdio: "inherit"
|
|
3660
3725
|
});
|
|
@@ -3666,12 +3731,12 @@ function npmInstall(tgzPath) {
|
|
|
3666
3731
|
}
|
|
3667
3732
|
}
|
|
3668
3733
|
function getPackageVersion(pluginName) {
|
|
3669
|
-
const pkgJsonPath =
|
|
3670
|
-
if (!
|
|
3734
|
+
const pkgJsonPath = path11.join(getPluginPath(pluginName), "package.json");
|
|
3735
|
+
if (!fs13.existsSync(pkgJsonPath)) {
|
|
3671
3736
|
return null;
|
|
3672
3737
|
}
|
|
3673
3738
|
try {
|
|
3674
|
-
const content =
|
|
3739
|
+
const content = fs13.readFileSync(pkgJsonPath, "utf-8");
|
|
3675
3740
|
const pkg2 = JSON.parse(content);
|
|
3676
3741
|
return pkg2.version || null;
|
|
3677
3742
|
} catch {
|
|
@@ -3679,49 +3744,49 @@ function getPackageVersion(pluginName) {
|
|
|
3679
3744
|
}
|
|
3680
3745
|
}
|
|
3681
3746
|
function readPluginPackageJson(pluginPath) {
|
|
3682
|
-
const pkgJsonPath =
|
|
3683
|
-
if (!
|
|
3747
|
+
const pkgJsonPath = path11.join(pluginPath, "package.json");
|
|
3748
|
+
if (!fs13.existsSync(pkgJsonPath)) {
|
|
3684
3749
|
return null;
|
|
3685
3750
|
}
|
|
3686
3751
|
try {
|
|
3687
|
-
const content =
|
|
3752
|
+
const content = fs13.readFileSync(pkgJsonPath, "utf-8");
|
|
3688
3753
|
return JSON.parse(content);
|
|
3689
3754
|
} catch {
|
|
3690
3755
|
return null;
|
|
3691
3756
|
}
|
|
3692
3757
|
}
|
|
3693
3758
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3694
|
-
const nodeModulesPath =
|
|
3695
|
-
const targetDir =
|
|
3696
|
-
const scopeDir =
|
|
3697
|
-
if (!
|
|
3698
|
-
|
|
3759
|
+
const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
|
|
3760
|
+
const targetDir = path11.join(nodeModulesPath, pluginName);
|
|
3761
|
+
const scopeDir = path11.dirname(targetDir);
|
|
3762
|
+
if (!fs13.existsSync(scopeDir)) {
|
|
3763
|
+
fs13.mkdirSync(scopeDir, { recursive: true });
|
|
3699
3764
|
}
|
|
3700
|
-
if (
|
|
3701
|
-
|
|
3765
|
+
if (fs13.existsSync(targetDir)) {
|
|
3766
|
+
fs13.rmSync(targetDir, { recursive: true });
|
|
3702
3767
|
}
|
|
3703
|
-
const tempDir =
|
|
3704
|
-
if (
|
|
3705
|
-
|
|
3768
|
+
const tempDir = path11.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3769
|
+
if (fs13.existsSync(tempDir)) {
|
|
3770
|
+
fs13.rmSync(tempDir, { recursive: true });
|
|
3706
3771
|
}
|
|
3707
|
-
|
|
3772
|
+
fs13.mkdirSync(tempDir, { recursive: true });
|
|
3708
3773
|
try {
|
|
3709
3774
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3710
|
-
const extractedDir =
|
|
3711
|
-
if (
|
|
3712
|
-
|
|
3775
|
+
const extractedDir = path11.join(tempDir, "package");
|
|
3776
|
+
if (fs13.existsSync(extractedDir)) {
|
|
3777
|
+
fs13.renameSync(extractedDir, targetDir);
|
|
3713
3778
|
} else {
|
|
3714
|
-
const files =
|
|
3779
|
+
const files = fs13.readdirSync(tempDir);
|
|
3715
3780
|
if (files.length === 1) {
|
|
3716
|
-
|
|
3781
|
+
fs13.renameSync(path11.join(tempDir, files[0]), targetDir);
|
|
3717
3782
|
} else {
|
|
3718
3783
|
throw new Error("Unexpected tgz structure");
|
|
3719
3784
|
}
|
|
3720
3785
|
}
|
|
3721
3786
|
return targetDir;
|
|
3722
3787
|
} finally {
|
|
3723
|
-
if (
|
|
3724
|
-
|
|
3788
|
+
if (fs13.existsSync(tempDir)) {
|
|
3789
|
+
fs13.rmSync(tempDir, { recursive: true });
|
|
3725
3790
|
}
|
|
3726
3791
|
}
|
|
3727
3792
|
}
|
|
@@ -3730,10 +3795,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3730
3795
|
return [];
|
|
3731
3796
|
}
|
|
3732
3797
|
const missing = [];
|
|
3733
|
-
const nodeModulesPath =
|
|
3798
|
+
const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
|
|
3734
3799
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3735
|
-
const depPath =
|
|
3736
|
-
if (!
|
|
3800
|
+
const depPath = path11.join(nodeModulesPath, depName);
|
|
3801
|
+
if (!fs13.existsSync(depPath)) {
|
|
3737
3802
|
missing.push(depName);
|
|
3738
3803
|
}
|
|
3739
3804
|
}
|
|
@@ -3744,7 +3809,7 @@ function installMissingDeps(deps) {
|
|
|
3744
3809
|
return;
|
|
3745
3810
|
}
|
|
3746
3811
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
3747
|
-
const result =
|
|
3812
|
+
const result = spawnSync6("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
3748
3813
|
cwd: getProjectRoot(),
|
|
3749
3814
|
stdio: "inherit"
|
|
3750
3815
|
});
|
|
@@ -3757,16 +3822,16 @@ function installMissingDeps(deps) {
|
|
|
3757
3822
|
}
|
|
3758
3823
|
function removePluginDirectory(pluginName) {
|
|
3759
3824
|
const pluginPath = getPluginPath(pluginName);
|
|
3760
|
-
if (
|
|
3761
|
-
|
|
3825
|
+
if (fs13.existsSync(pluginPath)) {
|
|
3826
|
+
fs13.rmSync(pluginPath, { recursive: true });
|
|
3762
3827
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3763
3828
|
}
|
|
3764
3829
|
}
|
|
3765
3830
|
|
|
3766
3831
|
// src/commands/action-plugin/api-client.ts
|
|
3767
3832
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3768
|
-
import
|
|
3769
|
-
import
|
|
3833
|
+
import fs14 from "fs";
|
|
3834
|
+
import path12 from "path";
|
|
3770
3835
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3771
3836
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3772
3837
|
const client = getHttpClient();
|
|
@@ -3830,19 +3895,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3830
3895
|
return Buffer.from(arrayBuffer);
|
|
3831
3896
|
}
|
|
3832
3897
|
function getPluginCacheDir() {
|
|
3833
|
-
return
|
|
3898
|
+
return path12.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3834
3899
|
}
|
|
3835
3900
|
function ensureCacheDir() {
|
|
3836
3901
|
const cacheDir = getPluginCacheDir();
|
|
3837
|
-
if (!
|
|
3838
|
-
|
|
3902
|
+
if (!fs14.existsSync(cacheDir)) {
|
|
3903
|
+
fs14.mkdirSync(cacheDir, { recursive: true });
|
|
3839
3904
|
}
|
|
3840
3905
|
}
|
|
3841
3906
|
function getTempFilePath(pluginKey, version) {
|
|
3842
3907
|
ensureCacheDir();
|
|
3843
3908
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3844
3909
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3845
|
-
return
|
|
3910
|
+
return path12.join(getPluginCacheDir(), filename);
|
|
3846
3911
|
}
|
|
3847
3912
|
var MAX_RETRIES = 2;
|
|
3848
3913
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3879,7 +3944,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3879
3944
|
);
|
|
3880
3945
|
}
|
|
3881
3946
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3882
|
-
|
|
3947
|
+
fs14.writeFileSync(tgzPath, tgzBuffer);
|
|
3883
3948
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3884
3949
|
return {
|
|
3885
3950
|
tgzPath,
|
|
@@ -3893,18 +3958,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3893
3958
|
ensureCacheDir();
|
|
3894
3959
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3895
3960
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3896
|
-
return
|
|
3961
|
+
return path12.join(getPluginCacheDir(), filename);
|
|
3897
3962
|
}
|
|
3898
3963
|
function hasCachedPlugin(pluginKey, version) {
|
|
3899
3964
|
const cachePath = getCachePath(pluginKey, version);
|
|
3900
|
-
return
|
|
3965
|
+
return fs14.existsSync(cachePath);
|
|
3901
3966
|
}
|
|
3902
3967
|
function listCachedPlugins() {
|
|
3903
3968
|
const cacheDir = getPluginCacheDir();
|
|
3904
|
-
if (!
|
|
3969
|
+
if (!fs14.existsSync(cacheDir)) {
|
|
3905
3970
|
return [];
|
|
3906
3971
|
}
|
|
3907
|
-
const files =
|
|
3972
|
+
const files = fs14.readdirSync(cacheDir);
|
|
3908
3973
|
const result = [];
|
|
3909
3974
|
for (const file of files) {
|
|
3910
3975
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3912,8 +3977,8 @@ function listCachedPlugins() {
|
|
|
3912
3977
|
if (!match) continue;
|
|
3913
3978
|
const [, rawName, version] = match;
|
|
3914
3979
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3915
|
-
const filePath =
|
|
3916
|
-
const stat =
|
|
3980
|
+
const filePath = path12.join(cacheDir, file);
|
|
3981
|
+
const stat = fs14.statSync(filePath);
|
|
3917
3982
|
result.push({
|
|
3918
3983
|
name,
|
|
3919
3984
|
version,
|
|
@@ -3926,14 +3991,14 @@ function listCachedPlugins() {
|
|
|
3926
3991
|
}
|
|
3927
3992
|
function cleanAllCache() {
|
|
3928
3993
|
const cacheDir = getPluginCacheDir();
|
|
3929
|
-
if (!
|
|
3994
|
+
if (!fs14.existsSync(cacheDir)) {
|
|
3930
3995
|
return 0;
|
|
3931
3996
|
}
|
|
3932
|
-
const files =
|
|
3997
|
+
const files = fs14.readdirSync(cacheDir);
|
|
3933
3998
|
let count = 0;
|
|
3934
3999
|
for (const file of files) {
|
|
3935
4000
|
if (file.endsWith(".tgz")) {
|
|
3936
|
-
|
|
4001
|
+
fs14.unlinkSync(path12.join(cacheDir, file));
|
|
3937
4002
|
count++;
|
|
3938
4003
|
}
|
|
3939
4004
|
}
|
|
@@ -3941,21 +4006,21 @@ function cleanAllCache() {
|
|
|
3941
4006
|
}
|
|
3942
4007
|
function cleanPluginCache(pluginKey, version) {
|
|
3943
4008
|
const cacheDir = getPluginCacheDir();
|
|
3944
|
-
if (!
|
|
4009
|
+
if (!fs14.existsSync(cacheDir)) {
|
|
3945
4010
|
return 0;
|
|
3946
4011
|
}
|
|
3947
4012
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3948
|
-
const files =
|
|
4013
|
+
const files = fs14.readdirSync(cacheDir);
|
|
3949
4014
|
let count = 0;
|
|
3950
4015
|
for (const file of files) {
|
|
3951
4016
|
if (version) {
|
|
3952
4017
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3953
|
-
|
|
4018
|
+
fs14.unlinkSync(path12.join(cacheDir, file));
|
|
3954
4019
|
count++;
|
|
3955
4020
|
}
|
|
3956
4021
|
} else {
|
|
3957
4022
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3958
|
-
|
|
4023
|
+
fs14.unlinkSync(path12.join(cacheDir, file));
|
|
3959
4024
|
count++;
|
|
3960
4025
|
}
|
|
3961
4026
|
}
|
|
@@ -4382,40 +4447,40 @@ var actionPluginCommandGroup = {
|
|
|
4382
4447
|
};
|
|
4383
4448
|
|
|
4384
4449
|
// src/commands/capability/utils.ts
|
|
4385
|
-
import
|
|
4450
|
+
import fs15 from "fs";
|
|
4386
4451
|
import { createRequire as createRequire2 } from "module";
|
|
4387
|
-
import
|
|
4452
|
+
import path13 from "path";
|
|
4388
4453
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4389
4454
|
function getProjectRoot2() {
|
|
4390
4455
|
return process.cwd();
|
|
4391
4456
|
}
|
|
4392
4457
|
function getCapabilitiesDir() {
|
|
4393
|
-
return
|
|
4458
|
+
return path13.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4394
4459
|
}
|
|
4395
4460
|
function getCapabilityPath(id) {
|
|
4396
|
-
return
|
|
4461
|
+
return path13.join(getCapabilitiesDir(), `${id}.json`);
|
|
4397
4462
|
}
|
|
4398
4463
|
function getPluginManifestPath(pluginKey) {
|
|
4399
|
-
return
|
|
4464
|
+
return path13.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4400
4465
|
}
|
|
4401
4466
|
function capabilitiesDirExists() {
|
|
4402
|
-
return
|
|
4467
|
+
return fs15.existsSync(getCapabilitiesDir());
|
|
4403
4468
|
}
|
|
4404
4469
|
function listCapabilityIds() {
|
|
4405
4470
|
const dir = getCapabilitiesDir();
|
|
4406
|
-
if (!
|
|
4471
|
+
if (!fs15.existsSync(dir)) {
|
|
4407
4472
|
return [];
|
|
4408
4473
|
}
|
|
4409
|
-
const files =
|
|
4474
|
+
const files = fs15.readdirSync(dir);
|
|
4410
4475
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4411
4476
|
}
|
|
4412
4477
|
function readCapability(id) {
|
|
4413
4478
|
const filePath = getCapabilityPath(id);
|
|
4414
|
-
if (!
|
|
4479
|
+
if (!fs15.existsSync(filePath)) {
|
|
4415
4480
|
throw new Error(`Capability not found: ${id}`);
|
|
4416
4481
|
}
|
|
4417
4482
|
try {
|
|
4418
|
-
const content =
|
|
4483
|
+
const content = fs15.readFileSync(filePath, "utf-8");
|
|
4419
4484
|
return JSON.parse(content);
|
|
4420
4485
|
} catch (error) {
|
|
4421
4486
|
if (error instanceof SyntaxError) {
|
|
@@ -4442,11 +4507,11 @@ function readAllCapabilities() {
|
|
|
4442
4507
|
}
|
|
4443
4508
|
function readPluginManifest(pluginKey) {
|
|
4444
4509
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4445
|
-
if (!
|
|
4510
|
+
if (!fs15.existsSync(manifestPath)) {
|
|
4446
4511
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4447
4512
|
}
|
|
4448
4513
|
try {
|
|
4449
|
-
const content =
|
|
4514
|
+
const content = fs15.readFileSync(manifestPath, "utf-8");
|
|
4450
4515
|
return JSON.parse(content);
|
|
4451
4516
|
} catch (error) {
|
|
4452
4517
|
if (error instanceof SyntaxError) {
|
|
@@ -4463,7 +4528,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4463
4528
|
}
|
|
4464
4529
|
async function loadPlugin(pluginKey) {
|
|
4465
4530
|
try {
|
|
4466
|
-
const userRequire = createRequire2(
|
|
4531
|
+
const userRequire = createRequire2(path13.join(getProjectRoot2(), "package.json"));
|
|
4467
4532
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4468
4533
|
const pluginModule = await import(resolvedPath);
|
|
4469
4534
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4626,8 +4691,8 @@ var capabilityCommandGroup = {
|
|
|
4626
4691
|
import { execFile } from "child_process";
|
|
4627
4692
|
|
|
4628
4693
|
// src/commands/component/registry-preparer.ts
|
|
4629
|
-
import
|
|
4630
|
-
import
|
|
4694
|
+
import fs16 from "fs";
|
|
4695
|
+
import path14 from "path";
|
|
4631
4696
|
import os from "os";
|
|
4632
4697
|
|
|
4633
4698
|
// src/commands/component/service.ts
|
|
@@ -4683,7 +4748,7 @@ async function sendInstallEvent(key) {
|
|
|
4683
4748
|
}
|
|
4684
4749
|
|
|
4685
4750
|
// src/commands/component/registry-preparer.ts
|
|
4686
|
-
var REGISTRY_TEMP_DIR =
|
|
4751
|
+
var REGISTRY_TEMP_DIR = path14.join(os.tmpdir(), "miaoda-registry");
|
|
4687
4752
|
function parseComponentKey(key) {
|
|
4688
4753
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4689
4754
|
if (!match) {
|
|
@@ -4695,11 +4760,11 @@ function parseComponentKey(key) {
|
|
|
4695
4760
|
}
|
|
4696
4761
|
function getLocalRegistryPath(key) {
|
|
4697
4762
|
const { scope, name } = parseComponentKey(key);
|
|
4698
|
-
return
|
|
4763
|
+
return path14.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4699
4764
|
}
|
|
4700
4765
|
function ensureDir(dirPath) {
|
|
4701
|
-
if (!
|
|
4702
|
-
|
|
4766
|
+
if (!fs16.existsSync(dirPath)) {
|
|
4767
|
+
fs16.mkdirSync(dirPath, { recursive: true });
|
|
4703
4768
|
}
|
|
4704
4769
|
}
|
|
4705
4770
|
async function prepareRecursive(key, visited) {
|
|
@@ -4732,8 +4797,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4732
4797
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4733
4798
|
};
|
|
4734
4799
|
const localPath = getLocalRegistryPath(key);
|
|
4735
|
-
ensureDir(
|
|
4736
|
-
|
|
4800
|
+
ensureDir(path14.dirname(localPath));
|
|
4801
|
+
fs16.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4737
4802
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4738
4803
|
}
|
|
4739
4804
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4743,18 +4808,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4743
4808
|
}
|
|
4744
4809
|
function cleanupTempDir() {
|
|
4745
4810
|
try {
|
|
4746
|
-
if (
|
|
4747
|
-
|
|
4811
|
+
if (fs16.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4812
|
+
fs16.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4748
4813
|
}
|
|
4749
4814
|
} catch {
|
|
4750
4815
|
}
|
|
4751
4816
|
}
|
|
4752
4817
|
function getDownloadedRegistryItem(itemId) {
|
|
4753
4818
|
const localPath = getLocalRegistryPath(itemId);
|
|
4754
|
-
if (!
|
|
4819
|
+
if (!fs16.existsSync(localPath)) {
|
|
4755
4820
|
return null;
|
|
4756
4821
|
}
|
|
4757
|
-
const content =
|
|
4822
|
+
const content = fs16.readFileSync(localPath, "utf-8");
|
|
4758
4823
|
return JSON.parse(content);
|
|
4759
4824
|
}
|
|
4760
4825
|
|
|
@@ -4922,58 +4987,58 @@ var componentCommandGroup = {
|
|
|
4922
4987
|
};
|
|
4923
4988
|
|
|
4924
4989
|
// src/commands/migration/version-manager.ts
|
|
4925
|
-
import
|
|
4926
|
-
import
|
|
4990
|
+
import fs17 from "fs";
|
|
4991
|
+
import path15 from "path";
|
|
4927
4992
|
var PACKAGE_JSON = "package.json";
|
|
4928
4993
|
var VERSION_FIELD = "migrationVersion";
|
|
4929
4994
|
function getPackageJsonPath2() {
|
|
4930
|
-
return
|
|
4995
|
+
return path15.join(process.cwd(), PACKAGE_JSON);
|
|
4931
4996
|
}
|
|
4932
4997
|
function getCurrentVersion() {
|
|
4933
4998
|
const pkgPath = getPackageJsonPath2();
|
|
4934
|
-
if (!
|
|
4999
|
+
if (!fs17.existsSync(pkgPath)) {
|
|
4935
5000
|
throw new Error("package.json not found");
|
|
4936
5001
|
}
|
|
4937
|
-
const pkg2 = JSON.parse(
|
|
5002
|
+
const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
|
|
4938
5003
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4939
5004
|
}
|
|
4940
5005
|
function setCurrentVersion(version) {
|
|
4941
5006
|
const pkgPath = getPackageJsonPath2();
|
|
4942
|
-
const pkg2 = JSON.parse(
|
|
5007
|
+
const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
|
|
4943
5008
|
pkg2[VERSION_FIELD] = version;
|
|
4944
|
-
|
|
5009
|
+
fs17.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4945
5010
|
}
|
|
4946
5011
|
|
|
4947
5012
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4948
|
-
import
|
|
4949
|
-
import
|
|
5013
|
+
import fs19 from "fs";
|
|
5014
|
+
import path17 from "path";
|
|
4950
5015
|
|
|
4951
5016
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4952
|
-
import
|
|
4953
|
-
import
|
|
5017
|
+
import fs18 from "fs";
|
|
5018
|
+
import path16 from "path";
|
|
4954
5019
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4955
5020
|
function getProjectRoot3() {
|
|
4956
5021
|
return process.cwd();
|
|
4957
5022
|
}
|
|
4958
5023
|
function getCapabilitiesDir2() {
|
|
4959
|
-
return
|
|
5024
|
+
return path16.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4960
5025
|
}
|
|
4961
5026
|
function getPluginManifestPath2(pluginKey) {
|
|
4962
|
-
return
|
|
5027
|
+
return path16.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4963
5028
|
}
|
|
4964
5029
|
|
|
4965
5030
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4966
5031
|
function detectJsonMigration() {
|
|
4967
5032
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4968
|
-
const oldFilePath =
|
|
4969
|
-
if (!
|
|
5033
|
+
const oldFilePath = path17.join(capabilitiesDir, "capabilities.json");
|
|
5034
|
+
if (!fs19.existsSync(oldFilePath)) {
|
|
4970
5035
|
return {
|
|
4971
5036
|
needsMigration: false,
|
|
4972
5037
|
reason: "capabilities.json not found"
|
|
4973
5038
|
};
|
|
4974
5039
|
}
|
|
4975
5040
|
try {
|
|
4976
|
-
const content =
|
|
5041
|
+
const content = fs19.readFileSync(oldFilePath, "utf-8");
|
|
4977
5042
|
const parsed = JSON.parse(content);
|
|
4978
5043
|
if (!Array.isArray(parsed)) {
|
|
4979
5044
|
return {
|
|
@@ -5024,8 +5089,8 @@ async function check(options) {
|
|
|
5024
5089
|
}
|
|
5025
5090
|
|
|
5026
5091
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5027
|
-
import
|
|
5028
|
-
import
|
|
5092
|
+
import fs20 from "fs";
|
|
5093
|
+
import path18 from "path";
|
|
5029
5094
|
|
|
5030
5095
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5031
5096
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5255,18 +5320,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5255
5320
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5256
5321
|
function loadExistingCapabilities() {
|
|
5257
5322
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5258
|
-
if (!
|
|
5323
|
+
if (!fs20.existsSync(capabilitiesDir)) {
|
|
5259
5324
|
return [];
|
|
5260
5325
|
}
|
|
5261
|
-
const files =
|
|
5326
|
+
const files = fs20.readdirSync(capabilitiesDir);
|
|
5262
5327
|
const capabilities = [];
|
|
5263
5328
|
for (const file of files) {
|
|
5264
5329
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5265
5330
|
continue;
|
|
5266
5331
|
}
|
|
5267
5332
|
try {
|
|
5268
|
-
const filePath =
|
|
5269
|
-
const content =
|
|
5333
|
+
const filePath = path18.join(capabilitiesDir, file);
|
|
5334
|
+
const content = fs20.readFileSync(filePath, "utf-8");
|
|
5270
5335
|
const capability = JSON.parse(content);
|
|
5271
5336
|
if (capability.id && capability.pluginKey) {
|
|
5272
5337
|
capabilities.push(capability);
|
|
@@ -5324,9 +5389,9 @@ async function migrateJsonFiles(options) {
|
|
|
5324
5389
|
}
|
|
5325
5390
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5326
5391
|
for (const cap of newCapabilities) {
|
|
5327
|
-
const filePath =
|
|
5392
|
+
const filePath = path18.join(capabilitiesDir, `${cap.id}.json`);
|
|
5328
5393
|
const content = JSON.stringify(cap, null, 2);
|
|
5329
|
-
|
|
5394
|
+
fs20.writeFileSync(filePath, content, "utf-8");
|
|
5330
5395
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5331
5396
|
}
|
|
5332
5397
|
return {
|
|
@@ -5338,11 +5403,11 @@ async function migrateJsonFiles(options) {
|
|
|
5338
5403
|
}
|
|
5339
5404
|
|
|
5340
5405
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5341
|
-
import
|
|
5406
|
+
import fs21 from "fs";
|
|
5342
5407
|
function isPluginInstalled2(pluginKey) {
|
|
5343
5408
|
const actionPlugins = readActionPlugins();
|
|
5344
5409
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5345
|
-
return
|
|
5410
|
+
return fs21.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5346
5411
|
}
|
|
5347
5412
|
function detectPluginsToInstall(capabilities) {
|
|
5348
5413
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5418,12 +5483,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5418
5483
|
}
|
|
5419
5484
|
|
|
5420
5485
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5421
|
-
import
|
|
5486
|
+
import path20 from "path";
|
|
5422
5487
|
import { Project as Project3 } from "ts-morph";
|
|
5423
5488
|
|
|
5424
5489
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5425
|
-
import
|
|
5426
|
-
import
|
|
5490
|
+
import fs22 from "fs";
|
|
5491
|
+
import path19 from "path";
|
|
5427
5492
|
var EXCLUDED_DIRS = [
|
|
5428
5493
|
"node_modules",
|
|
5429
5494
|
"dist",
|
|
@@ -5438,9 +5503,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5438
5503
|
/\.d\.ts$/
|
|
5439
5504
|
];
|
|
5440
5505
|
function scanDirectory(dir, files = []) {
|
|
5441
|
-
const entries =
|
|
5506
|
+
const entries = fs22.readdirSync(dir, { withFileTypes: true });
|
|
5442
5507
|
for (const entry of entries) {
|
|
5443
|
-
const fullPath =
|
|
5508
|
+
const fullPath = path19.join(dir, entry.name);
|
|
5444
5509
|
if (entry.isDirectory()) {
|
|
5445
5510
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5446
5511
|
continue;
|
|
@@ -5456,14 +5521,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5456
5521
|
return files;
|
|
5457
5522
|
}
|
|
5458
5523
|
function scanServerFiles() {
|
|
5459
|
-
const serverDir =
|
|
5460
|
-
if (!
|
|
5524
|
+
const serverDir = path19.join(getProjectRoot3(), "server");
|
|
5525
|
+
if (!fs22.existsSync(serverDir)) {
|
|
5461
5526
|
return [];
|
|
5462
5527
|
}
|
|
5463
5528
|
return scanDirectory(serverDir);
|
|
5464
5529
|
}
|
|
5465
5530
|
function hasCapabilityImport(filePath) {
|
|
5466
|
-
const content =
|
|
5531
|
+
const content = fs22.readFileSync(filePath, "utf-8");
|
|
5467
5532
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5468
5533
|
}
|
|
5469
5534
|
function scanFilesToMigrate() {
|
|
@@ -5840,7 +5905,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5840
5905
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5841
5906
|
const classInfo = analyzeClass(sourceFile);
|
|
5842
5907
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5843
|
-
const relativePath =
|
|
5908
|
+
const relativePath = path20.relative(getProjectRoot3(), filePath);
|
|
5844
5909
|
return {
|
|
5845
5910
|
filePath: relativePath,
|
|
5846
5911
|
imports,
|
|
@@ -5851,7 +5916,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5851
5916
|
};
|
|
5852
5917
|
}
|
|
5853
5918
|
function migrateFile(project, analysis, dryRun) {
|
|
5854
|
-
const absolutePath =
|
|
5919
|
+
const absolutePath = path20.join(getProjectRoot3(), analysis.filePath);
|
|
5855
5920
|
if (!analysis.canAutoMigrate) {
|
|
5856
5921
|
return {
|
|
5857
5922
|
filePath: analysis.filePath,
|
|
@@ -5954,17 +6019,17 @@ function getSuggestion(analysis) {
|
|
|
5954
6019
|
}
|
|
5955
6020
|
|
|
5956
6021
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5957
|
-
import
|
|
5958
|
-
import
|
|
6022
|
+
import fs23 from "fs";
|
|
6023
|
+
import path21 from "path";
|
|
5959
6024
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5960
6025
|
const deletedFiles = [];
|
|
5961
6026
|
const errors = [];
|
|
5962
6027
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5963
|
-
const oldJsonPath =
|
|
5964
|
-
if (
|
|
6028
|
+
const oldJsonPath = path21.join(capabilitiesDir, "capabilities.json");
|
|
6029
|
+
if (fs23.existsSync(oldJsonPath)) {
|
|
5965
6030
|
try {
|
|
5966
6031
|
if (!dryRun) {
|
|
5967
|
-
|
|
6032
|
+
fs23.unlinkSync(oldJsonPath);
|
|
5968
6033
|
}
|
|
5969
6034
|
deletedFiles.push("capabilities.json");
|
|
5970
6035
|
} catch (error) {
|
|
@@ -5972,11 +6037,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5972
6037
|
}
|
|
5973
6038
|
}
|
|
5974
6039
|
for (const cap of capabilities) {
|
|
5975
|
-
const tsFilePath =
|
|
5976
|
-
if (
|
|
6040
|
+
const tsFilePath = path21.join(capabilitiesDir, `${cap.id}.ts`);
|
|
6041
|
+
if (fs23.existsSync(tsFilePath)) {
|
|
5977
6042
|
try {
|
|
5978
6043
|
if (!dryRun) {
|
|
5979
|
-
|
|
6044
|
+
fs23.unlinkSync(tsFilePath);
|
|
5980
6045
|
}
|
|
5981
6046
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5982
6047
|
} catch (error) {
|
|
@@ -5992,8 +6057,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5992
6057
|
}
|
|
5993
6058
|
|
|
5994
6059
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5995
|
-
import
|
|
5996
|
-
import
|
|
6060
|
+
import fs24 from "fs";
|
|
6061
|
+
import path22 from "path";
|
|
5997
6062
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5998
6063
|
function printSummary(result) {
|
|
5999
6064
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6156,15 +6221,15 @@ async function generateReport(result) {
|
|
|
6156
6221
|
}
|
|
6157
6222
|
lines.push("");
|
|
6158
6223
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6159
|
-
if (!
|
|
6224
|
+
if (!fs24.existsSync(logDir)) {
|
|
6160
6225
|
return;
|
|
6161
6226
|
}
|
|
6162
|
-
const reportDir =
|
|
6163
|
-
if (!
|
|
6164
|
-
|
|
6227
|
+
const reportDir = path22.join(logDir, "migration");
|
|
6228
|
+
if (!fs24.existsSync(reportDir)) {
|
|
6229
|
+
fs24.mkdirSync(reportDir, { recursive: true });
|
|
6165
6230
|
}
|
|
6166
|
-
const reportPath =
|
|
6167
|
-
|
|
6231
|
+
const reportPath = path22.join(reportDir, REPORT_FILE);
|
|
6232
|
+
fs24.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6168
6233
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6169
6234
|
}
|
|
6170
6235
|
|
|
@@ -6696,10 +6761,10 @@ var migrationCommand = {
|
|
|
6696
6761
|
};
|
|
6697
6762
|
|
|
6698
6763
|
// src/commands/read-logs/index.ts
|
|
6699
|
-
import
|
|
6764
|
+
import path23 from "path";
|
|
6700
6765
|
|
|
6701
6766
|
// src/commands/read-logs/std-utils.ts
|
|
6702
|
-
import
|
|
6767
|
+
import fs25 from "fs";
|
|
6703
6768
|
function formatStdPrefixTime(localTime) {
|
|
6704
6769
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6705
6770
|
if (!match) return localTime;
|
|
@@ -6729,11 +6794,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6729
6794
|
return `[${time}] ${content}`;
|
|
6730
6795
|
}
|
|
6731
6796
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6732
|
-
const stat =
|
|
6797
|
+
const stat = fs25.statSync(filePath);
|
|
6733
6798
|
if (stat.size === 0) {
|
|
6734
6799
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6735
6800
|
}
|
|
6736
|
-
const fd =
|
|
6801
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6737
6802
|
const chunkSize = 64 * 1024;
|
|
6738
6803
|
let position = stat.size;
|
|
6739
6804
|
let remainder = "";
|
|
@@ -6747,7 +6812,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6747
6812
|
const length = Math.min(chunkSize, position);
|
|
6748
6813
|
position -= length;
|
|
6749
6814
|
const buffer = Buffer.alloc(length);
|
|
6750
|
-
|
|
6815
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6751
6816
|
let chunk = buffer.toString("utf8");
|
|
6752
6817
|
if (remainder) {
|
|
6753
6818
|
chunk += remainder;
|
|
@@ -6789,7 +6854,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6789
6854
|
}
|
|
6790
6855
|
}
|
|
6791
6856
|
} finally {
|
|
6792
|
-
|
|
6857
|
+
fs25.closeSync(fd);
|
|
6793
6858
|
}
|
|
6794
6859
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6795
6860
|
}
|
|
@@ -6810,21 +6875,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6810
6875
|
}
|
|
6811
6876
|
|
|
6812
6877
|
// src/commands/read-logs/tail.ts
|
|
6813
|
-
import
|
|
6878
|
+
import fs26 from "fs";
|
|
6814
6879
|
function fileExists(filePath) {
|
|
6815
6880
|
try {
|
|
6816
|
-
|
|
6881
|
+
fs26.accessSync(filePath, fs26.constants.F_OK | fs26.constants.R_OK);
|
|
6817
6882
|
return true;
|
|
6818
6883
|
} catch {
|
|
6819
6884
|
return false;
|
|
6820
6885
|
}
|
|
6821
6886
|
}
|
|
6822
6887
|
function readFileTailLines(filePath, maxLines) {
|
|
6823
|
-
const stat =
|
|
6888
|
+
const stat = fs26.statSync(filePath);
|
|
6824
6889
|
if (stat.size === 0) {
|
|
6825
6890
|
return [];
|
|
6826
6891
|
}
|
|
6827
|
-
const fd =
|
|
6892
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6828
6893
|
const chunkSize = 64 * 1024;
|
|
6829
6894
|
const chunks = [];
|
|
6830
6895
|
let position = stat.size;
|
|
@@ -6834,13 +6899,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6834
6899
|
const length = Math.min(chunkSize, position);
|
|
6835
6900
|
position -= length;
|
|
6836
6901
|
const buffer = Buffer.alloc(length);
|
|
6837
|
-
|
|
6902
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6838
6903
|
chunks.unshift(buffer.toString("utf8"));
|
|
6839
6904
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6840
6905
|
collectedLines += chunkLines;
|
|
6841
6906
|
}
|
|
6842
6907
|
} finally {
|
|
6843
|
-
|
|
6908
|
+
fs26.closeSync(fd);
|
|
6844
6909
|
}
|
|
6845
6910
|
const content = chunks.join("");
|
|
6846
6911
|
const allLines = content.split("\n");
|
|
@@ -6856,11 +6921,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6856
6921
|
return allLines.slice(allLines.length - maxLines);
|
|
6857
6922
|
}
|
|
6858
6923
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6859
|
-
const stat =
|
|
6924
|
+
const stat = fs26.statSync(filePath);
|
|
6860
6925
|
if (stat.size === 0) {
|
|
6861
6926
|
return { lines: [], totalLinesCount: 0 };
|
|
6862
6927
|
}
|
|
6863
|
-
const fd =
|
|
6928
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6864
6929
|
const chunkSize = 64 * 1024;
|
|
6865
6930
|
let position = stat.size;
|
|
6866
6931
|
let remainder = "";
|
|
@@ -6872,7 +6937,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6872
6937
|
const length = Math.min(chunkSize, position);
|
|
6873
6938
|
position -= length;
|
|
6874
6939
|
const buffer = Buffer.alloc(length);
|
|
6875
|
-
|
|
6940
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6876
6941
|
let chunk = buffer.toString("utf8");
|
|
6877
6942
|
if (remainder) {
|
|
6878
6943
|
chunk += remainder;
|
|
@@ -6903,7 +6968,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6903
6968
|
}
|
|
6904
6969
|
}
|
|
6905
6970
|
} finally {
|
|
6906
|
-
|
|
6971
|
+
fs26.closeSync(fd);
|
|
6907
6972
|
}
|
|
6908
6973
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6909
6974
|
}
|
|
@@ -7045,7 +7110,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7045
7110
|
}
|
|
7046
7111
|
|
|
7047
7112
|
// src/commands/read-logs/json-lines.ts
|
|
7048
|
-
import
|
|
7113
|
+
import fs27 from "fs";
|
|
7049
7114
|
function normalizePid(value) {
|
|
7050
7115
|
if (typeof value === "number") {
|
|
7051
7116
|
return String(value);
|
|
@@ -7096,11 +7161,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7096
7161
|
return set.size > 0 ? set : null;
|
|
7097
7162
|
}
|
|
7098
7163
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7099
|
-
const stat =
|
|
7164
|
+
const stat = fs27.statSync(filePath);
|
|
7100
7165
|
if (stat.size === 0) {
|
|
7101
7166
|
return { lines: [], totalLinesCount: 0 };
|
|
7102
7167
|
}
|
|
7103
|
-
const fd =
|
|
7168
|
+
const fd = fs27.openSync(filePath, "r");
|
|
7104
7169
|
const chunkSize = 64 * 1024;
|
|
7105
7170
|
let position = stat.size;
|
|
7106
7171
|
let remainder = "";
|
|
@@ -7115,7 +7180,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7115
7180
|
const length = Math.min(chunkSize, position);
|
|
7116
7181
|
position -= length;
|
|
7117
7182
|
const buffer = Buffer.alloc(length);
|
|
7118
|
-
|
|
7183
|
+
fs27.readSync(fd, buffer, 0, length, position);
|
|
7119
7184
|
let chunk = buffer.toString("utf8");
|
|
7120
7185
|
if (remainder) {
|
|
7121
7186
|
chunk += remainder;
|
|
@@ -7177,7 +7242,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7177
7242
|
}
|
|
7178
7243
|
}
|
|
7179
7244
|
} finally {
|
|
7180
|
-
|
|
7245
|
+
fs27.closeSync(fd);
|
|
7181
7246
|
}
|
|
7182
7247
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7183
7248
|
}
|
|
@@ -7220,11 +7285,11 @@ function extractTraceId(obj) {
|
|
|
7220
7285
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7221
7286
|
const wanted = traceId.trim();
|
|
7222
7287
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7223
|
-
const stat =
|
|
7288
|
+
const stat = fs27.statSync(filePath);
|
|
7224
7289
|
if (stat.size === 0) {
|
|
7225
7290
|
return { lines: [], totalLinesCount: 0 };
|
|
7226
7291
|
}
|
|
7227
|
-
const fd =
|
|
7292
|
+
const fd = fs27.openSync(filePath, "r");
|
|
7228
7293
|
const chunkSize = 64 * 1024;
|
|
7229
7294
|
let position = stat.size;
|
|
7230
7295
|
let remainder = "";
|
|
@@ -7237,7 +7302,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7237
7302
|
const length = Math.min(chunkSize, position);
|
|
7238
7303
|
position -= length;
|
|
7239
7304
|
const buffer = Buffer.alloc(length);
|
|
7240
|
-
|
|
7305
|
+
fs27.readSync(fd, buffer, 0, length, position);
|
|
7241
7306
|
let chunk = buffer.toString("utf8");
|
|
7242
7307
|
if (remainder) {
|
|
7243
7308
|
chunk += remainder;
|
|
@@ -7290,7 +7355,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7290
7355
|
}
|
|
7291
7356
|
}
|
|
7292
7357
|
} finally {
|
|
7293
|
-
|
|
7358
|
+
fs27.closeSync(fd);
|
|
7294
7359
|
}
|
|
7295
7360
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7296
7361
|
}
|
|
@@ -7299,11 +7364,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7299
7364
|
if (!wantedLevelSet) {
|
|
7300
7365
|
return { lines: [], totalLinesCount: 0 };
|
|
7301
7366
|
}
|
|
7302
|
-
const stat =
|
|
7367
|
+
const stat = fs27.statSync(filePath);
|
|
7303
7368
|
if (stat.size === 0) {
|
|
7304
7369
|
return { lines: [], totalLinesCount: 0 };
|
|
7305
7370
|
}
|
|
7306
|
-
const fd =
|
|
7371
|
+
const fd = fs27.openSync(filePath, "r");
|
|
7307
7372
|
const chunkSize = 64 * 1024;
|
|
7308
7373
|
let position = stat.size;
|
|
7309
7374
|
let remainder = "";
|
|
@@ -7315,7 +7380,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7315
7380
|
const length = Math.min(chunkSize, position);
|
|
7316
7381
|
position -= length;
|
|
7317
7382
|
const buffer = Buffer.alloc(length);
|
|
7318
|
-
|
|
7383
|
+
fs27.readSync(fd, buffer, 0, length, position);
|
|
7319
7384
|
let chunk = buffer.toString("utf8");
|
|
7320
7385
|
if (remainder) {
|
|
7321
7386
|
chunk += remainder;
|
|
@@ -7362,7 +7427,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7362
7427
|
}
|
|
7363
7428
|
}
|
|
7364
7429
|
} finally {
|
|
7365
|
-
|
|
7430
|
+
fs27.closeSync(fd);
|
|
7366
7431
|
}
|
|
7367
7432
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7368
7433
|
}
|
|
@@ -7596,30 +7661,30 @@ async function readLogsJsonResult(options) {
|
|
|
7596
7661
|
};
|
|
7597
7662
|
}
|
|
7598
7663
|
function resolveLogFilePath(logDir, type) {
|
|
7599
|
-
const base =
|
|
7664
|
+
const base = path23.isAbsolute(logDir) ? logDir : path23.join(process.cwd(), logDir);
|
|
7600
7665
|
if (type === "server") {
|
|
7601
|
-
return
|
|
7666
|
+
return path23.join(base, "server.log");
|
|
7602
7667
|
}
|
|
7603
7668
|
if (type === "trace") {
|
|
7604
|
-
return
|
|
7669
|
+
return path23.join(base, "trace.log");
|
|
7605
7670
|
}
|
|
7606
7671
|
if (type === "server-std") {
|
|
7607
|
-
return
|
|
7672
|
+
return path23.join(base, "server.std.log");
|
|
7608
7673
|
}
|
|
7609
7674
|
if (type === "client-std") {
|
|
7610
|
-
return
|
|
7675
|
+
return path23.join(base, "client.std.log");
|
|
7611
7676
|
}
|
|
7612
7677
|
if (type === "dev") {
|
|
7613
|
-
return
|
|
7678
|
+
return path23.join(base, "dev.log");
|
|
7614
7679
|
}
|
|
7615
7680
|
if (type === "dev-std") {
|
|
7616
|
-
return
|
|
7681
|
+
return path23.join(base, "dev.std.log");
|
|
7617
7682
|
}
|
|
7618
7683
|
if (type === "install-dep-std") {
|
|
7619
|
-
return
|
|
7684
|
+
return path23.join(base, "install-dep.std.log");
|
|
7620
7685
|
}
|
|
7621
7686
|
if (type === "browser") {
|
|
7622
|
-
return
|
|
7687
|
+
return path23.join(base, "browser.log");
|
|
7623
7688
|
}
|
|
7624
7689
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7625
7690
|
}
|
|
@@ -7796,9 +7861,9 @@ function camelToKebab(str) {
|
|
|
7796
7861
|
}
|
|
7797
7862
|
|
|
7798
7863
|
// src/commands/build/upload-static.handler.ts
|
|
7799
|
-
import * as
|
|
7864
|
+
import * as fs28 from "fs";
|
|
7800
7865
|
import * as os2 from "os";
|
|
7801
|
-
import * as
|
|
7866
|
+
import * as path24 from "path";
|
|
7802
7867
|
import { execFileSync } from "child_process";
|
|
7803
7868
|
function readCredentialsFromEnv() {
|
|
7804
7869
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7822,8 +7887,8 @@ async function uploadStatic(options) {
|
|
|
7822
7887
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7823
7888
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7824
7889
|
} = options;
|
|
7825
|
-
const resolvedStaticDir =
|
|
7826
|
-
if (!
|
|
7890
|
+
const resolvedStaticDir = path24.resolve(staticDir);
|
|
7891
|
+
if (!fs28.existsSync(resolvedStaticDir)) {
|
|
7827
7892
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7828
7893
|
return;
|
|
7829
7894
|
}
|
|
@@ -7856,8 +7921,8 @@ async function uploadStatic(options) {
|
|
|
7856
7921
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7857
7922
|
}
|
|
7858
7923
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7859
|
-
const confPath =
|
|
7860
|
-
|
|
7924
|
+
const confPath = path24.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7925
|
+
fs28.writeFileSync(confPath, "");
|
|
7861
7926
|
try {
|
|
7862
7927
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7863
7928
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7871,7 +7936,7 @@ async function uploadStatic(options) {
|
|
|
7871
7936
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7872
7937
|
} finally {
|
|
7873
7938
|
try {
|
|
7874
|
-
|
|
7939
|
+
fs28.unlinkSync(confPath);
|
|
7875
7940
|
} catch {
|
|
7876
7941
|
}
|
|
7877
7942
|
}
|
|
@@ -7891,8 +7956,8 @@ async function uploadStatic(options) {
|
|
|
7891
7956
|
}
|
|
7892
7957
|
}
|
|
7893
7958
|
function resolveTosutilPath(tosutilPath) {
|
|
7894
|
-
if (
|
|
7895
|
-
return
|
|
7959
|
+
if (path24.isAbsolute(tosutilPath)) {
|
|
7960
|
+
return fs28.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7896
7961
|
}
|
|
7897
7962
|
try {
|
|
7898
7963
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -7937,7 +8002,7 @@ async function resolveBucketId(appId) {
|
|
|
7937
8002
|
return bucketId;
|
|
7938
8003
|
}
|
|
7939
8004
|
function isDirEmpty(dirPath) {
|
|
7940
|
-
const entries =
|
|
8005
|
+
const entries = fs28.readdirSync(dirPath);
|
|
7941
8006
|
return entries.length === 0;
|
|
7942
8007
|
}
|
|
7943
8008
|
|
|
@@ -8032,12 +8097,12 @@ var commands = [
|
|
|
8032
8097
|
];
|
|
8033
8098
|
|
|
8034
8099
|
// src/index.ts
|
|
8035
|
-
var envPath =
|
|
8036
|
-
if (
|
|
8100
|
+
var envPath = path25.join(process.cwd(), ".env");
|
|
8101
|
+
if (fs29.existsSync(envPath)) {
|
|
8037
8102
|
dotenvConfig({ path: envPath });
|
|
8038
8103
|
}
|
|
8039
|
-
var __dirname =
|
|
8040
|
-
var pkg = JSON.parse(
|
|
8104
|
+
var __dirname = path25.dirname(fileURLToPath5(import.meta.url));
|
|
8105
|
+
var pkg = JSON.parse(fs29.readFileSync(path25.join(__dirname, "../package.json"), "utf-8"));
|
|
8041
8106
|
var cli = new FullstackCLI(pkg.version);
|
|
8042
8107
|
cli.useAll(commands);
|
|
8043
8108
|
cli.run();
|