@lark-apaas/fullstack-cli 1.1.45-alpha.3 → 1.1.45-alpha.5
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 +395 -467
- package/package.json +1 -1
- package/templates/.husky/pre-commit +0 -4
- package/templates/scripts/hooks/run-precommit.js +0 -86
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs28 from "fs";
|
|
3
|
+
import path24 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -2365,43 +2365,21 @@ var genDbSchemaCommand = {
|
|
|
2365
2365
|
};
|
|
2366
2366
|
|
|
2367
2367
|
// src/commands/sync/run.handler.ts
|
|
2368
|
-
import
|
|
2369
|
-
import
|
|
2368
|
+
import path4 from "path";
|
|
2369
|
+
import fs6 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 目录(总是覆盖)
|
|
2377
2377
|
{
|
|
2378
2378
|
from: "templates/scripts",
|
|
2379
2379
|
to: "scripts",
|
|
2380
2380
|
type: "directory",
|
|
2381
2381
|
overwrite: true
|
|
2382
2382
|
},
|
|
2383
|
-
// 1a. 同步 .husky 目录(hook 入口,可执行 sh 脚本)
|
|
2384
|
-
{
|
|
2385
|
-
from: "templates/.husky",
|
|
2386
|
-
to: ".husky",
|
|
2387
|
-
type: "directory",
|
|
2388
|
-
overwrite: true
|
|
2389
|
-
},
|
|
2390
|
-
// 1b. scripts.prepare:npm install 后自动激活 git hooks(不依赖 husky 库)
|
|
2391
|
-
// 直接写 core.hooksPath,并保底给 pre-commit 加执行位;非 git 仓库下静默退出
|
|
2392
|
-
{
|
|
2393
|
-
type: "add-script",
|
|
2394
|
-
name: "prepare",
|
|
2395
|
-
command: "chmod +x .husky/pre-commit 2>/dev/null; git config core.hooksPath .husky 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
|
-
},
|
|
2405
2383
|
// 2. 智能合并 nest-cli.json 配置(保留用户自定义的 assets、plugins 等)
|
|
2406
2384
|
{
|
|
2407
2385
|
from: "templates/nest-cli.json",
|
|
@@ -2462,6 +2440,14 @@ var syncConfig = {
|
|
|
2462
2440
|
to: ".spark_project",
|
|
2463
2441
|
type: "file",
|
|
2464
2442
|
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 "
|
|
2465
2451
|
}
|
|
2466
2452
|
],
|
|
2467
2453
|
// 文件权限设置
|
|
@@ -2549,117 +2535,18 @@ function deepMergeJson(user, template, arrayMerge = {}, currentPath = "") {
|
|
|
2549
2535
|
return result;
|
|
2550
2536
|
}
|
|
2551
2537
|
|
|
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/install-husky.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, ".husky", "pre-commit");
|
|
2636
|
-
if (!fs7.existsSync(hookFile)) {
|
|
2637
|
-
return { action: "skipped-no-hook-file" };
|
|
2638
|
-
}
|
|
2639
|
-
fs7.chmodSync(hookFile, 493);
|
|
2640
|
-
const res = spawnSync2("git", ["config", "core.hooksPath", ".husky"], {
|
|
2641
|
-
cwd: userProjectRoot,
|
|
2642
|
-
stdio: ["ignore", "inherit", "inherit"]
|
|
2643
|
-
});
|
|
2644
|
-
if (res.status !== 0) {
|
|
2645
|
-
throw new Error(`git config core.hooksPath exited with ${String(res.status)}`);
|
|
2646
|
-
}
|
|
2647
|
-
console.log("[fullstack-cli] \u2713 git hooks activated (core.hooksPath -> .husky)");
|
|
2648
|
-
return { action: "activated" };
|
|
2649
|
-
}
|
|
2650
|
-
|
|
2651
2538
|
// src/commands/sync/run.handler.ts
|
|
2652
2539
|
async function run2(options) {
|
|
2653
2540
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2654
2541
|
const __filename = fileURLToPath3(import.meta.url);
|
|
2655
|
-
const __dirname2 =
|
|
2656
|
-
const pluginRoot =
|
|
2542
|
+
const __dirname2 = path4.dirname(__filename);
|
|
2543
|
+
const pluginRoot = path4.resolve(__dirname2, "..");
|
|
2657
2544
|
if (userProjectRoot === pluginRoot) {
|
|
2658
2545
|
console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
|
|
2659
2546
|
process.exit(0);
|
|
2660
2547
|
}
|
|
2661
|
-
const userPackageJson =
|
|
2662
|
-
if (!
|
|
2548
|
+
const userPackageJson = path4.join(userProjectRoot, "package.json");
|
|
2549
|
+
if (!fs6.existsSync(userPackageJson)) {
|
|
2663
2550
|
console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
|
|
2664
2551
|
process.exit(0);
|
|
2665
2552
|
}
|
|
@@ -2675,16 +2562,9 @@ async function run2(options) {
|
|
|
2675
2562
|
for (const rule of config.sync) {
|
|
2676
2563
|
await syncRule(rule, pluginRoot, userProjectRoot);
|
|
2677
2564
|
}
|
|
2678
|
-
patchUserPackageJson(userProjectRoot);
|
|
2679
2565
|
if (config.permissions) {
|
|
2680
2566
|
setPermissions(config.permissions, userProjectRoot);
|
|
2681
2567
|
}
|
|
2682
|
-
try {
|
|
2683
|
-
activateGitHooks(userProjectRoot);
|
|
2684
|
-
} catch (error) {
|
|
2685
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2686
|
-
console.warn(`[fullstack-cli] \u26A0 Failed to activate git hooks: ${message}`);
|
|
2687
|
-
}
|
|
2688
2568
|
console.log("[fullstack-cli] Sync completed successfully \u2705");
|
|
2689
2569
|
} catch (error) {
|
|
2690
2570
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -2692,55 +2572,9 @@ async function run2(options) {
|
|
|
2692
2572
|
process.exit(1);
|
|
2693
2573
|
}
|
|
2694
2574
|
}
|
|
2695
|
-
function patchUserPackageJson(userProjectRoot) {
|
|
2696
|
-
try {
|
|
2697
|
-
const pkg2 = readPackageJson(userProjectRoot);
|
|
2698
|
-
const lintPatchResult = patchLintScriptForFilesSupport(pkg2);
|
|
2699
|
-
const huskyMigrated = migrateLegacyHuskySetup(pkg2);
|
|
2700
|
-
let needsWrite = false;
|
|
2701
|
-
let logMessage = "";
|
|
2702
|
-
if (lintPatchResult === "patched") {
|
|
2703
|
-
needsWrite = true;
|
|
2704
|
-
logMessage = "[fullstack-cli] \u2713 Patched scripts.lint to support --files";
|
|
2705
|
-
} else if (lintPatchResult === "already-patched") {
|
|
2706
|
-
console.log("[fullstack-cli] \u25CB scripts.lint already supports --files");
|
|
2707
|
-
} else if (lintPatchResult === "skipped-custom") {
|
|
2708
|
-
console.warn(
|
|
2709
|
-
"[fullstack-cli] \u26A0 Skipped patching scripts.lint because it has been customized"
|
|
2710
|
-
);
|
|
2711
|
-
}
|
|
2712
|
-
if (huskyMigrated) {
|
|
2713
|
-
needsWrite = true;
|
|
2714
|
-
}
|
|
2715
|
-
if (needsWrite) {
|
|
2716
|
-
writePackageJson(pkg2, userProjectRoot);
|
|
2717
|
-
if (logMessage) console.log(logMessage);
|
|
2718
|
-
}
|
|
2719
|
-
} catch (error) {
|
|
2720
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2721
|
-
console.warn(`[fullstack-cli] \u26A0 Could not patch package.json: ${message}`);
|
|
2722
|
-
}
|
|
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
|
-
}
|
|
2741
2575
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2742
2576
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2743
|
-
const destPath2 =
|
|
2577
|
+
const destPath2 = path4.join(userProjectRoot, rule.to);
|
|
2744
2578
|
if (rule.type === "delete-file") {
|
|
2745
2579
|
deleteFile(destPath2);
|
|
2746
2580
|
} else {
|
|
@@ -2749,32 +2583,37 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2749
2583
|
return;
|
|
2750
2584
|
}
|
|
2751
2585
|
if (rule.type === "remove-line") {
|
|
2752
|
-
const destPath2 =
|
|
2586
|
+
const destPath2 = path4.join(userProjectRoot, rule.to);
|
|
2753
2587
|
removeLineFromFile(destPath2, rule.pattern);
|
|
2754
2588
|
return;
|
|
2755
2589
|
}
|
|
2756
2590
|
if (rule.type === "add-script") {
|
|
2757
|
-
const packageJsonPath =
|
|
2591
|
+
const packageJsonPath = path4.join(userProjectRoot, "package.json");
|
|
2758
2592
|
addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
|
|
2759
2593
|
return;
|
|
2760
2594
|
}
|
|
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
|
+
}
|
|
2761
2600
|
if (rule.type === "add-line") {
|
|
2762
|
-
const destPath2 =
|
|
2601
|
+
const destPath2 = path4.join(userProjectRoot, rule.to);
|
|
2763
2602
|
addLineToFile(destPath2, rule.line);
|
|
2764
2603
|
return;
|
|
2765
2604
|
}
|
|
2766
2605
|
if (rule.type === "merge-json") {
|
|
2767
|
-
const srcPath2 =
|
|
2768
|
-
const destPath2 =
|
|
2606
|
+
const srcPath2 = path4.join(pluginRoot, rule.from);
|
|
2607
|
+
const destPath2 = path4.join(userProjectRoot, rule.to);
|
|
2769
2608
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2770
2609
|
return;
|
|
2771
2610
|
}
|
|
2772
2611
|
if (!("from" in rule)) {
|
|
2773
2612
|
return;
|
|
2774
2613
|
}
|
|
2775
|
-
const srcPath =
|
|
2776
|
-
const destPath =
|
|
2777
|
-
if (!
|
|
2614
|
+
const srcPath = path4.join(pluginRoot, rule.from);
|
|
2615
|
+
const destPath = path4.join(userProjectRoot, rule.to);
|
|
2616
|
+
if (!fs6.existsSync(srcPath)) {
|
|
2778
2617
|
console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
|
|
2779
2618
|
return;
|
|
2780
2619
|
}
|
|
@@ -2791,68 +2630,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2791
2630
|
}
|
|
2792
2631
|
}
|
|
2793
2632
|
function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
|
|
2794
|
-
if (onlyIfExists && !
|
|
2795
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2633
|
+
if (onlyIfExists && !fs6.existsSync(dest)) {
|
|
2634
|
+
console.log(`[fullstack-cli] \u25CB ${path4.basename(dest)} (skipped, target not exists)`);
|
|
2796
2635
|
return;
|
|
2797
2636
|
}
|
|
2798
|
-
const destDir =
|
|
2799
|
-
if (!
|
|
2800
|
-
|
|
2637
|
+
const destDir = path4.dirname(dest);
|
|
2638
|
+
if (!fs6.existsSync(destDir)) {
|
|
2639
|
+
fs6.mkdirSync(destDir, { recursive: true });
|
|
2801
2640
|
}
|
|
2802
|
-
if (
|
|
2803
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2641
|
+
if (fs6.existsSync(dest) && !overwrite) {
|
|
2642
|
+
console.log(`[fullstack-cli] \u25CB ${path4.basename(dest)} (skipped, already exists)`);
|
|
2804
2643
|
return;
|
|
2805
2644
|
}
|
|
2806
|
-
|
|
2807
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2645
|
+
fs6.copyFileSync(src, dest);
|
|
2646
|
+
console.log(`[fullstack-cli] \u2713 ${path4.basename(dest)}`);
|
|
2808
2647
|
}
|
|
2809
2648
|
function syncDirectory(src, dest, overwrite = true) {
|
|
2810
|
-
if (!
|
|
2811
|
-
|
|
2649
|
+
if (!fs6.existsSync(dest)) {
|
|
2650
|
+
fs6.mkdirSync(dest, { recursive: true });
|
|
2812
2651
|
}
|
|
2813
|
-
const files =
|
|
2652
|
+
const files = fs6.readdirSync(src);
|
|
2814
2653
|
let count = 0;
|
|
2815
2654
|
files.forEach((file) => {
|
|
2816
|
-
const srcFile =
|
|
2817
|
-
const destFile =
|
|
2818
|
-
const stats =
|
|
2655
|
+
const srcFile = path4.join(src, file);
|
|
2656
|
+
const destFile = path4.join(dest, file);
|
|
2657
|
+
const stats = fs6.statSync(srcFile);
|
|
2819
2658
|
if (stats.isDirectory()) {
|
|
2820
2659
|
syncDirectory(srcFile, destFile, overwrite);
|
|
2821
2660
|
} else {
|
|
2822
|
-
if (overwrite || !
|
|
2823
|
-
|
|
2824
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2661
|
+
if (overwrite || !fs6.existsSync(destFile)) {
|
|
2662
|
+
fs6.copyFileSync(srcFile, destFile);
|
|
2663
|
+
console.log(`[fullstack-cli] \u2713 ${path4.relative(dest, destFile)}`);
|
|
2825
2664
|
count++;
|
|
2826
2665
|
}
|
|
2827
2666
|
}
|
|
2828
2667
|
});
|
|
2829
2668
|
if (count > 0) {
|
|
2830
|
-
console.log(`[fullstack-cli] Synced ${count} files to ${
|
|
2669
|
+
console.log(`[fullstack-cli] Synced ${count} files to ${path4.basename(dest)}/`);
|
|
2831
2670
|
}
|
|
2832
2671
|
}
|
|
2833
2672
|
function appendToFile(src, dest) {
|
|
2834
|
-
const content =
|
|
2673
|
+
const content = fs6.readFileSync(src, "utf-8");
|
|
2835
2674
|
let existingContent = "";
|
|
2836
|
-
if (
|
|
2837
|
-
existingContent =
|
|
2675
|
+
if (fs6.existsSync(dest)) {
|
|
2676
|
+
existingContent = fs6.readFileSync(dest, "utf-8");
|
|
2838
2677
|
}
|
|
2839
2678
|
if (existingContent.includes(content.trim())) {
|
|
2840
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2679
|
+
console.log(`[fullstack-cli] \u25CB ${path4.basename(dest)} (already contains content)`);
|
|
2841
2680
|
return;
|
|
2842
2681
|
}
|
|
2843
|
-
|
|
2844
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2682
|
+
fs6.appendFileSync(dest, content);
|
|
2683
|
+
console.log(`[fullstack-cli] \u2713 ${path4.basename(dest)} (appended)`);
|
|
2845
2684
|
}
|
|
2846
2685
|
function setPermissions(permissions, projectRoot) {
|
|
2847
2686
|
for (const [pattern, mode] of Object.entries(permissions)) {
|
|
2848
2687
|
if (pattern === "**/*.sh") {
|
|
2849
|
-
const scriptsDir =
|
|
2850
|
-
if (
|
|
2851
|
-
const files =
|
|
2688
|
+
const scriptsDir = path4.join(projectRoot, "scripts");
|
|
2689
|
+
if (fs6.existsSync(scriptsDir)) {
|
|
2690
|
+
const files = fs6.readdirSync(scriptsDir);
|
|
2852
2691
|
files.forEach((file) => {
|
|
2853
2692
|
if (file.endsWith(".sh")) {
|
|
2854
|
-
const filePath =
|
|
2855
|
-
|
|
2693
|
+
const filePath = path4.join(scriptsDir, file);
|
|
2694
|
+
fs6.chmodSync(filePath, mode);
|
|
2856
2695
|
}
|
|
2857
2696
|
});
|
|
2858
2697
|
}
|
|
@@ -2860,27 +2699,27 @@ function setPermissions(permissions, projectRoot) {
|
|
|
2860
2699
|
}
|
|
2861
2700
|
}
|
|
2862
2701
|
function deleteFile(filePath) {
|
|
2863
|
-
if (
|
|
2864
|
-
|
|
2865
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2702
|
+
if (fs6.existsSync(filePath)) {
|
|
2703
|
+
fs6.unlinkSync(filePath);
|
|
2704
|
+
console.log(`[fullstack-cli] \u2713 ${path4.basename(filePath)} (deleted)`);
|
|
2866
2705
|
} else {
|
|
2867
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2706
|
+
console.log(`[fullstack-cli] \u25CB ${path4.basename(filePath)} (not found)`);
|
|
2868
2707
|
}
|
|
2869
2708
|
}
|
|
2870
2709
|
function deleteDirectory(dirPath) {
|
|
2871
|
-
if (
|
|
2872
|
-
|
|
2873
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2710
|
+
if (fs6.existsSync(dirPath)) {
|
|
2711
|
+
fs6.rmSync(dirPath, { recursive: true });
|
|
2712
|
+
console.log(`[fullstack-cli] \u2713 ${path4.basename(dirPath)} (deleted)`);
|
|
2874
2713
|
} else {
|
|
2875
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2714
|
+
console.log(`[fullstack-cli] \u25CB ${path4.basename(dirPath)} (not found)`);
|
|
2876
2715
|
}
|
|
2877
2716
|
}
|
|
2878
2717
|
function addScript(packageJsonPath, name, command, overwrite) {
|
|
2879
|
-
if (!
|
|
2718
|
+
if (!fs6.existsSync(packageJsonPath)) {
|
|
2880
2719
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2881
2720
|
return;
|
|
2882
2721
|
}
|
|
2883
|
-
const content =
|
|
2722
|
+
const content = fs6.readFileSync(packageJsonPath, "utf-8");
|
|
2884
2723
|
const pkg2 = JSON.parse(content);
|
|
2885
2724
|
if (!pkg2.scripts) {
|
|
2886
2725
|
pkg2.scripts = {};
|
|
@@ -2892,42 +2731,73 @@ function addScript(packageJsonPath, name, command, overwrite) {
|
|
|
2892
2731
|
}
|
|
2893
2732
|
}
|
|
2894
2733
|
pkg2.scripts[name] = command;
|
|
2895
|
-
|
|
2734
|
+
fs6.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2896
2735
|
console.log(`[fullstack-cli] \u2713 scripts.${name}`);
|
|
2897
2736
|
}
|
|
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
|
+
}
|
|
2898
2768
|
function addLineToFile(filePath, line) {
|
|
2899
|
-
const fileName =
|
|
2900
|
-
if (!
|
|
2769
|
+
const fileName = path4.basename(filePath);
|
|
2770
|
+
if (!fs6.existsSync(filePath)) {
|
|
2901
2771
|
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
2902
2772
|
return;
|
|
2903
2773
|
}
|
|
2904
|
-
const content =
|
|
2774
|
+
const content = fs6.readFileSync(filePath, "utf-8");
|
|
2905
2775
|
const lines = content.split("\n").map((l) => l.trim());
|
|
2906
2776
|
if (lines.includes(line)) {
|
|
2907
2777
|
console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
|
|
2908
2778
|
return;
|
|
2909
2779
|
}
|
|
2910
2780
|
const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
|
|
2911
|
-
|
|
2781
|
+
fs6.appendFileSync(filePath, appendContent);
|
|
2912
2782
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
2913
2783
|
}
|
|
2914
2784
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
2915
|
-
const fileName =
|
|
2916
|
-
if (!
|
|
2785
|
+
const fileName = path4.basename(dest);
|
|
2786
|
+
if (!fs6.existsSync(src)) {
|
|
2917
2787
|
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
2918
2788
|
return;
|
|
2919
2789
|
}
|
|
2920
|
-
const templateContent = JSON.parse(
|
|
2921
|
-
if (!
|
|
2922
|
-
const destDir =
|
|
2923
|
-
if (!
|
|
2924
|
-
|
|
2790
|
+
const templateContent = JSON.parse(fs6.readFileSync(src, "utf-8"));
|
|
2791
|
+
if (!fs6.existsSync(dest)) {
|
|
2792
|
+
const destDir = path4.dirname(dest);
|
|
2793
|
+
if (!fs6.existsSync(destDir)) {
|
|
2794
|
+
fs6.mkdirSync(destDir, { recursive: true });
|
|
2925
2795
|
}
|
|
2926
|
-
|
|
2796
|
+
fs6.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
2927
2797
|
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
2928
2798
|
return;
|
|
2929
2799
|
}
|
|
2930
|
-
const userContent = JSON.parse(
|
|
2800
|
+
const userContent = JSON.parse(fs6.readFileSync(dest, "utf-8"));
|
|
2931
2801
|
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
2932
2802
|
const userStr = JSON.stringify(userContent, null, 2);
|
|
2933
2803
|
const mergedStr = JSON.stringify(merged, null, 2);
|
|
@@ -2935,7 +2805,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
|
|
|
2935
2805
|
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
2936
2806
|
return;
|
|
2937
2807
|
}
|
|
2938
|
-
|
|
2808
|
+
fs6.writeFileSync(dest, mergedStr + "\n");
|
|
2939
2809
|
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
2940
2810
|
}
|
|
2941
2811
|
|
|
@@ -2995,16 +2865,16 @@ async function reportCreateInstanceEvent(pluginKey, version) {
|
|
|
2995
2865
|
}
|
|
2996
2866
|
|
|
2997
2867
|
// src/utils/git.ts
|
|
2998
|
-
import { execSync, spawnSync as
|
|
2999
|
-
import
|
|
3000
|
-
import
|
|
2868
|
+
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2869
|
+
import fs7 from "fs";
|
|
2870
|
+
import path5 from "path";
|
|
3001
2871
|
function isGitRepository(cwd = process.cwd()) {
|
|
3002
2872
|
try {
|
|
3003
|
-
const gitDir =
|
|
3004
|
-
if (
|
|
2873
|
+
const gitDir = path5.join(cwd, ".git");
|
|
2874
|
+
if (fs7.existsSync(gitDir)) {
|
|
3005
2875
|
return true;
|
|
3006
2876
|
}
|
|
3007
|
-
const result =
|
|
2877
|
+
const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
|
|
3008
2878
|
cwd,
|
|
3009
2879
|
stdio: "pipe",
|
|
3010
2880
|
encoding: "utf-8"
|
|
@@ -3030,11 +2900,11 @@ function getChangedFiles(cwd = process.cwd()) {
|
|
|
3030
2900
|
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
3031
2901
|
const filteredFiles = [];
|
|
3032
2902
|
for (const filePath of filesToStage) {
|
|
3033
|
-
if (
|
|
2903
|
+
if (fs7.existsSync(path5.join(cwd, filePath))) {
|
|
3034
2904
|
filteredFiles.push(filePath);
|
|
3035
2905
|
continue;
|
|
3036
2906
|
}
|
|
3037
|
-
const tracked =
|
|
2907
|
+
const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
3038
2908
|
cwd,
|
|
3039
2909
|
stdio: "pipe",
|
|
3040
2910
|
encoding: "utf-8"
|
|
@@ -3046,7 +2916,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
|
3046
2916
|
if (filteredFiles.length === 0) {
|
|
3047
2917
|
return;
|
|
3048
2918
|
}
|
|
3049
|
-
const result =
|
|
2919
|
+
const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
|
|
3050
2920
|
cwd,
|
|
3051
2921
|
stdio: "pipe",
|
|
3052
2922
|
encoding: "utf-8"
|
|
@@ -3057,7 +2927,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
|
3057
2927
|
}
|
|
3058
2928
|
}
|
|
3059
2929
|
function hasStagedChanges(cwd = process.cwd()) {
|
|
3060
|
-
const result =
|
|
2930
|
+
const result = spawnSync2("git", ["diff", "--cached", "--quiet"], {
|
|
3061
2931
|
cwd,
|
|
3062
2932
|
stdio: "pipe",
|
|
3063
2933
|
encoding: "utf-8"
|
|
@@ -3072,7 +2942,7 @@ function hasStagedChanges(cwd = process.cwd()) {
|
|
|
3072
2942
|
throw new Error(`Failed to check staged changes: ${errorMsg}`);
|
|
3073
2943
|
}
|
|
3074
2944
|
function gitCommit(message, cwd = process.cwd()) {
|
|
3075
|
-
const result =
|
|
2945
|
+
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
3076
2946
|
cwd,
|
|
3077
2947
|
stdio: "pipe",
|
|
3078
2948
|
encoding: "utf-8"
|
|
@@ -3114,16 +2984,74 @@ Auto-committed by fullstack-cli`;
|
|
|
3114
2984
|
}
|
|
3115
2985
|
}
|
|
3116
2986
|
|
|
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
|
+
|
|
3117
3045
|
// src/commands/upgrade/shared/utils.ts
|
|
3118
|
-
import
|
|
3119
|
-
import
|
|
3046
|
+
import path7 from "path";
|
|
3047
|
+
import fs9 from "fs";
|
|
3120
3048
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3121
3049
|
function getCliVersion() {
|
|
3122
3050
|
try {
|
|
3123
3051
|
const __filename = fileURLToPath4(import.meta.url);
|
|
3124
|
-
const __dirname2 =
|
|
3125
|
-
const pkgPath =
|
|
3126
|
-
const pkgContent =
|
|
3052
|
+
const __dirname2 = path7.dirname(__filename);
|
|
3053
|
+
const pkgPath = path7.resolve(__dirname2, "../../../package.json");
|
|
3054
|
+
const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
|
|
3127
3055
|
const pkg2 = JSON.parse(pkgContent);
|
|
3128
3056
|
return pkg2.version || "unknown";
|
|
3129
3057
|
} catch {
|
|
@@ -3181,9 +3109,9 @@ async function run3(options = {}) {
|
|
|
3181
3109
|
}
|
|
3182
3110
|
|
|
3183
3111
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3184
|
-
import { spawnSync as
|
|
3185
|
-
import
|
|
3186
|
-
import
|
|
3112
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
3113
|
+
import fs10 from "fs";
|
|
3114
|
+
import path8 from "path";
|
|
3187
3115
|
|
|
3188
3116
|
// src/utils/grayscale/config.ts
|
|
3189
3117
|
function getGrayscaleConfig(configJson) {
|
|
@@ -3402,7 +3330,7 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3402
3330
|
packages.forEach((pkg2) => {
|
|
3403
3331
|
const target = `${pkg2}@${version}`;
|
|
3404
3332
|
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
3405
|
-
const result =
|
|
3333
|
+
const result = spawnSync3("npm", ["install", target], {
|
|
3406
3334
|
cwd,
|
|
3407
3335
|
stdio: "inherit"
|
|
3408
3336
|
});
|
|
@@ -3414,7 +3342,7 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3414
3342
|
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
3415
3343
|
packages.forEach((pkg2) => {
|
|
3416
3344
|
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
3417
|
-
const result =
|
|
3345
|
+
const result = spawnSync3("npm", ["update", pkg2], {
|
|
3418
3346
|
cwd,
|
|
3419
3347
|
stdio: "inherit"
|
|
3420
3348
|
});
|
|
@@ -3431,8 +3359,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3431
3359
|
if (version) {
|
|
3432
3360
|
let current = "";
|
|
3433
3361
|
try {
|
|
3434
|
-
const installedPkgPath =
|
|
3435
|
-
const installedPkg = JSON.parse(
|
|
3362
|
+
const installedPkgPath = path8.join(cwd, "node_modules", pkg2, "package.json");
|
|
3363
|
+
const installedPkg = JSON.parse(fs10.readFileSync(installedPkgPath, "utf-8"));
|
|
3436
3364
|
current = installedPkg.version || "";
|
|
3437
3365
|
} catch (err) {
|
|
3438
3366
|
const code = err?.code;
|
|
@@ -3475,7 +3403,7 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3475
3403
|
}
|
|
3476
3404
|
const targets = upgradePlan.map(({ pkg: pkg2, version }) => `${pkg2}@${version}`);
|
|
3477
3405
|
console.log(`[fullstack-cli] Installing ${targets.join(" ")}...`);
|
|
3478
|
-
const result =
|
|
3406
|
+
const result = spawnSync3("npm", ["install", ...targets], {
|
|
3479
3407
|
cwd,
|
|
3480
3408
|
stdio: "inherit"
|
|
3481
3409
|
});
|
|
@@ -3549,9 +3477,9 @@ var depsCommand = {
|
|
|
3549
3477
|
};
|
|
3550
3478
|
|
|
3551
3479
|
// src/commands/upgrade/global-deps/run.handler.ts
|
|
3552
|
-
import { spawnSync as
|
|
3553
|
-
import
|
|
3554
|
-
import
|
|
3480
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
3481
|
+
import fs11 from "fs";
|
|
3482
|
+
import path9 from "path";
|
|
3555
3483
|
var MANAGED_GLOBAL_CLIS = [
|
|
3556
3484
|
"@lark-apaas/fullstack-cli",
|
|
3557
3485
|
"@lark-apaas/miaoda-cli"
|
|
@@ -3562,15 +3490,15 @@ function readGlobalInstalledVersion(pkg2) {
|
|
|
3562
3490
|
if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
|
|
3563
3491
|
candidates.push("/usr");
|
|
3564
3492
|
candidates.push("/usr/local");
|
|
3565
|
-
if (process.env.HOME) candidates.push(
|
|
3493
|
+
if (process.env.HOME) candidates.push(path9.join(process.env.HOME, ".npm-global"));
|
|
3566
3494
|
const seen = /* @__PURE__ */ new Set();
|
|
3567
3495
|
for (const prefix of candidates) {
|
|
3568
3496
|
if (seen.has(prefix)) continue;
|
|
3569
3497
|
seen.add(prefix);
|
|
3570
3498
|
try {
|
|
3571
|
-
const pkgPath =
|
|
3572
|
-
if (
|
|
3573
|
-
const meta = JSON.parse(
|
|
3499
|
+
const pkgPath = path9.join(prefix, "lib", "node_modules", pkg2, "package.json");
|
|
3500
|
+
if (fs11.existsSync(pkgPath)) {
|
|
3501
|
+
const meta = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
3574
3502
|
if (meta && typeof meta.version === "string") return meta.version;
|
|
3575
3503
|
}
|
|
3576
3504
|
} catch (err) {
|
|
@@ -3628,7 +3556,7 @@ async function run5(options = {}) {
|
|
|
3628
3556
|
npmArgs.push("--registry", options.registry);
|
|
3629
3557
|
}
|
|
3630
3558
|
console.log(`[fullstack-cli] Running: npm ${npmArgs.join(" ")}`);
|
|
3631
|
-
const result =
|
|
3559
|
+
const result = spawnSync4("npm", npmArgs, { stdio: "inherit" });
|
|
3632
3560
|
if (result.error || result.status !== 0) {
|
|
3633
3561
|
console.warn(
|
|
3634
3562
|
`[fullstack-cli] npm install -g failed: ${result.error?.message ?? `exit ${result.status}`}`
|
|
@@ -3667,9 +3595,9 @@ var upgradeCommand = {
|
|
|
3667
3595
|
};
|
|
3668
3596
|
|
|
3669
3597
|
// src/commands/action-plugin/utils.ts
|
|
3670
|
-
import
|
|
3671
|
-
import
|
|
3672
|
-
import { spawnSync as
|
|
3598
|
+
import fs12 from "fs";
|
|
3599
|
+
import path10 from "path";
|
|
3600
|
+
import { spawnSync as spawnSync5, execSync as execSync2 } from "child_process";
|
|
3673
3601
|
function parsePluginName(input) {
|
|
3674
3602
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
3675
3603
|
if (!match) {
|
|
@@ -3686,18 +3614,18 @@ function getProjectRoot() {
|
|
|
3686
3614
|
return process.cwd();
|
|
3687
3615
|
}
|
|
3688
3616
|
function getPackageJsonPath() {
|
|
3689
|
-
return
|
|
3617
|
+
return path10.join(getProjectRoot(), "package.json");
|
|
3690
3618
|
}
|
|
3691
3619
|
function getPluginPath(pluginName) {
|
|
3692
|
-
return
|
|
3620
|
+
return path10.join(getProjectRoot(), "node_modules", pluginName);
|
|
3693
3621
|
}
|
|
3694
3622
|
function readPackageJson2() {
|
|
3695
3623
|
const pkgPath = getPackageJsonPath();
|
|
3696
|
-
if (!
|
|
3624
|
+
if (!fs12.existsSync(pkgPath)) {
|
|
3697
3625
|
throw new Error("package.json not found in current directory");
|
|
3698
3626
|
}
|
|
3699
3627
|
try {
|
|
3700
|
-
const content =
|
|
3628
|
+
const content = fs12.readFileSync(pkgPath, "utf-8");
|
|
3701
3629
|
return JSON.parse(content);
|
|
3702
3630
|
} catch {
|
|
3703
3631
|
throw new Error("Failed to parse package.json");
|
|
@@ -3705,7 +3633,7 @@ function readPackageJson2() {
|
|
|
3705
3633
|
}
|
|
3706
3634
|
function writePackageJson2(pkg2) {
|
|
3707
3635
|
const pkgPath = getPackageJsonPath();
|
|
3708
|
-
|
|
3636
|
+
fs12.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3709
3637
|
}
|
|
3710
3638
|
function readActionPlugins() {
|
|
3711
3639
|
const pkg2 = readPackageJson2();
|
|
@@ -3726,7 +3654,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
3726
3654
|
}
|
|
3727
3655
|
function npmInstall(tgzPath) {
|
|
3728
3656
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
3729
|
-
const result =
|
|
3657
|
+
const result = spawnSync5("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
3730
3658
|
cwd: getProjectRoot(),
|
|
3731
3659
|
stdio: "inherit"
|
|
3732
3660
|
});
|
|
@@ -3738,12 +3666,12 @@ function npmInstall(tgzPath) {
|
|
|
3738
3666
|
}
|
|
3739
3667
|
}
|
|
3740
3668
|
function getPackageVersion(pluginName) {
|
|
3741
|
-
const pkgJsonPath =
|
|
3742
|
-
if (!
|
|
3669
|
+
const pkgJsonPath = path10.join(getPluginPath(pluginName), "package.json");
|
|
3670
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3743
3671
|
return null;
|
|
3744
3672
|
}
|
|
3745
3673
|
try {
|
|
3746
|
-
const content =
|
|
3674
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3747
3675
|
const pkg2 = JSON.parse(content);
|
|
3748
3676
|
return pkg2.version || null;
|
|
3749
3677
|
} catch {
|
|
@@ -3751,49 +3679,49 @@ function getPackageVersion(pluginName) {
|
|
|
3751
3679
|
}
|
|
3752
3680
|
}
|
|
3753
3681
|
function readPluginPackageJson(pluginPath) {
|
|
3754
|
-
const pkgJsonPath =
|
|
3755
|
-
if (!
|
|
3682
|
+
const pkgJsonPath = path10.join(pluginPath, "package.json");
|
|
3683
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3756
3684
|
return null;
|
|
3757
3685
|
}
|
|
3758
3686
|
try {
|
|
3759
|
-
const content =
|
|
3687
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3760
3688
|
return JSON.parse(content);
|
|
3761
3689
|
} catch {
|
|
3762
3690
|
return null;
|
|
3763
3691
|
}
|
|
3764
3692
|
}
|
|
3765
3693
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3766
|
-
const nodeModulesPath =
|
|
3767
|
-
const targetDir =
|
|
3768
|
-
const scopeDir =
|
|
3769
|
-
if (!
|
|
3770
|
-
|
|
3694
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3695
|
+
const targetDir = path10.join(nodeModulesPath, pluginName);
|
|
3696
|
+
const scopeDir = path10.dirname(targetDir);
|
|
3697
|
+
if (!fs12.existsSync(scopeDir)) {
|
|
3698
|
+
fs12.mkdirSync(scopeDir, { recursive: true });
|
|
3771
3699
|
}
|
|
3772
|
-
if (
|
|
3773
|
-
|
|
3700
|
+
if (fs12.existsSync(targetDir)) {
|
|
3701
|
+
fs12.rmSync(targetDir, { recursive: true });
|
|
3774
3702
|
}
|
|
3775
|
-
const tempDir =
|
|
3776
|
-
if (
|
|
3777
|
-
|
|
3703
|
+
const tempDir = path10.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3704
|
+
if (fs12.existsSync(tempDir)) {
|
|
3705
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3778
3706
|
}
|
|
3779
|
-
|
|
3707
|
+
fs12.mkdirSync(tempDir, { recursive: true });
|
|
3780
3708
|
try {
|
|
3781
3709
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3782
|
-
const extractedDir =
|
|
3783
|
-
if (
|
|
3784
|
-
|
|
3710
|
+
const extractedDir = path10.join(tempDir, "package");
|
|
3711
|
+
if (fs12.existsSync(extractedDir)) {
|
|
3712
|
+
fs12.renameSync(extractedDir, targetDir);
|
|
3785
3713
|
} else {
|
|
3786
|
-
const files =
|
|
3714
|
+
const files = fs12.readdirSync(tempDir);
|
|
3787
3715
|
if (files.length === 1) {
|
|
3788
|
-
|
|
3716
|
+
fs12.renameSync(path10.join(tempDir, files[0]), targetDir);
|
|
3789
3717
|
} else {
|
|
3790
3718
|
throw new Error("Unexpected tgz structure");
|
|
3791
3719
|
}
|
|
3792
3720
|
}
|
|
3793
3721
|
return targetDir;
|
|
3794
3722
|
} finally {
|
|
3795
|
-
if (
|
|
3796
|
-
|
|
3723
|
+
if (fs12.existsSync(tempDir)) {
|
|
3724
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3797
3725
|
}
|
|
3798
3726
|
}
|
|
3799
3727
|
}
|
|
@@ -3802,10 +3730,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3802
3730
|
return [];
|
|
3803
3731
|
}
|
|
3804
3732
|
const missing = [];
|
|
3805
|
-
const nodeModulesPath =
|
|
3733
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3806
3734
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3807
|
-
const depPath =
|
|
3808
|
-
if (!
|
|
3735
|
+
const depPath = path10.join(nodeModulesPath, depName);
|
|
3736
|
+
if (!fs12.existsSync(depPath)) {
|
|
3809
3737
|
missing.push(depName);
|
|
3810
3738
|
}
|
|
3811
3739
|
}
|
|
@@ -3816,7 +3744,7 @@ function installMissingDeps(deps) {
|
|
|
3816
3744
|
return;
|
|
3817
3745
|
}
|
|
3818
3746
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
3819
|
-
const result =
|
|
3747
|
+
const result = spawnSync5("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
3820
3748
|
cwd: getProjectRoot(),
|
|
3821
3749
|
stdio: "inherit"
|
|
3822
3750
|
});
|
|
@@ -3829,16 +3757,16 @@ function installMissingDeps(deps) {
|
|
|
3829
3757
|
}
|
|
3830
3758
|
function removePluginDirectory(pluginName) {
|
|
3831
3759
|
const pluginPath = getPluginPath(pluginName);
|
|
3832
|
-
if (
|
|
3833
|
-
|
|
3760
|
+
if (fs12.existsSync(pluginPath)) {
|
|
3761
|
+
fs12.rmSync(pluginPath, { recursive: true });
|
|
3834
3762
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3835
3763
|
}
|
|
3836
3764
|
}
|
|
3837
3765
|
|
|
3838
3766
|
// src/commands/action-plugin/api-client.ts
|
|
3839
3767
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3840
|
-
import
|
|
3841
|
-
import
|
|
3768
|
+
import fs13 from "fs";
|
|
3769
|
+
import path11 from "path";
|
|
3842
3770
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3843
3771
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3844
3772
|
const client = getHttpClient();
|
|
@@ -3902,19 +3830,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3902
3830
|
return Buffer.from(arrayBuffer);
|
|
3903
3831
|
}
|
|
3904
3832
|
function getPluginCacheDir() {
|
|
3905
|
-
return
|
|
3833
|
+
return path11.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3906
3834
|
}
|
|
3907
3835
|
function ensureCacheDir() {
|
|
3908
3836
|
const cacheDir = getPluginCacheDir();
|
|
3909
|
-
if (!
|
|
3910
|
-
|
|
3837
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3838
|
+
fs13.mkdirSync(cacheDir, { recursive: true });
|
|
3911
3839
|
}
|
|
3912
3840
|
}
|
|
3913
3841
|
function getTempFilePath(pluginKey, version) {
|
|
3914
3842
|
ensureCacheDir();
|
|
3915
3843
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3916
3844
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3917
|
-
return
|
|
3845
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3918
3846
|
}
|
|
3919
3847
|
var MAX_RETRIES = 2;
|
|
3920
3848
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3951,7 +3879,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3951
3879
|
);
|
|
3952
3880
|
}
|
|
3953
3881
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3954
|
-
|
|
3882
|
+
fs13.writeFileSync(tgzPath, tgzBuffer);
|
|
3955
3883
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3956
3884
|
return {
|
|
3957
3885
|
tgzPath,
|
|
@@ -3965,18 +3893,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3965
3893
|
ensureCacheDir();
|
|
3966
3894
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3967
3895
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3968
|
-
return
|
|
3896
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3969
3897
|
}
|
|
3970
3898
|
function hasCachedPlugin(pluginKey, version) {
|
|
3971
3899
|
const cachePath = getCachePath(pluginKey, version);
|
|
3972
|
-
return
|
|
3900
|
+
return fs13.existsSync(cachePath);
|
|
3973
3901
|
}
|
|
3974
3902
|
function listCachedPlugins() {
|
|
3975
3903
|
const cacheDir = getPluginCacheDir();
|
|
3976
|
-
if (!
|
|
3904
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3977
3905
|
return [];
|
|
3978
3906
|
}
|
|
3979
|
-
const files =
|
|
3907
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3980
3908
|
const result = [];
|
|
3981
3909
|
for (const file of files) {
|
|
3982
3910
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3984,8 +3912,8 @@ function listCachedPlugins() {
|
|
|
3984
3912
|
if (!match) continue;
|
|
3985
3913
|
const [, rawName, version] = match;
|
|
3986
3914
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3987
|
-
const filePath =
|
|
3988
|
-
const stat =
|
|
3915
|
+
const filePath = path11.join(cacheDir, file);
|
|
3916
|
+
const stat = fs13.statSync(filePath);
|
|
3989
3917
|
result.push({
|
|
3990
3918
|
name,
|
|
3991
3919
|
version,
|
|
@@ -3998,14 +3926,14 @@ function listCachedPlugins() {
|
|
|
3998
3926
|
}
|
|
3999
3927
|
function cleanAllCache() {
|
|
4000
3928
|
const cacheDir = getPluginCacheDir();
|
|
4001
|
-
if (!
|
|
3929
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
4002
3930
|
return 0;
|
|
4003
3931
|
}
|
|
4004
|
-
const files =
|
|
3932
|
+
const files = fs13.readdirSync(cacheDir);
|
|
4005
3933
|
let count = 0;
|
|
4006
3934
|
for (const file of files) {
|
|
4007
3935
|
if (file.endsWith(".tgz")) {
|
|
4008
|
-
|
|
3936
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
4009
3937
|
count++;
|
|
4010
3938
|
}
|
|
4011
3939
|
}
|
|
@@ -4013,21 +3941,21 @@ function cleanAllCache() {
|
|
|
4013
3941
|
}
|
|
4014
3942
|
function cleanPluginCache(pluginKey, version) {
|
|
4015
3943
|
const cacheDir = getPluginCacheDir();
|
|
4016
|
-
if (!
|
|
3944
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
4017
3945
|
return 0;
|
|
4018
3946
|
}
|
|
4019
3947
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4020
|
-
const files =
|
|
3948
|
+
const files = fs13.readdirSync(cacheDir);
|
|
4021
3949
|
let count = 0;
|
|
4022
3950
|
for (const file of files) {
|
|
4023
3951
|
if (version) {
|
|
4024
3952
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
4025
|
-
|
|
3953
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
4026
3954
|
count++;
|
|
4027
3955
|
}
|
|
4028
3956
|
} else {
|
|
4029
3957
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
4030
|
-
|
|
3958
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
4031
3959
|
count++;
|
|
4032
3960
|
}
|
|
4033
3961
|
}
|
|
@@ -4454,40 +4382,40 @@ var actionPluginCommandGroup = {
|
|
|
4454
4382
|
};
|
|
4455
4383
|
|
|
4456
4384
|
// src/commands/capability/utils.ts
|
|
4457
|
-
import
|
|
4385
|
+
import fs14 from "fs";
|
|
4458
4386
|
import { createRequire as createRequire2 } from "module";
|
|
4459
|
-
import
|
|
4387
|
+
import path12 from "path";
|
|
4460
4388
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4461
4389
|
function getProjectRoot2() {
|
|
4462
4390
|
return process.cwd();
|
|
4463
4391
|
}
|
|
4464
4392
|
function getCapabilitiesDir() {
|
|
4465
|
-
return
|
|
4393
|
+
return path12.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4466
4394
|
}
|
|
4467
4395
|
function getCapabilityPath(id) {
|
|
4468
|
-
return
|
|
4396
|
+
return path12.join(getCapabilitiesDir(), `${id}.json`);
|
|
4469
4397
|
}
|
|
4470
4398
|
function getPluginManifestPath(pluginKey) {
|
|
4471
|
-
return
|
|
4399
|
+
return path12.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4472
4400
|
}
|
|
4473
4401
|
function capabilitiesDirExists() {
|
|
4474
|
-
return
|
|
4402
|
+
return fs14.existsSync(getCapabilitiesDir());
|
|
4475
4403
|
}
|
|
4476
4404
|
function listCapabilityIds() {
|
|
4477
4405
|
const dir = getCapabilitiesDir();
|
|
4478
|
-
if (!
|
|
4406
|
+
if (!fs14.existsSync(dir)) {
|
|
4479
4407
|
return [];
|
|
4480
4408
|
}
|
|
4481
|
-
const files =
|
|
4409
|
+
const files = fs14.readdirSync(dir);
|
|
4482
4410
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4483
4411
|
}
|
|
4484
4412
|
function readCapability(id) {
|
|
4485
4413
|
const filePath = getCapabilityPath(id);
|
|
4486
|
-
if (!
|
|
4414
|
+
if (!fs14.existsSync(filePath)) {
|
|
4487
4415
|
throw new Error(`Capability not found: ${id}`);
|
|
4488
4416
|
}
|
|
4489
4417
|
try {
|
|
4490
|
-
const content =
|
|
4418
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4491
4419
|
return JSON.parse(content);
|
|
4492
4420
|
} catch (error) {
|
|
4493
4421
|
if (error instanceof SyntaxError) {
|
|
@@ -4514,11 +4442,11 @@ function readAllCapabilities() {
|
|
|
4514
4442
|
}
|
|
4515
4443
|
function readPluginManifest(pluginKey) {
|
|
4516
4444
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4517
|
-
if (!
|
|
4445
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
4518
4446
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4519
4447
|
}
|
|
4520
4448
|
try {
|
|
4521
|
-
const content =
|
|
4449
|
+
const content = fs14.readFileSync(manifestPath, "utf-8");
|
|
4522
4450
|
return JSON.parse(content);
|
|
4523
4451
|
} catch (error) {
|
|
4524
4452
|
if (error instanceof SyntaxError) {
|
|
@@ -4535,7 +4463,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4535
4463
|
}
|
|
4536
4464
|
async function loadPlugin(pluginKey) {
|
|
4537
4465
|
try {
|
|
4538
|
-
const userRequire = createRequire2(
|
|
4466
|
+
const userRequire = createRequire2(path12.join(getProjectRoot2(), "package.json"));
|
|
4539
4467
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4540
4468
|
const pluginModule = await import(resolvedPath);
|
|
4541
4469
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4698,8 +4626,8 @@ var capabilityCommandGroup = {
|
|
|
4698
4626
|
import { execFile } from "child_process";
|
|
4699
4627
|
|
|
4700
4628
|
// src/commands/component/registry-preparer.ts
|
|
4701
|
-
import
|
|
4702
|
-
import
|
|
4629
|
+
import fs15 from "fs";
|
|
4630
|
+
import path13 from "path";
|
|
4703
4631
|
import os from "os";
|
|
4704
4632
|
|
|
4705
4633
|
// src/commands/component/service.ts
|
|
@@ -4755,7 +4683,7 @@ async function sendInstallEvent(key) {
|
|
|
4755
4683
|
}
|
|
4756
4684
|
|
|
4757
4685
|
// src/commands/component/registry-preparer.ts
|
|
4758
|
-
var REGISTRY_TEMP_DIR =
|
|
4686
|
+
var REGISTRY_TEMP_DIR = path13.join(os.tmpdir(), "miaoda-registry");
|
|
4759
4687
|
function parseComponentKey(key) {
|
|
4760
4688
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4761
4689
|
if (!match) {
|
|
@@ -4767,11 +4695,11 @@ function parseComponentKey(key) {
|
|
|
4767
4695
|
}
|
|
4768
4696
|
function getLocalRegistryPath(key) {
|
|
4769
4697
|
const { scope, name } = parseComponentKey(key);
|
|
4770
|
-
return
|
|
4698
|
+
return path13.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4771
4699
|
}
|
|
4772
4700
|
function ensureDir(dirPath) {
|
|
4773
|
-
if (!
|
|
4774
|
-
|
|
4701
|
+
if (!fs15.existsSync(dirPath)) {
|
|
4702
|
+
fs15.mkdirSync(dirPath, { recursive: true });
|
|
4775
4703
|
}
|
|
4776
4704
|
}
|
|
4777
4705
|
async function prepareRecursive(key, visited) {
|
|
@@ -4804,8 +4732,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4804
4732
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4805
4733
|
};
|
|
4806
4734
|
const localPath = getLocalRegistryPath(key);
|
|
4807
|
-
ensureDir(
|
|
4808
|
-
|
|
4735
|
+
ensureDir(path13.dirname(localPath));
|
|
4736
|
+
fs15.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4809
4737
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4810
4738
|
}
|
|
4811
4739
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4815,18 +4743,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4815
4743
|
}
|
|
4816
4744
|
function cleanupTempDir() {
|
|
4817
4745
|
try {
|
|
4818
|
-
if (
|
|
4819
|
-
|
|
4746
|
+
if (fs15.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4747
|
+
fs15.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4820
4748
|
}
|
|
4821
4749
|
} catch {
|
|
4822
4750
|
}
|
|
4823
4751
|
}
|
|
4824
4752
|
function getDownloadedRegistryItem(itemId) {
|
|
4825
4753
|
const localPath = getLocalRegistryPath(itemId);
|
|
4826
|
-
if (!
|
|
4754
|
+
if (!fs15.existsSync(localPath)) {
|
|
4827
4755
|
return null;
|
|
4828
4756
|
}
|
|
4829
|
-
const content =
|
|
4757
|
+
const content = fs15.readFileSync(localPath, "utf-8");
|
|
4830
4758
|
return JSON.parse(content);
|
|
4831
4759
|
}
|
|
4832
4760
|
|
|
@@ -4994,58 +4922,58 @@ var componentCommandGroup = {
|
|
|
4994
4922
|
};
|
|
4995
4923
|
|
|
4996
4924
|
// src/commands/migration/version-manager.ts
|
|
4997
|
-
import
|
|
4998
|
-
import
|
|
4925
|
+
import fs16 from "fs";
|
|
4926
|
+
import path14 from "path";
|
|
4999
4927
|
var PACKAGE_JSON = "package.json";
|
|
5000
4928
|
var VERSION_FIELD = "migrationVersion";
|
|
5001
4929
|
function getPackageJsonPath2() {
|
|
5002
|
-
return
|
|
4930
|
+
return path14.join(process.cwd(), PACKAGE_JSON);
|
|
5003
4931
|
}
|
|
5004
4932
|
function getCurrentVersion() {
|
|
5005
4933
|
const pkgPath = getPackageJsonPath2();
|
|
5006
|
-
if (!
|
|
4934
|
+
if (!fs16.existsSync(pkgPath)) {
|
|
5007
4935
|
throw new Error("package.json not found");
|
|
5008
4936
|
}
|
|
5009
|
-
const pkg2 = JSON.parse(
|
|
4937
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
5010
4938
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
5011
4939
|
}
|
|
5012
4940
|
function setCurrentVersion(version) {
|
|
5013
4941
|
const pkgPath = getPackageJsonPath2();
|
|
5014
|
-
const pkg2 = JSON.parse(
|
|
4942
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
5015
4943
|
pkg2[VERSION_FIELD] = version;
|
|
5016
|
-
|
|
4944
|
+
fs16.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
5017
4945
|
}
|
|
5018
4946
|
|
|
5019
4947
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5020
|
-
import fs19 from "fs";
|
|
5021
|
-
import path17 from "path";
|
|
5022
|
-
|
|
5023
|
-
// src/commands/migration/versions/v001_capability/utils.ts
|
|
5024
4948
|
import fs18 from "fs";
|
|
5025
4949
|
import path16 from "path";
|
|
4950
|
+
|
|
4951
|
+
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4952
|
+
import fs17 from "fs";
|
|
4953
|
+
import path15 from "path";
|
|
5026
4954
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
5027
4955
|
function getProjectRoot3() {
|
|
5028
4956
|
return process.cwd();
|
|
5029
4957
|
}
|
|
5030
4958
|
function getCapabilitiesDir2() {
|
|
5031
|
-
return
|
|
4959
|
+
return path15.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
5032
4960
|
}
|
|
5033
4961
|
function getPluginManifestPath2(pluginKey) {
|
|
5034
|
-
return
|
|
4962
|
+
return path15.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
5035
4963
|
}
|
|
5036
4964
|
|
|
5037
4965
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5038
4966
|
function detectJsonMigration() {
|
|
5039
4967
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5040
|
-
const oldFilePath =
|
|
5041
|
-
if (!
|
|
4968
|
+
const oldFilePath = path16.join(capabilitiesDir, "capabilities.json");
|
|
4969
|
+
if (!fs18.existsSync(oldFilePath)) {
|
|
5042
4970
|
return {
|
|
5043
4971
|
needsMigration: false,
|
|
5044
4972
|
reason: "capabilities.json not found"
|
|
5045
4973
|
};
|
|
5046
4974
|
}
|
|
5047
4975
|
try {
|
|
5048
|
-
const content =
|
|
4976
|
+
const content = fs18.readFileSync(oldFilePath, "utf-8");
|
|
5049
4977
|
const parsed = JSON.parse(content);
|
|
5050
4978
|
if (!Array.isArray(parsed)) {
|
|
5051
4979
|
return {
|
|
@@ -5096,8 +5024,8 @@ async function check(options) {
|
|
|
5096
5024
|
}
|
|
5097
5025
|
|
|
5098
5026
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5099
|
-
import
|
|
5100
|
-
import
|
|
5027
|
+
import fs19 from "fs";
|
|
5028
|
+
import path17 from "path";
|
|
5101
5029
|
|
|
5102
5030
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5103
5031
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5327,18 +5255,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5327
5255
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5328
5256
|
function loadExistingCapabilities() {
|
|
5329
5257
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5330
|
-
if (!
|
|
5258
|
+
if (!fs19.existsSync(capabilitiesDir)) {
|
|
5331
5259
|
return [];
|
|
5332
5260
|
}
|
|
5333
|
-
const files =
|
|
5261
|
+
const files = fs19.readdirSync(capabilitiesDir);
|
|
5334
5262
|
const capabilities = [];
|
|
5335
5263
|
for (const file of files) {
|
|
5336
5264
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5337
5265
|
continue;
|
|
5338
5266
|
}
|
|
5339
5267
|
try {
|
|
5340
|
-
const filePath =
|
|
5341
|
-
const content =
|
|
5268
|
+
const filePath = path17.join(capabilitiesDir, file);
|
|
5269
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
5342
5270
|
const capability = JSON.parse(content);
|
|
5343
5271
|
if (capability.id && capability.pluginKey) {
|
|
5344
5272
|
capabilities.push(capability);
|
|
@@ -5396,9 +5324,9 @@ async function migrateJsonFiles(options) {
|
|
|
5396
5324
|
}
|
|
5397
5325
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5398
5326
|
for (const cap of newCapabilities) {
|
|
5399
|
-
const filePath =
|
|
5327
|
+
const filePath = path17.join(capabilitiesDir, `${cap.id}.json`);
|
|
5400
5328
|
const content = JSON.stringify(cap, null, 2);
|
|
5401
|
-
|
|
5329
|
+
fs19.writeFileSync(filePath, content, "utf-8");
|
|
5402
5330
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5403
5331
|
}
|
|
5404
5332
|
return {
|
|
@@ -5410,11 +5338,11 @@ async function migrateJsonFiles(options) {
|
|
|
5410
5338
|
}
|
|
5411
5339
|
|
|
5412
5340
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5413
|
-
import
|
|
5341
|
+
import fs20 from "fs";
|
|
5414
5342
|
function isPluginInstalled2(pluginKey) {
|
|
5415
5343
|
const actionPlugins = readActionPlugins();
|
|
5416
5344
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5417
|
-
return
|
|
5345
|
+
return fs20.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5418
5346
|
}
|
|
5419
5347
|
function detectPluginsToInstall(capabilities) {
|
|
5420
5348
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5490,12 +5418,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5490
5418
|
}
|
|
5491
5419
|
|
|
5492
5420
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5493
|
-
import
|
|
5421
|
+
import path19 from "path";
|
|
5494
5422
|
import { Project as Project3 } from "ts-morph";
|
|
5495
5423
|
|
|
5496
5424
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5497
|
-
import
|
|
5498
|
-
import
|
|
5425
|
+
import fs21 from "fs";
|
|
5426
|
+
import path18 from "path";
|
|
5499
5427
|
var EXCLUDED_DIRS = [
|
|
5500
5428
|
"node_modules",
|
|
5501
5429
|
"dist",
|
|
@@ -5510,9 +5438,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5510
5438
|
/\.d\.ts$/
|
|
5511
5439
|
];
|
|
5512
5440
|
function scanDirectory(dir, files = []) {
|
|
5513
|
-
const entries =
|
|
5441
|
+
const entries = fs21.readdirSync(dir, { withFileTypes: true });
|
|
5514
5442
|
for (const entry of entries) {
|
|
5515
|
-
const fullPath =
|
|
5443
|
+
const fullPath = path18.join(dir, entry.name);
|
|
5516
5444
|
if (entry.isDirectory()) {
|
|
5517
5445
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5518
5446
|
continue;
|
|
@@ -5528,14 +5456,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5528
5456
|
return files;
|
|
5529
5457
|
}
|
|
5530
5458
|
function scanServerFiles() {
|
|
5531
|
-
const serverDir =
|
|
5532
|
-
if (!
|
|
5459
|
+
const serverDir = path18.join(getProjectRoot3(), "server");
|
|
5460
|
+
if (!fs21.existsSync(serverDir)) {
|
|
5533
5461
|
return [];
|
|
5534
5462
|
}
|
|
5535
5463
|
return scanDirectory(serverDir);
|
|
5536
5464
|
}
|
|
5537
5465
|
function hasCapabilityImport(filePath) {
|
|
5538
|
-
const content =
|
|
5466
|
+
const content = fs21.readFileSync(filePath, "utf-8");
|
|
5539
5467
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5540
5468
|
}
|
|
5541
5469
|
function scanFilesToMigrate() {
|
|
@@ -5912,7 +5840,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5912
5840
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5913
5841
|
const classInfo = analyzeClass(sourceFile);
|
|
5914
5842
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5915
|
-
const relativePath =
|
|
5843
|
+
const relativePath = path19.relative(getProjectRoot3(), filePath);
|
|
5916
5844
|
return {
|
|
5917
5845
|
filePath: relativePath,
|
|
5918
5846
|
imports,
|
|
@@ -5923,7 +5851,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5923
5851
|
};
|
|
5924
5852
|
}
|
|
5925
5853
|
function migrateFile(project, analysis, dryRun) {
|
|
5926
|
-
const absolutePath =
|
|
5854
|
+
const absolutePath = path19.join(getProjectRoot3(), analysis.filePath);
|
|
5927
5855
|
if (!analysis.canAutoMigrate) {
|
|
5928
5856
|
return {
|
|
5929
5857
|
filePath: analysis.filePath,
|
|
@@ -6026,17 +5954,17 @@ function getSuggestion(analysis) {
|
|
|
6026
5954
|
}
|
|
6027
5955
|
|
|
6028
5956
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
6029
|
-
import
|
|
6030
|
-
import
|
|
5957
|
+
import fs22 from "fs";
|
|
5958
|
+
import path20 from "path";
|
|
6031
5959
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
6032
5960
|
const deletedFiles = [];
|
|
6033
5961
|
const errors = [];
|
|
6034
5962
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6035
|
-
const oldJsonPath =
|
|
6036
|
-
if (
|
|
5963
|
+
const oldJsonPath = path20.join(capabilitiesDir, "capabilities.json");
|
|
5964
|
+
if (fs22.existsSync(oldJsonPath)) {
|
|
6037
5965
|
try {
|
|
6038
5966
|
if (!dryRun) {
|
|
6039
|
-
|
|
5967
|
+
fs22.unlinkSync(oldJsonPath);
|
|
6040
5968
|
}
|
|
6041
5969
|
deletedFiles.push("capabilities.json");
|
|
6042
5970
|
} catch (error) {
|
|
@@ -6044,11 +5972,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6044
5972
|
}
|
|
6045
5973
|
}
|
|
6046
5974
|
for (const cap of capabilities) {
|
|
6047
|
-
const tsFilePath =
|
|
6048
|
-
if (
|
|
5975
|
+
const tsFilePath = path20.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5976
|
+
if (fs22.existsSync(tsFilePath)) {
|
|
6049
5977
|
try {
|
|
6050
5978
|
if (!dryRun) {
|
|
6051
|
-
|
|
5979
|
+
fs22.unlinkSync(tsFilePath);
|
|
6052
5980
|
}
|
|
6053
5981
|
deletedFiles.push(`${cap.id}.ts`);
|
|
6054
5982
|
} catch (error) {
|
|
@@ -6064,8 +5992,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6064
5992
|
}
|
|
6065
5993
|
|
|
6066
5994
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
6067
|
-
import
|
|
6068
|
-
import
|
|
5995
|
+
import fs23 from "fs";
|
|
5996
|
+
import path21 from "path";
|
|
6069
5997
|
var REPORT_FILE = "capability-migration-report.md";
|
|
6070
5998
|
function printSummary(result) {
|
|
6071
5999
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6228,15 +6156,15 @@ async function generateReport(result) {
|
|
|
6228
6156
|
}
|
|
6229
6157
|
lines.push("");
|
|
6230
6158
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6231
|
-
if (!
|
|
6159
|
+
if (!fs23.existsSync(logDir)) {
|
|
6232
6160
|
return;
|
|
6233
6161
|
}
|
|
6234
|
-
const reportDir =
|
|
6235
|
-
if (!
|
|
6236
|
-
|
|
6162
|
+
const reportDir = path21.join(logDir, "migration");
|
|
6163
|
+
if (!fs23.existsSync(reportDir)) {
|
|
6164
|
+
fs23.mkdirSync(reportDir, { recursive: true });
|
|
6237
6165
|
}
|
|
6238
|
-
const reportPath =
|
|
6239
|
-
|
|
6166
|
+
const reportPath = path21.join(reportDir, REPORT_FILE);
|
|
6167
|
+
fs23.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6240
6168
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6241
6169
|
}
|
|
6242
6170
|
|
|
@@ -6768,10 +6696,10 @@ var migrationCommand = {
|
|
|
6768
6696
|
};
|
|
6769
6697
|
|
|
6770
6698
|
// src/commands/read-logs/index.ts
|
|
6771
|
-
import
|
|
6699
|
+
import path22 from "path";
|
|
6772
6700
|
|
|
6773
6701
|
// src/commands/read-logs/std-utils.ts
|
|
6774
|
-
import
|
|
6702
|
+
import fs24 from "fs";
|
|
6775
6703
|
function formatStdPrefixTime(localTime) {
|
|
6776
6704
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6777
6705
|
if (!match) return localTime;
|
|
@@ -6801,11 +6729,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6801
6729
|
return `[${time}] ${content}`;
|
|
6802
6730
|
}
|
|
6803
6731
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6804
|
-
const stat =
|
|
6732
|
+
const stat = fs24.statSync(filePath);
|
|
6805
6733
|
if (stat.size === 0) {
|
|
6806
6734
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6807
6735
|
}
|
|
6808
|
-
const fd =
|
|
6736
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6809
6737
|
const chunkSize = 64 * 1024;
|
|
6810
6738
|
let position = stat.size;
|
|
6811
6739
|
let remainder = "";
|
|
@@ -6819,7 +6747,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6819
6747
|
const length = Math.min(chunkSize, position);
|
|
6820
6748
|
position -= length;
|
|
6821
6749
|
const buffer = Buffer.alloc(length);
|
|
6822
|
-
|
|
6750
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6823
6751
|
let chunk = buffer.toString("utf8");
|
|
6824
6752
|
if (remainder) {
|
|
6825
6753
|
chunk += remainder;
|
|
@@ -6861,7 +6789,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6861
6789
|
}
|
|
6862
6790
|
}
|
|
6863
6791
|
} finally {
|
|
6864
|
-
|
|
6792
|
+
fs24.closeSync(fd);
|
|
6865
6793
|
}
|
|
6866
6794
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6867
6795
|
}
|
|
@@ -6882,21 +6810,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6882
6810
|
}
|
|
6883
6811
|
|
|
6884
6812
|
// src/commands/read-logs/tail.ts
|
|
6885
|
-
import
|
|
6813
|
+
import fs25 from "fs";
|
|
6886
6814
|
function fileExists(filePath) {
|
|
6887
6815
|
try {
|
|
6888
|
-
|
|
6816
|
+
fs25.accessSync(filePath, fs25.constants.F_OK | fs25.constants.R_OK);
|
|
6889
6817
|
return true;
|
|
6890
6818
|
} catch {
|
|
6891
6819
|
return false;
|
|
6892
6820
|
}
|
|
6893
6821
|
}
|
|
6894
6822
|
function readFileTailLines(filePath, maxLines) {
|
|
6895
|
-
const stat =
|
|
6823
|
+
const stat = fs25.statSync(filePath);
|
|
6896
6824
|
if (stat.size === 0) {
|
|
6897
6825
|
return [];
|
|
6898
6826
|
}
|
|
6899
|
-
const fd =
|
|
6827
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6900
6828
|
const chunkSize = 64 * 1024;
|
|
6901
6829
|
const chunks = [];
|
|
6902
6830
|
let position = stat.size;
|
|
@@ -6906,13 +6834,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6906
6834
|
const length = Math.min(chunkSize, position);
|
|
6907
6835
|
position -= length;
|
|
6908
6836
|
const buffer = Buffer.alloc(length);
|
|
6909
|
-
|
|
6837
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6910
6838
|
chunks.unshift(buffer.toString("utf8"));
|
|
6911
6839
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6912
6840
|
collectedLines += chunkLines;
|
|
6913
6841
|
}
|
|
6914
6842
|
} finally {
|
|
6915
|
-
|
|
6843
|
+
fs25.closeSync(fd);
|
|
6916
6844
|
}
|
|
6917
6845
|
const content = chunks.join("");
|
|
6918
6846
|
const allLines = content.split("\n");
|
|
@@ -6928,11 +6856,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6928
6856
|
return allLines.slice(allLines.length - maxLines);
|
|
6929
6857
|
}
|
|
6930
6858
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6931
|
-
const stat =
|
|
6859
|
+
const stat = fs25.statSync(filePath);
|
|
6932
6860
|
if (stat.size === 0) {
|
|
6933
6861
|
return { lines: [], totalLinesCount: 0 };
|
|
6934
6862
|
}
|
|
6935
|
-
const fd =
|
|
6863
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6936
6864
|
const chunkSize = 64 * 1024;
|
|
6937
6865
|
let position = stat.size;
|
|
6938
6866
|
let remainder = "";
|
|
@@ -6944,7 +6872,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6944
6872
|
const length = Math.min(chunkSize, position);
|
|
6945
6873
|
position -= length;
|
|
6946
6874
|
const buffer = Buffer.alloc(length);
|
|
6947
|
-
|
|
6875
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6948
6876
|
let chunk = buffer.toString("utf8");
|
|
6949
6877
|
if (remainder) {
|
|
6950
6878
|
chunk += remainder;
|
|
@@ -6975,7 +6903,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6975
6903
|
}
|
|
6976
6904
|
}
|
|
6977
6905
|
} finally {
|
|
6978
|
-
|
|
6906
|
+
fs25.closeSync(fd);
|
|
6979
6907
|
}
|
|
6980
6908
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6981
6909
|
}
|
|
@@ -7117,7 +7045,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7117
7045
|
}
|
|
7118
7046
|
|
|
7119
7047
|
// src/commands/read-logs/json-lines.ts
|
|
7120
|
-
import
|
|
7048
|
+
import fs26 from "fs";
|
|
7121
7049
|
function normalizePid(value) {
|
|
7122
7050
|
if (typeof value === "number") {
|
|
7123
7051
|
return String(value);
|
|
@@ -7168,11 +7096,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7168
7096
|
return set.size > 0 ? set : null;
|
|
7169
7097
|
}
|
|
7170
7098
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7171
|
-
const stat =
|
|
7099
|
+
const stat = fs26.statSync(filePath);
|
|
7172
7100
|
if (stat.size === 0) {
|
|
7173
7101
|
return { lines: [], totalLinesCount: 0 };
|
|
7174
7102
|
}
|
|
7175
|
-
const fd =
|
|
7103
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7176
7104
|
const chunkSize = 64 * 1024;
|
|
7177
7105
|
let position = stat.size;
|
|
7178
7106
|
let remainder = "";
|
|
@@ -7187,7 +7115,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7187
7115
|
const length = Math.min(chunkSize, position);
|
|
7188
7116
|
position -= length;
|
|
7189
7117
|
const buffer = Buffer.alloc(length);
|
|
7190
|
-
|
|
7118
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7191
7119
|
let chunk = buffer.toString("utf8");
|
|
7192
7120
|
if (remainder) {
|
|
7193
7121
|
chunk += remainder;
|
|
@@ -7249,7 +7177,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7249
7177
|
}
|
|
7250
7178
|
}
|
|
7251
7179
|
} finally {
|
|
7252
|
-
|
|
7180
|
+
fs26.closeSync(fd);
|
|
7253
7181
|
}
|
|
7254
7182
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7255
7183
|
}
|
|
@@ -7292,11 +7220,11 @@ function extractTraceId(obj) {
|
|
|
7292
7220
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7293
7221
|
const wanted = traceId.trim();
|
|
7294
7222
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7295
|
-
const stat =
|
|
7223
|
+
const stat = fs26.statSync(filePath);
|
|
7296
7224
|
if (stat.size === 0) {
|
|
7297
7225
|
return { lines: [], totalLinesCount: 0 };
|
|
7298
7226
|
}
|
|
7299
|
-
const fd =
|
|
7227
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7300
7228
|
const chunkSize = 64 * 1024;
|
|
7301
7229
|
let position = stat.size;
|
|
7302
7230
|
let remainder = "";
|
|
@@ -7309,7 +7237,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7309
7237
|
const length = Math.min(chunkSize, position);
|
|
7310
7238
|
position -= length;
|
|
7311
7239
|
const buffer = Buffer.alloc(length);
|
|
7312
|
-
|
|
7240
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7313
7241
|
let chunk = buffer.toString("utf8");
|
|
7314
7242
|
if (remainder) {
|
|
7315
7243
|
chunk += remainder;
|
|
@@ -7362,7 +7290,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7362
7290
|
}
|
|
7363
7291
|
}
|
|
7364
7292
|
} finally {
|
|
7365
|
-
|
|
7293
|
+
fs26.closeSync(fd);
|
|
7366
7294
|
}
|
|
7367
7295
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7368
7296
|
}
|
|
@@ -7371,11 +7299,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7371
7299
|
if (!wantedLevelSet) {
|
|
7372
7300
|
return { lines: [], totalLinesCount: 0 };
|
|
7373
7301
|
}
|
|
7374
|
-
const stat =
|
|
7302
|
+
const stat = fs26.statSync(filePath);
|
|
7375
7303
|
if (stat.size === 0) {
|
|
7376
7304
|
return { lines: [], totalLinesCount: 0 };
|
|
7377
7305
|
}
|
|
7378
|
-
const fd =
|
|
7306
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7379
7307
|
const chunkSize = 64 * 1024;
|
|
7380
7308
|
let position = stat.size;
|
|
7381
7309
|
let remainder = "";
|
|
@@ -7387,7 +7315,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7387
7315
|
const length = Math.min(chunkSize, position);
|
|
7388
7316
|
position -= length;
|
|
7389
7317
|
const buffer = Buffer.alloc(length);
|
|
7390
|
-
|
|
7318
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7391
7319
|
let chunk = buffer.toString("utf8");
|
|
7392
7320
|
if (remainder) {
|
|
7393
7321
|
chunk += remainder;
|
|
@@ -7434,7 +7362,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7434
7362
|
}
|
|
7435
7363
|
}
|
|
7436
7364
|
} finally {
|
|
7437
|
-
|
|
7365
|
+
fs26.closeSync(fd);
|
|
7438
7366
|
}
|
|
7439
7367
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7440
7368
|
}
|
|
@@ -7668,30 +7596,30 @@ async function readLogsJsonResult(options) {
|
|
|
7668
7596
|
};
|
|
7669
7597
|
}
|
|
7670
7598
|
function resolveLogFilePath(logDir, type) {
|
|
7671
|
-
const base =
|
|
7599
|
+
const base = path22.isAbsolute(logDir) ? logDir : path22.join(process.cwd(), logDir);
|
|
7672
7600
|
if (type === "server") {
|
|
7673
|
-
return
|
|
7601
|
+
return path22.join(base, "server.log");
|
|
7674
7602
|
}
|
|
7675
7603
|
if (type === "trace") {
|
|
7676
|
-
return
|
|
7604
|
+
return path22.join(base, "trace.log");
|
|
7677
7605
|
}
|
|
7678
7606
|
if (type === "server-std") {
|
|
7679
|
-
return
|
|
7607
|
+
return path22.join(base, "server.std.log");
|
|
7680
7608
|
}
|
|
7681
7609
|
if (type === "client-std") {
|
|
7682
|
-
return
|
|
7610
|
+
return path22.join(base, "client.std.log");
|
|
7683
7611
|
}
|
|
7684
7612
|
if (type === "dev") {
|
|
7685
|
-
return
|
|
7613
|
+
return path22.join(base, "dev.log");
|
|
7686
7614
|
}
|
|
7687
7615
|
if (type === "dev-std") {
|
|
7688
|
-
return
|
|
7616
|
+
return path22.join(base, "dev.std.log");
|
|
7689
7617
|
}
|
|
7690
7618
|
if (type === "install-dep-std") {
|
|
7691
|
-
return
|
|
7619
|
+
return path22.join(base, "install-dep.std.log");
|
|
7692
7620
|
}
|
|
7693
7621
|
if (type === "browser") {
|
|
7694
|
-
return
|
|
7622
|
+
return path22.join(base, "browser.log");
|
|
7695
7623
|
}
|
|
7696
7624
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7697
7625
|
}
|
|
@@ -7868,9 +7796,9 @@ function camelToKebab(str) {
|
|
|
7868
7796
|
}
|
|
7869
7797
|
|
|
7870
7798
|
// src/commands/build/upload-static.handler.ts
|
|
7871
|
-
import * as
|
|
7799
|
+
import * as fs27 from "fs";
|
|
7872
7800
|
import * as os2 from "os";
|
|
7873
|
-
import * as
|
|
7801
|
+
import * as path23 from "path";
|
|
7874
7802
|
import { execFileSync } from "child_process";
|
|
7875
7803
|
function readCredentialsFromEnv() {
|
|
7876
7804
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7894,8 +7822,8 @@ async function uploadStatic(options) {
|
|
|
7894
7822
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7895
7823
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7896
7824
|
} = options;
|
|
7897
|
-
const resolvedStaticDir =
|
|
7898
|
-
if (!
|
|
7825
|
+
const resolvedStaticDir = path23.resolve(staticDir);
|
|
7826
|
+
if (!fs27.existsSync(resolvedStaticDir)) {
|
|
7899
7827
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7900
7828
|
return;
|
|
7901
7829
|
}
|
|
@@ -7928,8 +7856,8 @@ async function uploadStatic(options) {
|
|
|
7928
7856
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7929
7857
|
}
|
|
7930
7858
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7931
|
-
const confPath =
|
|
7932
|
-
|
|
7859
|
+
const confPath = path23.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7860
|
+
fs27.writeFileSync(confPath, "");
|
|
7933
7861
|
try {
|
|
7934
7862
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7935
7863
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7943,7 +7871,7 @@ async function uploadStatic(options) {
|
|
|
7943
7871
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7944
7872
|
} finally {
|
|
7945
7873
|
try {
|
|
7946
|
-
|
|
7874
|
+
fs27.unlinkSync(confPath);
|
|
7947
7875
|
} catch {
|
|
7948
7876
|
}
|
|
7949
7877
|
}
|
|
@@ -7963,8 +7891,8 @@ async function uploadStatic(options) {
|
|
|
7963
7891
|
}
|
|
7964
7892
|
}
|
|
7965
7893
|
function resolveTosutilPath(tosutilPath) {
|
|
7966
|
-
if (
|
|
7967
|
-
return
|
|
7894
|
+
if (path23.isAbsolute(tosutilPath)) {
|
|
7895
|
+
return fs27.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7968
7896
|
}
|
|
7969
7897
|
try {
|
|
7970
7898
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -8009,7 +7937,7 @@ async function resolveBucketId(appId) {
|
|
|
8009
7937
|
return bucketId;
|
|
8010
7938
|
}
|
|
8011
7939
|
function isDirEmpty(dirPath) {
|
|
8012
|
-
const entries =
|
|
7940
|
+
const entries = fs27.readdirSync(dirPath);
|
|
8013
7941
|
return entries.length === 0;
|
|
8014
7942
|
}
|
|
8015
7943
|
|
|
@@ -8104,12 +8032,12 @@ var commands = [
|
|
|
8104
8032
|
];
|
|
8105
8033
|
|
|
8106
8034
|
// src/index.ts
|
|
8107
|
-
var envPath =
|
|
8108
|
-
if (
|
|
8035
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
8036
|
+
if (fs28.existsSync(envPath)) {
|
|
8109
8037
|
dotenvConfig({ path: envPath });
|
|
8110
8038
|
}
|
|
8111
|
-
var __dirname =
|
|
8112
|
-
var pkg = JSON.parse(
|
|
8039
|
+
var __dirname = path24.dirname(fileURLToPath5(import.meta.url));
|
|
8040
|
+
var pkg = JSON.parse(fs28.readFileSync(path24.join(__dirname, "../package.json"), "utf-8"));
|
|
8113
8041
|
var cli = new FullstackCLI(pkg.version);
|
|
8114
8042
|
cli.useAll(commands);
|
|
8115
8043
|
cli.run();
|