@lark-apaas/fullstack-cli 1.1.22-alpha.8 → 1.1.22-alpha.9
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 +582 -258
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath as
|
|
2
|
+
import fs25 from "fs";
|
|
3
|
+
import path21 from "path";
|
|
4
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
@@ -2419,10 +2419,401 @@ var syncCommand = {
|
|
|
2419
2419
|
}
|
|
2420
2420
|
};
|
|
2421
2421
|
|
|
2422
|
-
// src/
|
|
2422
|
+
// src/utils/http-client.ts
|
|
2423
|
+
import { HttpClient } from "@lark-apaas/http-client";
|
|
2424
|
+
var clientInstance = null;
|
|
2425
|
+
function getHttpClient() {
|
|
2426
|
+
if (!clientInstance) {
|
|
2427
|
+
clientInstance = new HttpClient({
|
|
2428
|
+
timeout: 3e4,
|
|
2429
|
+
platform: {
|
|
2430
|
+
enabled: true
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
|
|
2434
|
+
if (canaryEnv) {
|
|
2435
|
+
clientInstance.interceptors.request.use((req) => {
|
|
2436
|
+
req.headers["x-tt-env"] = canaryEnv;
|
|
2437
|
+
return req;
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
return clientInstance;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// src/utils/telemetry.ts
|
|
2445
|
+
async function reportEvents(events) {
|
|
2446
|
+
if (events.length === 0) {
|
|
2447
|
+
return true;
|
|
2448
|
+
}
|
|
2449
|
+
try {
|
|
2450
|
+
const client = getHttpClient();
|
|
2451
|
+
const response = await client.post("/api/v1/studio/innerapi/resource_events", { events });
|
|
2452
|
+
if (!response.ok) {
|
|
2453
|
+
console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
|
|
2454
|
+
return false;
|
|
2455
|
+
}
|
|
2456
|
+
const result = await response.json();
|
|
2457
|
+
if (result.status_code !== "0") {
|
|
2458
|
+
console.warn(`[telemetry] API error: ${result.message}`);
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
return true;
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
|
|
2464
|
+
return false;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
async function reportInstallEvent(pluginKey, version) {
|
|
2468
|
+
await reportEvents([
|
|
2469
|
+
{
|
|
2470
|
+
resourceType: "plugin",
|
|
2471
|
+
resourceKey: pluginKey,
|
|
2472
|
+
eventType: "install",
|
|
2473
|
+
details: { version }
|
|
2474
|
+
}
|
|
2475
|
+
]);
|
|
2476
|
+
}
|
|
2477
|
+
async function reportCreateInstanceEvent(pluginKey, version) {
|
|
2478
|
+
await reportEvents([
|
|
2479
|
+
{
|
|
2480
|
+
resourceType: "plugin",
|
|
2481
|
+
resourceKey: pluginKey,
|
|
2482
|
+
eventType: "create_instance",
|
|
2483
|
+
details: { version }
|
|
2484
|
+
}
|
|
2485
|
+
]);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
// src/utils/git.ts
|
|
2489
|
+
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2423
2490
|
import fs7 from "fs";
|
|
2424
2491
|
import path5 from "path";
|
|
2425
|
-
|
|
2492
|
+
function isGitRepository(cwd = process.cwd()) {
|
|
2493
|
+
try {
|
|
2494
|
+
const gitDir = path5.join(cwd, ".git");
|
|
2495
|
+
if (fs7.existsSync(gitDir)) {
|
|
2496
|
+
return true;
|
|
2497
|
+
}
|
|
2498
|
+
const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
|
|
2499
|
+
cwd,
|
|
2500
|
+
stdio: "pipe",
|
|
2501
|
+
encoding: "utf-8"
|
|
2502
|
+
});
|
|
2503
|
+
return result.status === 0;
|
|
2504
|
+
} catch {
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
function getChangedFiles(cwd = process.cwd()) {
|
|
2509
|
+
try {
|
|
2510
|
+
const output = execSync("git status --porcelain", {
|
|
2511
|
+
cwd,
|
|
2512
|
+
stdio: "pipe",
|
|
2513
|
+
encoding: "utf-8"
|
|
2514
|
+
});
|
|
2515
|
+
return output.split("\n").filter((line) => line.trim()).map((line) => line.substring(3));
|
|
2516
|
+
} catch (error) {
|
|
2517
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2518
|
+
throw new Error(`Failed to get changed files: ${message}`);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
2522
|
+
const filteredFiles = [];
|
|
2523
|
+
for (const filePath of filesToStage) {
|
|
2524
|
+
if (fs7.existsSync(path5.join(cwd, filePath))) {
|
|
2525
|
+
filteredFiles.push(filePath);
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
2529
|
+
cwd,
|
|
2530
|
+
stdio: "pipe",
|
|
2531
|
+
encoding: "utf-8"
|
|
2532
|
+
});
|
|
2533
|
+
if (tracked.status === 0) {
|
|
2534
|
+
filteredFiles.push(filePath);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
if (filteredFiles.length === 0) {
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
|
|
2541
|
+
cwd,
|
|
2542
|
+
stdio: "pipe",
|
|
2543
|
+
encoding: "utf-8"
|
|
2544
|
+
});
|
|
2545
|
+
if (result.error || result.status !== 0) {
|
|
2546
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2547
|
+
throw new Error(`git add failed: ${errorMsg}`);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
function gitCommit(message, cwd = process.cwd()) {
|
|
2551
|
+
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
2552
|
+
cwd,
|
|
2553
|
+
stdio: "pipe",
|
|
2554
|
+
encoding: "utf-8"
|
|
2555
|
+
});
|
|
2556
|
+
if (result.error || result.status !== 0) {
|
|
2557
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2558
|
+
throw new Error(`git commit failed: ${errorMsg}`);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
|
|
2562
|
+
if (!isGitRepository(cwd)) {
|
|
2563
|
+
console.log("[fullstack-cli] \u26A0 Not a git repository, skipping auto-commit");
|
|
2564
|
+
return false;
|
|
2565
|
+
}
|
|
2566
|
+
const changedFiles = getChangedFiles(cwd);
|
|
2567
|
+
if (changedFiles.length === 0) {
|
|
2568
|
+
console.log("[fullstack-cli] No changes to commit");
|
|
2569
|
+
return false;
|
|
2570
|
+
}
|
|
2571
|
+
try {
|
|
2572
|
+
gitAddUpgradeFiles(cwd, filesToStage);
|
|
2573
|
+
const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
|
|
2574
|
+
|
|
2575
|
+
- Sync template files
|
|
2576
|
+
- Cleanup package.json config
|
|
2577
|
+
- Upgrade @lark-apaas dependencies (if any)
|
|
2578
|
+
|
|
2579
|
+
Auto-committed by fullstack-cli v${version}`;
|
|
2580
|
+
gitCommit(message, cwd);
|
|
2581
|
+
console.log(`[fullstack-cli] \u2713 Auto-committed ${changedFiles.length} changed file(s)`);
|
|
2582
|
+
return true;
|
|
2583
|
+
} catch (error) {
|
|
2584
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2585
|
+
throw new Error(`Failed to auto-commit changes: ${message}`);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
// src/utils/package-json.ts
|
|
2590
|
+
import fs8 from "fs";
|
|
2591
|
+
import path6 from "path";
|
|
2592
|
+
function readPackageJson(cwd = process.cwd()) {
|
|
2593
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2594
|
+
if (!fs8.existsSync(pkgPath)) {
|
|
2595
|
+
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2596
|
+
}
|
|
2597
|
+
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
2598
|
+
return JSON.parse(content);
|
|
2599
|
+
}
|
|
2600
|
+
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2601
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2602
|
+
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
2603
|
+
fs8.writeFileSync(pkgPath, content, "utf-8");
|
|
2604
|
+
}
|
|
2605
|
+
function removeUpgradeScript(pkg2) {
|
|
2606
|
+
if (!pkg2.scripts?.upgrade) {
|
|
2607
|
+
return false;
|
|
2608
|
+
}
|
|
2609
|
+
delete pkg2.scripts.upgrade;
|
|
2610
|
+
return true;
|
|
2611
|
+
}
|
|
2612
|
+
function cleanDevScript(pkg2) {
|
|
2613
|
+
if (!pkg2.scripts?.dev) {
|
|
2614
|
+
return false;
|
|
2615
|
+
}
|
|
2616
|
+
const originalDev = pkg2.scripts.dev;
|
|
2617
|
+
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
2618
|
+
if (cleanedDev !== originalDev) {
|
|
2619
|
+
pkg2.scripts.dev = cleanedDev;
|
|
2620
|
+
return true;
|
|
2621
|
+
}
|
|
2622
|
+
return false;
|
|
2623
|
+
}
|
|
2624
|
+
function cleanupPackageJson(cwd = process.cwd()) {
|
|
2625
|
+
try {
|
|
2626
|
+
const pkg2 = readPackageJson(cwd);
|
|
2627
|
+
let changed = false;
|
|
2628
|
+
if (removeUpgradeScript(pkg2)) {
|
|
2629
|
+
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
2630
|
+
changed = true;
|
|
2631
|
+
}
|
|
2632
|
+
if (cleanDevScript(pkg2)) {
|
|
2633
|
+
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
2634
|
+
changed = true;
|
|
2635
|
+
}
|
|
2636
|
+
if (changed) {
|
|
2637
|
+
writePackageJson(pkg2, cwd);
|
|
2638
|
+
}
|
|
2639
|
+
return changed;
|
|
2640
|
+
} catch (error) {
|
|
2641
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2642
|
+
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
2643
|
+
return false;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
// src/commands/upgrade/shared/utils.ts
|
|
2648
|
+
import path7 from "path";
|
|
2649
|
+
import fs9 from "fs";
|
|
2650
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2651
|
+
function getCliVersion() {
|
|
2652
|
+
try {
|
|
2653
|
+
const __filename = fileURLToPath4(import.meta.url);
|
|
2654
|
+
const __dirname2 = path7.dirname(__filename);
|
|
2655
|
+
const pkgPath = path7.resolve(__dirname2, "../../../package.json");
|
|
2656
|
+
const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
|
|
2657
|
+
const pkg2 = JSON.parse(pkgContent);
|
|
2658
|
+
return pkg2.version || "unknown";
|
|
2659
|
+
} catch {
|
|
2660
|
+
return "unknown";
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// src/commands/upgrade/get-upgrade-files.ts
|
|
2665
|
+
function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
2666
|
+
const syncConfig2 = genSyncConfig({ disableGenOpenapi });
|
|
2667
|
+
const filesToStage = /* @__PURE__ */ new Set();
|
|
2668
|
+
syncConfig2.sync.forEach((rule) => {
|
|
2669
|
+
if (rule.type === "file" || rule.type === "directory") {
|
|
2670
|
+
filesToStage.add(rule.to);
|
|
2671
|
+
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
2672
|
+
filesToStage.add(rule.to);
|
|
2673
|
+
} else if (rule.type === "add-script") {
|
|
2674
|
+
filesToStage.add("package.json");
|
|
2675
|
+
} else if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2676
|
+
filesToStage.add(rule.to);
|
|
2677
|
+
}
|
|
2678
|
+
});
|
|
2679
|
+
filesToStage.add("package.json");
|
|
2680
|
+
filesToStage.add("package-lock.json");
|
|
2681
|
+
return Array.from(filesToStage);
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
// src/commands/upgrade/run.handler.ts
|
|
2685
|
+
async function run3(options = {}) {
|
|
2686
|
+
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2687
|
+
console.log("[fullstack-cli] Starting upgrade...");
|
|
2688
|
+
try {
|
|
2689
|
+
console.log("[fullstack-cli] Step 1/3: Syncing template files...");
|
|
2690
|
+
await run2({ disableGenOpenapi: options.disableGenOpenapi ?? true });
|
|
2691
|
+
console.log("[fullstack-cli] Step 2/3: Cleaning up package.json...");
|
|
2692
|
+
const cleaned = cleanupPackageJson(userProjectRoot);
|
|
2693
|
+
if (!cleaned) {
|
|
2694
|
+
console.log("[fullstack-cli] \u25CB No cleanup needed");
|
|
2695
|
+
}
|
|
2696
|
+
const shouldCommit = options.commit ?? true;
|
|
2697
|
+
if (shouldCommit) {
|
|
2698
|
+
console.log("[fullstack-cli] Step 3/3: Committing changes...");
|
|
2699
|
+
const version = getCliVersion();
|
|
2700
|
+
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
|
|
2701
|
+
autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
|
|
2702
|
+
} else {
|
|
2703
|
+
console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
|
|
2704
|
+
}
|
|
2705
|
+
console.log("[fullstack-cli] Upgrade completed successfully \u2705");
|
|
2706
|
+
} catch (error) {
|
|
2707
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2708
|
+
console.error("[fullstack-cli] Failed to upgrade:", message);
|
|
2709
|
+
process.exit(1);
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
// src/commands/upgrade/deps/run.handler.ts
|
|
2714
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
2715
|
+
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
2716
|
+
const pkg2 = readPackageJson(cwd);
|
|
2717
|
+
const allPackages = /* @__PURE__ */ new Set();
|
|
2718
|
+
if (pkg2.dependencies) {
|
|
2719
|
+
Object.keys(pkg2.dependencies).forEach((name) => {
|
|
2720
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2721
|
+
allPackages.add(name);
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
if (pkg2.devDependencies) {
|
|
2726
|
+
Object.keys(pkg2.devDependencies).forEach((name) => {
|
|
2727
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2728
|
+
allPackages.add(name);
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
const packages = Array.from(allPackages);
|
|
2733
|
+
if (filterPackages) {
|
|
2734
|
+
const filter = new Set(filterPackages.split(",").map((p) => p.trim()));
|
|
2735
|
+
return packages.filter((p) => filter.has(p));
|
|
2736
|
+
}
|
|
2737
|
+
return packages;
|
|
2738
|
+
}
|
|
2739
|
+
function upgradePackages(packages, version, cwd) {
|
|
2740
|
+
if (version) {
|
|
2741
|
+
console.log(`[fullstack-cli] Upgrading to version ${version}...`);
|
|
2742
|
+
packages.forEach((pkg2) => {
|
|
2743
|
+
const target = `${pkg2}@${version}`;
|
|
2744
|
+
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
2745
|
+
const result = spawnSync3("npm", ["install", target], {
|
|
2746
|
+
cwd,
|
|
2747
|
+
stdio: "inherit"
|
|
2748
|
+
});
|
|
2749
|
+
if (result.error || result.status !== 0) {
|
|
2750
|
+
throw new Error(`Failed to install ${target}`);
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
} else {
|
|
2754
|
+
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
2755
|
+
packages.forEach((pkg2) => {
|
|
2756
|
+
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
2757
|
+
const result = spawnSync3("npm", ["update", pkg2], {
|
|
2758
|
+
cwd,
|
|
2759
|
+
stdio: "inherit"
|
|
2760
|
+
});
|
|
2761
|
+
if (result.error || result.status !== 0) {
|
|
2762
|
+
throw new Error(`Failed to update ${pkg2}`);
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
async function run4(options = {}) {
|
|
2768
|
+
const cwd = process.env.INIT_CWD || process.cwd();
|
|
2769
|
+
console.log("[fullstack-cli] Starting dependencies upgrade...");
|
|
2770
|
+
try {
|
|
2771
|
+
console.log("[fullstack-cli] Step 1/2: Scanning @lark-apaas dependencies...");
|
|
2772
|
+
const packages = findLarkAapaasPackages(cwd, options.packages);
|
|
2773
|
+
if (packages.length === 0) {
|
|
2774
|
+
console.log("[fullstack-cli] No @lark-apaas packages found");
|
|
2775
|
+
return;
|
|
2776
|
+
}
|
|
2777
|
+
console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
|
|
2778
|
+
packages.forEach((p) => console.log(` - ${p}`));
|
|
2779
|
+
console.log("[fullstack-cli] Step 2/2: Upgrading packages...");
|
|
2780
|
+
upgradePackages(packages, options.version, cwd);
|
|
2781
|
+
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
|
|
2782
|
+
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
2783
|
+
} catch (error) {
|
|
2784
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2785
|
+
console.error("[fullstack-cli] Failed to upgrade dependencies:", message);
|
|
2786
|
+
process.exit(1);
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
|
|
2790
|
+
// src/commands/upgrade/deps/index.ts
|
|
2791
|
+
var depsCommand = {
|
|
2792
|
+
name: "deps",
|
|
2793
|
+
description: "Upgrade @lark-apaas dependencies",
|
|
2794
|
+
register(parentCommand) {
|
|
2795
|
+
parentCommand.command(this.name).description(this.description).option("--version <version>", "Upgrade to specific version").option("--packages <packages>", "Only upgrade specific packages (comma-separated)").action(async (options) => {
|
|
2796
|
+
await run4(options);
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
};
|
|
2800
|
+
|
|
2801
|
+
// src/commands/upgrade/index.ts
|
|
2802
|
+
var upgradeCommand = {
|
|
2803
|
+
name: "upgrade",
|
|
2804
|
+
description: "Upgrade template files and auto-commit changes",
|
|
2805
|
+
register(program) {
|
|
2806
|
+
const upgradeCmd = program.command(this.name).description(this.description).option("--disable-gen-openapi", "Disable generating openapi.ts").option("--no-commit", "Skip auto-commit changes").action(async (options) => {
|
|
2807
|
+
await run3(options);
|
|
2808
|
+
});
|
|
2809
|
+
depsCommand.register(upgradeCmd);
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
|
|
2813
|
+
// src/commands/action-plugin/utils.ts
|
|
2814
|
+
import fs10 from "fs";
|
|
2815
|
+
import path8 from "path";
|
|
2816
|
+
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
2426
2817
|
function parsePluginName(input) {
|
|
2427
2818
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
2428
2819
|
if (!match) {
|
|
@@ -2439,35 +2830,35 @@ function getProjectRoot() {
|
|
|
2439
2830
|
return process.cwd();
|
|
2440
2831
|
}
|
|
2441
2832
|
function getPackageJsonPath() {
|
|
2442
|
-
return
|
|
2833
|
+
return path8.join(getProjectRoot(), "package.json");
|
|
2443
2834
|
}
|
|
2444
2835
|
function getPluginPath(pluginName) {
|
|
2445
|
-
return
|
|
2836
|
+
return path8.join(getProjectRoot(), "node_modules", pluginName);
|
|
2446
2837
|
}
|
|
2447
|
-
function
|
|
2838
|
+
function readPackageJson2() {
|
|
2448
2839
|
const pkgPath = getPackageJsonPath();
|
|
2449
|
-
if (!
|
|
2840
|
+
if (!fs10.existsSync(pkgPath)) {
|
|
2450
2841
|
throw new Error("package.json not found in current directory");
|
|
2451
2842
|
}
|
|
2452
2843
|
try {
|
|
2453
|
-
const content =
|
|
2844
|
+
const content = fs10.readFileSync(pkgPath, "utf-8");
|
|
2454
2845
|
return JSON.parse(content);
|
|
2455
2846
|
} catch {
|
|
2456
2847
|
throw new Error("Failed to parse package.json");
|
|
2457
2848
|
}
|
|
2458
2849
|
}
|
|
2459
|
-
function
|
|
2850
|
+
function writePackageJson2(pkg2) {
|
|
2460
2851
|
const pkgPath = getPackageJsonPath();
|
|
2461
|
-
|
|
2852
|
+
fs10.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
2462
2853
|
}
|
|
2463
2854
|
function readActionPlugins() {
|
|
2464
|
-
const pkg2 =
|
|
2855
|
+
const pkg2 = readPackageJson2();
|
|
2465
2856
|
return pkg2.actionPlugins || {};
|
|
2466
2857
|
}
|
|
2467
2858
|
function writeActionPlugins(plugins) {
|
|
2468
|
-
const pkg2 =
|
|
2859
|
+
const pkg2 = readPackageJson2();
|
|
2469
2860
|
pkg2.actionPlugins = plugins;
|
|
2470
|
-
|
|
2861
|
+
writePackageJson2(pkg2);
|
|
2471
2862
|
}
|
|
2472
2863
|
function isPluginInstalled(pluginName) {
|
|
2473
2864
|
const plugins = readActionPlugins();
|
|
@@ -2479,7 +2870,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
2479
2870
|
}
|
|
2480
2871
|
function npmInstall(tgzPath) {
|
|
2481
2872
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
2482
|
-
const result =
|
|
2873
|
+
const result = spawnSync4("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
2483
2874
|
cwd: getProjectRoot(),
|
|
2484
2875
|
stdio: "inherit"
|
|
2485
2876
|
});
|
|
@@ -2491,12 +2882,12 @@ function npmInstall(tgzPath) {
|
|
|
2491
2882
|
}
|
|
2492
2883
|
}
|
|
2493
2884
|
function getPackageVersion(pluginName) {
|
|
2494
|
-
const pkgJsonPath =
|
|
2495
|
-
if (!
|
|
2885
|
+
const pkgJsonPath = path8.join(getPluginPath(pluginName), "package.json");
|
|
2886
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2496
2887
|
return null;
|
|
2497
2888
|
}
|
|
2498
2889
|
try {
|
|
2499
|
-
const content =
|
|
2890
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2500
2891
|
const pkg2 = JSON.parse(content);
|
|
2501
2892
|
return pkg2.version || null;
|
|
2502
2893
|
} catch {
|
|
@@ -2504,49 +2895,49 @@ function getPackageVersion(pluginName) {
|
|
|
2504
2895
|
}
|
|
2505
2896
|
}
|
|
2506
2897
|
function readPluginPackageJson(pluginPath) {
|
|
2507
|
-
const pkgJsonPath =
|
|
2508
|
-
if (!
|
|
2898
|
+
const pkgJsonPath = path8.join(pluginPath, "package.json");
|
|
2899
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2509
2900
|
return null;
|
|
2510
2901
|
}
|
|
2511
2902
|
try {
|
|
2512
|
-
const content =
|
|
2903
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2513
2904
|
return JSON.parse(content);
|
|
2514
2905
|
} catch {
|
|
2515
2906
|
return null;
|
|
2516
2907
|
}
|
|
2517
2908
|
}
|
|
2518
2909
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
2519
|
-
const nodeModulesPath =
|
|
2520
|
-
const targetDir =
|
|
2521
|
-
const scopeDir =
|
|
2522
|
-
if (!
|
|
2523
|
-
|
|
2910
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
2911
|
+
const targetDir = path8.join(nodeModulesPath, pluginName);
|
|
2912
|
+
const scopeDir = path8.dirname(targetDir);
|
|
2913
|
+
if (!fs10.existsSync(scopeDir)) {
|
|
2914
|
+
fs10.mkdirSync(scopeDir, { recursive: true });
|
|
2524
2915
|
}
|
|
2525
|
-
if (
|
|
2526
|
-
|
|
2916
|
+
if (fs10.existsSync(targetDir)) {
|
|
2917
|
+
fs10.rmSync(targetDir, { recursive: true });
|
|
2527
2918
|
}
|
|
2528
|
-
const tempDir =
|
|
2529
|
-
if (
|
|
2530
|
-
|
|
2919
|
+
const tempDir = path8.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
2920
|
+
if (fs10.existsSync(tempDir)) {
|
|
2921
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2531
2922
|
}
|
|
2532
|
-
|
|
2923
|
+
fs10.mkdirSync(tempDir, { recursive: true });
|
|
2533
2924
|
try {
|
|
2534
|
-
|
|
2535
|
-
const extractedDir =
|
|
2536
|
-
if (
|
|
2537
|
-
|
|
2925
|
+
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
2926
|
+
const extractedDir = path8.join(tempDir, "package");
|
|
2927
|
+
if (fs10.existsSync(extractedDir)) {
|
|
2928
|
+
fs10.renameSync(extractedDir, targetDir);
|
|
2538
2929
|
} else {
|
|
2539
|
-
const files =
|
|
2930
|
+
const files = fs10.readdirSync(tempDir);
|
|
2540
2931
|
if (files.length === 1) {
|
|
2541
|
-
|
|
2932
|
+
fs10.renameSync(path8.join(tempDir, files[0]), targetDir);
|
|
2542
2933
|
} else {
|
|
2543
2934
|
throw new Error("Unexpected tgz structure");
|
|
2544
2935
|
}
|
|
2545
2936
|
}
|
|
2546
2937
|
return targetDir;
|
|
2547
2938
|
} finally {
|
|
2548
|
-
if (
|
|
2549
|
-
|
|
2939
|
+
if (fs10.existsSync(tempDir)) {
|
|
2940
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2550
2941
|
}
|
|
2551
2942
|
}
|
|
2552
2943
|
}
|
|
@@ -2555,10 +2946,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
2555
2946
|
return [];
|
|
2556
2947
|
}
|
|
2557
2948
|
const missing = [];
|
|
2558
|
-
const nodeModulesPath =
|
|
2949
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
2559
2950
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
2560
|
-
const depPath =
|
|
2561
|
-
if (!
|
|
2951
|
+
const depPath = path8.join(nodeModulesPath, depName);
|
|
2952
|
+
if (!fs10.existsSync(depPath)) {
|
|
2562
2953
|
missing.push(depName);
|
|
2563
2954
|
}
|
|
2564
2955
|
}
|
|
@@ -2569,7 +2960,7 @@ function installMissingDeps(deps) {
|
|
|
2569
2960
|
return;
|
|
2570
2961
|
}
|
|
2571
2962
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
2572
|
-
const result =
|
|
2963
|
+
const result = spawnSync4("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
2573
2964
|
cwd: getProjectRoot(),
|
|
2574
2965
|
stdio: "inherit"
|
|
2575
2966
|
});
|
|
@@ -2582,84 +2973,16 @@ function installMissingDeps(deps) {
|
|
|
2582
2973
|
}
|
|
2583
2974
|
function removePluginDirectory(pluginName) {
|
|
2584
2975
|
const pluginPath = getPluginPath(pluginName);
|
|
2585
|
-
if (
|
|
2586
|
-
|
|
2976
|
+
if (fs10.existsSync(pluginPath)) {
|
|
2977
|
+
fs10.rmSync(pluginPath, { recursive: true });
|
|
2587
2978
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
2588
2979
|
}
|
|
2589
2980
|
}
|
|
2590
2981
|
|
|
2591
2982
|
// src/commands/action-plugin/api-client.ts
|
|
2592
2983
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
2593
|
-
import
|
|
2594
|
-
import
|
|
2595
|
-
|
|
2596
|
-
// src/utils/http-client.ts
|
|
2597
|
-
import { HttpClient } from "@lark-apaas/http-client";
|
|
2598
|
-
var clientInstance = null;
|
|
2599
|
-
function getHttpClient() {
|
|
2600
|
-
if (!clientInstance) {
|
|
2601
|
-
clientInstance = new HttpClient({
|
|
2602
|
-
timeout: 3e4,
|
|
2603
|
-
platform: {
|
|
2604
|
-
enabled: true
|
|
2605
|
-
}
|
|
2606
|
-
});
|
|
2607
|
-
const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
|
|
2608
|
-
if (canaryEnv) {
|
|
2609
|
-
clientInstance.interceptors.request.use((req) => {
|
|
2610
|
-
req.headers["x-tt-env"] = canaryEnv;
|
|
2611
|
-
return req;
|
|
2612
|
-
});
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
return clientInstance;
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
// src/utils/telemetry.ts
|
|
2619
|
-
async function reportEvents(events) {
|
|
2620
|
-
if (events.length === 0) {
|
|
2621
|
-
return true;
|
|
2622
|
-
}
|
|
2623
|
-
try {
|
|
2624
|
-
const client = getHttpClient();
|
|
2625
|
-
const response = await client.post("/api/v1/studio/innerapi/resource_events", { events });
|
|
2626
|
-
if (!response.ok) {
|
|
2627
|
-
console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
|
|
2628
|
-
return false;
|
|
2629
|
-
}
|
|
2630
|
-
const result = await response.json();
|
|
2631
|
-
if (result.status_code !== "0") {
|
|
2632
|
-
console.warn(`[telemetry] API error: ${result.message}`);
|
|
2633
|
-
return false;
|
|
2634
|
-
}
|
|
2635
|
-
return true;
|
|
2636
|
-
} catch (error) {
|
|
2637
|
-
console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
|
|
2638
|
-
return false;
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
async function reportInstallEvent(pluginKey, version) {
|
|
2642
|
-
await reportEvents([
|
|
2643
|
-
{
|
|
2644
|
-
resourceType: "plugin",
|
|
2645
|
-
resourceKey: pluginKey,
|
|
2646
|
-
eventType: "install",
|
|
2647
|
-
details: { version }
|
|
2648
|
-
}
|
|
2649
|
-
]);
|
|
2650
|
-
}
|
|
2651
|
-
async function reportCreateInstanceEvent(pluginKey, version) {
|
|
2652
|
-
await reportEvents([
|
|
2653
|
-
{
|
|
2654
|
-
resourceType: "plugin",
|
|
2655
|
-
resourceKey: pluginKey,
|
|
2656
|
-
eventType: "create_instance",
|
|
2657
|
-
details: { version }
|
|
2658
|
-
}
|
|
2659
|
-
]);
|
|
2660
|
-
}
|
|
2661
|
-
|
|
2662
|
-
// src/commands/action-plugin/api-client.ts
|
|
2984
|
+
import fs11 from "fs";
|
|
2985
|
+
import path9 from "path";
|
|
2663
2986
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
2664
2987
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
2665
2988
|
const client = getHttpClient();
|
|
@@ -2723,19 +3046,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
2723
3046
|
return Buffer.from(arrayBuffer);
|
|
2724
3047
|
}
|
|
2725
3048
|
function getPluginCacheDir() {
|
|
2726
|
-
return
|
|
3049
|
+
return path9.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
2727
3050
|
}
|
|
2728
3051
|
function ensureCacheDir() {
|
|
2729
3052
|
const cacheDir = getPluginCacheDir();
|
|
2730
|
-
if (!
|
|
2731
|
-
|
|
3053
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
3054
|
+
fs11.mkdirSync(cacheDir, { recursive: true });
|
|
2732
3055
|
}
|
|
2733
3056
|
}
|
|
2734
3057
|
function getTempFilePath(pluginKey, version) {
|
|
2735
3058
|
ensureCacheDir();
|
|
2736
3059
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2737
3060
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2738
|
-
return
|
|
3061
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2739
3062
|
}
|
|
2740
3063
|
var MAX_RETRIES = 2;
|
|
2741
3064
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -2772,7 +3095,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
2772
3095
|
);
|
|
2773
3096
|
}
|
|
2774
3097
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
2775
|
-
|
|
3098
|
+
fs11.writeFileSync(tgzPath, tgzBuffer);
|
|
2776
3099
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
2777
3100
|
return {
|
|
2778
3101
|
tgzPath,
|
|
@@ -2786,18 +3109,18 @@ function getCachePath(pluginKey, version) {
|
|
|
2786
3109
|
ensureCacheDir();
|
|
2787
3110
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2788
3111
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2789
|
-
return
|
|
3112
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2790
3113
|
}
|
|
2791
3114
|
function hasCachedPlugin(pluginKey, version) {
|
|
2792
3115
|
const cachePath = getCachePath(pluginKey, version);
|
|
2793
|
-
return
|
|
3116
|
+
return fs11.existsSync(cachePath);
|
|
2794
3117
|
}
|
|
2795
3118
|
function listCachedPlugins() {
|
|
2796
3119
|
const cacheDir = getPluginCacheDir();
|
|
2797
|
-
if (!
|
|
3120
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2798
3121
|
return [];
|
|
2799
3122
|
}
|
|
2800
|
-
const files =
|
|
3123
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2801
3124
|
const result = [];
|
|
2802
3125
|
for (const file of files) {
|
|
2803
3126
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -2805,8 +3128,8 @@ function listCachedPlugins() {
|
|
|
2805
3128
|
if (!match) continue;
|
|
2806
3129
|
const [, rawName, version] = match;
|
|
2807
3130
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
2808
|
-
const filePath =
|
|
2809
|
-
const stat =
|
|
3131
|
+
const filePath = path9.join(cacheDir, file);
|
|
3132
|
+
const stat = fs11.statSync(filePath);
|
|
2810
3133
|
result.push({
|
|
2811
3134
|
name,
|
|
2812
3135
|
version,
|
|
@@ -2819,14 +3142,14 @@ function listCachedPlugins() {
|
|
|
2819
3142
|
}
|
|
2820
3143
|
function cleanAllCache() {
|
|
2821
3144
|
const cacheDir = getPluginCacheDir();
|
|
2822
|
-
if (!
|
|
3145
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2823
3146
|
return 0;
|
|
2824
3147
|
}
|
|
2825
|
-
const files =
|
|
3148
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2826
3149
|
let count = 0;
|
|
2827
3150
|
for (const file of files) {
|
|
2828
3151
|
if (file.endsWith(".tgz")) {
|
|
2829
|
-
|
|
3152
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2830
3153
|
count++;
|
|
2831
3154
|
}
|
|
2832
3155
|
}
|
|
@@ -2834,21 +3157,21 @@ function cleanAllCache() {
|
|
|
2834
3157
|
}
|
|
2835
3158
|
function cleanPluginCache(pluginKey, version) {
|
|
2836
3159
|
const cacheDir = getPluginCacheDir();
|
|
2837
|
-
if (!
|
|
3160
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2838
3161
|
return 0;
|
|
2839
3162
|
}
|
|
2840
3163
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2841
|
-
const files =
|
|
3164
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2842
3165
|
let count = 0;
|
|
2843
3166
|
for (const file of files) {
|
|
2844
3167
|
if (version) {
|
|
2845
3168
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
2846
|
-
|
|
3169
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2847
3170
|
count++;
|
|
2848
3171
|
}
|
|
2849
3172
|
} else {
|
|
2850
3173
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
2851
|
-
|
|
3174
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2852
3175
|
count++;
|
|
2853
3176
|
}
|
|
2854
3177
|
}
|
|
@@ -3275,40 +3598,40 @@ var actionPluginCommandGroup = {
|
|
|
3275
3598
|
};
|
|
3276
3599
|
|
|
3277
3600
|
// src/commands/capability/utils.ts
|
|
3278
|
-
import
|
|
3601
|
+
import fs12 from "fs";
|
|
3279
3602
|
import { createRequire as createRequire2 } from "module";
|
|
3280
|
-
import
|
|
3603
|
+
import path10 from "path";
|
|
3281
3604
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
3282
3605
|
function getProjectRoot2() {
|
|
3283
3606
|
return process.cwd();
|
|
3284
3607
|
}
|
|
3285
3608
|
function getCapabilitiesDir() {
|
|
3286
|
-
return
|
|
3609
|
+
return path10.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
3287
3610
|
}
|
|
3288
3611
|
function getCapabilityPath(id) {
|
|
3289
|
-
return
|
|
3612
|
+
return path10.join(getCapabilitiesDir(), `${id}.json`);
|
|
3290
3613
|
}
|
|
3291
3614
|
function getPluginManifestPath(pluginKey) {
|
|
3292
|
-
return
|
|
3615
|
+
return path10.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
3293
3616
|
}
|
|
3294
3617
|
function capabilitiesDirExists() {
|
|
3295
|
-
return
|
|
3618
|
+
return fs12.existsSync(getCapabilitiesDir());
|
|
3296
3619
|
}
|
|
3297
3620
|
function listCapabilityIds() {
|
|
3298
3621
|
const dir = getCapabilitiesDir();
|
|
3299
|
-
if (!
|
|
3622
|
+
if (!fs12.existsSync(dir)) {
|
|
3300
3623
|
return [];
|
|
3301
3624
|
}
|
|
3302
|
-
const files =
|
|
3625
|
+
const files = fs12.readdirSync(dir);
|
|
3303
3626
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
3304
3627
|
}
|
|
3305
3628
|
function readCapability(id) {
|
|
3306
3629
|
const filePath = getCapabilityPath(id);
|
|
3307
|
-
if (!
|
|
3630
|
+
if (!fs12.existsSync(filePath)) {
|
|
3308
3631
|
throw new Error(`Capability not found: ${id}`);
|
|
3309
3632
|
}
|
|
3310
3633
|
try {
|
|
3311
|
-
const content =
|
|
3634
|
+
const content = fs12.readFileSync(filePath, "utf-8");
|
|
3312
3635
|
return JSON.parse(content);
|
|
3313
3636
|
} catch (error) {
|
|
3314
3637
|
if (error instanceof SyntaxError) {
|
|
@@ -3335,11 +3658,11 @@ function readAllCapabilities() {
|
|
|
3335
3658
|
}
|
|
3336
3659
|
function readPluginManifest(pluginKey) {
|
|
3337
3660
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
3338
|
-
if (!
|
|
3661
|
+
if (!fs12.existsSync(manifestPath)) {
|
|
3339
3662
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
3340
3663
|
}
|
|
3341
3664
|
try {
|
|
3342
|
-
const content =
|
|
3665
|
+
const content = fs12.readFileSync(manifestPath, "utf-8");
|
|
3343
3666
|
return JSON.parse(content);
|
|
3344
3667
|
} catch (error) {
|
|
3345
3668
|
if (error instanceof SyntaxError) {
|
|
@@ -3356,7 +3679,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
3356
3679
|
}
|
|
3357
3680
|
async function loadPlugin(pluginKey) {
|
|
3358
3681
|
try {
|
|
3359
|
-
const userRequire = createRequire2(
|
|
3682
|
+
const userRequire = createRequire2(path10.join(getProjectRoot2(), "package.json"));
|
|
3360
3683
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
3361
3684
|
const pluginModule = await import(resolvedPath);
|
|
3362
3685
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -3519,8 +3842,8 @@ var capabilityCommandGroup = {
|
|
|
3519
3842
|
import { execFile } from "child_process";
|
|
3520
3843
|
|
|
3521
3844
|
// src/commands/component/registry-preparer.ts
|
|
3522
|
-
import
|
|
3523
|
-
import
|
|
3845
|
+
import fs13 from "fs";
|
|
3846
|
+
import path11 from "path";
|
|
3524
3847
|
import os from "os";
|
|
3525
3848
|
|
|
3526
3849
|
// src/commands/component/service.ts
|
|
@@ -3576,7 +3899,7 @@ async function sendInstallEvent(key) {
|
|
|
3576
3899
|
}
|
|
3577
3900
|
|
|
3578
3901
|
// src/commands/component/registry-preparer.ts
|
|
3579
|
-
var REGISTRY_TEMP_DIR =
|
|
3902
|
+
var REGISTRY_TEMP_DIR = path11.join(os.tmpdir(), "miaoda-registry");
|
|
3580
3903
|
function parseComponentKey(key) {
|
|
3581
3904
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3582
3905
|
if (!match) {
|
|
@@ -3588,11 +3911,11 @@ function parseComponentKey(key) {
|
|
|
3588
3911
|
}
|
|
3589
3912
|
function getLocalRegistryPath(key) {
|
|
3590
3913
|
const { scope, name } = parseComponentKey(key);
|
|
3591
|
-
return
|
|
3914
|
+
return path11.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3592
3915
|
}
|
|
3593
3916
|
function ensureDir(dirPath) {
|
|
3594
|
-
if (!
|
|
3595
|
-
|
|
3917
|
+
if (!fs13.existsSync(dirPath)) {
|
|
3918
|
+
fs13.mkdirSync(dirPath, { recursive: true });
|
|
3596
3919
|
}
|
|
3597
3920
|
}
|
|
3598
3921
|
async function prepareRecursive(key, visited) {
|
|
@@ -3625,8 +3948,8 @@ async function prepareRecursive(key, visited) {
|
|
|
3625
3948
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3626
3949
|
};
|
|
3627
3950
|
const localPath = getLocalRegistryPath(key);
|
|
3628
|
-
ensureDir(
|
|
3629
|
-
|
|
3951
|
+
ensureDir(path11.dirname(localPath));
|
|
3952
|
+
fs13.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3630
3953
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3631
3954
|
}
|
|
3632
3955
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -3636,18 +3959,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
3636
3959
|
}
|
|
3637
3960
|
function cleanupTempDir() {
|
|
3638
3961
|
try {
|
|
3639
|
-
if (
|
|
3640
|
-
|
|
3962
|
+
if (fs13.existsSync(REGISTRY_TEMP_DIR)) {
|
|
3963
|
+
fs13.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3641
3964
|
}
|
|
3642
3965
|
} catch {
|
|
3643
3966
|
}
|
|
3644
3967
|
}
|
|
3645
3968
|
function getDownloadedRegistryItem(itemId) {
|
|
3646
3969
|
const localPath = getLocalRegistryPath(itemId);
|
|
3647
|
-
if (!
|
|
3970
|
+
if (!fs13.existsSync(localPath)) {
|
|
3648
3971
|
return null;
|
|
3649
3972
|
}
|
|
3650
|
-
const content =
|
|
3973
|
+
const content = fs13.readFileSync(localPath, "utf-8");
|
|
3651
3974
|
return JSON.parse(content);
|
|
3652
3975
|
}
|
|
3653
3976
|
|
|
@@ -3815,58 +4138,58 @@ var componentCommandGroup = {
|
|
|
3815
4138
|
};
|
|
3816
4139
|
|
|
3817
4140
|
// src/commands/migration/version-manager.ts
|
|
3818
|
-
import
|
|
3819
|
-
import
|
|
4141
|
+
import fs14 from "fs";
|
|
4142
|
+
import path12 from "path";
|
|
3820
4143
|
var PACKAGE_JSON = "package.json";
|
|
3821
4144
|
var VERSION_FIELD = "migrationVersion";
|
|
3822
4145
|
function getPackageJsonPath2() {
|
|
3823
|
-
return
|
|
4146
|
+
return path12.join(process.cwd(), PACKAGE_JSON);
|
|
3824
4147
|
}
|
|
3825
4148
|
function getCurrentVersion() {
|
|
3826
4149
|
const pkgPath = getPackageJsonPath2();
|
|
3827
|
-
if (!
|
|
4150
|
+
if (!fs14.existsSync(pkgPath)) {
|
|
3828
4151
|
throw new Error("package.json not found");
|
|
3829
4152
|
}
|
|
3830
|
-
const pkg2 = JSON.parse(
|
|
4153
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3831
4154
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
3832
4155
|
}
|
|
3833
4156
|
function setCurrentVersion(version) {
|
|
3834
4157
|
const pkgPath = getPackageJsonPath2();
|
|
3835
|
-
const pkg2 = JSON.parse(
|
|
4158
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3836
4159
|
pkg2[VERSION_FIELD] = version;
|
|
3837
|
-
|
|
4160
|
+
fs14.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3838
4161
|
}
|
|
3839
4162
|
|
|
3840
4163
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3841
|
-
import
|
|
3842
|
-
import
|
|
4164
|
+
import fs16 from "fs";
|
|
4165
|
+
import path14 from "path";
|
|
3843
4166
|
|
|
3844
4167
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
3845
|
-
import
|
|
3846
|
-
import
|
|
4168
|
+
import fs15 from "fs";
|
|
4169
|
+
import path13 from "path";
|
|
3847
4170
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
3848
4171
|
function getProjectRoot3() {
|
|
3849
4172
|
return process.cwd();
|
|
3850
4173
|
}
|
|
3851
4174
|
function getCapabilitiesDir2() {
|
|
3852
|
-
return
|
|
4175
|
+
return path13.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
3853
4176
|
}
|
|
3854
4177
|
function getPluginManifestPath2(pluginKey) {
|
|
3855
|
-
return
|
|
4178
|
+
return path13.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
3856
4179
|
}
|
|
3857
4180
|
|
|
3858
4181
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3859
4182
|
function detectJsonMigration() {
|
|
3860
4183
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3861
|
-
const oldFilePath =
|
|
3862
|
-
if (!
|
|
4184
|
+
const oldFilePath = path14.join(capabilitiesDir, "capabilities.json");
|
|
4185
|
+
if (!fs16.existsSync(oldFilePath)) {
|
|
3863
4186
|
return {
|
|
3864
4187
|
needsMigration: false,
|
|
3865
4188
|
reason: "capabilities.json not found"
|
|
3866
4189
|
};
|
|
3867
4190
|
}
|
|
3868
4191
|
try {
|
|
3869
|
-
const content =
|
|
4192
|
+
const content = fs16.readFileSync(oldFilePath, "utf-8");
|
|
3870
4193
|
const parsed = JSON.parse(content);
|
|
3871
4194
|
if (!Array.isArray(parsed)) {
|
|
3872
4195
|
return {
|
|
@@ -3917,8 +4240,8 @@ async function check(options) {
|
|
|
3917
4240
|
}
|
|
3918
4241
|
|
|
3919
4242
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
3920
|
-
import
|
|
3921
|
-
import
|
|
4243
|
+
import fs17 from "fs";
|
|
4244
|
+
import path15 from "path";
|
|
3922
4245
|
|
|
3923
4246
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
3924
4247
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4148,18 +4471,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4148
4471
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4149
4472
|
function loadExistingCapabilities() {
|
|
4150
4473
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4151
|
-
if (!
|
|
4474
|
+
if (!fs17.existsSync(capabilitiesDir)) {
|
|
4152
4475
|
return [];
|
|
4153
4476
|
}
|
|
4154
|
-
const files =
|
|
4477
|
+
const files = fs17.readdirSync(capabilitiesDir);
|
|
4155
4478
|
const capabilities = [];
|
|
4156
4479
|
for (const file of files) {
|
|
4157
4480
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4158
4481
|
continue;
|
|
4159
4482
|
}
|
|
4160
4483
|
try {
|
|
4161
|
-
const filePath =
|
|
4162
|
-
const content =
|
|
4484
|
+
const filePath = path15.join(capabilitiesDir, file);
|
|
4485
|
+
const content = fs17.readFileSync(filePath, "utf-8");
|
|
4163
4486
|
const capability = JSON.parse(content);
|
|
4164
4487
|
if (capability.id && capability.pluginKey) {
|
|
4165
4488
|
capabilities.push(capability);
|
|
@@ -4217,9 +4540,9 @@ async function migrateJsonFiles(options) {
|
|
|
4217
4540
|
}
|
|
4218
4541
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4219
4542
|
for (const cap of newCapabilities) {
|
|
4220
|
-
const filePath =
|
|
4543
|
+
const filePath = path15.join(capabilitiesDir, `${cap.id}.json`);
|
|
4221
4544
|
const content = JSON.stringify(cap, null, 2);
|
|
4222
|
-
|
|
4545
|
+
fs17.writeFileSync(filePath, content, "utf-8");
|
|
4223
4546
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4224
4547
|
}
|
|
4225
4548
|
return {
|
|
@@ -4231,11 +4554,11 @@ async function migrateJsonFiles(options) {
|
|
|
4231
4554
|
}
|
|
4232
4555
|
|
|
4233
4556
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4234
|
-
import
|
|
4557
|
+
import fs18 from "fs";
|
|
4235
4558
|
function isPluginInstalled2(pluginKey) {
|
|
4236
4559
|
const actionPlugins = readActionPlugins();
|
|
4237
4560
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4238
|
-
return
|
|
4561
|
+
return fs18.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4239
4562
|
}
|
|
4240
4563
|
function detectPluginsToInstall(capabilities) {
|
|
4241
4564
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -4311,12 +4634,12 @@ async function installPlugins(capabilities, options) {
|
|
|
4311
4634
|
}
|
|
4312
4635
|
|
|
4313
4636
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
4314
|
-
import
|
|
4637
|
+
import path17 from "path";
|
|
4315
4638
|
import { Project as Project3 } from "ts-morph";
|
|
4316
4639
|
|
|
4317
4640
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
4318
|
-
import
|
|
4319
|
-
import
|
|
4641
|
+
import fs19 from "fs";
|
|
4642
|
+
import path16 from "path";
|
|
4320
4643
|
var EXCLUDED_DIRS = [
|
|
4321
4644
|
"node_modules",
|
|
4322
4645
|
"dist",
|
|
@@ -4331,9 +4654,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
4331
4654
|
/\.d\.ts$/
|
|
4332
4655
|
];
|
|
4333
4656
|
function scanDirectory(dir, files = []) {
|
|
4334
|
-
const entries =
|
|
4657
|
+
const entries = fs19.readdirSync(dir, { withFileTypes: true });
|
|
4335
4658
|
for (const entry of entries) {
|
|
4336
|
-
const fullPath =
|
|
4659
|
+
const fullPath = path16.join(dir, entry.name);
|
|
4337
4660
|
if (entry.isDirectory()) {
|
|
4338
4661
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
4339
4662
|
continue;
|
|
@@ -4349,14 +4672,14 @@ function scanDirectory(dir, files = []) {
|
|
|
4349
4672
|
return files;
|
|
4350
4673
|
}
|
|
4351
4674
|
function scanServerFiles() {
|
|
4352
|
-
const serverDir =
|
|
4353
|
-
if (!
|
|
4675
|
+
const serverDir = path16.join(getProjectRoot3(), "server");
|
|
4676
|
+
if (!fs19.existsSync(serverDir)) {
|
|
4354
4677
|
return [];
|
|
4355
4678
|
}
|
|
4356
4679
|
return scanDirectory(serverDir);
|
|
4357
4680
|
}
|
|
4358
4681
|
function hasCapabilityImport(filePath) {
|
|
4359
|
-
const content =
|
|
4682
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
4360
4683
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
4361
4684
|
}
|
|
4362
4685
|
function scanFilesToMigrate() {
|
|
@@ -4733,7 +5056,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4733
5056
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
4734
5057
|
const classInfo = analyzeClass(sourceFile);
|
|
4735
5058
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
4736
|
-
const relativePath =
|
|
5059
|
+
const relativePath = path17.relative(getProjectRoot3(), filePath);
|
|
4737
5060
|
return {
|
|
4738
5061
|
filePath: relativePath,
|
|
4739
5062
|
imports,
|
|
@@ -4744,7 +5067,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4744
5067
|
};
|
|
4745
5068
|
}
|
|
4746
5069
|
function migrateFile(project, analysis, dryRun) {
|
|
4747
|
-
const absolutePath =
|
|
5070
|
+
const absolutePath = path17.join(getProjectRoot3(), analysis.filePath);
|
|
4748
5071
|
if (!analysis.canAutoMigrate) {
|
|
4749
5072
|
return {
|
|
4750
5073
|
filePath: analysis.filePath,
|
|
@@ -4847,17 +5170,17 @@ function getSuggestion(analysis) {
|
|
|
4847
5170
|
}
|
|
4848
5171
|
|
|
4849
5172
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
4850
|
-
import
|
|
4851
|
-
import
|
|
5173
|
+
import fs20 from "fs";
|
|
5174
|
+
import path18 from "path";
|
|
4852
5175
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
4853
5176
|
const deletedFiles = [];
|
|
4854
5177
|
const errors = [];
|
|
4855
5178
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4856
|
-
const oldJsonPath =
|
|
4857
|
-
if (
|
|
5179
|
+
const oldJsonPath = path18.join(capabilitiesDir, "capabilities.json");
|
|
5180
|
+
if (fs20.existsSync(oldJsonPath)) {
|
|
4858
5181
|
try {
|
|
4859
5182
|
if (!dryRun) {
|
|
4860
|
-
|
|
5183
|
+
fs20.unlinkSync(oldJsonPath);
|
|
4861
5184
|
}
|
|
4862
5185
|
deletedFiles.push("capabilities.json");
|
|
4863
5186
|
} catch (error) {
|
|
@@ -4865,11 +5188,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4865
5188
|
}
|
|
4866
5189
|
}
|
|
4867
5190
|
for (const cap of capabilities) {
|
|
4868
|
-
const tsFilePath =
|
|
4869
|
-
if (
|
|
5191
|
+
const tsFilePath = path18.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5192
|
+
if (fs20.existsSync(tsFilePath)) {
|
|
4870
5193
|
try {
|
|
4871
5194
|
if (!dryRun) {
|
|
4872
|
-
|
|
5195
|
+
fs20.unlinkSync(tsFilePath);
|
|
4873
5196
|
}
|
|
4874
5197
|
deletedFiles.push(`${cap.id}.ts`);
|
|
4875
5198
|
} catch (error) {
|
|
@@ -4885,8 +5208,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4885
5208
|
}
|
|
4886
5209
|
|
|
4887
5210
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
4888
|
-
import
|
|
4889
|
-
import
|
|
5211
|
+
import fs21 from "fs";
|
|
5212
|
+
import path19 from "path";
|
|
4890
5213
|
var REPORT_FILE = "capability-migration-report.md";
|
|
4891
5214
|
function printSummary(result) {
|
|
4892
5215
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -5049,15 +5372,15 @@ async function generateReport(result) {
|
|
|
5049
5372
|
}
|
|
5050
5373
|
lines.push("");
|
|
5051
5374
|
const logDir = process.env.LOG_DIR || "logs";
|
|
5052
|
-
if (!
|
|
5375
|
+
if (!fs21.existsSync(logDir)) {
|
|
5053
5376
|
return;
|
|
5054
5377
|
}
|
|
5055
|
-
const reportDir =
|
|
5056
|
-
if (!
|
|
5057
|
-
|
|
5378
|
+
const reportDir = path19.join(logDir, "migration");
|
|
5379
|
+
if (!fs21.existsSync(reportDir)) {
|
|
5380
|
+
fs21.mkdirSync(reportDir, { recursive: true });
|
|
5058
5381
|
}
|
|
5059
|
-
const reportPath =
|
|
5060
|
-
|
|
5382
|
+
const reportPath = path19.join(reportDir, REPORT_FILE);
|
|
5383
|
+
fs21.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
5061
5384
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
5062
5385
|
}
|
|
5063
5386
|
|
|
@@ -5234,7 +5557,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
|
|
|
5234
5557
|
}
|
|
5235
5558
|
|
|
5236
5559
|
// src/commands/migration/versions/v001_capability/run.ts
|
|
5237
|
-
async function
|
|
5560
|
+
async function run5(options) {
|
|
5238
5561
|
try {
|
|
5239
5562
|
const migrationOptions = {
|
|
5240
5563
|
dryRun: options.dryRun ?? false
|
|
@@ -5299,7 +5622,7 @@ var v001CapabilityMigration = {
|
|
|
5299
5622
|
name: "capability",
|
|
5300
5623
|
description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
|
|
5301
5624
|
check,
|
|
5302
|
-
run:
|
|
5625
|
+
run: run5
|
|
5303
5626
|
};
|
|
5304
5627
|
|
|
5305
5628
|
// src/commands/migration/versions/index.ts
|
|
@@ -5589,10 +5912,10 @@ var migrationCommand = {
|
|
|
5589
5912
|
};
|
|
5590
5913
|
|
|
5591
5914
|
// src/commands/read-logs/index.ts
|
|
5592
|
-
import
|
|
5915
|
+
import path20 from "path";
|
|
5593
5916
|
|
|
5594
5917
|
// src/commands/read-logs/std-utils.ts
|
|
5595
|
-
import
|
|
5918
|
+
import fs22 from "fs";
|
|
5596
5919
|
function formatStdPrefixTime(localTime) {
|
|
5597
5920
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5598
5921
|
if (!match) return localTime;
|
|
@@ -5622,11 +5945,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5622
5945
|
return `[${time}] ${content}`;
|
|
5623
5946
|
}
|
|
5624
5947
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5625
|
-
const stat =
|
|
5948
|
+
const stat = fs22.statSync(filePath);
|
|
5626
5949
|
if (stat.size === 0) {
|
|
5627
5950
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5628
5951
|
}
|
|
5629
|
-
const fd =
|
|
5952
|
+
const fd = fs22.openSync(filePath, "r");
|
|
5630
5953
|
const chunkSize = 64 * 1024;
|
|
5631
5954
|
let position = stat.size;
|
|
5632
5955
|
let remainder = "";
|
|
@@ -5640,7 +5963,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5640
5963
|
const length = Math.min(chunkSize, position);
|
|
5641
5964
|
position -= length;
|
|
5642
5965
|
const buffer = Buffer.alloc(length);
|
|
5643
|
-
|
|
5966
|
+
fs22.readSync(fd, buffer, 0, length, position);
|
|
5644
5967
|
let chunk = buffer.toString("utf8");
|
|
5645
5968
|
if (remainder) {
|
|
5646
5969
|
chunk += remainder;
|
|
@@ -5682,7 +6005,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5682
6005
|
}
|
|
5683
6006
|
}
|
|
5684
6007
|
} finally {
|
|
5685
|
-
|
|
6008
|
+
fs22.closeSync(fd);
|
|
5686
6009
|
}
|
|
5687
6010
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5688
6011
|
}
|
|
@@ -5703,21 +6026,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5703
6026
|
}
|
|
5704
6027
|
|
|
5705
6028
|
// src/commands/read-logs/tail.ts
|
|
5706
|
-
import
|
|
6029
|
+
import fs23 from "fs";
|
|
5707
6030
|
function fileExists(filePath) {
|
|
5708
6031
|
try {
|
|
5709
|
-
|
|
6032
|
+
fs23.accessSync(filePath, fs23.constants.F_OK | fs23.constants.R_OK);
|
|
5710
6033
|
return true;
|
|
5711
6034
|
} catch {
|
|
5712
6035
|
return false;
|
|
5713
6036
|
}
|
|
5714
6037
|
}
|
|
5715
6038
|
function readFileTailLines(filePath, maxLines) {
|
|
5716
|
-
const stat =
|
|
6039
|
+
const stat = fs23.statSync(filePath);
|
|
5717
6040
|
if (stat.size === 0) {
|
|
5718
6041
|
return [];
|
|
5719
6042
|
}
|
|
5720
|
-
const fd =
|
|
6043
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5721
6044
|
const chunkSize = 64 * 1024;
|
|
5722
6045
|
const chunks = [];
|
|
5723
6046
|
let position = stat.size;
|
|
@@ -5727,13 +6050,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5727
6050
|
const length = Math.min(chunkSize, position);
|
|
5728
6051
|
position -= length;
|
|
5729
6052
|
const buffer = Buffer.alloc(length);
|
|
5730
|
-
|
|
6053
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5731
6054
|
chunks.unshift(buffer.toString("utf8"));
|
|
5732
6055
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
5733
6056
|
collectedLines += chunkLines;
|
|
5734
6057
|
}
|
|
5735
6058
|
} finally {
|
|
5736
|
-
|
|
6059
|
+
fs23.closeSync(fd);
|
|
5737
6060
|
}
|
|
5738
6061
|
const content = chunks.join("");
|
|
5739
6062
|
const allLines = content.split("\n");
|
|
@@ -5749,11 +6072,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5749
6072
|
return allLines.slice(allLines.length - maxLines);
|
|
5750
6073
|
}
|
|
5751
6074
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
5752
|
-
const stat =
|
|
6075
|
+
const stat = fs23.statSync(filePath);
|
|
5753
6076
|
if (stat.size === 0) {
|
|
5754
6077
|
return { lines: [], totalLinesCount: 0 };
|
|
5755
6078
|
}
|
|
5756
|
-
const fd =
|
|
6079
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5757
6080
|
const chunkSize = 64 * 1024;
|
|
5758
6081
|
let position = stat.size;
|
|
5759
6082
|
let remainder = "";
|
|
@@ -5765,7 +6088,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5765
6088
|
const length = Math.min(chunkSize, position);
|
|
5766
6089
|
position -= length;
|
|
5767
6090
|
const buffer = Buffer.alloc(length);
|
|
5768
|
-
|
|
6091
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5769
6092
|
let chunk = buffer.toString("utf8");
|
|
5770
6093
|
if (remainder) {
|
|
5771
6094
|
chunk += remainder;
|
|
@@ -5796,7 +6119,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5796
6119
|
}
|
|
5797
6120
|
}
|
|
5798
6121
|
} finally {
|
|
5799
|
-
|
|
6122
|
+
fs23.closeSync(fd);
|
|
5800
6123
|
}
|
|
5801
6124
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5802
6125
|
}
|
|
@@ -5938,7 +6261,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
5938
6261
|
}
|
|
5939
6262
|
|
|
5940
6263
|
// src/commands/read-logs/json-lines.ts
|
|
5941
|
-
import
|
|
6264
|
+
import fs24 from "fs";
|
|
5942
6265
|
function normalizePid(value) {
|
|
5943
6266
|
if (typeof value === "number") {
|
|
5944
6267
|
return String(value);
|
|
@@ -5989,11 +6312,11 @@ function buildWantedLevelSet(levels) {
|
|
|
5989
6312
|
return set.size > 0 ? set : null;
|
|
5990
6313
|
}
|
|
5991
6314
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
5992
|
-
const stat =
|
|
6315
|
+
const stat = fs24.statSync(filePath);
|
|
5993
6316
|
if (stat.size === 0) {
|
|
5994
6317
|
return { lines: [], totalLinesCount: 0 };
|
|
5995
6318
|
}
|
|
5996
|
-
const fd =
|
|
6319
|
+
const fd = fs24.openSync(filePath, "r");
|
|
5997
6320
|
const chunkSize = 64 * 1024;
|
|
5998
6321
|
let position = stat.size;
|
|
5999
6322
|
let remainder = "";
|
|
@@ -6008,7 +6331,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6008
6331
|
const length = Math.min(chunkSize, position);
|
|
6009
6332
|
position -= length;
|
|
6010
6333
|
const buffer = Buffer.alloc(length);
|
|
6011
|
-
|
|
6334
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6012
6335
|
let chunk = buffer.toString("utf8");
|
|
6013
6336
|
if (remainder) {
|
|
6014
6337
|
chunk += remainder;
|
|
@@ -6070,7 +6393,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6070
6393
|
}
|
|
6071
6394
|
}
|
|
6072
6395
|
} finally {
|
|
6073
|
-
|
|
6396
|
+
fs24.closeSync(fd);
|
|
6074
6397
|
}
|
|
6075
6398
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6076
6399
|
}
|
|
@@ -6113,11 +6436,11 @@ function extractTraceId(obj) {
|
|
|
6113
6436
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6114
6437
|
const wanted = traceId.trim();
|
|
6115
6438
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6116
|
-
const stat =
|
|
6439
|
+
const stat = fs24.statSync(filePath);
|
|
6117
6440
|
if (stat.size === 0) {
|
|
6118
6441
|
return { lines: [], totalLinesCount: 0 };
|
|
6119
6442
|
}
|
|
6120
|
-
const fd =
|
|
6443
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6121
6444
|
const chunkSize = 64 * 1024;
|
|
6122
6445
|
let position = stat.size;
|
|
6123
6446
|
let remainder = "";
|
|
@@ -6130,7 +6453,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6130
6453
|
const length = Math.min(chunkSize, position);
|
|
6131
6454
|
position -= length;
|
|
6132
6455
|
const buffer = Buffer.alloc(length);
|
|
6133
|
-
|
|
6456
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6134
6457
|
let chunk = buffer.toString("utf8");
|
|
6135
6458
|
if (remainder) {
|
|
6136
6459
|
chunk += remainder;
|
|
@@ -6183,7 +6506,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6183
6506
|
}
|
|
6184
6507
|
}
|
|
6185
6508
|
} finally {
|
|
6186
|
-
|
|
6509
|
+
fs24.closeSync(fd);
|
|
6187
6510
|
}
|
|
6188
6511
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6189
6512
|
}
|
|
@@ -6192,11 +6515,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6192
6515
|
if (!wantedLevelSet) {
|
|
6193
6516
|
return { lines: [], totalLinesCount: 0 };
|
|
6194
6517
|
}
|
|
6195
|
-
const stat =
|
|
6518
|
+
const stat = fs24.statSync(filePath);
|
|
6196
6519
|
if (stat.size === 0) {
|
|
6197
6520
|
return { lines: [], totalLinesCount: 0 };
|
|
6198
6521
|
}
|
|
6199
|
-
const fd =
|
|
6522
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6200
6523
|
const chunkSize = 64 * 1024;
|
|
6201
6524
|
let position = stat.size;
|
|
6202
6525
|
let remainder = "";
|
|
@@ -6208,7 +6531,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6208
6531
|
const length = Math.min(chunkSize, position);
|
|
6209
6532
|
position -= length;
|
|
6210
6533
|
const buffer = Buffer.alloc(length);
|
|
6211
|
-
|
|
6534
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6212
6535
|
let chunk = buffer.toString("utf8");
|
|
6213
6536
|
if (remainder) {
|
|
6214
6537
|
chunk += remainder;
|
|
@@ -6255,7 +6578,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6255
6578
|
}
|
|
6256
6579
|
}
|
|
6257
6580
|
} finally {
|
|
6258
|
-
|
|
6581
|
+
fs24.closeSync(fd);
|
|
6259
6582
|
}
|
|
6260
6583
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6261
6584
|
}
|
|
@@ -6489,34 +6812,34 @@ async function readLogsJsonResult(options) {
|
|
|
6489
6812
|
};
|
|
6490
6813
|
}
|
|
6491
6814
|
function resolveLogFilePath(logDir, type) {
|
|
6492
|
-
const base =
|
|
6815
|
+
const base = path20.isAbsolute(logDir) ? logDir : path20.join(process.cwd(), logDir);
|
|
6493
6816
|
if (type === "server") {
|
|
6494
|
-
return
|
|
6817
|
+
return path20.join(base, "server.log");
|
|
6495
6818
|
}
|
|
6496
6819
|
if (type === "trace") {
|
|
6497
|
-
return
|
|
6820
|
+
return path20.join(base, "trace.log");
|
|
6498
6821
|
}
|
|
6499
6822
|
if (type === "server-std") {
|
|
6500
|
-
return
|
|
6823
|
+
return path20.join(base, "server.std.log");
|
|
6501
6824
|
}
|
|
6502
6825
|
if (type === "client-std") {
|
|
6503
|
-
return
|
|
6826
|
+
return path20.join(base, "client.std.log");
|
|
6504
6827
|
}
|
|
6505
6828
|
if (type === "dev") {
|
|
6506
|
-
return
|
|
6829
|
+
return path20.join(base, "dev.log");
|
|
6507
6830
|
}
|
|
6508
6831
|
if (type === "dev-std") {
|
|
6509
|
-
return
|
|
6832
|
+
return path20.join(base, "dev.std.log");
|
|
6510
6833
|
}
|
|
6511
6834
|
if (type === "install-dep-std") {
|
|
6512
|
-
return
|
|
6835
|
+
return path20.join(base, "install-dep.std.log");
|
|
6513
6836
|
}
|
|
6514
6837
|
if (type === "browser") {
|
|
6515
|
-
return
|
|
6838
|
+
return path20.join(base, "browser.log");
|
|
6516
6839
|
}
|
|
6517
6840
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6518
6841
|
}
|
|
6519
|
-
async function
|
|
6842
|
+
async function run6(options) {
|
|
6520
6843
|
const result = await readLogsJsonResult(options);
|
|
6521
6844
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
6522
6845
|
}
|
|
@@ -6558,7 +6881,7 @@ var readLogsCommand = {
|
|
|
6558
6881
|
const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
|
|
6559
6882
|
const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
|
|
6560
6883
|
const levels = parseCommaSeparatedList(rawOptions.level);
|
|
6561
|
-
await
|
|
6884
|
+
await run6({ logDir, type, maxLines, offset, traceId, levels });
|
|
6562
6885
|
} catch (error) {
|
|
6563
6886
|
const message = error instanceof Error ? error.message : String(error);
|
|
6564
6887
|
process.stderr.write(message + "\n");
|
|
@@ -6647,6 +6970,7 @@ var buildCommandGroup = {
|
|
|
6647
6970
|
var commands = [
|
|
6648
6971
|
genDbSchemaCommand,
|
|
6649
6972
|
syncCommand,
|
|
6973
|
+
upgradeCommand,
|
|
6650
6974
|
actionPluginCommandGroup,
|
|
6651
6975
|
capabilityCommandGroup,
|
|
6652
6976
|
componentCommandGroup,
|
|
@@ -6656,12 +6980,12 @@ var commands = [
|
|
|
6656
6980
|
];
|
|
6657
6981
|
|
|
6658
6982
|
// src/index.ts
|
|
6659
|
-
var envPath =
|
|
6660
|
-
if (
|
|
6983
|
+
var envPath = path21.join(process.cwd(), ".env");
|
|
6984
|
+
if (fs25.existsSync(envPath)) {
|
|
6661
6985
|
dotenvConfig({ path: envPath });
|
|
6662
6986
|
}
|
|
6663
|
-
var __dirname =
|
|
6664
|
-
var pkg = JSON.parse(
|
|
6987
|
+
var __dirname = path21.dirname(fileURLToPath5(import.meta.url));
|
|
6988
|
+
var pkg = JSON.parse(fs25.readFileSync(path21.join(__dirname, "../package.json"), "utf-8"));
|
|
6665
6989
|
var cli = new FullstackCLI(pkg.version);
|
|
6666
6990
|
cli.useAll(commands);
|
|
6667
6991
|
cli.run();
|