@lark-apaas/fullstack-cli 1.1.22-alpha.1 → 1.1.22-alpha.10
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 +621 -250
- 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,420 @@ 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 hasStagedChanges(cwd = process.cwd()) {
|
|
2551
|
+
const result = spawnSync2("git", ["diff", "--cached", "--quiet"], {
|
|
2552
|
+
cwd,
|
|
2553
|
+
stdio: "pipe",
|
|
2554
|
+
encoding: "utf-8"
|
|
2555
|
+
});
|
|
2556
|
+
if (result.status === 0) {
|
|
2557
|
+
return false;
|
|
2558
|
+
}
|
|
2559
|
+
if (result.status === 1) {
|
|
2560
|
+
return true;
|
|
2561
|
+
}
|
|
2562
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2563
|
+
throw new Error(`Failed to check staged changes: ${errorMsg}`);
|
|
2564
|
+
}
|
|
2565
|
+
function gitCommit(message, cwd = process.cwd()) {
|
|
2566
|
+
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
2567
|
+
cwd,
|
|
2568
|
+
stdio: "pipe",
|
|
2569
|
+
encoding: "utf-8"
|
|
2570
|
+
});
|
|
2571
|
+
if (result.error || result.status !== 0) {
|
|
2572
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2573
|
+
throw new Error(`git commit failed: ${errorMsg}`);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
|
|
2577
|
+
if (!isGitRepository(cwd)) {
|
|
2578
|
+
console.log("[fullstack-cli] \u26A0 Not a git repository, skipping auto-commit");
|
|
2579
|
+
return false;
|
|
2580
|
+
}
|
|
2581
|
+
const changedFiles = getChangedFiles(cwd);
|
|
2582
|
+
if (changedFiles.length === 0) {
|
|
2583
|
+
console.log("[fullstack-cli] No changes to commit");
|
|
2584
|
+
return false;
|
|
2585
|
+
}
|
|
2586
|
+
try {
|
|
2587
|
+
gitAddUpgradeFiles(cwd, filesToStage);
|
|
2588
|
+
if (!hasStagedChanges(cwd)) {
|
|
2589
|
+
console.log("[fullstack-cli] No upgrade changes to commit");
|
|
2590
|
+
return false;
|
|
2591
|
+
}
|
|
2592
|
+
const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
|
|
2593
|
+
|
|
2594
|
+
- Sync template files
|
|
2595
|
+
- Cleanup package.json config
|
|
2596
|
+
- Upgrade @lark-apaas dependencies (if any)
|
|
2597
|
+
|
|
2598
|
+
Auto-committed by fullstack-cli v${version}`;
|
|
2599
|
+
gitCommit(message, cwd);
|
|
2600
|
+
console.log(`[fullstack-cli] \u2713 Auto-committed ${changedFiles.length} changed file(s)`);
|
|
2601
|
+
return true;
|
|
2602
|
+
} catch (error) {
|
|
2603
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2604
|
+
throw new Error(`Failed to auto-commit changes: ${message}`);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
// src/utils/package-json.ts
|
|
2609
|
+
import fs8 from "fs";
|
|
2610
|
+
import path6 from "path";
|
|
2611
|
+
function readPackageJson(cwd = process.cwd()) {
|
|
2612
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2613
|
+
if (!fs8.existsSync(pkgPath)) {
|
|
2614
|
+
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2615
|
+
}
|
|
2616
|
+
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
2617
|
+
return JSON.parse(content);
|
|
2618
|
+
}
|
|
2619
|
+
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2620
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2621
|
+
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
2622
|
+
fs8.writeFileSync(pkgPath, content, "utf-8");
|
|
2623
|
+
}
|
|
2624
|
+
function removeUpgradeScript(pkg2) {
|
|
2625
|
+
if (!pkg2.scripts?.upgrade) {
|
|
2626
|
+
return false;
|
|
2627
|
+
}
|
|
2628
|
+
delete pkg2.scripts.upgrade;
|
|
2629
|
+
return true;
|
|
2630
|
+
}
|
|
2631
|
+
function cleanDevScript(pkg2) {
|
|
2632
|
+
if (!pkg2.scripts?.dev) {
|
|
2633
|
+
return false;
|
|
2634
|
+
}
|
|
2635
|
+
const originalDev = pkg2.scripts.dev;
|
|
2636
|
+
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
2637
|
+
if (cleanedDev !== originalDev) {
|
|
2638
|
+
pkg2.scripts.dev = cleanedDev;
|
|
2639
|
+
return true;
|
|
2640
|
+
}
|
|
2641
|
+
return false;
|
|
2642
|
+
}
|
|
2643
|
+
function cleanupPackageJson(cwd = process.cwd()) {
|
|
2644
|
+
try {
|
|
2645
|
+
const pkg2 = readPackageJson(cwd);
|
|
2646
|
+
let changed = false;
|
|
2647
|
+
if (removeUpgradeScript(pkg2)) {
|
|
2648
|
+
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
2649
|
+
changed = true;
|
|
2650
|
+
}
|
|
2651
|
+
if (cleanDevScript(pkg2)) {
|
|
2652
|
+
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
2653
|
+
changed = true;
|
|
2654
|
+
}
|
|
2655
|
+
if (changed) {
|
|
2656
|
+
writePackageJson(pkg2, cwd);
|
|
2657
|
+
}
|
|
2658
|
+
return changed;
|
|
2659
|
+
} catch (error) {
|
|
2660
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2661
|
+
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
2662
|
+
return false;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
// src/commands/upgrade/shared/utils.ts
|
|
2667
|
+
import path7 from "path";
|
|
2668
|
+
import fs9 from "fs";
|
|
2669
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2670
|
+
function getCliVersion() {
|
|
2671
|
+
try {
|
|
2672
|
+
const __filename = fileURLToPath4(import.meta.url);
|
|
2673
|
+
const __dirname2 = path7.dirname(__filename);
|
|
2674
|
+
const pkgPath = path7.resolve(__dirname2, "../../../package.json");
|
|
2675
|
+
const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
|
|
2676
|
+
const pkg2 = JSON.parse(pkgContent);
|
|
2677
|
+
return pkg2.version || "unknown";
|
|
2678
|
+
} catch {
|
|
2679
|
+
return "unknown";
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
// src/commands/upgrade/get-upgrade-files.ts
|
|
2684
|
+
function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
2685
|
+
const syncConfig2 = genSyncConfig({ disableGenOpenapi });
|
|
2686
|
+
const filesToStage = /* @__PURE__ */ new Set();
|
|
2687
|
+
syncConfig2.sync.forEach((rule) => {
|
|
2688
|
+
if (rule.type === "file" || rule.type === "directory") {
|
|
2689
|
+
filesToStage.add(rule.to);
|
|
2690
|
+
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
2691
|
+
filesToStage.add(rule.to);
|
|
2692
|
+
} else if (rule.type === "add-script") {
|
|
2693
|
+
filesToStage.add("package.json");
|
|
2694
|
+
} else if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2695
|
+
filesToStage.add(rule.to);
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
filesToStage.add("package.json");
|
|
2699
|
+
filesToStage.add("package-lock.json");
|
|
2700
|
+
return Array.from(filesToStage);
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
// src/commands/upgrade/run.handler.ts
|
|
2704
|
+
async function run3(options = {}) {
|
|
2705
|
+
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2706
|
+
console.log("[fullstack-cli] Starting upgrade...");
|
|
2707
|
+
try {
|
|
2708
|
+
console.log("[fullstack-cli] Step 1/3: Syncing template files...");
|
|
2709
|
+
await run2({ disableGenOpenapi: options.disableGenOpenapi ?? true });
|
|
2710
|
+
console.log("[fullstack-cli] Step 2/3: Cleaning up package.json...");
|
|
2711
|
+
const cleaned = cleanupPackageJson(userProjectRoot);
|
|
2712
|
+
if (!cleaned) {
|
|
2713
|
+
console.log("[fullstack-cli] \u25CB No cleanup needed");
|
|
2714
|
+
}
|
|
2715
|
+
const shouldCommit = options.commit ?? true;
|
|
2716
|
+
if (shouldCommit) {
|
|
2717
|
+
console.log("[fullstack-cli] Step 3/3: Committing changes...");
|
|
2718
|
+
const version = getCliVersion();
|
|
2719
|
+
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
|
|
2720
|
+
autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
|
|
2721
|
+
} else {
|
|
2722
|
+
console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
|
|
2723
|
+
}
|
|
2724
|
+
console.log("[fullstack-cli] Upgrade completed successfully \u2705");
|
|
2725
|
+
} catch (error) {
|
|
2726
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2727
|
+
console.error("[fullstack-cli] Failed to upgrade:", message);
|
|
2728
|
+
process.exit(1);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
// src/commands/upgrade/deps/run.handler.ts
|
|
2733
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
2734
|
+
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
2735
|
+
const pkg2 = readPackageJson(cwd);
|
|
2736
|
+
const allPackages = /* @__PURE__ */ new Set();
|
|
2737
|
+
if (pkg2.dependencies) {
|
|
2738
|
+
Object.keys(pkg2.dependencies).forEach((name) => {
|
|
2739
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2740
|
+
allPackages.add(name);
|
|
2741
|
+
}
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
if (pkg2.devDependencies) {
|
|
2745
|
+
Object.keys(pkg2.devDependencies).forEach((name) => {
|
|
2746
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2747
|
+
allPackages.add(name);
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
const packages = Array.from(allPackages);
|
|
2752
|
+
if (filterPackages) {
|
|
2753
|
+
const filter = new Set(filterPackages.split(",").map((p) => p.trim()));
|
|
2754
|
+
return packages.filter((p) => filter.has(p));
|
|
2755
|
+
}
|
|
2756
|
+
return packages;
|
|
2757
|
+
}
|
|
2758
|
+
function upgradePackages(packages, version, cwd) {
|
|
2759
|
+
if (version) {
|
|
2760
|
+
console.log(`[fullstack-cli] Upgrading to version ${version}...`);
|
|
2761
|
+
packages.forEach((pkg2) => {
|
|
2762
|
+
const target = `${pkg2}@${version}`;
|
|
2763
|
+
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
2764
|
+
const result = spawnSync3("npm", ["install", target], {
|
|
2765
|
+
cwd,
|
|
2766
|
+
stdio: "inherit"
|
|
2767
|
+
});
|
|
2768
|
+
if (result.error || result.status !== 0) {
|
|
2769
|
+
throw new Error(`Failed to install ${target}`);
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
} else {
|
|
2773
|
+
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
2774
|
+
packages.forEach((pkg2) => {
|
|
2775
|
+
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
2776
|
+
const result = spawnSync3("npm", ["update", pkg2], {
|
|
2777
|
+
cwd,
|
|
2778
|
+
stdio: "inherit"
|
|
2779
|
+
});
|
|
2780
|
+
if (result.error || result.status !== 0) {
|
|
2781
|
+
throw new Error(`Failed to update ${pkg2}`);
|
|
2782
|
+
}
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
async function run4(options = {}) {
|
|
2787
|
+
const cwd = process.env.INIT_CWD || process.cwd();
|
|
2788
|
+
console.log("[fullstack-cli] Starting dependencies upgrade...");
|
|
2789
|
+
try {
|
|
2790
|
+
console.log("[fullstack-cli] Step 1/2: Scanning @lark-apaas dependencies...");
|
|
2791
|
+
const packages = findLarkAapaasPackages(cwd, options.packages);
|
|
2792
|
+
if (packages.length === 0) {
|
|
2793
|
+
console.log("[fullstack-cli] No @lark-apaas packages found");
|
|
2794
|
+
return;
|
|
2795
|
+
}
|
|
2796
|
+
console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
|
|
2797
|
+
packages.forEach((p) => console.log(` - ${p}`));
|
|
2798
|
+
console.log("[fullstack-cli] Step 2/2: Upgrading packages...");
|
|
2799
|
+
upgradePackages(packages, options.version, cwd);
|
|
2800
|
+
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
|
|
2801
|
+
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
2802
|
+
} catch (error) {
|
|
2803
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2804
|
+
console.error("[fullstack-cli] Failed to upgrade dependencies:", message);
|
|
2805
|
+
process.exit(1);
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
// src/commands/upgrade/deps/index.ts
|
|
2810
|
+
var depsCommand = {
|
|
2811
|
+
name: "deps",
|
|
2812
|
+
description: "Upgrade @lark-apaas dependencies",
|
|
2813
|
+
register(parentCommand) {
|
|
2814
|
+
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) => {
|
|
2815
|
+
await run4(options);
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
};
|
|
2819
|
+
|
|
2820
|
+
// src/commands/upgrade/index.ts
|
|
2821
|
+
var upgradeCommand = {
|
|
2822
|
+
name: "upgrade",
|
|
2823
|
+
description: "Upgrade template files and auto-commit changes",
|
|
2824
|
+
register(program) {
|
|
2825
|
+
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) => {
|
|
2826
|
+
await run3(options);
|
|
2827
|
+
});
|
|
2828
|
+
depsCommand.register(upgradeCmd);
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
|
|
2832
|
+
// src/commands/action-plugin/utils.ts
|
|
2833
|
+
import fs10 from "fs";
|
|
2834
|
+
import path8 from "path";
|
|
2835
|
+
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
2426
2836
|
function parsePluginName(input) {
|
|
2427
2837
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
2428
2838
|
if (!match) {
|
|
@@ -2439,35 +2849,35 @@ function getProjectRoot() {
|
|
|
2439
2849
|
return process.cwd();
|
|
2440
2850
|
}
|
|
2441
2851
|
function getPackageJsonPath() {
|
|
2442
|
-
return
|
|
2852
|
+
return path8.join(getProjectRoot(), "package.json");
|
|
2443
2853
|
}
|
|
2444
2854
|
function getPluginPath(pluginName) {
|
|
2445
|
-
return
|
|
2855
|
+
return path8.join(getProjectRoot(), "node_modules", pluginName);
|
|
2446
2856
|
}
|
|
2447
|
-
function
|
|
2857
|
+
function readPackageJson2() {
|
|
2448
2858
|
const pkgPath = getPackageJsonPath();
|
|
2449
|
-
if (!
|
|
2859
|
+
if (!fs10.existsSync(pkgPath)) {
|
|
2450
2860
|
throw new Error("package.json not found in current directory");
|
|
2451
2861
|
}
|
|
2452
2862
|
try {
|
|
2453
|
-
const content =
|
|
2863
|
+
const content = fs10.readFileSync(pkgPath, "utf-8");
|
|
2454
2864
|
return JSON.parse(content);
|
|
2455
2865
|
} catch {
|
|
2456
2866
|
throw new Error("Failed to parse package.json");
|
|
2457
2867
|
}
|
|
2458
2868
|
}
|
|
2459
|
-
function
|
|
2869
|
+
function writePackageJson2(pkg2) {
|
|
2460
2870
|
const pkgPath = getPackageJsonPath();
|
|
2461
|
-
|
|
2871
|
+
fs10.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
2462
2872
|
}
|
|
2463
2873
|
function readActionPlugins() {
|
|
2464
|
-
const pkg2 =
|
|
2874
|
+
const pkg2 = readPackageJson2();
|
|
2465
2875
|
return pkg2.actionPlugins || {};
|
|
2466
2876
|
}
|
|
2467
2877
|
function writeActionPlugins(plugins) {
|
|
2468
|
-
const pkg2 =
|
|
2878
|
+
const pkg2 = readPackageJson2();
|
|
2469
2879
|
pkg2.actionPlugins = plugins;
|
|
2470
|
-
|
|
2880
|
+
writePackageJson2(pkg2);
|
|
2471
2881
|
}
|
|
2472
2882
|
function isPluginInstalled(pluginName) {
|
|
2473
2883
|
const plugins = readActionPlugins();
|
|
@@ -2479,7 +2889,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
2479
2889
|
}
|
|
2480
2890
|
function npmInstall(tgzPath) {
|
|
2481
2891
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
2482
|
-
const result =
|
|
2892
|
+
const result = spawnSync4("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
2483
2893
|
cwd: getProjectRoot(),
|
|
2484
2894
|
stdio: "inherit"
|
|
2485
2895
|
});
|
|
@@ -2491,12 +2901,12 @@ function npmInstall(tgzPath) {
|
|
|
2491
2901
|
}
|
|
2492
2902
|
}
|
|
2493
2903
|
function getPackageVersion(pluginName) {
|
|
2494
|
-
const pkgJsonPath =
|
|
2495
|
-
if (!
|
|
2904
|
+
const pkgJsonPath = path8.join(getPluginPath(pluginName), "package.json");
|
|
2905
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2496
2906
|
return null;
|
|
2497
2907
|
}
|
|
2498
2908
|
try {
|
|
2499
|
-
const content =
|
|
2909
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2500
2910
|
const pkg2 = JSON.parse(content);
|
|
2501
2911
|
return pkg2.version || null;
|
|
2502
2912
|
} catch {
|
|
@@ -2504,49 +2914,49 @@ function getPackageVersion(pluginName) {
|
|
|
2504
2914
|
}
|
|
2505
2915
|
}
|
|
2506
2916
|
function readPluginPackageJson(pluginPath) {
|
|
2507
|
-
const pkgJsonPath =
|
|
2508
|
-
if (!
|
|
2917
|
+
const pkgJsonPath = path8.join(pluginPath, "package.json");
|
|
2918
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2509
2919
|
return null;
|
|
2510
2920
|
}
|
|
2511
2921
|
try {
|
|
2512
|
-
const content =
|
|
2922
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2513
2923
|
return JSON.parse(content);
|
|
2514
2924
|
} catch {
|
|
2515
2925
|
return null;
|
|
2516
2926
|
}
|
|
2517
2927
|
}
|
|
2518
2928
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
2519
|
-
const nodeModulesPath =
|
|
2520
|
-
const targetDir =
|
|
2521
|
-
const scopeDir =
|
|
2522
|
-
if (!
|
|
2523
|
-
|
|
2929
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
2930
|
+
const targetDir = path8.join(nodeModulesPath, pluginName);
|
|
2931
|
+
const scopeDir = path8.dirname(targetDir);
|
|
2932
|
+
if (!fs10.existsSync(scopeDir)) {
|
|
2933
|
+
fs10.mkdirSync(scopeDir, { recursive: true });
|
|
2524
2934
|
}
|
|
2525
|
-
if (
|
|
2526
|
-
|
|
2935
|
+
if (fs10.existsSync(targetDir)) {
|
|
2936
|
+
fs10.rmSync(targetDir, { recursive: true });
|
|
2527
2937
|
}
|
|
2528
|
-
const tempDir =
|
|
2529
|
-
if (
|
|
2530
|
-
|
|
2938
|
+
const tempDir = path8.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
2939
|
+
if (fs10.existsSync(tempDir)) {
|
|
2940
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2531
2941
|
}
|
|
2532
|
-
|
|
2942
|
+
fs10.mkdirSync(tempDir, { recursive: true });
|
|
2533
2943
|
try {
|
|
2534
|
-
|
|
2535
|
-
const extractedDir =
|
|
2536
|
-
if (
|
|
2537
|
-
|
|
2944
|
+
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
2945
|
+
const extractedDir = path8.join(tempDir, "package");
|
|
2946
|
+
if (fs10.existsSync(extractedDir)) {
|
|
2947
|
+
fs10.renameSync(extractedDir, targetDir);
|
|
2538
2948
|
} else {
|
|
2539
|
-
const files =
|
|
2949
|
+
const files = fs10.readdirSync(tempDir);
|
|
2540
2950
|
if (files.length === 1) {
|
|
2541
|
-
|
|
2951
|
+
fs10.renameSync(path8.join(tempDir, files[0]), targetDir);
|
|
2542
2952
|
} else {
|
|
2543
2953
|
throw new Error("Unexpected tgz structure");
|
|
2544
2954
|
}
|
|
2545
2955
|
}
|
|
2546
2956
|
return targetDir;
|
|
2547
2957
|
} finally {
|
|
2548
|
-
if (
|
|
2549
|
-
|
|
2958
|
+
if (fs10.existsSync(tempDir)) {
|
|
2959
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2550
2960
|
}
|
|
2551
2961
|
}
|
|
2552
2962
|
}
|
|
@@ -2555,10 +2965,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
2555
2965
|
return [];
|
|
2556
2966
|
}
|
|
2557
2967
|
const missing = [];
|
|
2558
|
-
const nodeModulesPath =
|
|
2968
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
2559
2969
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
2560
|
-
const depPath =
|
|
2561
|
-
if (!
|
|
2970
|
+
const depPath = path8.join(nodeModulesPath, depName);
|
|
2971
|
+
if (!fs10.existsSync(depPath)) {
|
|
2562
2972
|
missing.push(depName);
|
|
2563
2973
|
}
|
|
2564
2974
|
}
|
|
@@ -2569,7 +2979,7 @@ function installMissingDeps(deps) {
|
|
|
2569
2979
|
return;
|
|
2570
2980
|
}
|
|
2571
2981
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
2572
|
-
const result =
|
|
2982
|
+
const result = spawnSync4("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
2573
2983
|
cwd: getProjectRoot(),
|
|
2574
2984
|
stdio: "inherit"
|
|
2575
2985
|
});
|
|
@@ -2582,76 +2992,16 @@ function installMissingDeps(deps) {
|
|
|
2582
2992
|
}
|
|
2583
2993
|
function removePluginDirectory(pluginName) {
|
|
2584
2994
|
const pluginPath = getPluginPath(pluginName);
|
|
2585
|
-
if (
|
|
2586
|
-
|
|
2995
|
+
if (fs10.existsSync(pluginPath)) {
|
|
2996
|
+
fs10.rmSync(pluginPath, { recursive: true });
|
|
2587
2997
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
2588
2998
|
}
|
|
2589
2999
|
}
|
|
2590
3000
|
|
|
2591
3001
|
// src/commands/action-plugin/api-client.ts
|
|
2592
3002
|
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("/resource_events", {
|
|
2626
|
-
body: JSON.stringify({ events })
|
|
2627
|
-
});
|
|
2628
|
-
if (!response.ok) {
|
|
2629
|
-
console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
|
|
2630
|
-
return false;
|
|
2631
|
-
}
|
|
2632
|
-
const result = await response.json();
|
|
2633
|
-
if (result.status_code !== "0") {
|
|
2634
|
-
console.warn(`[telemetry] API error: ${result.message}`);
|
|
2635
|
-
return false;
|
|
2636
|
-
}
|
|
2637
|
-
return true;
|
|
2638
|
-
} catch (error) {
|
|
2639
|
-
console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
|
|
2640
|
-
return false;
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
async function reportInstallEvent(pluginKey, version) {
|
|
2644
|
-
await reportEvents([
|
|
2645
|
-
{
|
|
2646
|
-
resourceType: "plugin",
|
|
2647
|
-
resourceKey: pluginKey,
|
|
2648
|
-
eventType: "install",
|
|
2649
|
-
details: { version }
|
|
2650
|
-
}
|
|
2651
|
-
]);
|
|
2652
|
-
}
|
|
2653
|
-
|
|
2654
|
-
// src/commands/action-plugin/api-client.ts
|
|
3003
|
+
import fs11 from "fs";
|
|
3004
|
+
import path9 from "path";
|
|
2655
3005
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
2656
3006
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
2657
3007
|
const client = getHttpClient();
|
|
@@ -2715,19 +3065,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
2715
3065
|
return Buffer.from(arrayBuffer);
|
|
2716
3066
|
}
|
|
2717
3067
|
function getPluginCacheDir() {
|
|
2718
|
-
return
|
|
3068
|
+
return path9.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
2719
3069
|
}
|
|
2720
3070
|
function ensureCacheDir() {
|
|
2721
3071
|
const cacheDir = getPluginCacheDir();
|
|
2722
|
-
if (!
|
|
2723
|
-
|
|
3072
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
3073
|
+
fs11.mkdirSync(cacheDir, { recursive: true });
|
|
2724
3074
|
}
|
|
2725
3075
|
}
|
|
2726
3076
|
function getTempFilePath(pluginKey, version) {
|
|
2727
3077
|
ensureCacheDir();
|
|
2728
3078
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2729
3079
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2730
|
-
return
|
|
3080
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2731
3081
|
}
|
|
2732
3082
|
var MAX_RETRIES = 2;
|
|
2733
3083
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -2764,7 +3114,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
2764
3114
|
);
|
|
2765
3115
|
}
|
|
2766
3116
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
2767
|
-
|
|
3117
|
+
fs11.writeFileSync(tgzPath, tgzBuffer);
|
|
2768
3118
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
2769
3119
|
return {
|
|
2770
3120
|
tgzPath,
|
|
@@ -2778,18 +3128,18 @@ function getCachePath(pluginKey, version) {
|
|
|
2778
3128
|
ensureCacheDir();
|
|
2779
3129
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2780
3130
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2781
|
-
return
|
|
3131
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2782
3132
|
}
|
|
2783
3133
|
function hasCachedPlugin(pluginKey, version) {
|
|
2784
3134
|
const cachePath = getCachePath(pluginKey, version);
|
|
2785
|
-
return
|
|
3135
|
+
return fs11.existsSync(cachePath);
|
|
2786
3136
|
}
|
|
2787
3137
|
function listCachedPlugins() {
|
|
2788
3138
|
const cacheDir = getPluginCacheDir();
|
|
2789
|
-
if (!
|
|
3139
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2790
3140
|
return [];
|
|
2791
3141
|
}
|
|
2792
|
-
const files =
|
|
3142
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2793
3143
|
const result = [];
|
|
2794
3144
|
for (const file of files) {
|
|
2795
3145
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -2797,8 +3147,8 @@ function listCachedPlugins() {
|
|
|
2797
3147
|
if (!match) continue;
|
|
2798
3148
|
const [, rawName, version] = match;
|
|
2799
3149
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
2800
|
-
const filePath =
|
|
2801
|
-
const stat =
|
|
3150
|
+
const filePath = path9.join(cacheDir, file);
|
|
3151
|
+
const stat = fs11.statSync(filePath);
|
|
2802
3152
|
result.push({
|
|
2803
3153
|
name,
|
|
2804
3154
|
version,
|
|
@@ -2811,14 +3161,14 @@ function listCachedPlugins() {
|
|
|
2811
3161
|
}
|
|
2812
3162
|
function cleanAllCache() {
|
|
2813
3163
|
const cacheDir = getPluginCacheDir();
|
|
2814
|
-
if (!
|
|
3164
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2815
3165
|
return 0;
|
|
2816
3166
|
}
|
|
2817
|
-
const files =
|
|
3167
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2818
3168
|
let count = 0;
|
|
2819
3169
|
for (const file of files) {
|
|
2820
3170
|
if (file.endsWith(".tgz")) {
|
|
2821
|
-
|
|
3171
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2822
3172
|
count++;
|
|
2823
3173
|
}
|
|
2824
3174
|
}
|
|
@@ -2826,21 +3176,21 @@ function cleanAllCache() {
|
|
|
2826
3176
|
}
|
|
2827
3177
|
function cleanPluginCache(pluginKey, version) {
|
|
2828
3178
|
const cacheDir = getPluginCacheDir();
|
|
2829
|
-
if (!
|
|
3179
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2830
3180
|
return 0;
|
|
2831
3181
|
}
|
|
2832
3182
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2833
|
-
const files =
|
|
3183
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2834
3184
|
let count = 0;
|
|
2835
3185
|
for (const file of files) {
|
|
2836
3186
|
if (version) {
|
|
2837
3187
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
2838
|
-
|
|
3188
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2839
3189
|
count++;
|
|
2840
3190
|
}
|
|
2841
3191
|
} else {
|
|
2842
3192
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
2843
|
-
|
|
3193
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2844
3194
|
count++;
|
|
2845
3195
|
}
|
|
2846
3196
|
}
|
|
@@ -2934,6 +3284,8 @@ async function installOne(nameWithVersion) {
|
|
|
2934
3284
|
if (actualVersion === requestedVersion) {
|
|
2935
3285
|
console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
|
|
2936
3286
|
syncActionPluginsRecord(name, actualVersion);
|
|
3287
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
3288
|
+
});
|
|
2937
3289
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
2938
3290
|
}
|
|
2939
3291
|
}
|
|
@@ -2944,6 +3296,8 @@ async function installOne(nameWithVersion) {
|
|
|
2944
3296
|
if (actualVersion === targetVersion) {
|
|
2945
3297
|
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${actualVersion})`);
|
|
2946
3298
|
syncActionPluginsRecord(name, actualVersion);
|
|
3299
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
3300
|
+
});
|
|
2947
3301
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
2948
3302
|
}
|
|
2949
3303
|
console.log(`[action-plugin] Found newer version: ${targetVersion} (installed: ${actualVersion || "none"})`);
|
|
@@ -2976,6 +3330,8 @@ async function installOne(nameWithVersion) {
|
|
|
2976
3330
|
console.log(`[action-plugin] Successfully installed ${name}@${installedVersion} (${source})`);
|
|
2977
3331
|
reportInstallEvent(name, installedVersion).catch(() => {
|
|
2978
3332
|
});
|
|
3333
|
+
reportCreateInstanceEvent(name, installedVersion).catch(() => {
|
|
3334
|
+
});
|
|
2979
3335
|
return { name, version: installedVersion, success: true };
|
|
2980
3336
|
} catch (error) {
|
|
2981
3337
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -3261,40 +3617,40 @@ var actionPluginCommandGroup = {
|
|
|
3261
3617
|
};
|
|
3262
3618
|
|
|
3263
3619
|
// src/commands/capability/utils.ts
|
|
3264
|
-
import
|
|
3620
|
+
import fs12 from "fs";
|
|
3265
3621
|
import { createRequire as createRequire2 } from "module";
|
|
3266
|
-
import
|
|
3622
|
+
import path10 from "path";
|
|
3267
3623
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
3268
3624
|
function getProjectRoot2() {
|
|
3269
3625
|
return process.cwd();
|
|
3270
3626
|
}
|
|
3271
3627
|
function getCapabilitiesDir() {
|
|
3272
|
-
return
|
|
3628
|
+
return path10.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
3273
3629
|
}
|
|
3274
3630
|
function getCapabilityPath(id) {
|
|
3275
|
-
return
|
|
3631
|
+
return path10.join(getCapabilitiesDir(), `${id}.json`);
|
|
3276
3632
|
}
|
|
3277
3633
|
function getPluginManifestPath(pluginKey) {
|
|
3278
|
-
return
|
|
3634
|
+
return path10.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
3279
3635
|
}
|
|
3280
3636
|
function capabilitiesDirExists() {
|
|
3281
|
-
return
|
|
3637
|
+
return fs12.existsSync(getCapabilitiesDir());
|
|
3282
3638
|
}
|
|
3283
3639
|
function listCapabilityIds() {
|
|
3284
3640
|
const dir = getCapabilitiesDir();
|
|
3285
|
-
if (!
|
|
3641
|
+
if (!fs12.existsSync(dir)) {
|
|
3286
3642
|
return [];
|
|
3287
3643
|
}
|
|
3288
|
-
const files =
|
|
3644
|
+
const files = fs12.readdirSync(dir);
|
|
3289
3645
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
3290
3646
|
}
|
|
3291
3647
|
function readCapability(id) {
|
|
3292
3648
|
const filePath = getCapabilityPath(id);
|
|
3293
|
-
if (!
|
|
3649
|
+
if (!fs12.existsSync(filePath)) {
|
|
3294
3650
|
throw new Error(`Capability not found: ${id}`);
|
|
3295
3651
|
}
|
|
3296
3652
|
try {
|
|
3297
|
-
const content =
|
|
3653
|
+
const content = fs12.readFileSync(filePath, "utf-8");
|
|
3298
3654
|
return JSON.parse(content);
|
|
3299
3655
|
} catch (error) {
|
|
3300
3656
|
if (error instanceof SyntaxError) {
|
|
@@ -3321,11 +3677,11 @@ function readAllCapabilities() {
|
|
|
3321
3677
|
}
|
|
3322
3678
|
function readPluginManifest(pluginKey) {
|
|
3323
3679
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
3324
|
-
if (!
|
|
3680
|
+
if (!fs12.existsSync(manifestPath)) {
|
|
3325
3681
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
3326
3682
|
}
|
|
3327
3683
|
try {
|
|
3328
|
-
const content =
|
|
3684
|
+
const content = fs12.readFileSync(manifestPath, "utf-8");
|
|
3329
3685
|
return JSON.parse(content);
|
|
3330
3686
|
} catch (error) {
|
|
3331
3687
|
if (error instanceof SyntaxError) {
|
|
@@ -3342,7 +3698,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
3342
3698
|
}
|
|
3343
3699
|
async function loadPlugin(pluginKey) {
|
|
3344
3700
|
try {
|
|
3345
|
-
const userRequire = createRequire2(
|
|
3701
|
+
const userRequire = createRequire2(path10.join(getProjectRoot2(), "package.json"));
|
|
3346
3702
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
3347
3703
|
const pluginModule = await import(resolvedPath);
|
|
3348
3704
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -3501,9 +3857,12 @@ var capabilityCommandGroup = {
|
|
|
3501
3857
|
commands: [listCommand2]
|
|
3502
3858
|
};
|
|
3503
3859
|
|
|
3860
|
+
// src/commands/component/add.handler.ts
|
|
3861
|
+
import { execFile } from "child_process";
|
|
3862
|
+
|
|
3504
3863
|
// src/commands/component/registry-preparer.ts
|
|
3505
|
-
import
|
|
3506
|
-
import
|
|
3864
|
+
import fs13 from "fs";
|
|
3865
|
+
import path11 from "path";
|
|
3507
3866
|
import os from "os";
|
|
3508
3867
|
|
|
3509
3868
|
// src/commands/component/service.ts
|
|
@@ -3559,7 +3918,7 @@ async function sendInstallEvent(key) {
|
|
|
3559
3918
|
}
|
|
3560
3919
|
|
|
3561
3920
|
// src/commands/component/registry-preparer.ts
|
|
3562
|
-
var REGISTRY_TEMP_DIR =
|
|
3921
|
+
var REGISTRY_TEMP_DIR = path11.join(os.tmpdir(), "miaoda-registry");
|
|
3563
3922
|
function parseComponentKey(key) {
|
|
3564
3923
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3565
3924
|
if (!match) {
|
|
@@ -3571,11 +3930,11 @@ function parseComponentKey(key) {
|
|
|
3571
3930
|
}
|
|
3572
3931
|
function getLocalRegistryPath(key) {
|
|
3573
3932
|
const { scope, name } = parseComponentKey(key);
|
|
3574
|
-
return
|
|
3933
|
+
return path11.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3575
3934
|
}
|
|
3576
3935
|
function ensureDir(dirPath) {
|
|
3577
|
-
if (!
|
|
3578
|
-
|
|
3936
|
+
if (!fs13.existsSync(dirPath)) {
|
|
3937
|
+
fs13.mkdirSync(dirPath, { recursive: true });
|
|
3579
3938
|
}
|
|
3580
3939
|
}
|
|
3581
3940
|
async function prepareRecursive(key, visited) {
|
|
@@ -3608,8 +3967,8 @@ async function prepareRecursive(key, visited) {
|
|
|
3608
3967
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3609
3968
|
};
|
|
3610
3969
|
const localPath = getLocalRegistryPath(key);
|
|
3611
|
-
ensureDir(
|
|
3612
|
-
|
|
3970
|
+
ensureDir(path11.dirname(localPath));
|
|
3971
|
+
fs13.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3613
3972
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3614
3973
|
}
|
|
3615
3974
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -3619,18 +3978,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
3619
3978
|
}
|
|
3620
3979
|
function cleanupTempDir() {
|
|
3621
3980
|
try {
|
|
3622
|
-
if (
|
|
3623
|
-
|
|
3981
|
+
if (fs13.existsSync(REGISTRY_TEMP_DIR)) {
|
|
3982
|
+
fs13.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3624
3983
|
}
|
|
3625
3984
|
} catch {
|
|
3626
3985
|
}
|
|
3627
3986
|
}
|
|
3628
3987
|
function getDownloadedRegistryItem(itemId) {
|
|
3629
3988
|
const localPath = getLocalRegistryPath(itemId);
|
|
3630
|
-
if (!
|
|
3989
|
+
if (!fs13.existsSync(localPath)) {
|
|
3631
3990
|
return null;
|
|
3632
3991
|
}
|
|
3633
|
-
const content =
|
|
3992
|
+
const content = fs13.readFileSync(localPath, "utf-8");
|
|
3634
3993
|
return JSON.parse(content);
|
|
3635
3994
|
}
|
|
3636
3995
|
|
|
@@ -3730,6 +4089,16 @@ async function executeShadcnAdd(registryItemPath) {
|
|
|
3730
4089
|
}
|
|
3731
4090
|
|
|
3732
4091
|
// src/commands/component/add.handler.ts
|
|
4092
|
+
function runActionPluginInit() {
|
|
4093
|
+
return new Promise((resolve) => {
|
|
4094
|
+
execFile("fullstack-cli", ["action-plugin", "init"], { cwd: process.cwd(), stdio: "ignore" }, (error) => {
|
|
4095
|
+
if (error) {
|
|
4096
|
+
debug("action-plugin init \u5931\u8D25: %s", error.message);
|
|
4097
|
+
}
|
|
4098
|
+
resolve();
|
|
4099
|
+
});
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
3733
4102
|
function printResult(result) {
|
|
3734
4103
|
console.log(JSON.stringify(result, null, 2));
|
|
3735
4104
|
}
|
|
@@ -3766,6 +4135,7 @@ async function add(key) {
|
|
|
3766
4135
|
errors: [{ message: errorMessage }]
|
|
3767
4136
|
});
|
|
3768
4137
|
} finally {
|
|
4138
|
+
await runActionPluginInit();
|
|
3769
4139
|
cleanupTempDir();
|
|
3770
4140
|
}
|
|
3771
4141
|
}
|
|
@@ -3787,58 +4157,58 @@ var componentCommandGroup = {
|
|
|
3787
4157
|
};
|
|
3788
4158
|
|
|
3789
4159
|
// src/commands/migration/version-manager.ts
|
|
3790
|
-
import
|
|
3791
|
-
import
|
|
4160
|
+
import fs14 from "fs";
|
|
4161
|
+
import path12 from "path";
|
|
3792
4162
|
var PACKAGE_JSON = "package.json";
|
|
3793
4163
|
var VERSION_FIELD = "migrationVersion";
|
|
3794
4164
|
function getPackageJsonPath2() {
|
|
3795
|
-
return
|
|
4165
|
+
return path12.join(process.cwd(), PACKAGE_JSON);
|
|
3796
4166
|
}
|
|
3797
4167
|
function getCurrentVersion() {
|
|
3798
4168
|
const pkgPath = getPackageJsonPath2();
|
|
3799
|
-
if (!
|
|
4169
|
+
if (!fs14.existsSync(pkgPath)) {
|
|
3800
4170
|
throw new Error("package.json not found");
|
|
3801
4171
|
}
|
|
3802
|
-
const pkg2 = JSON.parse(
|
|
4172
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3803
4173
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
3804
4174
|
}
|
|
3805
4175
|
function setCurrentVersion(version) {
|
|
3806
4176
|
const pkgPath = getPackageJsonPath2();
|
|
3807
|
-
const pkg2 = JSON.parse(
|
|
4177
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3808
4178
|
pkg2[VERSION_FIELD] = version;
|
|
3809
|
-
|
|
4179
|
+
fs14.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3810
4180
|
}
|
|
3811
4181
|
|
|
3812
4182
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3813
|
-
import
|
|
3814
|
-
import
|
|
4183
|
+
import fs16 from "fs";
|
|
4184
|
+
import path14 from "path";
|
|
3815
4185
|
|
|
3816
4186
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
3817
|
-
import
|
|
3818
|
-
import
|
|
4187
|
+
import fs15 from "fs";
|
|
4188
|
+
import path13 from "path";
|
|
3819
4189
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
3820
4190
|
function getProjectRoot3() {
|
|
3821
4191
|
return process.cwd();
|
|
3822
4192
|
}
|
|
3823
4193
|
function getCapabilitiesDir2() {
|
|
3824
|
-
return
|
|
4194
|
+
return path13.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
3825
4195
|
}
|
|
3826
4196
|
function getPluginManifestPath2(pluginKey) {
|
|
3827
|
-
return
|
|
4197
|
+
return path13.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
3828
4198
|
}
|
|
3829
4199
|
|
|
3830
4200
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3831
4201
|
function detectJsonMigration() {
|
|
3832
4202
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3833
|
-
const oldFilePath =
|
|
3834
|
-
if (!
|
|
4203
|
+
const oldFilePath = path14.join(capabilitiesDir, "capabilities.json");
|
|
4204
|
+
if (!fs16.existsSync(oldFilePath)) {
|
|
3835
4205
|
return {
|
|
3836
4206
|
needsMigration: false,
|
|
3837
4207
|
reason: "capabilities.json not found"
|
|
3838
4208
|
};
|
|
3839
4209
|
}
|
|
3840
4210
|
try {
|
|
3841
|
-
const content =
|
|
4211
|
+
const content = fs16.readFileSync(oldFilePath, "utf-8");
|
|
3842
4212
|
const parsed = JSON.parse(content);
|
|
3843
4213
|
if (!Array.isArray(parsed)) {
|
|
3844
4214
|
return {
|
|
@@ -3889,8 +4259,8 @@ async function check(options) {
|
|
|
3889
4259
|
}
|
|
3890
4260
|
|
|
3891
4261
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
3892
|
-
import
|
|
3893
|
-
import
|
|
4262
|
+
import fs17 from "fs";
|
|
4263
|
+
import path15 from "path";
|
|
3894
4264
|
|
|
3895
4265
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
3896
4266
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4120,18 +4490,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4120
4490
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4121
4491
|
function loadExistingCapabilities() {
|
|
4122
4492
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4123
|
-
if (!
|
|
4493
|
+
if (!fs17.existsSync(capabilitiesDir)) {
|
|
4124
4494
|
return [];
|
|
4125
4495
|
}
|
|
4126
|
-
const files =
|
|
4496
|
+
const files = fs17.readdirSync(capabilitiesDir);
|
|
4127
4497
|
const capabilities = [];
|
|
4128
4498
|
for (const file of files) {
|
|
4129
4499
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4130
4500
|
continue;
|
|
4131
4501
|
}
|
|
4132
4502
|
try {
|
|
4133
|
-
const filePath =
|
|
4134
|
-
const content =
|
|
4503
|
+
const filePath = path15.join(capabilitiesDir, file);
|
|
4504
|
+
const content = fs17.readFileSync(filePath, "utf-8");
|
|
4135
4505
|
const capability = JSON.parse(content);
|
|
4136
4506
|
if (capability.id && capability.pluginKey) {
|
|
4137
4507
|
capabilities.push(capability);
|
|
@@ -4189,9 +4559,9 @@ async function migrateJsonFiles(options) {
|
|
|
4189
4559
|
}
|
|
4190
4560
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4191
4561
|
for (const cap of newCapabilities) {
|
|
4192
|
-
const filePath =
|
|
4562
|
+
const filePath = path15.join(capabilitiesDir, `${cap.id}.json`);
|
|
4193
4563
|
const content = JSON.stringify(cap, null, 2);
|
|
4194
|
-
|
|
4564
|
+
fs17.writeFileSync(filePath, content, "utf-8");
|
|
4195
4565
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4196
4566
|
}
|
|
4197
4567
|
return {
|
|
@@ -4203,11 +4573,11 @@ async function migrateJsonFiles(options) {
|
|
|
4203
4573
|
}
|
|
4204
4574
|
|
|
4205
4575
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4206
|
-
import
|
|
4576
|
+
import fs18 from "fs";
|
|
4207
4577
|
function isPluginInstalled2(pluginKey) {
|
|
4208
4578
|
const actionPlugins = readActionPlugins();
|
|
4209
4579
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4210
|
-
return
|
|
4580
|
+
return fs18.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4211
4581
|
}
|
|
4212
4582
|
function detectPluginsToInstall(capabilities) {
|
|
4213
4583
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -4283,12 +4653,12 @@ async function installPlugins(capabilities, options) {
|
|
|
4283
4653
|
}
|
|
4284
4654
|
|
|
4285
4655
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
4286
|
-
import
|
|
4656
|
+
import path17 from "path";
|
|
4287
4657
|
import { Project as Project3 } from "ts-morph";
|
|
4288
4658
|
|
|
4289
4659
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
4290
|
-
import
|
|
4291
|
-
import
|
|
4660
|
+
import fs19 from "fs";
|
|
4661
|
+
import path16 from "path";
|
|
4292
4662
|
var EXCLUDED_DIRS = [
|
|
4293
4663
|
"node_modules",
|
|
4294
4664
|
"dist",
|
|
@@ -4303,9 +4673,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
4303
4673
|
/\.d\.ts$/
|
|
4304
4674
|
];
|
|
4305
4675
|
function scanDirectory(dir, files = []) {
|
|
4306
|
-
const entries =
|
|
4676
|
+
const entries = fs19.readdirSync(dir, { withFileTypes: true });
|
|
4307
4677
|
for (const entry of entries) {
|
|
4308
|
-
const fullPath =
|
|
4678
|
+
const fullPath = path16.join(dir, entry.name);
|
|
4309
4679
|
if (entry.isDirectory()) {
|
|
4310
4680
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
4311
4681
|
continue;
|
|
@@ -4321,14 +4691,14 @@ function scanDirectory(dir, files = []) {
|
|
|
4321
4691
|
return files;
|
|
4322
4692
|
}
|
|
4323
4693
|
function scanServerFiles() {
|
|
4324
|
-
const serverDir =
|
|
4325
|
-
if (!
|
|
4694
|
+
const serverDir = path16.join(getProjectRoot3(), "server");
|
|
4695
|
+
if (!fs19.existsSync(serverDir)) {
|
|
4326
4696
|
return [];
|
|
4327
4697
|
}
|
|
4328
4698
|
return scanDirectory(serverDir);
|
|
4329
4699
|
}
|
|
4330
4700
|
function hasCapabilityImport(filePath) {
|
|
4331
|
-
const content =
|
|
4701
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
4332
4702
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
4333
4703
|
}
|
|
4334
4704
|
function scanFilesToMigrate() {
|
|
@@ -4705,7 +5075,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4705
5075
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
4706
5076
|
const classInfo = analyzeClass(sourceFile);
|
|
4707
5077
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
4708
|
-
const relativePath =
|
|
5078
|
+
const relativePath = path17.relative(getProjectRoot3(), filePath);
|
|
4709
5079
|
return {
|
|
4710
5080
|
filePath: relativePath,
|
|
4711
5081
|
imports,
|
|
@@ -4716,7 +5086,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4716
5086
|
};
|
|
4717
5087
|
}
|
|
4718
5088
|
function migrateFile(project, analysis, dryRun) {
|
|
4719
|
-
const absolutePath =
|
|
5089
|
+
const absolutePath = path17.join(getProjectRoot3(), analysis.filePath);
|
|
4720
5090
|
if (!analysis.canAutoMigrate) {
|
|
4721
5091
|
return {
|
|
4722
5092
|
filePath: analysis.filePath,
|
|
@@ -4819,17 +5189,17 @@ function getSuggestion(analysis) {
|
|
|
4819
5189
|
}
|
|
4820
5190
|
|
|
4821
5191
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
4822
|
-
import
|
|
4823
|
-
import
|
|
5192
|
+
import fs20 from "fs";
|
|
5193
|
+
import path18 from "path";
|
|
4824
5194
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
4825
5195
|
const deletedFiles = [];
|
|
4826
5196
|
const errors = [];
|
|
4827
5197
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4828
|
-
const oldJsonPath =
|
|
4829
|
-
if (
|
|
5198
|
+
const oldJsonPath = path18.join(capabilitiesDir, "capabilities.json");
|
|
5199
|
+
if (fs20.existsSync(oldJsonPath)) {
|
|
4830
5200
|
try {
|
|
4831
5201
|
if (!dryRun) {
|
|
4832
|
-
|
|
5202
|
+
fs20.unlinkSync(oldJsonPath);
|
|
4833
5203
|
}
|
|
4834
5204
|
deletedFiles.push("capabilities.json");
|
|
4835
5205
|
} catch (error) {
|
|
@@ -4837,11 +5207,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4837
5207
|
}
|
|
4838
5208
|
}
|
|
4839
5209
|
for (const cap of capabilities) {
|
|
4840
|
-
const tsFilePath =
|
|
4841
|
-
if (
|
|
5210
|
+
const tsFilePath = path18.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5211
|
+
if (fs20.existsSync(tsFilePath)) {
|
|
4842
5212
|
try {
|
|
4843
5213
|
if (!dryRun) {
|
|
4844
|
-
|
|
5214
|
+
fs20.unlinkSync(tsFilePath);
|
|
4845
5215
|
}
|
|
4846
5216
|
deletedFiles.push(`${cap.id}.ts`);
|
|
4847
5217
|
} catch (error) {
|
|
@@ -4857,8 +5227,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4857
5227
|
}
|
|
4858
5228
|
|
|
4859
5229
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
4860
|
-
import
|
|
4861
|
-
import
|
|
5230
|
+
import fs21 from "fs";
|
|
5231
|
+
import path19 from "path";
|
|
4862
5232
|
var REPORT_FILE = "capability-migration-report.md";
|
|
4863
5233
|
function printSummary(result) {
|
|
4864
5234
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -5021,15 +5391,15 @@ async function generateReport(result) {
|
|
|
5021
5391
|
}
|
|
5022
5392
|
lines.push("");
|
|
5023
5393
|
const logDir = process.env.LOG_DIR || "logs";
|
|
5024
|
-
if (!
|
|
5394
|
+
if (!fs21.existsSync(logDir)) {
|
|
5025
5395
|
return;
|
|
5026
5396
|
}
|
|
5027
|
-
const reportDir =
|
|
5028
|
-
if (!
|
|
5029
|
-
|
|
5397
|
+
const reportDir = path19.join(logDir, "migration");
|
|
5398
|
+
if (!fs21.existsSync(reportDir)) {
|
|
5399
|
+
fs21.mkdirSync(reportDir, { recursive: true });
|
|
5030
5400
|
}
|
|
5031
|
-
const reportPath =
|
|
5032
|
-
|
|
5401
|
+
const reportPath = path19.join(reportDir, REPORT_FILE);
|
|
5402
|
+
fs21.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
5033
5403
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
5034
5404
|
}
|
|
5035
5405
|
|
|
@@ -5206,7 +5576,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
|
|
|
5206
5576
|
}
|
|
5207
5577
|
|
|
5208
5578
|
// src/commands/migration/versions/v001_capability/run.ts
|
|
5209
|
-
async function
|
|
5579
|
+
async function run5(options) {
|
|
5210
5580
|
try {
|
|
5211
5581
|
const migrationOptions = {
|
|
5212
5582
|
dryRun: options.dryRun ?? false
|
|
@@ -5271,7 +5641,7 @@ var v001CapabilityMigration = {
|
|
|
5271
5641
|
name: "capability",
|
|
5272
5642
|
description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
|
|
5273
5643
|
check,
|
|
5274
|
-
run:
|
|
5644
|
+
run: run5
|
|
5275
5645
|
};
|
|
5276
5646
|
|
|
5277
5647
|
// src/commands/migration/versions/index.ts
|
|
@@ -5561,10 +5931,10 @@ var migrationCommand = {
|
|
|
5561
5931
|
};
|
|
5562
5932
|
|
|
5563
5933
|
// src/commands/read-logs/index.ts
|
|
5564
|
-
import
|
|
5934
|
+
import path20 from "path";
|
|
5565
5935
|
|
|
5566
5936
|
// src/commands/read-logs/std-utils.ts
|
|
5567
|
-
import
|
|
5937
|
+
import fs22 from "fs";
|
|
5568
5938
|
function formatStdPrefixTime(localTime) {
|
|
5569
5939
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5570
5940
|
if (!match) return localTime;
|
|
@@ -5594,11 +5964,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5594
5964
|
return `[${time}] ${content}`;
|
|
5595
5965
|
}
|
|
5596
5966
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5597
|
-
const stat =
|
|
5967
|
+
const stat = fs22.statSync(filePath);
|
|
5598
5968
|
if (stat.size === 0) {
|
|
5599
5969
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5600
5970
|
}
|
|
5601
|
-
const fd =
|
|
5971
|
+
const fd = fs22.openSync(filePath, "r");
|
|
5602
5972
|
const chunkSize = 64 * 1024;
|
|
5603
5973
|
let position = stat.size;
|
|
5604
5974
|
let remainder = "";
|
|
@@ -5612,7 +5982,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5612
5982
|
const length = Math.min(chunkSize, position);
|
|
5613
5983
|
position -= length;
|
|
5614
5984
|
const buffer = Buffer.alloc(length);
|
|
5615
|
-
|
|
5985
|
+
fs22.readSync(fd, buffer, 0, length, position);
|
|
5616
5986
|
let chunk = buffer.toString("utf8");
|
|
5617
5987
|
if (remainder) {
|
|
5618
5988
|
chunk += remainder;
|
|
@@ -5654,7 +6024,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5654
6024
|
}
|
|
5655
6025
|
}
|
|
5656
6026
|
} finally {
|
|
5657
|
-
|
|
6027
|
+
fs22.closeSync(fd);
|
|
5658
6028
|
}
|
|
5659
6029
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5660
6030
|
}
|
|
@@ -5675,21 +6045,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5675
6045
|
}
|
|
5676
6046
|
|
|
5677
6047
|
// src/commands/read-logs/tail.ts
|
|
5678
|
-
import
|
|
6048
|
+
import fs23 from "fs";
|
|
5679
6049
|
function fileExists(filePath) {
|
|
5680
6050
|
try {
|
|
5681
|
-
|
|
6051
|
+
fs23.accessSync(filePath, fs23.constants.F_OK | fs23.constants.R_OK);
|
|
5682
6052
|
return true;
|
|
5683
6053
|
} catch {
|
|
5684
6054
|
return false;
|
|
5685
6055
|
}
|
|
5686
6056
|
}
|
|
5687
6057
|
function readFileTailLines(filePath, maxLines) {
|
|
5688
|
-
const stat =
|
|
6058
|
+
const stat = fs23.statSync(filePath);
|
|
5689
6059
|
if (stat.size === 0) {
|
|
5690
6060
|
return [];
|
|
5691
6061
|
}
|
|
5692
|
-
const fd =
|
|
6062
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5693
6063
|
const chunkSize = 64 * 1024;
|
|
5694
6064
|
const chunks = [];
|
|
5695
6065
|
let position = stat.size;
|
|
@@ -5699,13 +6069,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5699
6069
|
const length = Math.min(chunkSize, position);
|
|
5700
6070
|
position -= length;
|
|
5701
6071
|
const buffer = Buffer.alloc(length);
|
|
5702
|
-
|
|
6072
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5703
6073
|
chunks.unshift(buffer.toString("utf8"));
|
|
5704
6074
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
5705
6075
|
collectedLines += chunkLines;
|
|
5706
6076
|
}
|
|
5707
6077
|
} finally {
|
|
5708
|
-
|
|
6078
|
+
fs23.closeSync(fd);
|
|
5709
6079
|
}
|
|
5710
6080
|
const content = chunks.join("");
|
|
5711
6081
|
const allLines = content.split("\n");
|
|
@@ -5721,11 +6091,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5721
6091
|
return allLines.slice(allLines.length - maxLines);
|
|
5722
6092
|
}
|
|
5723
6093
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
5724
|
-
const stat =
|
|
6094
|
+
const stat = fs23.statSync(filePath);
|
|
5725
6095
|
if (stat.size === 0) {
|
|
5726
6096
|
return { lines: [], totalLinesCount: 0 };
|
|
5727
6097
|
}
|
|
5728
|
-
const fd =
|
|
6098
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5729
6099
|
const chunkSize = 64 * 1024;
|
|
5730
6100
|
let position = stat.size;
|
|
5731
6101
|
let remainder = "";
|
|
@@ -5737,7 +6107,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5737
6107
|
const length = Math.min(chunkSize, position);
|
|
5738
6108
|
position -= length;
|
|
5739
6109
|
const buffer = Buffer.alloc(length);
|
|
5740
|
-
|
|
6110
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5741
6111
|
let chunk = buffer.toString("utf8");
|
|
5742
6112
|
if (remainder) {
|
|
5743
6113
|
chunk += remainder;
|
|
@@ -5768,7 +6138,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5768
6138
|
}
|
|
5769
6139
|
}
|
|
5770
6140
|
} finally {
|
|
5771
|
-
|
|
6141
|
+
fs23.closeSync(fd);
|
|
5772
6142
|
}
|
|
5773
6143
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5774
6144
|
}
|
|
@@ -5910,7 +6280,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
5910
6280
|
}
|
|
5911
6281
|
|
|
5912
6282
|
// src/commands/read-logs/json-lines.ts
|
|
5913
|
-
import
|
|
6283
|
+
import fs24 from "fs";
|
|
5914
6284
|
function normalizePid(value) {
|
|
5915
6285
|
if (typeof value === "number") {
|
|
5916
6286
|
return String(value);
|
|
@@ -5961,11 +6331,11 @@ function buildWantedLevelSet(levels) {
|
|
|
5961
6331
|
return set.size > 0 ? set : null;
|
|
5962
6332
|
}
|
|
5963
6333
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
5964
|
-
const stat =
|
|
6334
|
+
const stat = fs24.statSync(filePath);
|
|
5965
6335
|
if (stat.size === 0) {
|
|
5966
6336
|
return { lines: [], totalLinesCount: 0 };
|
|
5967
6337
|
}
|
|
5968
|
-
const fd =
|
|
6338
|
+
const fd = fs24.openSync(filePath, "r");
|
|
5969
6339
|
const chunkSize = 64 * 1024;
|
|
5970
6340
|
let position = stat.size;
|
|
5971
6341
|
let remainder = "";
|
|
@@ -5980,7 +6350,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
5980
6350
|
const length = Math.min(chunkSize, position);
|
|
5981
6351
|
position -= length;
|
|
5982
6352
|
const buffer = Buffer.alloc(length);
|
|
5983
|
-
|
|
6353
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
5984
6354
|
let chunk = buffer.toString("utf8");
|
|
5985
6355
|
if (remainder) {
|
|
5986
6356
|
chunk += remainder;
|
|
@@ -6042,7 +6412,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6042
6412
|
}
|
|
6043
6413
|
}
|
|
6044
6414
|
} finally {
|
|
6045
|
-
|
|
6415
|
+
fs24.closeSync(fd);
|
|
6046
6416
|
}
|
|
6047
6417
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6048
6418
|
}
|
|
@@ -6085,11 +6455,11 @@ function extractTraceId(obj) {
|
|
|
6085
6455
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6086
6456
|
const wanted = traceId.trim();
|
|
6087
6457
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6088
|
-
const stat =
|
|
6458
|
+
const stat = fs24.statSync(filePath);
|
|
6089
6459
|
if (stat.size === 0) {
|
|
6090
6460
|
return { lines: [], totalLinesCount: 0 };
|
|
6091
6461
|
}
|
|
6092
|
-
const fd =
|
|
6462
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6093
6463
|
const chunkSize = 64 * 1024;
|
|
6094
6464
|
let position = stat.size;
|
|
6095
6465
|
let remainder = "";
|
|
@@ -6102,7 +6472,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6102
6472
|
const length = Math.min(chunkSize, position);
|
|
6103
6473
|
position -= length;
|
|
6104
6474
|
const buffer = Buffer.alloc(length);
|
|
6105
|
-
|
|
6475
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6106
6476
|
let chunk = buffer.toString("utf8");
|
|
6107
6477
|
if (remainder) {
|
|
6108
6478
|
chunk += remainder;
|
|
@@ -6155,7 +6525,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6155
6525
|
}
|
|
6156
6526
|
}
|
|
6157
6527
|
} finally {
|
|
6158
|
-
|
|
6528
|
+
fs24.closeSync(fd);
|
|
6159
6529
|
}
|
|
6160
6530
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6161
6531
|
}
|
|
@@ -6164,11 +6534,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6164
6534
|
if (!wantedLevelSet) {
|
|
6165
6535
|
return { lines: [], totalLinesCount: 0 };
|
|
6166
6536
|
}
|
|
6167
|
-
const stat =
|
|
6537
|
+
const stat = fs24.statSync(filePath);
|
|
6168
6538
|
if (stat.size === 0) {
|
|
6169
6539
|
return { lines: [], totalLinesCount: 0 };
|
|
6170
6540
|
}
|
|
6171
|
-
const fd =
|
|
6541
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6172
6542
|
const chunkSize = 64 * 1024;
|
|
6173
6543
|
let position = stat.size;
|
|
6174
6544
|
let remainder = "";
|
|
@@ -6180,7 +6550,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6180
6550
|
const length = Math.min(chunkSize, position);
|
|
6181
6551
|
position -= length;
|
|
6182
6552
|
const buffer = Buffer.alloc(length);
|
|
6183
|
-
|
|
6553
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6184
6554
|
let chunk = buffer.toString("utf8");
|
|
6185
6555
|
if (remainder) {
|
|
6186
6556
|
chunk += remainder;
|
|
@@ -6227,7 +6597,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6227
6597
|
}
|
|
6228
6598
|
}
|
|
6229
6599
|
} finally {
|
|
6230
|
-
|
|
6600
|
+
fs24.closeSync(fd);
|
|
6231
6601
|
}
|
|
6232
6602
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6233
6603
|
}
|
|
@@ -6461,34 +6831,34 @@ async function readLogsJsonResult(options) {
|
|
|
6461
6831
|
};
|
|
6462
6832
|
}
|
|
6463
6833
|
function resolveLogFilePath(logDir, type) {
|
|
6464
|
-
const base =
|
|
6834
|
+
const base = path20.isAbsolute(logDir) ? logDir : path20.join(process.cwd(), logDir);
|
|
6465
6835
|
if (type === "server") {
|
|
6466
|
-
return
|
|
6836
|
+
return path20.join(base, "server.log");
|
|
6467
6837
|
}
|
|
6468
6838
|
if (type === "trace") {
|
|
6469
|
-
return
|
|
6839
|
+
return path20.join(base, "trace.log");
|
|
6470
6840
|
}
|
|
6471
6841
|
if (type === "server-std") {
|
|
6472
|
-
return
|
|
6842
|
+
return path20.join(base, "server.std.log");
|
|
6473
6843
|
}
|
|
6474
6844
|
if (type === "client-std") {
|
|
6475
|
-
return
|
|
6845
|
+
return path20.join(base, "client.std.log");
|
|
6476
6846
|
}
|
|
6477
6847
|
if (type === "dev") {
|
|
6478
|
-
return
|
|
6848
|
+
return path20.join(base, "dev.log");
|
|
6479
6849
|
}
|
|
6480
6850
|
if (type === "dev-std") {
|
|
6481
|
-
return
|
|
6851
|
+
return path20.join(base, "dev.std.log");
|
|
6482
6852
|
}
|
|
6483
6853
|
if (type === "install-dep-std") {
|
|
6484
|
-
return
|
|
6854
|
+
return path20.join(base, "install-dep.std.log");
|
|
6485
6855
|
}
|
|
6486
6856
|
if (type === "browser") {
|
|
6487
|
-
return
|
|
6857
|
+
return path20.join(base, "browser.log");
|
|
6488
6858
|
}
|
|
6489
6859
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6490
6860
|
}
|
|
6491
|
-
async function
|
|
6861
|
+
async function run6(options) {
|
|
6492
6862
|
const result = await readLogsJsonResult(options);
|
|
6493
6863
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
6494
6864
|
}
|
|
@@ -6530,7 +6900,7 @@ var readLogsCommand = {
|
|
|
6530
6900
|
const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
|
|
6531
6901
|
const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
|
|
6532
6902
|
const levels = parseCommaSeparatedList(rawOptions.level);
|
|
6533
|
-
await
|
|
6903
|
+
await run6({ logDir, type, maxLines, offset, traceId, levels });
|
|
6534
6904
|
} catch (error) {
|
|
6535
6905
|
const message = error instanceof Error ? error.message : String(error);
|
|
6536
6906
|
process.stderr.write(message + "\n");
|
|
@@ -6619,6 +6989,7 @@ var buildCommandGroup = {
|
|
|
6619
6989
|
var commands = [
|
|
6620
6990
|
genDbSchemaCommand,
|
|
6621
6991
|
syncCommand,
|
|
6992
|
+
upgradeCommand,
|
|
6622
6993
|
actionPluginCommandGroup,
|
|
6623
6994
|
capabilityCommandGroup,
|
|
6624
6995
|
componentCommandGroup,
|
|
@@ -6628,12 +6999,12 @@ var commands = [
|
|
|
6628
6999
|
];
|
|
6629
7000
|
|
|
6630
7001
|
// src/index.ts
|
|
6631
|
-
var envPath =
|
|
6632
|
-
if (
|
|
7002
|
+
var envPath = path21.join(process.cwd(), ".env");
|
|
7003
|
+
if (fs25.existsSync(envPath)) {
|
|
6633
7004
|
dotenvConfig({ path: envPath });
|
|
6634
7005
|
}
|
|
6635
|
-
var __dirname =
|
|
6636
|
-
var pkg = JSON.parse(
|
|
7006
|
+
var __dirname = path21.dirname(fileURLToPath5(import.meta.url));
|
|
7007
|
+
var pkg = JSON.parse(fs25.readFileSync(path21.join(__dirname, "../package.json"), "utf-8"));
|
|
6637
7008
|
var cli = new FullstackCLI(pkg.version);
|
|
6638
7009
|
cli.useAll(commands);
|
|
6639
7010
|
cli.run();
|