@lark-apaas/fullstack-cli 1.1.22-alpha.6 → 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/README.md +41 -3
- package/dist/index.js +357 -539
- 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;
|
|
@@ -3786,9 +3515,12 @@ var capabilityCommandGroup = {
|
|
|
3786
3515
|
commands: [listCommand2]
|
|
3787
3516
|
};
|
|
3788
3517
|
|
|
3518
|
+
// src/commands/component/add.handler.ts
|
|
3519
|
+
import { execFile } from "child_process";
|
|
3520
|
+
|
|
3789
3521
|
// src/commands/component/registry-preparer.ts
|
|
3790
|
-
import
|
|
3791
|
-
import
|
|
3522
|
+
import fs10 from "fs";
|
|
3523
|
+
import path8 from "path";
|
|
3792
3524
|
import os from "os";
|
|
3793
3525
|
|
|
3794
3526
|
// src/commands/component/service.ts
|
|
@@ -3844,7 +3576,7 @@ async function sendInstallEvent(key) {
|
|
|
3844
3576
|
}
|
|
3845
3577
|
|
|
3846
3578
|
// src/commands/component/registry-preparer.ts
|
|
3847
|
-
var REGISTRY_TEMP_DIR =
|
|
3579
|
+
var REGISTRY_TEMP_DIR = path8.join(os.tmpdir(), "miaoda-registry");
|
|
3848
3580
|
function parseComponentKey(key) {
|
|
3849
3581
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3850
3582
|
if (!match) {
|
|
@@ -3856,11 +3588,11 @@ function parseComponentKey(key) {
|
|
|
3856
3588
|
}
|
|
3857
3589
|
function getLocalRegistryPath(key) {
|
|
3858
3590
|
const { scope, name } = parseComponentKey(key);
|
|
3859
|
-
return
|
|
3591
|
+
return path8.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3860
3592
|
}
|
|
3861
3593
|
function ensureDir(dirPath) {
|
|
3862
|
-
if (!
|
|
3863
|
-
|
|
3594
|
+
if (!fs10.existsSync(dirPath)) {
|
|
3595
|
+
fs10.mkdirSync(dirPath, { recursive: true });
|
|
3864
3596
|
}
|
|
3865
3597
|
}
|
|
3866
3598
|
async function prepareRecursive(key, visited) {
|
|
@@ -3893,8 +3625,8 @@ async function prepareRecursive(key, visited) {
|
|
|
3893
3625
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3894
3626
|
};
|
|
3895
3627
|
const localPath = getLocalRegistryPath(key);
|
|
3896
|
-
ensureDir(
|
|
3897
|
-
|
|
3628
|
+
ensureDir(path8.dirname(localPath));
|
|
3629
|
+
fs10.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3898
3630
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3899
3631
|
}
|
|
3900
3632
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -3904,18 +3636,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
3904
3636
|
}
|
|
3905
3637
|
function cleanupTempDir() {
|
|
3906
3638
|
try {
|
|
3907
|
-
if (
|
|
3908
|
-
|
|
3639
|
+
if (fs10.existsSync(REGISTRY_TEMP_DIR)) {
|
|
3640
|
+
fs10.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3909
3641
|
}
|
|
3910
3642
|
} catch {
|
|
3911
3643
|
}
|
|
3912
3644
|
}
|
|
3913
3645
|
function getDownloadedRegistryItem(itemId) {
|
|
3914
3646
|
const localPath = getLocalRegistryPath(itemId);
|
|
3915
|
-
if (!
|
|
3647
|
+
if (!fs10.existsSync(localPath)) {
|
|
3916
3648
|
return null;
|
|
3917
3649
|
}
|
|
3918
|
-
const content =
|
|
3650
|
+
const content = fs10.readFileSync(localPath, "utf-8");
|
|
3919
3651
|
return JSON.parse(content);
|
|
3920
3652
|
}
|
|
3921
3653
|
|
|
@@ -4015,6 +3747,16 @@ async function executeShadcnAdd(registryItemPath) {
|
|
|
4015
3747
|
}
|
|
4016
3748
|
|
|
4017
3749
|
// src/commands/component/add.handler.ts
|
|
3750
|
+
function runActionPluginInit() {
|
|
3751
|
+
return new Promise((resolve) => {
|
|
3752
|
+
execFile("fullstack-cli", ["action-plugin", "init"], { cwd: process.cwd(), stdio: "ignore" }, (error) => {
|
|
3753
|
+
if (error) {
|
|
3754
|
+
debug("action-plugin init \u5931\u8D25: %s", error.message);
|
|
3755
|
+
}
|
|
3756
|
+
resolve();
|
|
3757
|
+
});
|
|
3758
|
+
});
|
|
3759
|
+
}
|
|
4018
3760
|
function printResult(result) {
|
|
4019
3761
|
console.log(JSON.stringify(result, null, 2));
|
|
4020
3762
|
}
|
|
@@ -4051,6 +3793,7 @@ async function add(key) {
|
|
|
4051
3793
|
errors: [{ message: errorMessage }]
|
|
4052
3794
|
});
|
|
4053
3795
|
} finally {
|
|
3796
|
+
await runActionPluginInit();
|
|
4054
3797
|
cleanupTempDir();
|
|
4055
3798
|
}
|
|
4056
3799
|
}
|
|
@@ -4072,58 +3815,58 @@ var componentCommandGroup = {
|
|
|
4072
3815
|
};
|
|
4073
3816
|
|
|
4074
3817
|
// src/commands/migration/version-manager.ts
|
|
4075
|
-
import
|
|
4076
|
-
import
|
|
3818
|
+
import fs11 from "fs";
|
|
3819
|
+
import path9 from "path";
|
|
4077
3820
|
var PACKAGE_JSON = "package.json";
|
|
4078
3821
|
var VERSION_FIELD = "migrationVersion";
|
|
4079
3822
|
function getPackageJsonPath2() {
|
|
4080
|
-
return
|
|
3823
|
+
return path9.join(process.cwd(), PACKAGE_JSON);
|
|
4081
3824
|
}
|
|
4082
3825
|
function getCurrentVersion() {
|
|
4083
3826
|
const pkgPath = getPackageJsonPath2();
|
|
4084
|
-
if (!
|
|
3827
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
4085
3828
|
throw new Error("package.json not found");
|
|
4086
3829
|
}
|
|
4087
|
-
const pkg2 = JSON.parse(
|
|
3830
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
4088
3831
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4089
3832
|
}
|
|
4090
3833
|
function setCurrentVersion(version) {
|
|
4091
3834
|
const pkgPath = getPackageJsonPath2();
|
|
4092
|
-
const pkg2 = JSON.parse(
|
|
3835
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
4093
3836
|
pkg2[VERSION_FIELD] = version;
|
|
4094
|
-
|
|
3837
|
+
fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4095
3838
|
}
|
|
4096
3839
|
|
|
4097
3840
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4098
|
-
import
|
|
4099
|
-
import
|
|
3841
|
+
import fs13 from "fs";
|
|
3842
|
+
import path11 from "path";
|
|
4100
3843
|
|
|
4101
3844
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4102
|
-
import
|
|
4103
|
-
import
|
|
3845
|
+
import fs12 from "fs";
|
|
3846
|
+
import path10 from "path";
|
|
4104
3847
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4105
3848
|
function getProjectRoot3() {
|
|
4106
3849
|
return process.cwd();
|
|
4107
3850
|
}
|
|
4108
3851
|
function getCapabilitiesDir2() {
|
|
4109
|
-
return
|
|
3852
|
+
return path10.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4110
3853
|
}
|
|
4111
3854
|
function getPluginManifestPath2(pluginKey) {
|
|
4112
|
-
return
|
|
3855
|
+
return path10.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4113
3856
|
}
|
|
4114
3857
|
|
|
4115
3858
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4116
3859
|
function detectJsonMigration() {
|
|
4117
3860
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4118
|
-
const oldFilePath =
|
|
4119
|
-
if (!
|
|
3861
|
+
const oldFilePath = path11.join(capabilitiesDir, "capabilities.json");
|
|
3862
|
+
if (!fs13.existsSync(oldFilePath)) {
|
|
4120
3863
|
return {
|
|
4121
3864
|
needsMigration: false,
|
|
4122
3865
|
reason: "capabilities.json not found"
|
|
4123
3866
|
};
|
|
4124
3867
|
}
|
|
4125
3868
|
try {
|
|
4126
|
-
const content =
|
|
3869
|
+
const content = fs13.readFileSync(oldFilePath, "utf-8");
|
|
4127
3870
|
const parsed = JSON.parse(content);
|
|
4128
3871
|
if (!Array.isArray(parsed)) {
|
|
4129
3872
|
return {
|
|
@@ -4174,8 +3917,8 @@ async function check(options) {
|
|
|
4174
3917
|
}
|
|
4175
3918
|
|
|
4176
3919
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4177
|
-
import
|
|
4178
|
-
import
|
|
3920
|
+
import fs14 from "fs";
|
|
3921
|
+
import path12 from "path";
|
|
4179
3922
|
|
|
4180
3923
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
4181
3924
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4405,18 +4148,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4405
4148
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4406
4149
|
function loadExistingCapabilities() {
|
|
4407
4150
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4408
|
-
if (!
|
|
4151
|
+
if (!fs14.existsSync(capabilitiesDir)) {
|
|
4409
4152
|
return [];
|
|
4410
4153
|
}
|
|
4411
|
-
const files =
|
|
4154
|
+
const files = fs14.readdirSync(capabilitiesDir);
|
|
4412
4155
|
const capabilities = [];
|
|
4413
4156
|
for (const file of files) {
|
|
4414
4157
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4415
4158
|
continue;
|
|
4416
4159
|
}
|
|
4417
4160
|
try {
|
|
4418
|
-
const filePath =
|
|
4419
|
-
const content =
|
|
4161
|
+
const filePath = path12.join(capabilitiesDir, file);
|
|
4162
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4420
4163
|
const capability = JSON.parse(content);
|
|
4421
4164
|
if (capability.id && capability.pluginKey) {
|
|
4422
4165
|
capabilities.push(capability);
|
|
@@ -4474,9 +4217,9 @@ async function migrateJsonFiles(options) {
|
|
|
4474
4217
|
}
|
|
4475
4218
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4476
4219
|
for (const cap of newCapabilities) {
|
|
4477
|
-
const filePath =
|
|
4220
|
+
const filePath = path12.join(capabilitiesDir, `${cap.id}.json`);
|
|
4478
4221
|
const content = JSON.stringify(cap, null, 2);
|
|
4479
|
-
|
|
4222
|
+
fs14.writeFileSync(filePath, content, "utf-8");
|
|
4480
4223
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4481
4224
|
}
|
|
4482
4225
|
return {
|
|
@@ -4488,11 +4231,11 @@ async function migrateJsonFiles(options) {
|
|
|
4488
4231
|
}
|
|
4489
4232
|
|
|
4490
4233
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4491
|
-
import
|
|
4234
|
+
import fs15 from "fs";
|
|
4492
4235
|
function isPluginInstalled2(pluginKey) {
|
|
4493
4236
|
const actionPlugins = readActionPlugins();
|
|
4494
4237
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4495
|
-
return
|
|
4238
|
+
return fs15.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4496
4239
|
}
|
|
4497
4240
|
function detectPluginsToInstall(capabilities) {
|
|
4498
4241
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -4568,12 +4311,12 @@ async function installPlugins(capabilities, options) {
|
|
|
4568
4311
|
}
|
|
4569
4312
|
|
|
4570
4313
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
4571
|
-
import
|
|
4314
|
+
import path14 from "path";
|
|
4572
4315
|
import { Project as Project3 } from "ts-morph";
|
|
4573
4316
|
|
|
4574
4317
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
4575
|
-
import
|
|
4576
|
-
import
|
|
4318
|
+
import fs16 from "fs";
|
|
4319
|
+
import path13 from "path";
|
|
4577
4320
|
var EXCLUDED_DIRS = [
|
|
4578
4321
|
"node_modules",
|
|
4579
4322
|
"dist",
|
|
@@ -4588,9 +4331,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
4588
4331
|
/\.d\.ts$/
|
|
4589
4332
|
];
|
|
4590
4333
|
function scanDirectory(dir, files = []) {
|
|
4591
|
-
const entries =
|
|
4334
|
+
const entries = fs16.readdirSync(dir, { withFileTypes: true });
|
|
4592
4335
|
for (const entry of entries) {
|
|
4593
|
-
const fullPath =
|
|
4336
|
+
const fullPath = path13.join(dir, entry.name);
|
|
4594
4337
|
if (entry.isDirectory()) {
|
|
4595
4338
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
4596
4339
|
continue;
|
|
@@ -4606,14 +4349,14 @@ function scanDirectory(dir, files = []) {
|
|
|
4606
4349
|
return files;
|
|
4607
4350
|
}
|
|
4608
4351
|
function scanServerFiles() {
|
|
4609
|
-
const serverDir =
|
|
4610
|
-
if (!
|
|
4352
|
+
const serverDir = path13.join(getProjectRoot3(), "server");
|
|
4353
|
+
if (!fs16.existsSync(serverDir)) {
|
|
4611
4354
|
return [];
|
|
4612
4355
|
}
|
|
4613
4356
|
return scanDirectory(serverDir);
|
|
4614
4357
|
}
|
|
4615
4358
|
function hasCapabilityImport(filePath) {
|
|
4616
|
-
const content =
|
|
4359
|
+
const content = fs16.readFileSync(filePath, "utf-8");
|
|
4617
4360
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
4618
4361
|
}
|
|
4619
4362
|
function scanFilesToMigrate() {
|
|
@@ -4990,7 +4733,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4990
4733
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
4991
4734
|
const classInfo = analyzeClass(sourceFile);
|
|
4992
4735
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
4993
|
-
const relativePath =
|
|
4736
|
+
const relativePath = path14.relative(getProjectRoot3(), filePath);
|
|
4994
4737
|
return {
|
|
4995
4738
|
filePath: relativePath,
|
|
4996
4739
|
imports,
|
|
@@ -5001,7 +4744,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5001
4744
|
};
|
|
5002
4745
|
}
|
|
5003
4746
|
function migrateFile(project, analysis, dryRun) {
|
|
5004
|
-
const absolutePath =
|
|
4747
|
+
const absolutePath = path14.join(getProjectRoot3(), analysis.filePath);
|
|
5005
4748
|
if (!analysis.canAutoMigrate) {
|
|
5006
4749
|
return {
|
|
5007
4750
|
filePath: analysis.filePath,
|
|
@@ -5104,17 +4847,17 @@ function getSuggestion(analysis) {
|
|
|
5104
4847
|
}
|
|
5105
4848
|
|
|
5106
4849
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5107
|
-
import
|
|
5108
|
-
import
|
|
4850
|
+
import fs17 from "fs";
|
|
4851
|
+
import path15 from "path";
|
|
5109
4852
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5110
4853
|
const deletedFiles = [];
|
|
5111
4854
|
const errors = [];
|
|
5112
4855
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5113
|
-
const oldJsonPath =
|
|
5114
|
-
if (
|
|
4856
|
+
const oldJsonPath = path15.join(capabilitiesDir, "capabilities.json");
|
|
4857
|
+
if (fs17.existsSync(oldJsonPath)) {
|
|
5115
4858
|
try {
|
|
5116
4859
|
if (!dryRun) {
|
|
5117
|
-
|
|
4860
|
+
fs17.unlinkSync(oldJsonPath);
|
|
5118
4861
|
}
|
|
5119
4862
|
deletedFiles.push("capabilities.json");
|
|
5120
4863
|
} catch (error) {
|
|
@@ -5122,11 +4865,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5122
4865
|
}
|
|
5123
4866
|
}
|
|
5124
4867
|
for (const cap of capabilities) {
|
|
5125
|
-
const tsFilePath =
|
|
5126
|
-
if (
|
|
4868
|
+
const tsFilePath = path15.join(capabilitiesDir, `${cap.id}.ts`);
|
|
4869
|
+
if (fs17.existsSync(tsFilePath)) {
|
|
5127
4870
|
try {
|
|
5128
4871
|
if (!dryRun) {
|
|
5129
|
-
|
|
4872
|
+
fs17.unlinkSync(tsFilePath);
|
|
5130
4873
|
}
|
|
5131
4874
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5132
4875
|
} catch (error) {
|
|
@@ -5142,8 +4885,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5142
4885
|
}
|
|
5143
4886
|
|
|
5144
4887
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5145
|
-
import
|
|
5146
|
-
import
|
|
4888
|
+
import fs18 from "fs";
|
|
4889
|
+
import path16 from "path";
|
|
5147
4890
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5148
4891
|
function printSummary(result) {
|
|
5149
4892
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -5306,15 +5049,15 @@ async function generateReport(result) {
|
|
|
5306
5049
|
}
|
|
5307
5050
|
lines.push("");
|
|
5308
5051
|
const logDir = process.env.LOG_DIR || "logs";
|
|
5309
|
-
if (!
|
|
5052
|
+
if (!fs18.existsSync(logDir)) {
|
|
5310
5053
|
return;
|
|
5311
5054
|
}
|
|
5312
|
-
const reportDir =
|
|
5313
|
-
if (!
|
|
5314
|
-
|
|
5055
|
+
const reportDir = path16.join(logDir, "migration");
|
|
5056
|
+
if (!fs18.existsSync(reportDir)) {
|
|
5057
|
+
fs18.mkdirSync(reportDir, { recursive: true });
|
|
5315
5058
|
}
|
|
5316
|
-
const reportPath =
|
|
5317
|
-
|
|
5059
|
+
const reportPath = path16.join(reportDir, REPORT_FILE);
|
|
5060
|
+
fs18.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
5318
5061
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
5319
5062
|
}
|
|
5320
5063
|
|
|
@@ -5491,7 +5234,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
|
|
|
5491
5234
|
}
|
|
5492
5235
|
|
|
5493
5236
|
// src/commands/migration/versions/v001_capability/run.ts
|
|
5494
|
-
async function
|
|
5237
|
+
async function run3(options) {
|
|
5495
5238
|
try {
|
|
5496
5239
|
const migrationOptions = {
|
|
5497
5240
|
dryRun: options.dryRun ?? false
|
|
@@ -5556,7 +5299,7 @@ var v001CapabilityMigration = {
|
|
|
5556
5299
|
name: "capability",
|
|
5557
5300
|
description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
|
|
5558
5301
|
check,
|
|
5559
|
-
run:
|
|
5302
|
+
run: run3
|
|
5560
5303
|
};
|
|
5561
5304
|
|
|
5562
5305
|
// src/commands/migration/versions/index.ts
|
|
@@ -5846,10 +5589,10 @@ var migrationCommand = {
|
|
|
5846
5589
|
};
|
|
5847
5590
|
|
|
5848
5591
|
// src/commands/read-logs/index.ts
|
|
5849
|
-
import
|
|
5592
|
+
import path17 from "path";
|
|
5850
5593
|
|
|
5851
5594
|
// src/commands/read-logs/std-utils.ts
|
|
5852
|
-
import
|
|
5595
|
+
import fs19 from "fs";
|
|
5853
5596
|
function formatStdPrefixTime(localTime) {
|
|
5854
5597
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5855
5598
|
if (!match) return localTime;
|
|
@@ -5879,11 +5622,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5879
5622
|
return `[${time}] ${content}`;
|
|
5880
5623
|
}
|
|
5881
5624
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5882
|
-
const stat =
|
|
5625
|
+
const stat = fs19.statSync(filePath);
|
|
5883
5626
|
if (stat.size === 0) {
|
|
5884
5627
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5885
5628
|
}
|
|
5886
|
-
const fd =
|
|
5629
|
+
const fd = fs19.openSync(filePath, "r");
|
|
5887
5630
|
const chunkSize = 64 * 1024;
|
|
5888
5631
|
let position = stat.size;
|
|
5889
5632
|
let remainder = "";
|
|
@@ -5897,7 +5640,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5897
5640
|
const length = Math.min(chunkSize, position);
|
|
5898
5641
|
position -= length;
|
|
5899
5642
|
const buffer = Buffer.alloc(length);
|
|
5900
|
-
|
|
5643
|
+
fs19.readSync(fd, buffer, 0, length, position);
|
|
5901
5644
|
let chunk = buffer.toString("utf8");
|
|
5902
5645
|
if (remainder) {
|
|
5903
5646
|
chunk += remainder;
|
|
@@ -5939,7 +5682,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5939
5682
|
}
|
|
5940
5683
|
}
|
|
5941
5684
|
} finally {
|
|
5942
|
-
|
|
5685
|
+
fs19.closeSync(fd);
|
|
5943
5686
|
}
|
|
5944
5687
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5945
5688
|
}
|
|
@@ -5960,21 +5703,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5960
5703
|
}
|
|
5961
5704
|
|
|
5962
5705
|
// src/commands/read-logs/tail.ts
|
|
5963
|
-
import
|
|
5706
|
+
import fs20 from "fs";
|
|
5964
5707
|
function fileExists(filePath) {
|
|
5965
5708
|
try {
|
|
5966
|
-
|
|
5709
|
+
fs20.accessSync(filePath, fs20.constants.F_OK | fs20.constants.R_OK);
|
|
5967
5710
|
return true;
|
|
5968
5711
|
} catch {
|
|
5969
5712
|
return false;
|
|
5970
5713
|
}
|
|
5971
5714
|
}
|
|
5972
5715
|
function readFileTailLines(filePath, maxLines) {
|
|
5973
|
-
const stat =
|
|
5716
|
+
const stat = fs20.statSync(filePath);
|
|
5974
5717
|
if (stat.size === 0) {
|
|
5975
5718
|
return [];
|
|
5976
5719
|
}
|
|
5977
|
-
const fd =
|
|
5720
|
+
const fd = fs20.openSync(filePath, "r");
|
|
5978
5721
|
const chunkSize = 64 * 1024;
|
|
5979
5722
|
const chunks = [];
|
|
5980
5723
|
let position = stat.size;
|
|
@@ -5984,13 +5727,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5984
5727
|
const length = Math.min(chunkSize, position);
|
|
5985
5728
|
position -= length;
|
|
5986
5729
|
const buffer = Buffer.alloc(length);
|
|
5987
|
-
|
|
5730
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
5988
5731
|
chunks.unshift(buffer.toString("utf8"));
|
|
5989
5732
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
5990
5733
|
collectedLines += chunkLines;
|
|
5991
5734
|
}
|
|
5992
5735
|
} finally {
|
|
5993
|
-
|
|
5736
|
+
fs20.closeSync(fd);
|
|
5994
5737
|
}
|
|
5995
5738
|
const content = chunks.join("");
|
|
5996
5739
|
const allLines = content.split("\n");
|
|
@@ -6006,11 +5749,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6006
5749
|
return allLines.slice(allLines.length - maxLines);
|
|
6007
5750
|
}
|
|
6008
5751
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6009
|
-
const stat =
|
|
5752
|
+
const stat = fs20.statSync(filePath);
|
|
6010
5753
|
if (stat.size === 0) {
|
|
6011
5754
|
return { lines: [], totalLinesCount: 0 };
|
|
6012
5755
|
}
|
|
6013
|
-
const fd =
|
|
5756
|
+
const fd = fs20.openSync(filePath, "r");
|
|
6014
5757
|
const chunkSize = 64 * 1024;
|
|
6015
5758
|
let position = stat.size;
|
|
6016
5759
|
let remainder = "";
|
|
@@ -6022,7 +5765,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6022
5765
|
const length = Math.min(chunkSize, position);
|
|
6023
5766
|
position -= length;
|
|
6024
5767
|
const buffer = Buffer.alloc(length);
|
|
6025
|
-
|
|
5768
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
6026
5769
|
let chunk = buffer.toString("utf8");
|
|
6027
5770
|
if (remainder) {
|
|
6028
5771
|
chunk += remainder;
|
|
@@ -6053,7 +5796,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6053
5796
|
}
|
|
6054
5797
|
}
|
|
6055
5798
|
} finally {
|
|
6056
|
-
|
|
5799
|
+
fs20.closeSync(fd);
|
|
6057
5800
|
}
|
|
6058
5801
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6059
5802
|
}
|
|
@@ -6195,7 +5938,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
6195
5938
|
}
|
|
6196
5939
|
|
|
6197
5940
|
// src/commands/read-logs/json-lines.ts
|
|
6198
|
-
import
|
|
5941
|
+
import fs21 from "fs";
|
|
6199
5942
|
function normalizePid(value) {
|
|
6200
5943
|
if (typeof value === "number") {
|
|
6201
5944
|
return String(value);
|
|
@@ -6246,11 +5989,11 @@ function buildWantedLevelSet(levels) {
|
|
|
6246
5989
|
return set.size > 0 ? set : null;
|
|
6247
5990
|
}
|
|
6248
5991
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
6249
|
-
const stat =
|
|
5992
|
+
const stat = fs21.statSync(filePath);
|
|
6250
5993
|
if (stat.size === 0) {
|
|
6251
5994
|
return { lines: [], totalLinesCount: 0 };
|
|
6252
5995
|
}
|
|
6253
|
-
const fd =
|
|
5996
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6254
5997
|
const chunkSize = 64 * 1024;
|
|
6255
5998
|
let position = stat.size;
|
|
6256
5999
|
let remainder = "";
|
|
@@ -6265,7 +6008,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6265
6008
|
const length = Math.min(chunkSize, position);
|
|
6266
6009
|
position -= length;
|
|
6267
6010
|
const buffer = Buffer.alloc(length);
|
|
6268
|
-
|
|
6011
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6269
6012
|
let chunk = buffer.toString("utf8");
|
|
6270
6013
|
if (remainder) {
|
|
6271
6014
|
chunk += remainder;
|
|
@@ -6327,7 +6070,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6327
6070
|
}
|
|
6328
6071
|
}
|
|
6329
6072
|
} finally {
|
|
6330
|
-
|
|
6073
|
+
fs21.closeSync(fd);
|
|
6331
6074
|
}
|
|
6332
6075
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6333
6076
|
}
|
|
@@ -6370,11 +6113,11 @@ function extractTraceId(obj) {
|
|
|
6370
6113
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6371
6114
|
const wanted = traceId.trim();
|
|
6372
6115
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6373
|
-
const stat =
|
|
6116
|
+
const stat = fs21.statSync(filePath);
|
|
6374
6117
|
if (stat.size === 0) {
|
|
6375
6118
|
return { lines: [], totalLinesCount: 0 };
|
|
6376
6119
|
}
|
|
6377
|
-
const fd =
|
|
6120
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6378
6121
|
const chunkSize = 64 * 1024;
|
|
6379
6122
|
let position = stat.size;
|
|
6380
6123
|
let remainder = "";
|
|
@@ -6387,7 +6130,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6387
6130
|
const length = Math.min(chunkSize, position);
|
|
6388
6131
|
position -= length;
|
|
6389
6132
|
const buffer = Buffer.alloc(length);
|
|
6390
|
-
|
|
6133
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6391
6134
|
let chunk = buffer.toString("utf8");
|
|
6392
6135
|
if (remainder) {
|
|
6393
6136
|
chunk += remainder;
|
|
@@ -6440,7 +6183,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6440
6183
|
}
|
|
6441
6184
|
}
|
|
6442
6185
|
} finally {
|
|
6443
|
-
|
|
6186
|
+
fs21.closeSync(fd);
|
|
6444
6187
|
}
|
|
6445
6188
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6446
6189
|
}
|
|
@@ -6449,11 +6192,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6449
6192
|
if (!wantedLevelSet) {
|
|
6450
6193
|
return { lines: [], totalLinesCount: 0 };
|
|
6451
6194
|
}
|
|
6452
|
-
const stat =
|
|
6195
|
+
const stat = fs21.statSync(filePath);
|
|
6453
6196
|
if (stat.size === 0) {
|
|
6454
6197
|
return { lines: [], totalLinesCount: 0 };
|
|
6455
6198
|
}
|
|
6456
|
-
const fd =
|
|
6199
|
+
const fd = fs21.openSync(filePath, "r");
|
|
6457
6200
|
const chunkSize = 64 * 1024;
|
|
6458
6201
|
let position = stat.size;
|
|
6459
6202
|
let remainder = "";
|
|
@@ -6465,7 +6208,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6465
6208
|
const length = Math.min(chunkSize, position);
|
|
6466
6209
|
position -= length;
|
|
6467
6210
|
const buffer = Buffer.alloc(length);
|
|
6468
|
-
|
|
6211
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
6469
6212
|
let chunk = buffer.toString("utf8");
|
|
6470
6213
|
if (remainder) {
|
|
6471
6214
|
chunk += remainder;
|
|
@@ -6512,7 +6255,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6512
6255
|
}
|
|
6513
6256
|
}
|
|
6514
6257
|
} finally {
|
|
6515
|
-
|
|
6258
|
+
fs21.closeSync(fd);
|
|
6516
6259
|
}
|
|
6517
6260
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6518
6261
|
}
|
|
@@ -6746,34 +6489,34 @@ async function readLogsJsonResult(options) {
|
|
|
6746
6489
|
};
|
|
6747
6490
|
}
|
|
6748
6491
|
function resolveLogFilePath(logDir, type) {
|
|
6749
|
-
const base =
|
|
6492
|
+
const base = path17.isAbsolute(logDir) ? logDir : path17.join(process.cwd(), logDir);
|
|
6750
6493
|
if (type === "server") {
|
|
6751
|
-
return
|
|
6494
|
+
return path17.join(base, "server.log");
|
|
6752
6495
|
}
|
|
6753
6496
|
if (type === "trace") {
|
|
6754
|
-
return
|
|
6497
|
+
return path17.join(base, "trace.log");
|
|
6755
6498
|
}
|
|
6756
6499
|
if (type === "server-std") {
|
|
6757
|
-
return
|
|
6500
|
+
return path17.join(base, "server.std.log");
|
|
6758
6501
|
}
|
|
6759
6502
|
if (type === "client-std") {
|
|
6760
|
-
return
|
|
6503
|
+
return path17.join(base, "client.std.log");
|
|
6761
6504
|
}
|
|
6762
6505
|
if (type === "dev") {
|
|
6763
|
-
return
|
|
6506
|
+
return path17.join(base, "dev.log");
|
|
6764
6507
|
}
|
|
6765
6508
|
if (type === "dev-std") {
|
|
6766
|
-
return
|
|
6509
|
+
return path17.join(base, "dev.std.log");
|
|
6767
6510
|
}
|
|
6768
6511
|
if (type === "install-dep-std") {
|
|
6769
|
-
return
|
|
6512
|
+
return path17.join(base, "install-dep.std.log");
|
|
6770
6513
|
}
|
|
6771
6514
|
if (type === "browser") {
|
|
6772
|
-
return
|
|
6515
|
+
return path17.join(base, "browser.log");
|
|
6773
6516
|
}
|
|
6774
6517
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6775
6518
|
}
|
|
6776
|
-
async function
|
|
6519
|
+
async function run4(options) {
|
|
6777
6520
|
const result = await readLogsJsonResult(options);
|
|
6778
6521
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
6779
6522
|
}
|
|
@@ -6815,7 +6558,7 @@ var readLogsCommand = {
|
|
|
6815
6558
|
const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
|
|
6816
6559
|
const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
|
|
6817
6560
|
const levels = parseCommaSeparatedList(rawOptions.level);
|
|
6818
|
-
await
|
|
6561
|
+
await run4({ logDir, type, maxLines, offset, traceId, levels });
|
|
6819
6562
|
} catch (error) {
|
|
6820
6563
|
const message = error instanceof Error ? error.message : String(error);
|
|
6821
6564
|
process.stderr.write(message + "\n");
|
|
@@ -6825,25 +6568,100 @@ var readLogsCommand = {
|
|
|
6825
6568
|
}
|
|
6826
6569
|
};
|
|
6827
6570
|
|
|
6571
|
+
// src/commands/build/types.ts
|
|
6572
|
+
var SCENE_CONFIGS = {
|
|
6573
|
+
pipeline: {
|
|
6574
|
+
name: "pipeline",
|
|
6575
|
+
requiredOptions: ["commitId"],
|
|
6576
|
+
buildRequestBody: (opts) => ({ commitID: opts.commitId })
|
|
6577
|
+
},
|
|
6578
|
+
static: {
|
|
6579
|
+
name: "static",
|
|
6580
|
+
requiredOptions: [],
|
|
6581
|
+
buildRequestBody: () => ({ commitID: "" })
|
|
6582
|
+
}
|
|
6583
|
+
};
|
|
6584
|
+
|
|
6585
|
+
// src/commands/build/api-client.ts
|
|
6586
|
+
async function genArtifactUploadCredential(appId, body) {
|
|
6587
|
+
const client = getHttpClient();
|
|
6588
|
+
const url = `/v1/app/${appId}/pipeline/gen_artifact_upload_credential`;
|
|
6589
|
+
const response = await client.post(url, body);
|
|
6590
|
+
if (!response.ok || response.status !== 200) {
|
|
6591
|
+
throw new Error(
|
|
6592
|
+
`API request failed: ${response.status} ${response.statusText}`
|
|
6593
|
+
);
|
|
6594
|
+
}
|
|
6595
|
+
return response.json();
|
|
6596
|
+
}
|
|
6597
|
+
|
|
6598
|
+
// src/commands/build/get-token.handler.ts
|
|
6599
|
+
async function getToken(options) {
|
|
6600
|
+
try {
|
|
6601
|
+
const sceneConfig = SCENE_CONFIGS[options.scene];
|
|
6602
|
+
if (!sceneConfig) {
|
|
6603
|
+
const available = Object.keys(SCENE_CONFIGS).join(", ");
|
|
6604
|
+
console.error(
|
|
6605
|
+
`[build] Error: invalid scene "${options.scene}". Available scenes: ${available}`
|
|
6606
|
+
);
|
|
6607
|
+
process.exit(1);
|
|
6608
|
+
}
|
|
6609
|
+
for (const key of sceneConfig.requiredOptions) {
|
|
6610
|
+
if (!options[key]) {
|
|
6611
|
+
console.error(
|
|
6612
|
+
`[build] Error: --${camelToKebab(key)} is required for scene "${options.scene}"`
|
|
6613
|
+
);
|
|
6614
|
+
process.exit(1);
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6617
|
+
const body = sceneConfig.buildRequestBody(options);
|
|
6618
|
+
const response = await genArtifactUploadCredential(options.appId, body);
|
|
6619
|
+
console.log(JSON.stringify(response));
|
|
6620
|
+
} catch (error) {
|
|
6621
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6622
|
+
console.error(`[build] Error: ${message}`);
|
|
6623
|
+
process.exit(1);
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6626
|
+
function camelToKebab(str) {
|
|
6627
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
6628
|
+
}
|
|
6629
|
+
|
|
6630
|
+
// src/commands/build/index.ts
|
|
6631
|
+
var getTokenCommand = {
|
|
6632
|
+
name: "get-token",
|
|
6633
|
+
description: "Get artifact upload credential (STI token)",
|
|
6634
|
+
register(program) {
|
|
6635
|
+
program.command(this.name).description(this.description).requiredOption("--app-id <id>", "Application ID").requiredOption("--scene <scene>", "Build scene (pipeline, static)").option("--commit-id <id>", "Git commit ID (required for pipeline scene)").action(async (options) => {
|
|
6636
|
+
await getToken(options);
|
|
6637
|
+
});
|
|
6638
|
+
}
|
|
6639
|
+
};
|
|
6640
|
+
var buildCommandGroup = {
|
|
6641
|
+
name: "build",
|
|
6642
|
+
description: "Build related commands",
|
|
6643
|
+
commands: [getTokenCommand]
|
|
6644
|
+
};
|
|
6645
|
+
|
|
6828
6646
|
// src/commands/index.ts
|
|
6829
6647
|
var commands = [
|
|
6830
6648
|
genDbSchemaCommand,
|
|
6831
6649
|
syncCommand,
|
|
6832
|
-
upgradeCommand,
|
|
6833
6650
|
actionPluginCommandGroup,
|
|
6834
6651
|
capabilityCommandGroup,
|
|
6835
6652
|
componentCommandGroup,
|
|
6836
6653
|
migrationCommand,
|
|
6837
|
-
readLogsCommand
|
|
6654
|
+
readLogsCommand,
|
|
6655
|
+
buildCommandGroup
|
|
6838
6656
|
];
|
|
6839
6657
|
|
|
6840
6658
|
// src/index.ts
|
|
6841
|
-
var envPath =
|
|
6842
|
-
if (
|
|
6659
|
+
var envPath = path18.join(process.cwd(), ".env");
|
|
6660
|
+
if (fs22.existsSync(envPath)) {
|
|
6843
6661
|
dotenvConfig({ path: envPath });
|
|
6844
6662
|
}
|
|
6845
|
-
var __dirname =
|
|
6846
|
-
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"));
|
|
6847
6665
|
var cli = new FullstackCLI(pkg.version);
|
|
6848
6666
|
cli.useAll(commands);
|
|
6849
6667
|
cli.run();
|