@lark-apaas/fullstack-cli 1.1.22-alpha.7 → 1.1.22-alpha.8
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 +266 -538
- 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 fs22 from "fs";
|
|
3
|
+
import path18 from "path";
|
|
4
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
@@ -2419,357 +2419,10 @@ var syncCommand = {
|
|
|
2419
2419
|
}
|
|
2420
2420
|
};
|
|
2421
2421
|
|
|
2422
|
-
// src/
|
|
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/git.ts
|
|
2445
|
-
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2422
|
+
// src/commands/action-plugin/utils.ts
|
|
2446
2423
|
import fs7 from "fs";
|
|
2447
2424
|
import path5 from "path";
|
|
2448
|
-
|
|
2449
|
-
try {
|
|
2450
|
-
const gitDir = path5.join(cwd, ".git");
|
|
2451
|
-
if (fs7.existsSync(gitDir)) {
|
|
2452
|
-
return true;
|
|
2453
|
-
}
|
|
2454
|
-
const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
|
|
2455
|
-
cwd,
|
|
2456
|
-
stdio: "pipe",
|
|
2457
|
-
encoding: "utf-8"
|
|
2458
|
-
});
|
|
2459
|
-
return result.status === 0;
|
|
2460
|
-
} catch {
|
|
2461
|
-
return false;
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
function getChangedFiles(cwd = process.cwd()) {
|
|
2465
|
-
try {
|
|
2466
|
-
const output = execSync("git status --porcelain", {
|
|
2467
|
-
cwd,
|
|
2468
|
-
stdio: "pipe",
|
|
2469
|
-
encoding: "utf-8"
|
|
2470
|
-
});
|
|
2471
|
-
return output.split("\n").filter((line) => line.trim()).map((line) => line.substring(3));
|
|
2472
|
-
} catch (error) {
|
|
2473
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2474
|
-
throw new Error(`Failed to get changed files: ${message}`);
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
2478
|
-
const filteredFiles = [];
|
|
2479
|
-
for (const filePath of filesToStage) {
|
|
2480
|
-
if (fs7.existsSync(path5.join(cwd, filePath))) {
|
|
2481
|
-
filteredFiles.push(filePath);
|
|
2482
|
-
continue;
|
|
2483
|
-
}
|
|
2484
|
-
const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
2485
|
-
cwd,
|
|
2486
|
-
stdio: "pipe",
|
|
2487
|
-
encoding: "utf-8"
|
|
2488
|
-
});
|
|
2489
|
-
if (tracked.status === 0) {
|
|
2490
|
-
filteredFiles.push(filePath);
|
|
2491
|
-
}
|
|
2492
|
-
}
|
|
2493
|
-
if (filteredFiles.length === 0) {
|
|
2494
|
-
return;
|
|
2495
|
-
}
|
|
2496
|
-
const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
|
|
2497
|
-
cwd,
|
|
2498
|
-
stdio: "pipe",
|
|
2499
|
-
encoding: "utf-8"
|
|
2500
|
-
});
|
|
2501
|
-
if (result.error || result.status !== 0) {
|
|
2502
|
-
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2503
|
-
throw new Error(`git add failed: ${errorMsg}`);
|
|
2504
|
-
}
|
|
2505
|
-
}
|
|
2506
|
-
function gitCommit(message, cwd = process.cwd()) {
|
|
2507
|
-
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
2508
|
-
cwd,
|
|
2509
|
-
stdio: "pipe",
|
|
2510
|
-
encoding: "utf-8"
|
|
2511
|
-
});
|
|
2512
|
-
if (result.error || result.status !== 0) {
|
|
2513
|
-
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2514
|
-
throw new Error(`git commit failed: ${errorMsg}`);
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
|
|
2518
|
-
if (!isGitRepository(cwd)) {
|
|
2519
|
-
console.log("[fullstack-cli] \u26A0 Not a git repository, skipping auto-commit");
|
|
2520
|
-
return false;
|
|
2521
|
-
}
|
|
2522
|
-
const changedFiles = getChangedFiles(cwd);
|
|
2523
|
-
if (changedFiles.length === 0) {
|
|
2524
|
-
console.log("[fullstack-cli] No changes to commit");
|
|
2525
|
-
return false;
|
|
2526
|
-
}
|
|
2527
|
-
try {
|
|
2528
|
-
gitAddUpgradeFiles(cwd, filesToStage);
|
|
2529
|
-
const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
|
|
2530
|
-
|
|
2531
|
-
- Sync template files
|
|
2532
|
-
- Cleanup package.json config
|
|
2533
|
-
- Upgrade @lark-apaas dependencies (if any)
|
|
2534
|
-
|
|
2535
|
-
Auto-committed by fullstack-cli v${version}`;
|
|
2536
|
-
gitCommit(message, cwd);
|
|
2537
|
-
console.log(`[fullstack-cli] \u2713 Auto-committed ${changedFiles.length} changed file(s)`);
|
|
2538
|
-
return true;
|
|
2539
|
-
} catch (error) {
|
|
2540
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2541
|
-
throw new Error(`Failed to auto-commit changes: ${message}`);
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
|
|
2545
|
-
// src/utils/package-json.ts
|
|
2546
|
-
import fs8 from "fs";
|
|
2547
|
-
import path6 from "path";
|
|
2548
|
-
function readPackageJson(cwd = process.cwd()) {
|
|
2549
|
-
const pkgPath = path6.join(cwd, "package.json");
|
|
2550
|
-
if (!fs8.existsSync(pkgPath)) {
|
|
2551
|
-
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2552
|
-
}
|
|
2553
|
-
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
2554
|
-
return JSON.parse(content);
|
|
2555
|
-
}
|
|
2556
|
-
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2557
|
-
const pkgPath = path6.join(cwd, "package.json");
|
|
2558
|
-
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
2559
|
-
fs8.writeFileSync(pkgPath, content, "utf-8");
|
|
2560
|
-
}
|
|
2561
|
-
function removeUpgradeScript(pkg2) {
|
|
2562
|
-
if (!pkg2.scripts?.upgrade) {
|
|
2563
|
-
return false;
|
|
2564
|
-
}
|
|
2565
|
-
delete pkg2.scripts.upgrade;
|
|
2566
|
-
return true;
|
|
2567
|
-
}
|
|
2568
|
-
function cleanDevScript(pkg2) {
|
|
2569
|
-
if (!pkg2.scripts?.dev) {
|
|
2570
|
-
return false;
|
|
2571
|
-
}
|
|
2572
|
-
const originalDev = pkg2.scripts.dev;
|
|
2573
|
-
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
2574
|
-
if (cleanedDev !== originalDev) {
|
|
2575
|
-
pkg2.scripts.dev = cleanedDev;
|
|
2576
|
-
return true;
|
|
2577
|
-
}
|
|
2578
|
-
return false;
|
|
2579
|
-
}
|
|
2580
|
-
function cleanupPackageJson(cwd = process.cwd()) {
|
|
2581
|
-
try {
|
|
2582
|
-
const pkg2 = readPackageJson(cwd);
|
|
2583
|
-
let changed = false;
|
|
2584
|
-
if (removeUpgradeScript(pkg2)) {
|
|
2585
|
-
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
2586
|
-
changed = true;
|
|
2587
|
-
}
|
|
2588
|
-
if (cleanDevScript(pkg2)) {
|
|
2589
|
-
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
2590
|
-
changed = true;
|
|
2591
|
-
}
|
|
2592
|
-
if (changed) {
|
|
2593
|
-
writePackageJson(pkg2, cwd);
|
|
2594
|
-
}
|
|
2595
|
-
return changed;
|
|
2596
|
-
} catch (error) {
|
|
2597
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2598
|
-
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
2599
|
-
return false;
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
// src/commands/upgrade/shared/utils.ts
|
|
2604
|
-
import path7 from "path";
|
|
2605
|
-
import fs9 from "fs";
|
|
2606
|
-
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2607
|
-
function getCliVersion() {
|
|
2608
|
-
try {
|
|
2609
|
-
const __filename = fileURLToPath4(import.meta.url);
|
|
2610
|
-
const __dirname2 = path7.dirname(__filename);
|
|
2611
|
-
const pkgPath = path7.resolve(__dirname2, "../../../package.json");
|
|
2612
|
-
const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
|
|
2613
|
-
const pkg2 = JSON.parse(pkgContent);
|
|
2614
|
-
return pkg2.version || "unknown";
|
|
2615
|
-
} catch {
|
|
2616
|
-
return "unknown";
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
// src/commands/upgrade/get-upgrade-files.ts
|
|
2621
|
-
function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
2622
|
-
const syncConfig2 = genSyncConfig({ disableGenOpenapi });
|
|
2623
|
-
const filesToStage = /* @__PURE__ */ new Set();
|
|
2624
|
-
syncConfig2.sync.forEach((rule) => {
|
|
2625
|
-
if (rule.type === "file" || rule.type === "directory") {
|
|
2626
|
-
filesToStage.add(rule.to);
|
|
2627
|
-
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
2628
|
-
filesToStage.add(rule.to);
|
|
2629
|
-
} else if (rule.type === "add-script") {
|
|
2630
|
-
filesToStage.add("package.json");
|
|
2631
|
-
} else if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2632
|
-
filesToStage.add(rule.to);
|
|
2633
|
-
}
|
|
2634
|
-
});
|
|
2635
|
-
filesToStage.add("package.json");
|
|
2636
|
-
filesToStage.add("package-lock.json");
|
|
2637
|
-
return Array.from(filesToStage);
|
|
2638
|
-
}
|
|
2639
|
-
|
|
2640
|
-
// src/commands/upgrade/run.handler.ts
|
|
2641
|
-
async function run3(options = {}) {
|
|
2642
|
-
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2643
|
-
console.log("[fullstack-cli] Starting upgrade...");
|
|
2644
|
-
try {
|
|
2645
|
-
console.log("[fullstack-cli] Step 1/3: Syncing template files...");
|
|
2646
|
-
await run2({ disableGenOpenapi: options.disableGenOpenapi ?? true });
|
|
2647
|
-
console.log("[fullstack-cli] Step 2/3: Cleaning up package.json...");
|
|
2648
|
-
const cleaned = cleanupPackageJson(userProjectRoot);
|
|
2649
|
-
if (!cleaned) {
|
|
2650
|
-
console.log("[fullstack-cli] \u25CB No cleanup needed");
|
|
2651
|
-
}
|
|
2652
|
-
const shouldCommit = options.commit ?? true;
|
|
2653
|
-
if (shouldCommit) {
|
|
2654
|
-
console.log("[fullstack-cli] Step 3/3: Committing changes...");
|
|
2655
|
-
const version = getCliVersion();
|
|
2656
|
-
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
|
|
2657
|
-
autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
|
|
2658
|
-
} else {
|
|
2659
|
-
console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
|
|
2660
|
-
}
|
|
2661
|
-
console.log("[fullstack-cli] Upgrade completed successfully \u2705");
|
|
2662
|
-
} catch (error) {
|
|
2663
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2664
|
-
console.error("[fullstack-cli] Failed to upgrade:", message);
|
|
2665
|
-
process.exit(1);
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
// src/commands/upgrade/deps/run.handler.ts
|
|
2670
|
-
import { spawnSync as spawnSync3 } from "child_process";
|
|
2671
|
-
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
2672
|
-
const pkg2 = readPackageJson(cwd);
|
|
2673
|
-
const allPackages = /* @__PURE__ */ new Set();
|
|
2674
|
-
if (pkg2.dependencies) {
|
|
2675
|
-
Object.keys(pkg2.dependencies).forEach((name) => {
|
|
2676
|
-
if (name.startsWith("@lark-apaas/")) {
|
|
2677
|
-
allPackages.add(name);
|
|
2678
|
-
}
|
|
2679
|
-
});
|
|
2680
|
-
}
|
|
2681
|
-
if (pkg2.devDependencies) {
|
|
2682
|
-
Object.keys(pkg2.devDependencies).forEach((name) => {
|
|
2683
|
-
if (name.startsWith("@lark-apaas/")) {
|
|
2684
|
-
allPackages.add(name);
|
|
2685
|
-
}
|
|
2686
|
-
});
|
|
2687
|
-
}
|
|
2688
|
-
const packages = Array.from(allPackages);
|
|
2689
|
-
if (filterPackages) {
|
|
2690
|
-
const filter = new Set(filterPackages.split(",").map((p) => p.trim()));
|
|
2691
|
-
return packages.filter((p) => filter.has(p));
|
|
2692
|
-
}
|
|
2693
|
-
return packages;
|
|
2694
|
-
}
|
|
2695
|
-
function upgradePackages(packages, version, cwd) {
|
|
2696
|
-
if (version) {
|
|
2697
|
-
console.log(`[fullstack-cli] Upgrading to version ${version}...`);
|
|
2698
|
-
packages.forEach((pkg2) => {
|
|
2699
|
-
const target = `${pkg2}@${version}`;
|
|
2700
|
-
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
2701
|
-
const result = spawnSync3("npm", ["install", target], {
|
|
2702
|
-
cwd,
|
|
2703
|
-
stdio: "inherit"
|
|
2704
|
-
});
|
|
2705
|
-
if (result.error || result.status !== 0) {
|
|
2706
|
-
throw new Error(`Failed to install ${target}`);
|
|
2707
|
-
}
|
|
2708
|
-
});
|
|
2709
|
-
} else {
|
|
2710
|
-
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
2711
|
-
packages.forEach((pkg2) => {
|
|
2712
|
-
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
2713
|
-
const result = spawnSync3("npm", ["update", pkg2], {
|
|
2714
|
-
cwd,
|
|
2715
|
-
stdio: "inherit"
|
|
2716
|
-
});
|
|
2717
|
-
if (result.error || result.status !== 0) {
|
|
2718
|
-
throw new Error(`Failed to update ${pkg2}`);
|
|
2719
|
-
}
|
|
2720
|
-
});
|
|
2721
|
-
}
|
|
2722
|
-
}
|
|
2723
|
-
async function run4(options = {}) {
|
|
2724
|
-
const cwd = process.env.INIT_CWD || process.cwd();
|
|
2725
|
-
console.log("[fullstack-cli] Starting dependencies upgrade...");
|
|
2726
|
-
try {
|
|
2727
|
-
console.log("[fullstack-cli] Step 1/2: Scanning @lark-apaas dependencies...");
|
|
2728
|
-
const packages = findLarkAapaasPackages(cwd, options.packages);
|
|
2729
|
-
if (packages.length === 0) {
|
|
2730
|
-
console.log("[fullstack-cli] No @lark-apaas packages found");
|
|
2731
|
-
return;
|
|
2732
|
-
}
|
|
2733
|
-
console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
|
|
2734
|
-
packages.forEach((p) => console.log(` - ${p}`));
|
|
2735
|
-
console.log("[fullstack-cli] Step 2/2: Upgrading packages...");
|
|
2736
|
-
upgradePackages(packages, options.version, cwd);
|
|
2737
|
-
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
|
|
2738
|
-
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
2739
|
-
} catch (error) {
|
|
2740
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2741
|
-
console.error("[fullstack-cli] Failed to upgrade dependencies:", message);
|
|
2742
|
-
process.exit(1);
|
|
2743
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
// src/commands/upgrade/deps/index.ts
|
|
2747
|
-
var depsCommand = {
|
|
2748
|
-
name: "deps",
|
|
2749
|
-
description: "Upgrade @lark-apaas dependencies",
|
|
2750
|
-
register(parentCommand) {
|
|
2751
|
-
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) => {
|
|
2752
|
-
await run4(options);
|
|
2753
|
-
});
|
|
2754
|
-
}
|
|
2755
|
-
};
|
|
2756
|
-
|
|
2757
|
-
// src/commands/upgrade/index.ts
|
|
2758
|
-
var upgradeCommand = {
|
|
2759
|
-
name: "upgrade",
|
|
2760
|
-
description: "Upgrade template files and auto-commit changes",
|
|
2761
|
-
register(program) {
|
|
2762
|
-
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) => {
|
|
2763
|
-
await run3(options);
|
|
2764
|
-
});
|
|
2765
|
-
depsCommand.register(upgradeCmd);
|
|
2766
|
-
}
|
|
2767
|
-
};
|
|
2768
|
-
|
|
2769
|
-
// src/commands/action-plugin/utils.ts
|
|
2770
|
-
import fs10 from "fs";
|
|
2771
|
-
import path8 from "path";
|
|
2772
|
-
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
2425
|
+
import { spawnSync as spawnSync2, execSync } from "child_process";
|
|
2773
2426
|
function parsePluginName(input) {
|
|
2774
2427
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
2775
2428
|
if (!match) {
|
|
@@ -2786,35 +2439,35 @@ function getProjectRoot() {
|
|
|
2786
2439
|
return process.cwd();
|
|
2787
2440
|
}
|
|
2788
2441
|
function getPackageJsonPath() {
|
|
2789
|
-
return
|
|
2442
|
+
return path5.join(getProjectRoot(), "package.json");
|
|
2790
2443
|
}
|
|
2791
2444
|
function getPluginPath(pluginName) {
|
|
2792
|
-
return
|
|
2445
|
+
return path5.join(getProjectRoot(), "node_modules", pluginName);
|
|
2793
2446
|
}
|
|
2794
|
-
function
|
|
2447
|
+
function readPackageJson() {
|
|
2795
2448
|
const pkgPath = getPackageJsonPath();
|
|
2796
|
-
if (!
|
|
2449
|
+
if (!fs7.existsSync(pkgPath)) {
|
|
2797
2450
|
throw new Error("package.json not found in current directory");
|
|
2798
2451
|
}
|
|
2799
2452
|
try {
|
|
2800
|
-
const content =
|
|
2453
|
+
const content = fs7.readFileSync(pkgPath, "utf-8");
|
|
2801
2454
|
return JSON.parse(content);
|
|
2802
2455
|
} catch {
|
|
2803
2456
|
throw new Error("Failed to parse package.json");
|
|
2804
2457
|
}
|
|
2805
2458
|
}
|
|
2806
|
-
function
|
|
2459
|
+
function writePackageJson(pkg2) {
|
|
2807
2460
|
const pkgPath = getPackageJsonPath();
|
|
2808
|
-
|
|
2461
|
+
fs7.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
2809
2462
|
}
|
|
2810
2463
|
function readActionPlugins() {
|
|
2811
|
-
const pkg2 =
|
|
2464
|
+
const pkg2 = readPackageJson();
|
|
2812
2465
|
return pkg2.actionPlugins || {};
|
|
2813
2466
|
}
|
|
2814
2467
|
function writeActionPlugins(plugins) {
|
|
2815
|
-
const pkg2 =
|
|
2468
|
+
const pkg2 = readPackageJson();
|
|
2816
2469
|
pkg2.actionPlugins = plugins;
|
|
2817
|
-
|
|
2470
|
+
writePackageJson(pkg2);
|
|
2818
2471
|
}
|
|
2819
2472
|
function isPluginInstalled(pluginName) {
|
|
2820
2473
|
const plugins = readActionPlugins();
|
|
@@ -2826,7 +2479,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
2826
2479
|
}
|
|
2827
2480
|
function npmInstall(tgzPath) {
|
|
2828
2481
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
2829
|
-
const result =
|
|
2482
|
+
const result = spawnSync2("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
2830
2483
|
cwd: getProjectRoot(),
|
|
2831
2484
|
stdio: "inherit"
|
|
2832
2485
|
});
|
|
@@ -2838,12 +2491,12 @@ function npmInstall(tgzPath) {
|
|
|
2838
2491
|
}
|
|
2839
2492
|
}
|
|
2840
2493
|
function getPackageVersion(pluginName) {
|
|
2841
|
-
const pkgJsonPath =
|
|
2842
|
-
if (!
|
|
2494
|
+
const pkgJsonPath = path5.join(getPluginPath(pluginName), "package.json");
|
|
2495
|
+
if (!fs7.existsSync(pkgJsonPath)) {
|
|
2843
2496
|
return null;
|
|
2844
2497
|
}
|
|
2845
2498
|
try {
|
|
2846
|
-
const content =
|
|
2499
|
+
const content = fs7.readFileSync(pkgJsonPath, "utf-8");
|
|
2847
2500
|
const pkg2 = JSON.parse(content);
|
|
2848
2501
|
return pkg2.version || null;
|
|
2849
2502
|
} catch {
|
|
@@ -2851,49 +2504,49 @@ function getPackageVersion(pluginName) {
|
|
|
2851
2504
|
}
|
|
2852
2505
|
}
|
|
2853
2506
|
function readPluginPackageJson(pluginPath) {
|
|
2854
|
-
const pkgJsonPath =
|
|
2855
|
-
if (!
|
|
2507
|
+
const pkgJsonPath = path5.join(pluginPath, "package.json");
|
|
2508
|
+
if (!fs7.existsSync(pkgJsonPath)) {
|
|
2856
2509
|
return null;
|
|
2857
2510
|
}
|
|
2858
2511
|
try {
|
|
2859
|
-
const content =
|
|
2512
|
+
const content = fs7.readFileSync(pkgJsonPath, "utf-8");
|
|
2860
2513
|
return JSON.parse(content);
|
|
2861
2514
|
} catch {
|
|
2862
2515
|
return null;
|
|
2863
2516
|
}
|
|
2864
2517
|
}
|
|
2865
2518
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
2866
|
-
const nodeModulesPath =
|
|
2867
|
-
const targetDir =
|
|
2868
|
-
const scopeDir =
|
|
2869
|
-
if (!
|
|
2870
|
-
|
|
2519
|
+
const nodeModulesPath = path5.join(getProjectRoot(), "node_modules");
|
|
2520
|
+
const targetDir = path5.join(nodeModulesPath, pluginName);
|
|
2521
|
+
const scopeDir = path5.dirname(targetDir);
|
|
2522
|
+
if (!fs7.existsSync(scopeDir)) {
|
|
2523
|
+
fs7.mkdirSync(scopeDir, { recursive: true });
|
|
2871
2524
|
}
|
|
2872
|
-
if (
|
|
2873
|
-
|
|
2525
|
+
if (fs7.existsSync(targetDir)) {
|
|
2526
|
+
fs7.rmSync(targetDir, { recursive: true });
|
|
2874
2527
|
}
|
|
2875
|
-
const tempDir =
|
|
2876
|
-
if (
|
|
2877
|
-
|
|
2528
|
+
const tempDir = path5.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
2529
|
+
if (fs7.existsSync(tempDir)) {
|
|
2530
|
+
fs7.rmSync(tempDir, { recursive: true });
|
|
2878
2531
|
}
|
|
2879
|
-
|
|
2532
|
+
fs7.mkdirSync(tempDir, { recursive: true });
|
|
2880
2533
|
try {
|
|
2881
|
-
|
|
2882
|
-
const extractedDir =
|
|
2883
|
-
if (
|
|
2884
|
-
|
|
2534
|
+
execSync(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
2535
|
+
const extractedDir = path5.join(tempDir, "package");
|
|
2536
|
+
if (fs7.existsSync(extractedDir)) {
|
|
2537
|
+
fs7.renameSync(extractedDir, targetDir);
|
|
2885
2538
|
} else {
|
|
2886
|
-
const files =
|
|
2539
|
+
const files = fs7.readdirSync(tempDir);
|
|
2887
2540
|
if (files.length === 1) {
|
|
2888
|
-
|
|
2541
|
+
fs7.renameSync(path5.join(tempDir, files[0]), targetDir);
|
|
2889
2542
|
} else {
|
|
2890
2543
|
throw new Error("Unexpected tgz structure");
|
|
2891
2544
|
}
|
|
2892
2545
|
}
|
|
2893
2546
|
return targetDir;
|
|
2894
2547
|
} finally {
|
|
2895
|
-
if (
|
|
2896
|
-
|
|
2548
|
+
if (fs7.existsSync(tempDir)) {
|
|
2549
|
+
fs7.rmSync(tempDir, { recursive: true });
|
|
2897
2550
|
}
|
|
2898
2551
|
}
|
|
2899
2552
|
}
|
|
@@ -2902,10 +2555,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
2902
2555
|
return [];
|
|
2903
2556
|
}
|
|
2904
2557
|
const missing = [];
|
|
2905
|
-
const nodeModulesPath =
|
|
2558
|
+
const nodeModulesPath = path5.join(getProjectRoot(), "node_modules");
|
|
2906
2559
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
2907
|
-
const depPath =
|
|
2908
|
-
if (!
|
|
2560
|
+
const depPath = path5.join(nodeModulesPath, depName);
|
|
2561
|
+
if (!fs7.existsSync(depPath)) {
|
|
2909
2562
|
missing.push(depName);
|
|
2910
2563
|
}
|
|
2911
2564
|
}
|
|
@@ -2916,7 +2569,7 @@ function installMissingDeps(deps) {
|
|
|
2916
2569
|
return;
|
|
2917
2570
|
}
|
|
2918
2571
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
2919
|
-
const result =
|
|
2572
|
+
const result = spawnSync2("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
2920
2573
|
cwd: getProjectRoot(),
|
|
2921
2574
|
stdio: "inherit"
|
|
2922
2575
|
});
|
|
@@ -2929,16 +2582,84 @@ function installMissingDeps(deps) {
|
|
|
2929
2582
|
}
|
|
2930
2583
|
function removePluginDirectory(pluginName) {
|
|
2931
2584
|
const pluginPath = getPluginPath(pluginName);
|
|
2932
|
-
if (
|
|
2933
|
-
|
|
2585
|
+
if (fs7.existsSync(pluginPath)) {
|
|
2586
|
+
fs7.rmSync(pluginPath, { recursive: true });
|
|
2934
2587
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
2935
2588
|
}
|
|
2936
2589
|
}
|
|
2937
2590
|
|
|
2938
2591
|
// src/commands/action-plugin/api-client.ts
|
|
2939
2592
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
2940
|
-
import
|
|
2941
|
-
import
|
|
2593
|
+
import fs8 from "fs";
|
|
2594
|
+
import path6 from "path";
|
|
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
|
|
2942
2663
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
2943
2664
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
2944
2665
|
const client = getHttpClient();
|
|
@@ -3002,19 +2723,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3002
2723
|
return Buffer.from(arrayBuffer);
|
|
3003
2724
|
}
|
|
3004
2725
|
function getPluginCacheDir() {
|
|
3005
|
-
return
|
|
2726
|
+
return path6.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3006
2727
|
}
|
|
3007
2728
|
function ensureCacheDir() {
|
|
3008
2729
|
const cacheDir = getPluginCacheDir();
|
|
3009
|
-
if (!
|
|
3010
|
-
|
|
2730
|
+
if (!fs8.existsSync(cacheDir)) {
|
|
2731
|
+
fs8.mkdirSync(cacheDir, { recursive: true });
|
|
3011
2732
|
}
|
|
3012
2733
|
}
|
|
3013
2734
|
function getTempFilePath(pluginKey, version) {
|
|
3014
2735
|
ensureCacheDir();
|
|
3015
2736
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3016
2737
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3017
|
-
return
|
|
2738
|
+
return path6.join(getPluginCacheDir(), filename);
|
|
3018
2739
|
}
|
|
3019
2740
|
var MAX_RETRIES = 2;
|
|
3020
2741
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3051,7 +2772,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3051
2772
|
);
|
|
3052
2773
|
}
|
|
3053
2774
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3054
|
-
|
|
2775
|
+
fs8.writeFileSync(tgzPath, tgzBuffer);
|
|
3055
2776
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3056
2777
|
return {
|
|
3057
2778
|
tgzPath,
|
|
@@ -3065,18 +2786,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3065
2786
|
ensureCacheDir();
|
|
3066
2787
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3067
2788
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3068
|
-
return
|
|
2789
|
+
return path6.join(getPluginCacheDir(), filename);
|
|
3069
2790
|
}
|
|
3070
2791
|
function hasCachedPlugin(pluginKey, version) {
|
|
3071
2792
|
const cachePath = getCachePath(pluginKey, version);
|
|
3072
|
-
return
|
|
2793
|
+
return fs8.existsSync(cachePath);
|
|
3073
2794
|
}
|
|
3074
2795
|
function listCachedPlugins() {
|
|
3075
2796
|
const cacheDir = getPluginCacheDir();
|
|
3076
|
-
if (!
|
|
2797
|
+
if (!fs8.existsSync(cacheDir)) {
|
|
3077
2798
|
return [];
|
|
3078
2799
|
}
|
|
3079
|
-
const files =
|
|
2800
|
+
const files = fs8.readdirSync(cacheDir);
|
|
3080
2801
|
const result = [];
|
|
3081
2802
|
for (const file of files) {
|
|
3082
2803
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3084,8 +2805,8 @@ function listCachedPlugins() {
|
|
|
3084
2805
|
if (!match) continue;
|
|
3085
2806
|
const [, rawName, version] = match;
|
|
3086
2807
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3087
|
-
const filePath =
|
|
3088
|
-
const stat =
|
|
2808
|
+
const filePath = path6.join(cacheDir, file);
|
|
2809
|
+
const stat = fs8.statSync(filePath);
|
|
3089
2810
|
result.push({
|
|
3090
2811
|
name,
|
|
3091
2812
|
version,
|
|
@@ -3098,14 +2819,14 @@ function listCachedPlugins() {
|
|
|
3098
2819
|
}
|
|
3099
2820
|
function cleanAllCache() {
|
|
3100
2821
|
const cacheDir = getPluginCacheDir();
|
|
3101
|
-
if (!
|
|
2822
|
+
if (!fs8.existsSync(cacheDir)) {
|
|
3102
2823
|
return 0;
|
|
3103
2824
|
}
|
|
3104
|
-
const files =
|
|
2825
|
+
const files = fs8.readdirSync(cacheDir);
|
|
3105
2826
|
let count = 0;
|
|
3106
2827
|
for (const file of files) {
|
|
3107
2828
|
if (file.endsWith(".tgz")) {
|
|
3108
|
-
|
|
2829
|
+
fs8.unlinkSync(path6.join(cacheDir, file));
|
|
3109
2830
|
count++;
|
|
3110
2831
|
}
|
|
3111
2832
|
}
|
|
@@ -3113,21 +2834,21 @@ function cleanAllCache() {
|
|
|
3113
2834
|
}
|
|
3114
2835
|
function cleanPluginCache(pluginKey, version) {
|
|
3115
2836
|
const cacheDir = getPluginCacheDir();
|
|
3116
|
-
if (!
|
|
2837
|
+
if (!fs8.existsSync(cacheDir)) {
|
|
3117
2838
|
return 0;
|
|
3118
2839
|
}
|
|
3119
2840
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3120
|
-
const files =
|
|
2841
|
+
const files = fs8.readdirSync(cacheDir);
|
|
3121
2842
|
let count = 0;
|
|
3122
2843
|
for (const file of files) {
|
|
3123
2844
|
if (version) {
|
|
3124
2845
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3125
|
-
|
|
2846
|
+
fs8.unlinkSync(path6.join(cacheDir, file));
|
|
3126
2847
|
count++;
|
|
3127
2848
|
}
|
|
3128
2849
|
} else {
|
|
3129
2850
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3130
|
-
|
|
2851
|
+
fs8.unlinkSync(path6.join(cacheDir, file));
|
|
3131
2852
|
count++;
|
|
3132
2853
|
}
|
|
3133
2854
|
}
|
|
@@ -3221,6 +2942,8 @@ async function installOne(nameWithVersion) {
|
|
|
3221
2942
|
if (actualVersion === requestedVersion) {
|
|
3222
2943
|
console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
|
|
3223
2944
|
syncActionPluginsRecord(name, actualVersion);
|
|
2945
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
2946
|
+
});
|
|
3224
2947
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
3225
2948
|
}
|
|
3226
2949
|
}
|
|
@@ -3231,6 +2954,8 @@ async function installOne(nameWithVersion) {
|
|
|
3231
2954
|
if (actualVersion === targetVersion) {
|
|
3232
2955
|
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${actualVersion})`);
|
|
3233
2956
|
syncActionPluginsRecord(name, actualVersion);
|
|
2957
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
2958
|
+
});
|
|
3234
2959
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
3235
2960
|
}
|
|
3236
2961
|
console.log(`[action-plugin] Found newer version: ${targetVersion} (installed: ${actualVersion || "none"})`);
|
|
@@ -3261,6 +2986,10 @@ async function installOne(nameWithVersion) {
|
|
|
3261
2986
|
writeActionPlugins(plugins);
|
|
3262
2987
|
const source = fromCache ? "from cache" : "downloaded";
|
|
3263
2988
|
console.log(`[action-plugin] Successfully installed ${name}@${installedVersion} (${source})`);
|
|
2989
|
+
reportInstallEvent(name, installedVersion).catch(() => {
|
|
2990
|
+
});
|
|
2991
|
+
reportCreateInstanceEvent(name, installedVersion).catch(() => {
|
|
2992
|
+
});
|
|
3264
2993
|
return { name, version: installedVersion, success: true };
|
|
3265
2994
|
} catch (error) {
|
|
3266
2995
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -3546,40 +3275,40 @@ var actionPluginCommandGroup = {
|
|
|
3546
3275
|
};
|
|
3547
3276
|
|
|
3548
3277
|
// src/commands/capability/utils.ts
|
|
3549
|
-
import
|
|
3278
|
+
import fs9 from "fs";
|
|
3550
3279
|
import { createRequire as createRequire2 } from "module";
|
|
3551
|
-
import
|
|
3280
|
+
import path7 from "path";
|
|
3552
3281
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
3553
3282
|
function getProjectRoot2() {
|
|
3554
3283
|
return process.cwd();
|
|
3555
3284
|
}
|
|
3556
3285
|
function getCapabilitiesDir() {
|
|
3557
|
-
return
|
|
3286
|
+
return path7.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
3558
3287
|
}
|
|
3559
3288
|
function getCapabilityPath(id) {
|
|
3560
|
-
return
|
|
3289
|
+
return path7.join(getCapabilitiesDir(), `${id}.json`);
|
|
3561
3290
|
}
|
|
3562
3291
|
function getPluginManifestPath(pluginKey) {
|
|
3563
|
-
return
|
|
3292
|
+
return path7.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
3564
3293
|
}
|
|
3565
3294
|
function capabilitiesDirExists() {
|
|
3566
|
-
return
|
|
3295
|
+
return fs9.existsSync(getCapabilitiesDir());
|
|
3567
3296
|
}
|
|
3568
3297
|
function listCapabilityIds() {
|
|
3569
3298
|
const dir = getCapabilitiesDir();
|
|
3570
|
-
if (!
|
|
3299
|
+
if (!fs9.existsSync(dir)) {
|
|
3571
3300
|
return [];
|
|
3572
3301
|
}
|
|
3573
|
-
const files =
|
|
3302
|
+
const files = fs9.readdirSync(dir);
|
|
3574
3303
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
3575
3304
|
}
|
|
3576
3305
|
function readCapability(id) {
|
|
3577
3306
|
const filePath = getCapabilityPath(id);
|
|
3578
|
-
if (!
|
|
3307
|
+
if (!fs9.existsSync(filePath)) {
|
|
3579
3308
|
throw new Error(`Capability not found: ${id}`);
|
|
3580
3309
|
}
|
|
3581
3310
|
try {
|
|
3582
|
-
const content =
|
|
3311
|
+
const content = fs9.readFileSync(filePath, "utf-8");
|
|
3583
3312
|
return JSON.parse(content);
|
|
3584
3313
|
} catch (error) {
|
|
3585
3314
|
if (error instanceof SyntaxError) {
|
|
@@ -3606,11 +3335,11 @@ function readAllCapabilities() {
|
|
|
3606
3335
|
}
|
|
3607
3336
|
function readPluginManifest(pluginKey) {
|
|
3608
3337
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
3609
|
-
if (!
|
|
3338
|
+
if (!fs9.existsSync(manifestPath)) {
|
|
3610
3339
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
3611
3340
|
}
|
|
3612
3341
|
try {
|
|
3613
|
-
const content =
|
|
3342
|
+
const content = fs9.readFileSync(manifestPath, "utf-8");
|
|
3614
3343
|
return JSON.parse(content);
|
|
3615
3344
|
} catch (error) {
|
|
3616
3345
|
if (error instanceof SyntaxError) {
|
|
@@ -3627,7 +3356,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
3627
3356
|
}
|
|
3628
3357
|
async function loadPlugin(pluginKey) {
|
|
3629
3358
|
try {
|
|
3630
|
-
const userRequire = createRequire2(
|
|
3359
|
+
const userRequire = createRequire2(path7.join(getProjectRoot2(), "package.json"));
|
|
3631
3360
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
3632
3361
|
const pluginModule = await import(resolvedPath);
|
|
3633
3362
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -3790,8 +3519,8 @@ var capabilityCommandGroup = {
|
|
|
3790
3519
|
import { execFile } from "child_process";
|
|
3791
3520
|
|
|
3792
3521
|
// src/commands/component/registry-preparer.ts
|
|
3793
|
-
import
|
|
3794
|
-
import
|
|
3522
|
+
import fs10 from "fs";
|
|
3523
|
+
import path8 from "path";
|
|
3795
3524
|
import os from "os";
|
|
3796
3525
|
|
|
3797
3526
|
// src/commands/component/service.ts
|
|
@@ -3847,7 +3576,7 @@ async function sendInstallEvent(key) {
|
|
|
3847
3576
|
}
|
|
3848
3577
|
|
|
3849
3578
|
// src/commands/component/registry-preparer.ts
|
|
3850
|
-
var REGISTRY_TEMP_DIR =
|
|
3579
|
+
var REGISTRY_TEMP_DIR = path8.join(os.tmpdir(), "miaoda-registry");
|
|
3851
3580
|
function parseComponentKey(key) {
|
|
3852
3581
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3853
3582
|
if (!match) {
|
|
@@ -3859,11 +3588,11 @@ function parseComponentKey(key) {
|
|
|
3859
3588
|
}
|
|
3860
3589
|
function getLocalRegistryPath(key) {
|
|
3861
3590
|
const { scope, name } = parseComponentKey(key);
|
|
3862
|
-
return
|
|
3591
|
+
return path8.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3863
3592
|
}
|
|
3864
3593
|
function ensureDir(dirPath) {
|
|
3865
|
-
if (!
|
|
3866
|
-
|
|
3594
|
+
if (!fs10.existsSync(dirPath)) {
|
|
3595
|
+
fs10.mkdirSync(dirPath, { recursive: true });
|
|
3867
3596
|
}
|
|
3868
3597
|
}
|
|
3869
3598
|
async function prepareRecursive(key, visited) {
|
|
@@ -3896,8 +3625,8 @@ async function prepareRecursive(key, visited) {
|
|
|
3896
3625
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3897
3626
|
};
|
|
3898
3627
|
const localPath = getLocalRegistryPath(key);
|
|
3899
|
-
ensureDir(
|
|
3900
|
-
|
|
3628
|
+
ensureDir(path8.dirname(localPath));
|
|
3629
|
+
fs10.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3901
3630
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3902
3631
|
}
|
|
3903
3632
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -3907,18 +3636,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
3907
3636
|
}
|
|
3908
3637
|
function cleanupTempDir() {
|
|
3909
3638
|
try {
|
|
3910
|
-
if (
|
|
3911
|
-
|
|
3639
|
+
if (fs10.existsSync(REGISTRY_TEMP_DIR)) {
|
|
3640
|
+
fs10.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3912
3641
|
}
|
|
3913
3642
|
} catch {
|
|
3914
3643
|
}
|
|
3915
3644
|
}
|
|
3916
3645
|
function getDownloadedRegistryItem(itemId) {
|
|
3917
3646
|
const localPath = getLocalRegistryPath(itemId);
|
|
3918
|
-
if (!
|
|
3647
|
+
if (!fs10.existsSync(localPath)) {
|
|
3919
3648
|
return null;
|
|
3920
3649
|
}
|
|
3921
|
-
const content =
|
|
3650
|
+
const content = fs10.readFileSync(localPath, "utf-8");
|
|
3922
3651
|
return JSON.parse(content);
|
|
3923
3652
|
}
|
|
3924
3653
|
|
|
@@ -4086,58 +3815,58 @@ var componentCommandGroup = {
|
|
|
4086
3815
|
};
|
|
4087
3816
|
|
|
4088
3817
|
// src/commands/migration/version-manager.ts
|
|
4089
|
-
import
|
|
4090
|
-
import
|
|
3818
|
+
import fs11 from "fs";
|
|
3819
|
+
import path9 from "path";
|
|
4091
3820
|
var PACKAGE_JSON = "package.json";
|
|
4092
3821
|
var VERSION_FIELD = "migrationVersion";
|
|
4093
3822
|
function getPackageJsonPath2() {
|
|
4094
|
-
return
|
|
3823
|
+
return path9.join(process.cwd(), PACKAGE_JSON);
|
|
4095
3824
|
}
|
|
4096
3825
|
function getCurrentVersion() {
|
|
4097
3826
|
const pkgPath = getPackageJsonPath2();
|
|
4098
|
-
if (!
|
|
3827
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
4099
3828
|
throw new Error("package.json not found");
|
|
4100
3829
|
}
|
|
4101
|
-
const pkg2 = JSON.parse(
|
|
3830
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
4102
3831
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4103
3832
|
}
|
|
4104
3833
|
function setCurrentVersion(version) {
|
|
4105
3834
|
const pkgPath = getPackageJsonPath2();
|
|
4106
|
-
const pkg2 = JSON.parse(
|
|
3835
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
4107
3836
|
pkg2[VERSION_FIELD] = version;
|
|
4108
|
-
|
|
3837
|
+
fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4109
3838
|
}
|
|
4110
3839
|
|
|
4111
3840
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4112
|
-
import
|
|
4113
|
-
import
|
|
3841
|
+
import fs13 from "fs";
|
|
3842
|
+
import path11 from "path";
|
|
4114
3843
|
|
|
4115
3844
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4116
|
-
import
|
|
4117
|
-
import
|
|
3845
|
+
import fs12 from "fs";
|
|
3846
|
+
import path10 from "path";
|
|
4118
3847
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4119
3848
|
function getProjectRoot3() {
|
|
4120
3849
|
return process.cwd();
|
|
4121
3850
|
}
|
|
4122
3851
|
function getCapabilitiesDir2() {
|
|
4123
|
-
return
|
|
3852
|
+
return path10.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4124
3853
|
}
|
|
4125
3854
|
function getPluginManifestPath2(pluginKey) {
|
|
4126
|
-
return
|
|
3855
|
+
return path10.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4127
3856
|
}
|
|
4128
3857
|
|
|
4129
3858
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4130
3859
|
function detectJsonMigration() {
|
|
4131
3860
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4132
|
-
const oldFilePath =
|
|
4133
|
-
if (!
|
|
3861
|
+
const oldFilePath = path11.join(capabilitiesDir, "capabilities.json");
|
|
3862
|
+
if (!fs13.existsSync(oldFilePath)) {
|
|
4134
3863
|
return {
|
|
4135
3864
|
needsMigration: false,
|
|
4136
3865
|
reason: "capabilities.json not found"
|
|
4137
3866
|
};
|
|
4138
3867
|
}
|
|
4139
3868
|
try {
|
|
4140
|
-
const content =
|
|
3869
|
+
const content = fs13.readFileSync(oldFilePath, "utf-8");
|
|
4141
3870
|
const parsed = JSON.parse(content);
|
|
4142
3871
|
if (!Array.isArray(parsed)) {
|
|
4143
3872
|
return {
|
|
@@ -4188,8 +3917,8 @@ async function check(options) {
|
|
|
4188
3917
|
}
|
|
4189
3918
|
|
|
4190
3919
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4191
|
-
import
|
|
4192
|
-
import
|
|
3920
|
+
import fs14 from "fs";
|
|
3921
|
+
import path12 from "path";
|
|
4193
3922
|
|
|
4194
3923
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
4195
3924
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4419,18 +4148,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4419
4148
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4420
4149
|
function loadExistingCapabilities() {
|
|
4421
4150
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4422
|
-
if (!
|
|
4151
|
+
if (!fs14.existsSync(capabilitiesDir)) {
|
|
4423
4152
|
return [];
|
|
4424
4153
|
}
|
|
4425
|
-
const files =
|
|
4154
|
+
const files = fs14.readdirSync(capabilitiesDir);
|
|
4426
4155
|
const capabilities = [];
|
|
4427
4156
|
for (const file of files) {
|
|
4428
4157
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4429
4158
|
continue;
|
|
4430
4159
|
}
|
|
4431
4160
|
try {
|
|
4432
|
-
const filePath =
|
|
4433
|
-
const content =
|
|
4161
|
+
const filePath = path12.join(capabilitiesDir, file);
|
|
4162
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4434
4163
|
const capability = JSON.parse(content);
|
|
4435
4164
|
if (capability.id && capability.pluginKey) {
|
|
4436
4165
|
capabilities.push(capability);
|
|
@@ -4488,9 +4217,9 @@ async function migrateJsonFiles(options) {
|
|
|
4488
4217
|
}
|
|
4489
4218
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4490
4219
|
for (const cap of newCapabilities) {
|
|
4491
|
-
const filePath =
|
|
4220
|
+
const filePath = path12.join(capabilitiesDir, `${cap.id}.json`);
|
|
4492
4221
|
const content = JSON.stringify(cap, null, 2);
|
|
4493
|
-
|
|
4222
|
+
fs14.writeFileSync(filePath, content, "utf-8");
|
|
4494
4223
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4495
4224
|
}
|
|
4496
4225
|
return {
|
|
@@ -4502,11 +4231,11 @@ async function migrateJsonFiles(options) {
|
|
|
4502
4231
|
}
|
|
4503
4232
|
|
|
4504
4233
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4505
|
-
import
|
|
4234
|
+
import fs15 from "fs";
|
|
4506
4235
|
function isPluginInstalled2(pluginKey) {
|
|
4507
4236
|
const actionPlugins = readActionPlugins();
|
|
4508
4237
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4509
|
-
return
|
|
4238
|
+
return fs15.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4510
4239
|
}
|
|
4511
4240
|
function detectPluginsToInstall(capabilities) {
|
|
4512
4241
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -4582,12 +4311,12 @@ async function installPlugins(capabilities, options) {
|
|
|
4582
4311
|
}
|
|
4583
4312
|
|
|
4584
4313
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
4585
|
-
import
|
|
4314
|
+
import path14 from "path";
|
|
4586
4315
|
import { Project as Project3 } from "ts-morph";
|
|
4587
4316
|
|
|
4588
4317
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
4589
|
-
import
|
|
4590
|
-
import
|
|
4318
|
+
import fs16 from "fs";
|
|
4319
|
+
import path13 from "path";
|
|
4591
4320
|
var EXCLUDED_DIRS = [
|
|
4592
4321
|
"node_modules",
|
|
4593
4322
|
"dist",
|
|
@@ -4602,9 +4331,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
4602
4331
|
/\.d\.ts$/
|
|
4603
4332
|
];
|
|
4604
4333
|
function scanDirectory(dir, files = []) {
|
|
4605
|
-
const entries =
|
|
4334
|
+
const entries = fs16.readdirSync(dir, { withFileTypes: true });
|
|
4606
4335
|
for (const entry of entries) {
|
|
4607
|
-
const fullPath =
|
|
4336
|
+
const fullPath = path13.join(dir, entry.name);
|
|
4608
4337
|
if (entry.isDirectory()) {
|
|
4609
4338
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
4610
4339
|
continue;
|
|
@@ -4620,14 +4349,14 @@ function scanDirectory(dir, files = []) {
|
|
|
4620
4349
|
return files;
|
|
4621
4350
|
}
|
|
4622
4351
|
function scanServerFiles() {
|
|
4623
|
-
const serverDir =
|
|
4624
|
-
if (!
|
|
4352
|
+
const serverDir = path13.join(getProjectRoot3(), "server");
|
|
4353
|
+
if (!fs16.existsSync(serverDir)) {
|
|
4625
4354
|
return [];
|
|
4626
4355
|
}
|
|
4627
4356
|
return scanDirectory(serverDir);
|
|
4628
4357
|
}
|
|
4629
4358
|
function hasCapabilityImport(filePath) {
|
|
4630
|
-
const content =
|
|
4359
|
+
const content = fs16.readFileSync(filePath, "utf-8");
|
|
4631
4360
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
4632
4361
|
}
|
|
4633
4362
|
function scanFilesToMigrate() {
|
|
@@ -5004,7 +4733,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5004
4733
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5005
4734
|
const classInfo = analyzeClass(sourceFile);
|
|
5006
4735
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5007
|
-
const relativePath =
|
|
4736
|
+
const relativePath = path14.relative(getProjectRoot3(), filePath);
|
|
5008
4737
|
return {
|
|
5009
4738
|
filePath: relativePath,
|
|
5010
4739
|
imports,
|
|
@@ -5015,7 +4744,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5015
4744
|
};
|
|
5016
4745
|
}
|
|
5017
4746
|
function migrateFile(project, analysis, dryRun) {
|
|
5018
|
-
const absolutePath =
|
|
4747
|
+
const absolutePath = path14.join(getProjectRoot3(), analysis.filePath);
|
|
5019
4748
|
if (!analysis.canAutoMigrate) {
|
|
5020
4749
|
return {
|
|
5021
4750
|
filePath: analysis.filePath,
|
|
@@ -5118,17 +4847,17 @@ function getSuggestion(analysis) {
|
|
|
5118
4847
|
}
|
|
5119
4848
|
|
|
5120
4849
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5121
|
-
import
|
|
5122
|
-
import
|
|
4850
|
+
import fs17 from "fs";
|
|
4851
|
+
import path15 from "path";
|
|
5123
4852
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5124
4853
|
const deletedFiles = [];
|
|
5125
4854
|
const errors = [];
|
|
5126
4855
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5127
|
-
const oldJsonPath =
|
|
5128
|
-
if (
|
|
4856
|
+
const oldJsonPath = path15.join(capabilitiesDir, "capabilities.json");
|
|
4857
|
+
if (fs17.existsSync(oldJsonPath)) {
|
|
5129
4858
|
try {
|
|
5130
4859
|
if (!dryRun) {
|
|
5131
|
-
|
|
4860
|
+
fs17.unlinkSync(oldJsonPath);
|
|
5132
4861
|
}
|
|
5133
4862
|
deletedFiles.push("capabilities.json");
|
|
5134
4863
|
} catch (error) {
|
|
@@ -5136,11 +4865,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5136
4865
|
}
|
|
5137
4866
|
}
|
|
5138
4867
|
for (const cap of capabilities) {
|
|
5139
|
-
const tsFilePath =
|
|
5140
|
-
if (
|
|
4868
|
+
const tsFilePath = path15.join(capabilitiesDir, `${cap.id}.ts`);
|
|
4869
|
+
if (fs17.existsSync(tsFilePath)) {
|
|
5141
4870
|
try {
|
|
5142
4871
|
if (!dryRun) {
|
|
5143
|
-
|
|
4872
|
+
fs17.unlinkSync(tsFilePath);
|
|
5144
4873
|
}
|
|
5145
4874
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5146
4875
|
} catch (error) {
|
|
@@ -5156,8 +4885,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5156
4885
|
}
|
|
5157
4886
|
|
|
5158
4887
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5159
|
-
import
|
|
5160
|
-
import
|
|
4888
|
+
import fs18 from "fs";
|
|
4889
|
+
import path16 from "path";
|
|
5161
4890
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5162
4891
|
function printSummary(result) {
|
|
5163
4892
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -5320,15 +5049,15 @@ async function generateReport(result) {
|
|
|
5320
5049
|
}
|
|
5321
5050
|
lines.push("");
|
|
5322
5051
|
const logDir = process.env.LOG_DIR || "logs";
|
|
5323
|
-
if (!
|
|
5052
|
+
if (!fs18.existsSync(logDir)) {
|
|
5324
5053
|
return;
|
|
5325
5054
|
}
|
|
5326
|
-
const reportDir =
|
|
5327
|
-
if (!
|
|
5328
|
-
|
|
5055
|
+
const reportDir = path16.join(logDir, "migration");
|
|
5056
|
+
if (!fs18.existsSync(reportDir)) {
|
|
5057
|
+
fs18.mkdirSync(reportDir, { recursive: true });
|
|
5329
5058
|
}
|
|
5330
|
-
const reportPath =
|
|
5331
|
-
|
|
5059
|
+
const reportPath = path16.join(reportDir, REPORT_FILE);
|
|
5060
|
+
fs18.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
5332
5061
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
5333
5062
|
}
|
|
5334
5063
|
|
|
@@ -5505,7 +5234,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
|
|
|
5505
5234
|
}
|
|
5506
5235
|
|
|
5507
5236
|
// src/commands/migration/versions/v001_capability/run.ts
|
|
5508
|
-
async function
|
|
5237
|
+
async function run3(options) {
|
|
5509
5238
|
try {
|
|
5510
5239
|
const migrationOptions = {
|
|
5511
5240
|
dryRun: options.dryRun ?? false
|
|
@@ -5570,7 +5299,7 @@ var v001CapabilityMigration = {
|
|
|
5570
5299
|
name: "capability",
|
|
5571
5300
|
description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
|
|
5572
5301
|
check,
|
|
5573
|
-
run:
|
|
5302
|
+
run: run3
|
|
5574
5303
|
};
|
|
5575
5304
|
|
|
5576
5305
|
// src/commands/migration/versions/index.ts
|
|
@@ -5860,10 +5589,10 @@ var migrationCommand = {
|
|
|
5860
5589
|
};
|
|
5861
5590
|
|
|
5862
5591
|
// src/commands/read-logs/index.ts
|
|
5863
|
-
import
|
|
5592
|
+
import path17 from "path";
|
|
5864
5593
|
|
|
5865
5594
|
// src/commands/read-logs/std-utils.ts
|
|
5866
|
-
import
|
|
5595
|
+
import fs19 from "fs";
|
|
5867
5596
|
function formatStdPrefixTime(localTime) {
|
|
5868
5597
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5869
5598
|
if (!match) return localTime;
|
|
@@ -5893,11 +5622,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5893
5622
|
return `[${time}] ${content}`;
|
|
5894
5623
|
}
|
|
5895
5624
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5896
|
-
const stat =
|
|
5625
|
+
const stat = fs19.statSync(filePath);
|
|
5897
5626
|
if (stat.size === 0) {
|
|
5898
5627
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5899
5628
|
}
|
|
5900
|
-
const fd =
|
|
5629
|
+
const fd = fs19.openSync(filePath, "r");
|
|
5901
5630
|
const chunkSize = 64 * 1024;
|
|
5902
5631
|
let position = stat.size;
|
|
5903
5632
|
let remainder = "";
|
|
@@ -5911,7 +5640,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5911
5640
|
const length = Math.min(chunkSize, position);
|
|
5912
5641
|
position -= length;
|
|
5913
5642
|
const buffer = Buffer.alloc(length);
|
|
5914
|
-
|
|
5643
|
+
fs19.readSync(fd, buffer, 0, length, position);
|
|
5915
5644
|
let chunk = buffer.toString("utf8");
|
|
5916
5645
|
if (remainder) {
|
|
5917
5646
|
chunk += remainder;
|
|
@@ -5953,7 +5682,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5953
5682
|
}
|
|
5954
5683
|
}
|
|
5955
5684
|
} finally {
|
|
5956
|
-
|
|
5685
|
+
fs19.closeSync(fd);
|
|
5957
5686
|
}
|
|
5958
5687
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5959
5688
|
}
|
|
@@ -5974,21 +5703,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5974
5703
|
}
|
|
5975
5704
|
|
|
5976
5705
|
// src/commands/read-logs/tail.ts
|
|
5977
|
-
import
|
|
5706
|
+
import fs20 from "fs";
|
|
5978
5707
|
function fileExists(filePath) {
|
|
5979
5708
|
try {
|
|
5980
|
-
|
|
5709
|
+
fs20.accessSync(filePath, fs20.constants.F_OK | fs20.constants.R_OK);
|
|
5981
5710
|
return true;
|
|
5982
5711
|
} catch {
|
|
5983
5712
|
return false;
|
|
5984
5713
|
}
|
|
5985
5714
|
}
|
|
5986
5715
|
function readFileTailLines(filePath, maxLines) {
|
|
5987
|
-
const stat =
|
|
5716
|
+
const stat = fs20.statSync(filePath);
|
|
5988
5717
|
if (stat.size === 0) {
|
|
5989
5718
|
return [];
|
|
5990
5719
|
}
|
|
5991
|
-
const fd =
|
|
5720
|
+
const fd = fs20.openSync(filePath, "r");
|
|
5992
5721
|
const chunkSize = 64 * 1024;
|
|
5993
5722
|
const chunks = [];
|
|
5994
5723
|
let position = stat.size;
|
|
@@ -5998,13 +5727,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5998
5727
|
const length = Math.min(chunkSize, position);
|
|
5999
5728
|
position -= length;
|
|
6000
5729
|
const buffer = Buffer.alloc(length);
|
|
6001
|
-
|
|
5730
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
6002
5731
|
chunks.unshift(buffer.toString("utf8"));
|
|
6003
5732
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6004
5733
|
collectedLines += chunkLines;
|
|
6005
5734
|
}
|
|
6006
5735
|
} finally {
|
|
6007
|
-
|
|
5736
|
+
fs20.closeSync(fd);
|
|
6008
5737
|
}
|
|
6009
5738
|
const content = chunks.join("");
|
|
6010
5739
|
const allLines = content.split("\n");
|
|
@@ -6020,11 +5749,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6020
5749
|
return allLines.slice(allLines.length - maxLines);
|
|
6021
5750
|
}
|
|
6022
5751
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6023
|
-
const stat =
|
|
5752
|
+
const stat = fs20.statSync(filePath);
|
|
6024
5753
|
if (stat.size === 0) {
|
|
6025
5754
|
return { lines: [], totalLinesCount: 0 };
|
|
6026
5755
|
}
|
|
6027
|
-
const fd =
|
|
5756
|
+
const fd = fs20.openSync(filePath, "r");
|
|
6028
5757
|
const chunkSize = 64 * 1024;
|
|
6029
5758
|
let position = stat.size;
|
|
6030
5759
|
let remainder = "";
|
|
@@ -6036,7 +5765,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6036
5765
|
const length = Math.min(chunkSize, position);
|
|
6037
5766
|
position -= length;
|
|
6038
5767
|
const buffer = Buffer.alloc(length);
|
|
6039
|
-
|
|
5768
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
6040
5769
|
let chunk = buffer.toString("utf8");
|
|
6041
5770
|
if (remainder) {
|
|
6042
5771
|
chunk += remainder;
|
|
@@ -6067,7 +5796,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6067
5796
|
}
|
|
6068
5797
|
}
|
|
6069
5798
|
} finally {
|
|
6070
|
-
|
|
5799
|
+
fs20.closeSync(fd);
|
|
6071
5800
|
}
|
|
6072
5801
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6073
5802
|
}
|
|
@@ -6209,7 +5938,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
6209
5938
|
}
|
|
6210
5939
|
|
|
6211
5940
|
// src/commands/read-logs/json-lines.ts
|
|
6212
|
-
import
|
|
5941
|
+
import fs21 from "fs";
|
|
6213
5942
|
function normalizePid(value) {
|
|
6214
5943
|
if (typeof value === "number") {
|
|
6215
5944
|
return String(value);
|
|
@@ -6260,11 +5989,11 @@ function buildWantedLevelSet(levels) {
|
|
|
6260
5989
|
return set.size > 0 ? set : null;
|
|
6261
5990
|
}
|
|
6262
5991
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
6263
|
-
const stat =
|
|
5992
|
+
const stat = fs21.statSync(filePath);
|
|
6264
5993
|
if (stat.size === 0) {
|
|
6265
5994
|
return { lines: [], totalLinesCount: 0 };
|
|
6266
5995
|
}
|
|
6267
|
-
const fd =
|
|
5996
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6268
5997
|
const chunkSize = 64 * 1024;
|
|
6269
5998
|
let position = stat.size;
|
|
6270
5999
|
let remainder = "";
|
|
@@ -6279,7 +6008,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6279
6008
|
const length = Math.min(chunkSize, position);
|
|
6280
6009
|
position -= length;
|
|
6281
6010
|
const buffer = Buffer.alloc(length);
|
|
6282
|
-
|
|
6011
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6283
6012
|
let chunk = buffer.toString("utf8");
|
|
6284
6013
|
if (remainder) {
|
|
6285
6014
|
chunk += remainder;
|
|
@@ -6341,7 +6070,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6341
6070
|
}
|
|
6342
6071
|
}
|
|
6343
6072
|
} finally {
|
|
6344
|
-
|
|
6073
|
+
fs21.closeSync(fd);
|
|
6345
6074
|
}
|
|
6346
6075
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6347
6076
|
}
|
|
@@ -6384,11 +6113,11 @@ function extractTraceId(obj) {
|
|
|
6384
6113
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6385
6114
|
const wanted = traceId.trim();
|
|
6386
6115
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6387
|
-
const stat =
|
|
6116
|
+
const stat = fs21.statSync(filePath);
|
|
6388
6117
|
if (stat.size === 0) {
|
|
6389
6118
|
return { lines: [], totalLinesCount: 0 };
|
|
6390
6119
|
}
|
|
6391
|
-
const fd =
|
|
6120
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6392
6121
|
const chunkSize = 64 * 1024;
|
|
6393
6122
|
let position = stat.size;
|
|
6394
6123
|
let remainder = "";
|
|
@@ -6401,7 +6130,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6401
6130
|
const length = Math.min(chunkSize, position);
|
|
6402
6131
|
position -= length;
|
|
6403
6132
|
const buffer = Buffer.alloc(length);
|
|
6404
|
-
|
|
6133
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6405
6134
|
let chunk = buffer.toString("utf8");
|
|
6406
6135
|
if (remainder) {
|
|
6407
6136
|
chunk += remainder;
|
|
@@ -6454,7 +6183,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6454
6183
|
}
|
|
6455
6184
|
}
|
|
6456
6185
|
} finally {
|
|
6457
|
-
|
|
6186
|
+
fs21.closeSync(fd);
|
|
6458
6187
|
}
|
|
6459
6188
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6460
6189
|
}
|
|
@@ -6463,11 +6192,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6463
6192
|
if (!wantedLevelSet) {
|
|
6464
6193
|
return { lines: [], totalLinesCount: 0 };
|
|
6465
6194
|
}
|
|
6466
|
-
const stat =
|
|
6195
|
+
const stat = fs21.statSync(filePath);
|
|
6467
6196
|
if (stat.size === 0) {
|
|
6468
6197
|
return { lines: [], totalLinesCount: 0 };
|
|
6469
6198
|
}
|
|
6470
|
-
const fd =
|
|
6199
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6471
6200
|
const chunkSize = 64 * 1024;
|
|
6472
6201
|
let position = stat.size;
|
|
6473
6202
|
let remainder = "";
|
|
@@ -6479,7 +6208,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6479
6208
|
const length = Math.min(chunkSize, position);
|
|
6480
6209
|
position -= length;
|
|
6481
6210
|
const buffer = Buffer.alloc(length);
|
|
6482
|
-
|
|
6211
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6483
6212
|
let chunk = buffer.toString("utf8");
|
|
6484
6213
|
if (remainder) {
|
|
6485
6214
|
chunk += remainder;
|
|
@@ -6526,7 +6255,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6526
6255
|
}
|
|
6527
6256
|
}
|
|
6528
6257
|
} finally {
|
|
6529
|
-
|
|
6258
|
+
fs21.closeSync(fd);
|
|
6530
6259
|
}
|
|
6531
6260
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6532
6261
|
}
|
|
@@ -6760,34 +6489,34 @@ async function readLogsJsonResult(options) {
|
|
|
6760
6489
|
};
|
|
6761
6490
|
}
|
|
6762
6491
|
function resolveLogFilePath(logDir, type) {
|
|
6763
|
-
const base =
|
|
6492
|
+
const base = path17.isAbsolute(logDir) ? logDir : path17.join(process.cwd(), logDir);
|
|
6764
6493
|
if (type === "server") {
|
|
6765
|
-
return
|
|
6494
|
+
return path17.join(base, "server.log");
|
|
6766
6495
|
}
|
|
6767
6496
|
if (type === "trace") {
|
|
6768
|
-
return
|
|
6497
|
+
return path17.join(base, "trace.log");
|
|
6769
6498
|
}
|
|
6770
6499
|
if (type === "server-std") {
|
|
6771
|
-
return
|
|
6500
|
+
return path17.join(base, "server.std.log");
|
|
6772
6501
|
}
|
|
6773
6502
|
if (type === "client-std") {
|
|
6774
|
-
return
|
|
6503
|
+
return path17.join(base, "client.std.log");
|
|
6775
6504
|
}
|
|
6776
6505
|
if (type === "dev") {
|
|
6777
|
-
return
|
|
6506
|
+
return path17.join(base, "dev.log");
|
|
6778
6507
|
}
|
|
6779
6508
|
if (type === "dev-std") {
|
|
6780
|
-
return
|
|
6509
|
+
return path17.join(base, "dev.std.log");
|
|
6781
6510
|
}
|
|
6782
6511
|
if (type === "install-dep-std") {
|
|
6783
|
-
return
|
|
6512
|
+
return path17.join(base, "install-dep.std.log");
|
|
6784
6513
|
}
|
|
6785
6514
|
if (type === "browser") {
|
|
6786
|
-
return
|
|
6515
|
+
return path17.join(base, "browser.log");
|
|
6787
6516
|
}
|
|
6788
6517
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6789
6518
|
}
|
|
6790
|
-
async function
|
|
6519
|
+
async function run4(options) {
|
|
6791
6520
|
const result = await readLogsJsonResult(options);
|
|
6792
6521
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
6793
6522
|
}
|
|
@@ -6829,7 +6558,7 @@ var readLogsCommand = {
|
|
|
6829
6558
|
const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
|
|
6830
6559
|
const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
|
|
6831
6560
|
const levels = parseCommaSeparatedList(rawOptions.level);
|
|
6832
|
-
await
|
|
6561
|
+
await run4({ logDir, type, maxLines, offset, traceId, levels });
|
|
6833
6562
|
} catch (error) {
|
|
6834
6563
|
const message = error instanceof Error ? error.message : String(error);
|
|
6835
6564
|
process.stderr.write(message + "\n");
|
|
@@ -6918,7 +6647,6 @@ var buildCommandGroup = {
|
|
|
6918
6647
|
var commands = [
|
|
6919
6648
|
genDbSchemaCommand,
|
|
6920
6649
|
syncCommand,
|
|
6921
|
-
upgradeCommand,
|
|
6922
6650
|
actionPluginCommandGroup,
|
|
6923
6651
|
capabilityCommandGroup,
|
|
6924
6652
|
componentCommandGroup,
|
|
@@ -6928,12 +6656,12 @@ var commands = [
|
|
|
6928
6656
|
];
|
|
6929
6657
|
|
|
6930
6658
|
// src/index.ts
|
|
6931
|
-
var envPath =
|
|
6932
|
-
if (
|
|
6659
|
+
var envPath = path18.join(process.cwd(), ".env");
|
|
6660
|
+
if (fs22.existsSync(envPath)) {
|
|
6933
6661
|
dotenvConfig({ path: envPath });
|
|
6934
6662
|
}
|
|
6935
|
-
var __dirname =
|
|
6936
|
-
var pkg = JSON.parse(
|
|
6663
|
+
var __dirname = path18.dirname(fileURLToPath4(import.meta.url));
|
|
6664
|
+
var pkg = JSON.parse(fs22.readFileSync(path18.join(__dirname, "../package.json"), "utf-8"));
|
|
6937
6665
|
var cli = new FullstackCLI(pkg.version);
|
|
6938
6666
|
cli.useAll(commands);
|
|
6939
6667
|
cli.run();
|