@lark-apaas/fullstack-cli 1.1.20 → 1.1.22-alpha.0
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 +430 -106
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs22 from "fs";
|
|
3
|
+
import path18 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -481,6 +481,7 @@ var replaceUnknownTransform = {
|
|
|
481
481
|
transform(ctx) {
|
|
482
482
|
const { sourceFile, stats } = ctx;
|
|
483
483
|
const fullText = sourceFile.getFullText();
|
|
484
|
+
const replacements = [];
|
|
484
485
|
sourceFile.forEachDescendant((node) => {
|
|
485
486
|
if (!Node5.isCallExpression(node)) {
|
|
486
487
|
return;
|
|
@@ -511,13 +512,23 @@ var replaceUnknownTransform = {
|
|
|
511
512
|
break;
|
|
512
513
|
}
|
|
513
514
|
}
|
|
515
|
+
replacements.push({
|
|
516
|
+
expression,
|
|
517
|
+
factoryName,
|
|
518
|
+
foundKnownType,
|
|
519
|
+
isArrayType,
|
|
520
|
+
node
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
for (const { expression, factoryName, foundKnownType, isArrayType, node } of replacements) {
|
|
514
524
|
expression.replaceWithText(factoryName);
|
|
515
525
|
if (isArrayType && foundKnownType) {
|
|
516
526
|
const parent = node.getParent();
|
|
517
527
|
if (Node5.isPropertyAccessExpression(parent) && parent.getName() === "array") {
|
|
518
528
|
const grandParent = parent.getParent();
|
|
519
529
|
if (Node5.isCallExpression(grandParent)) {
|
|
520
|
-
|
|
530
|
+
const nodeText = node.getText();
|
|
531
|
+
grandParent.replaceWithText(nodeText);
|
|
521
532
|
}
|
|
522
533
|
}
|
|
523
534
|
}
|
|
@@ -526,7 +537,7 @@ var replaceUnknownTransform = {
|
|
|
526
537
|
} else {
|
|
527
538
|
stats.fallbackToText++;
|
|
528
539
|
}
|
|
529
|
-
}
|
|
540
|
+
}
|
|
530
541
|
const todoCommentRegex = /\/\/ TODO: failed to parse database type '[^']+'\s*\n/g;
|
|
531
542
|
const currentText = sourceFile.getFullText();
|
|
532
543
|
const cleanedText = currentText.replace(todoCommentRegex, "");
|
|
@@ -3452,59 +3463,344 @@ var capabilityCommandGroup = {
|
|
|
3452
3463
|
commands: [listCommand2]
|
|
3453
3464
|
};
|
|
3454
3465
|
|
|
3455
|
-
// src/commands/
|
|
3466
|
+
// src/commands/component/registry-preparer.ts
|
|
3456
3467
|
import fs10 from "fs";
|
|
3457
3468
|
import path8 from "path";
|
|
3469
|
+
import os from "os";
|
|
3470
|
+
|
|
3471
|
+
// src/commands/component/service.ts
|
|
3472
|
+
import { mapValues } from "es-toolkit";
|
|
3473
|
+
|
|
3474
|
+
// src/commands/component/utils.ts
|
|
3475
|
+
import createDebug from "debug";
|
|
3476
|
+
var debug = createDebug("component");
|
|
3477
|
+
|
|
3478
|
+
// src/commands/component/service.ts
|
|
3479
|
+
async function getComponents(keys) {
|
|
3480
|
+
const client = getHttpClient();
|
|
3481
|
+
debug("\u8C03\u7528 /components/batch_get %o", keys);
|
|
3482
|
+
const response = await client.post(
|
|
3483
|
+
`/api/v1/studio/innerapi/components/batch_get?keys=${keys.join(",")}`
|
|
3484
|
+
);
|
|
3485
|
+
if (response.status !== 200) {
|
|
3486
|
+
throw new Error(
|
|
3487
|
+
`\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25\uFF1A${response.status} ${response.statusText}`
|
|
3488
|
+
);
|
|
3489
|
+
}
|
|
3490
|
+
const result = await response.json();
|
|
3491
|
+
if (result.status_code !== "0") {
|
|
3492
|
+
debug("\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\uFF1A%o", result);
|
|
3493
|
+
throw new Error(`\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25\uFF1A${result.error_msg}`);
|
|
3494
|
+
}
|
|
3495
|
+
return mapValues(result.data.components, ([component]) => component);
|
|
3496
|
+
}
|
|
3497
|
+
async function getRegistryItem(url) {
|
|
3498
|
+
const client = getHttpClient();
|
|
3499
|
+
debug("\u4E0B\u8F7D registry-item.json\uFF1A%s", url);
|
|
3500
|
+
const response = await client.get(url);
|
|
3501
|
+
if (!response.ok) {
|
|
3502
|
+
throw new Error(
|
|
3503
|
+
`\u4E0B\u8F7D registry-item.json \u5931\u8D25\uFF1A${response.status} ${response.statusText}`
|
|
3504
|
+
);
|
|
3505
|
+
}
|
|
3506
|
+
const item = await response.json();
|
|
3507
|
+
return item;
|
|
3508
|
+
}
|
|
3509
|
+
async function sendInstallEvent(key) {
|
|
3510
|
+
const client = getHttpClient();
|
|
3511
|
+
await client.post("/api/v1/studio/innerapi/resource_events", {
|
|
3512
|
+
events: [
|
|
3513
|
+
{
|
|
3514
|
+
resourceType: "component",
|
|
3515
|
+
resourceKey: key,
|
|
3516
|
+
eventType: "install",
|
|
3517
|
+
details: {}
|
|
3518
|
+
}
|
|
3519
|
+
]
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
// src/commands/component/registry-preparer.ts
|
|
3524
|
+
var REGISTRY_TEMP_DIR = path8.join(os.tmpdir(), "miaoda-registry");
|
|
3525
|
+
function parseComponentKey(key) {
|
|
3526
|
+
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3527
|
+
if (!match) {
|
|
3528
|
+
throw new Error(
|
|
3529
|
+
`Invalid component key format: ${key}. Expected format: @scope/name`
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
return { scope: match[1], name: match[2] };
|
|
3533
|
+
}
|
|
3534
|
+
function getLocalRegistryPath(key) {
|
|
3535
|
+
const { scope, name } = parseComponentKey(key);
|
|
3536
|
+
return path8.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3537
|
+
}
|
|
3538
|
+
function ensureDir(dirPath) {
|
|
3539
|
+
if (!fs10.existsSync(dirPath)) {
|
|
3540
|
+
fs10.mkdirSync(dirPath, { recursive: true });
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
async function prepareRecursive(key, visited) {
|
|
3544
|
+
if (visited.has(key)) {
|
|
3545
|
+
debug("\u8DF3\u8FC7\u5DF2\u5904\u7406\u7684\u7EC4\u4EF6: %s", key);
|
|
3546
|
+
return;
|
|
3547
|
+
}
|
|
3548
|
+
visited.add(key);
|
|
3549
|
+
debug("\u5904\u7406\u7EC4\u4EF6: %s", key);
|
|
3550
|
+
debug("\u83B7\u53D6\u7EC4\u4EF6\u4E0B\u8F7D\u4FE1\u606F...");
|
|
3551
|
+
const infoMap = await getComponents([key]);
|
|
3552
|
+
const info = infoMap[key];
|
|
3553
|
+
debug("\u7EC4\u4EF6\u4FE1\u606F: %o", info);
|
|
3554
|
+
if (!info) {
|
|
3555
|
+
throw new Error(`Component not found: ${key}`);
|
|
3556
|
+
}
|
|
3557
|
+
if (info.status !== "active") {
|
|
3558
|
+
throw new Error(`Component is not active: ${key}`);
|
|
3559
|
+
}
|
|
3560
|
+
debug("\u4E0B\u8F7D registry item: %s", info.downloadURL);
|
|
3561
|
+
const registryItem = await getRegistryItem(info.downloadURL);
|
|
3562
|
+
debug("registry item \u5185\u5BB9: %o", registryItem);
|
|
3563
|
+
const deps = registryItem.registryDependencies || [];
|
|
3564
|
+
debug("\u4F9D\u8D56\u5217\u8868: %o", deps);
|
|
3565
|
+
for (const dep of deps) {
|
|
3566
|
+
await prepareRecursive(dep, visited);
|
|
3567
|
+
}
|
|
3568
|
+
const rewrittenItem = {
|
|
3569
|
+
...registryItem,
|
|
3570
|
+
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3571
|
+
};
|
|
3572
|
+
const localPath = getLocalRegistryPath(key);
|
|
3573
|
+
ensureDir(path8.dirname(localPath));
|
|
3574
|
+
fs10.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3575
|
+
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3576
|
+
}
|
|
3577
|
+
async function prepareComponentRegistryItems(id) {
|
|
3578
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3579
|
+
await prepareRecursive(id, visited);
|
|
3580
|
+
return getLocalRegistryPath(id);
|
|
3581
|
+
}
|
|
3582
|
+
function cleanupTempDir() {
|
|
3583
|
+
try {
|
|
3584
|
+
if (fs10.existsSync(REGISTRY_TEMP_DIR)) {
|
|
3585
|
+
fs10.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3586
|
+
}
|
|
3587
|
+
} catch {
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
function getDownloadedRegistryItem(itemId) {
|
|
3591
|
+
const localPath = getLocalRegistryPath(itemId);
|
|
3592
|
+
if (!fs10.existsSync(localPath)) {
|
|
3593
|
+
return null;
|
|
3594
|
+
}
|
|
3595
|
+
const content = fs10.readFileSync(localPath, "utf-8");
|
|
3596
|
+
return JSON.parse(content);
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
// src/commands/component/shadcn-executor.ts
|
|
3600
|
+
import * as pty from "@lydell/node-pty";
|
|
3601
|
+
function parseOutput(output) {
|
|
3602
|
+
const state = {
|
|
3603
|
+
currentSection: null,
|
|
3604
|
+
files: /* @__PURE__ */ new Set()
|
|
3605
|
+
};
|
|
3606
|
+
const lines = output.split("\n");
|
|
3607
|
+
for (const line of lines) {
|
|
3608
|
+
const trimmedLine = line.trim();
|
|
3609
|
+
if (/Created \d+ files?:/.test(trimmedLine)) {
|
|
3610
|
+
state.currentSection = "created";
|
|
3611
|
+
continue;
|
|
3612
|
+
}
|
|
3613
|
+
if (/Updated \d+ files?:/.test(trimmedLine)) {
|
|
3614
|
+
state.currentSection = "updated";
|
|
3615
|
+
continue;
|
|
3616
|
+
}
|
|
3617
|
+
if (/Skipped \d+ files?:/.test(trimmedLine)) {
|
|
3618
|
+
state.currentSection = "skipped";
|
|
3619
|
+
continue;
|
|
3620
|
+
}
|
|
3621
|
+
if (state.currentSection && trimmedLine.startsWith("- ")) {
|
|
3622
|
+
const filePath = trimmedLine.slice(2).trim();
|
|
3623
|
+
if (filePath && filePath.includes("/")) {
|
|
3624
|
+
state.files.add(filePath);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
if (state.currentSection && trimmedLine.length > 1 && !trimmedLine.startsWith("- ")) {
|
|
3628
|
+
state.currentSection = null;
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
return Array.from(state.files);
|
|
3632
|
+
}
|
|
3633
|
+
function toFileInfo(filePath) {
|
|
3634
|
+
const name = filePath.split("/").pop() || filePath;
|
|
3635
|
+
return { name, path: filePath };
|
|
3636
|
+
}
|
|
3637
|
+
var PROMPT_PATTERNS = [
|
|
3638
|
+
// 文件覆盖确认 - 回答 n(不覆盖)
|
|
3639
|
+
{ pattern: /overwrite/i, answer: "n\n" },
|
|
3640
|
+
// 主题/样式选择 - 回答 n(不安装额外主题)
|
|
3641
|
+
{ pattern: /theme/i, answer: "n\n" },
|
|
3642
|
+
{ pattern: /style/i, answer: "n\n" },
|
|
3643
|
+
// 继续确认 - 回答 y
|
|
3644
|
+
{ pattern: /continue\?/i, answer: "y\n" },
|
|
3645
|
+
{ pattern: /proceed\?/i, answer: "y\n" }
|
|
3646
|
+
];
|
|
3647
|
+
async function executeShadcnAdd(registryItemPath) {
|
|
3648
|
+
return new Promise((resolve) => {
|
|
3649
|
+
let output = "";
|
|
3650
|
+
const args = ["--yes", "shadcn@3.8.2", "add", registryItemPath];
|
|
3651
|
+
const ptyProcess = pty.spawn("npx", args, {
|
|
3652
|
+
name: "xterm-color",
|
|
3653
|
+
cols: 120,
|
|
3654
|
+
rows: 30,
|
|
3655
|
+
cwd: process.cwd(),
|
|
3656
|
+
env: {
|
|
3657
|
+
...process.env,
|
|
3658
|
+
// 禁用颜色输出以便解析
|
|
3659
|
+
NO_COLOR: "1",
|
|
3660
|
+
FORCE_COLOR: "0"
|
|
3661
|
+
}
|
|
3662
|
+
});
|
|
3663
|
+
ptyProcess.onData((data) => {
|
|
3664
|
+
output += data;
|
|
3665
|
+
for (const { pattern, answer } of PROMPT_PATTERNS) {
|
|
3666
|
+
if (pattern.test(data)) {
|
|
3667
|
+
ptyProcess.write(answer);
|
|
3668
|
+
return;
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
});
|
|
3672
|
+
const timeoutId = setTimeout(() => {
|
|
3673
|
+
ptyProcess.kill();
|
|
3674
|
+
resolve({
|
|
3675
|
+
success: false,
|
|
3676
|
+
files: [],
|
|
3677
|
+
error: "\u6267\u884C\u8D85\u65F6"
|
|
3678
|
+
});
|
|
3679
|
+
}, 3 * 60 * 1e3);
|
|
3680
|
+
ptyProcess.onExit(({ exitCode }) => {
|
|
3681
|
+
clearTimeout(timeoutId);
|
|
3682
|
+
const success = exitCode === 0;
|
|
3683
|
+
const filePaths = parseOutput(output);
|
|
3684
|
+
const files = filePaths.map(toFileInfo);
|
|
3685
|
+
resolve({
|
|
3686
|
+
success,
|
|
3687
|
+
files,
|
|
3688
|
+
error: success ? void 0 : output || `Process exited with code ${exitCode}`
|
|
3689
|
+
});
|
|
3690
|
+
});
|
|
3691
|
+
});
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
// src/commands/component/add.handler.ts
|
|
3695
|
+
function printResult(result) {
|
|
3696
|
+
console.log(JSON.stringify(result, null, 2));
|
|
3697
|
+
}
|
|
3698
|
+
async function addComponent(key) {
|
|
3699
|
+
debug("\u5F00\u59CB\u5B89\u88C5\u7EC4\u4EF6: %s", key);
|
|
3700
|
+
debug("\u51C6\u5907 registry items...");
|
|
3701
|
+
const registryItemPath = await prepareComponentRegistryItems(key);
|
|
3702
|
+
debug("registry item \u8DEF\u5F84: %s", registryItemPath);
|
|
3703
|
+
const registryItem = getDownloadedRegistryItem(key);
|
|
3704
|
+
debug("\u83B7\u53D6\u5230 registry item: %o", registryItem);
|
|
3705
|
+
debug("\u6267\u884C shadcn add...");
|
|
3706
|
+
const executeResult = await executeShadcnAdd(registryItemPath);
|
|
3707
|
+
debug("shadcn \u6267\u884C\u7ED3\u679C: %o", executeResult);
|
|
3708
|
+
if (!executeResult.success) {
|
|
3709
|
+
throw new Error(executeResult.error || "\u5B89\u88C5\u5931\u8D25\uFF0C\u672A\u77E5\u539F\u56E0");
|
|
3710
|
+
}
|
|
3711
|
+
return {
|
|
3712
|
+
success: true,
|
|
3713
|
+
name: key,
|
|
3714
|
+
description: registryItem?.description || "",
|
|
3715
|
+
files: executeResult.files,
|
|
3716
|
+
docs: registryItem?.docs || ""
|
|
3717
|
+
};
|
|
3718
|
+
}
|
|
3719
|
+
async function add(key) {
|
|
3720
|
+
try {
|
|
3721
|
+
const result = await addComponent(key);
|
|
3722
|
+
printResult(result);
|
|
3723
|
+
void sendInstallEvent(key);
|
|
3724
|
+
} catch (error) {
|
|
3725
|
+
const errorMessage = error instanceof Error ? error.message : "\u5B89\u88C5\u5931\u8D25\uFF0C\u539F\u56E0\u672A\u77E5";
|
|
3726
|
+
printResult({
|
|
3727
|
+
success: false,
|
|
3728
|
+
errors: [{ message: errorMessage }]
|
|
3729
|
+
});
|
|
3730
|
+
} finally {
|
|
3731
|
+
cleanupTempDir();
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
// src/commands/component/index.ts
|
|
3736
|
+
var addCommand = {
|
|
3737
|
+
name: "add",
|
|
3738
|
+
description: "\u5B89\u88C5\u5999\u642D\u7EC4\u4EF6\u5E02\u573A\u4E2D\u7684\u7EC4\u4EF6",
|
|
3739
|
+
register(program) {
|
|
3740
|
+
program.command(this.name).description(this.description).argument("<component>", "\u7EC4\u4EF6 ID (\u4F8B\u5982 @miaoda/button)").action(async (component) => {
|
|
3741
|
+
await add(component);
|
|
3742
|
+
});
|
|
3743
|
+
}
|
|
3744
|
+
};
|
|
3745
|
+
var componentCommandGroup = {
|
|
3746
|
+
name: "component",
|
|
3747
|
+
description: "\u7EC4\u4EF6\u76F8\u5173\u547D\u4EE4",
|
|
3748
|
+
commands: [addCommand]
|
|
3749
|
+
};
|
|
3750
|
+
|
|
3751
|
+
// src/commands/migration/version-manager.ts
|
|
3752
|
+
import fs11 from "fs";
|
|
3753
|
+
import path9 from "path";
|
|
3458
3754
|
var PACKAGE_JSON = "package.json";
|
|
3459
3755
|
var VERSION_FIELD = "migrationVersion";
|
|
3460
3756
|
function getPackageJsonPath2() {
|
|
3461
|
-
return
|
|
3757
|
+
return path9.join(process.cwd(), PACKAGE_JSON);
|
|
3462
3758
|
}
|
|
3463
3759
|
function getCurrentVersion() {
|
|
3464
3760
|
const pkgPath = getPackageJsonPath2();
|
|
3465
|
-
if (!
|
|
3761
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
3466
3762
|
throw new Error("package.json not found");
|
|
3467
3763
|
}
|
|
3468
|
-
const pkg2 = JSON.parse(
|
|
3764
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
3469
3765
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
3470
3766
|
}
|
|
3471
3767
|
function setCurrentVersion(version) {
|
|
3472
3768
|
const pkgPath = getPackageJsonPath2();
|
|
3473
|
-
const pkg2 = JSON.parse(
|
|
3769
|
+
const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
|
|
3474
3770
|
pkg2[VERSION_FIELD] = version;
|
|
3475
|
-
|
|
3771
|
+
fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3476
3772
|
}
|
|
3477
3773
|
|
|
3478
3774
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3479
|
-
import
|
|
3480
|
-
import
|
|
3775
|
+
import fs13 from "fs";
|
|
3776
|
+
import path11 from "path";
|
|
3481
3777
|
|
|
3482
3778
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
3483
|
-
import
|
|
3484
|
-
import
|
|
3779
|
+
import fs12 from "fs";
|
|
3780
|
+
import path10 from "path";
|
|
3485
3781
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
3486
3782
|
function getProjectRoot3() {
|
|
3487
3783
|
return process.cwd();
|
|
3488
3784
|
}
|
|
3489
3785
|
function getCapabilitiesDir2() {
|
|
3490
|
-
return
|
|
3786
|
+
return path10.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
3491
3787
|
}
|
|
3492
3788
|
function getPluginManifestPath2(pluginKey) {
|
|
3493
|
-
return
|
|
3789
|
+
return path10.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
3494
3790
|
}
|
|
3495
3791
|
|
|
3496
3792
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3497
3793
|
function detectJsonMigration() {
|
|
3498
3794
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3499
|
-
const oldFilePath =
|
|
3500
|
-
if (!
|
|
3795
|
+
const oldFilePath = path11.join(capabilitiesDir, "capabilities.json");
|
|
3796
|
+
if (!fs13.existsSync(oldFilePath)) {
|
|
3501
3797
|
return {
|
|
3502
3798
|
needsMigration: false,
|
|
3503
3799
|
reason: "capabilities.json not found"
|
|
3504
3800
|
};
|
|
3505
3801
|
}
|
|
3506
3802
|
try {
|
|
3507
|
-
const content =
|
|
3803
|
+
const content = fs13.readFileSync(oldFilePath, "utf-8");
|
|
3508
3804
|
const parsed = JSON.parse(content);
|
|
3509
3805
|
if (!Array.isArray(parsed)) {
|
|
3510
3806
|
return {
|
|
@@ -3555,8 +3851,8 @@ async function check(options) {
|
|
|
3555
3851
|
}
|
|
3556
3852
|
|
|
3557
3853
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
3558
|
-
import
|
|
3559
|
-
import
|
|
3854
|
+
import fs14 from "fs";
|
|
3855
|
+
import path12 from "path";
|
|
3560
3856
|
|
|
3561
3857
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
3562
3858
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -3786,18 +4082,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
3786
4082
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
3787
4083
|
function loadExistingCapabilities() {
|
|
3788
4084
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3789
|
-
if (!
|
|
4085
|
+
if (!fs14.existsSync(capabilitiesDir)) {
|
|
3790
4086
|
return [];
|
|
3791
4087
|
}
|
|
3792
|
-
const files =
|
|
4088
|
+
const files = fs14.readdirSync(capabilitiesDir);
|
|
3793
4089
|
const capabilities = [];
|
|
3794
4090
|
for (const file of files) {
|
|
3795
4091
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
3796
4092
|
continue;
|
|
3797
4093
|
}
|
|
3798
4094
|
try {
|
|
3799
|
-
const filePath =
|
|
3800
|
-
const content =
|
|
4095
|
+
const filePath = path12.join(capabilitiesDir, file);
|
|
4096
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
3801
4097
|
const capability = JSON.parse(content);
|
|
3802
4098
|
if (capability.id && capability.pluginKey) {
|
|
3803
4099
|
capabilities.push(capability);
|
|
@@ -3855,9 +4151,9 @@ async function migrateJsonFiles(options) {
|
|
|
3855
4151
|
}
|
|
3856
4152
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3857
4153
|
for (const cap of newCapabilities) {
|
|
3858
|
-
const filePath =
|
|
4154
|
+
const filePath = path12.join(capabilitiesDir, `${cap.id}.json`);
|
|
3859
4155
|
const content = JSON.stringify(cap, null, 2);
|
|
3860
|
-
|
|
4156
|
+
fs14.writeFileSync(filePath, content, "utf-8");
|
|
3861
4157
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
3862
4158
|
}
|
|
3863
4159
|
return {
|
|
@@ -3869,11 +4165,11 @@ async function migrateJsonFiles(options) {
|
|
|
3869
4165
|
}
|
|
3870
4166
|
|
|
3871
4167
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
3872
|
-
import
|
|
4168
|
+
import fs15 from "fs";
|
|
3873
4169
|
function isPluginInstalled2(pluginKey) {
|
|
3874
4170
|
const actionPlugins = readActionPlugins();
|
|
3875
4171
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
3876
|
-
return
|
|
4172
|
+
return fs15.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
3877
4173
|
}
|
|
3878
4174
|
function detectPluginsToInstall(capabilities) {
|
|
3879
4175
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -3949,12 +4245,12 @@ async function installPlugins(capabilities, options) {
|
|
|
3949
4245
|
}
|
|
3950
4246
|
|
|
3951
4247
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
3952
|
-
import
|
|
4248
|
+
import path14 from "path";
|
|
3953
4249
|
import { Project as Project3 } from "ts-morph";
|
|
3954
4250
|
|
|
3955
4251
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
3956
|
-
import
|
|
3957
|
-
import
|
|
4252
|
+
import fs16 from "fs";
|
|
4253
|
+
import path13 from "path";
|
|
3958
4254
|
var EXCLUDED_DIRS = [
|
|
3959
4255
|
"node_modules",
|
|
3960
4256
|
"dist",
|
|
@@ -3969,9 +4265,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
3969
4265
|
/\.d\.ts$/
|
|
3970
4266
|
];
|
|
3971
4267
|
function scanDirectory(dir, files = []) {
|
|
3972
|
-
const entries =
|
|
4268
|
+
const entries = fs16.readdirSync(dir, { withFileTypes: true });
|
|
3973
4269
|
for (const entry of entries) {
|
|
3974
|
-
const fullPath =
|
|
4270
|
+
const fullPath = path13.join(dir, entry.name);
|
|
3975
4271
|
if (entry.isDirectory()) {
|
|
3976
4272
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
3977
4273
|
continue;
|
|
@@ -3987,14 +4283,14 @@ function scanDirectory(dir, files = []) {
|
|
|
3987
4283
|
return files;
|
|
3988
4284
|
}
|
|
3989
4285
|
function scanServerFiles() {
|
|
3990
|
-
const serverDir =
|
|
3991
|
-
if (!
|
|
4286
|
+
const serverDir = path13.join(getProjectRoot3(), "server");
|
|
4287
|
+
if (!fs16.existsSync(serverDir)) {
|
|
3992
4288
|
return [];
|
|
3993
4289
|
}
|
|
3994
4290
|
return scanDirectory(serverDir);
|
|
3995
4291
|
}
|
|
3996
4292
|
function hasCapabilityImport(filePath) {
|
|
3997
|
-
const content =
|
|
4293
|
+
const content = fs16.readFileSync(filePath, "utf-8");
|
|
3998
4294
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
3999
4295
|
}
|
|
4000
4296
|
function scanFilesToMigrate() {
|
|
@@ -4371,7 +4667,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4371
4667
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
4372
4668
|
const classInfo = analyzeClass(sourceFile);
|
|
4373
4669
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
4374
|
-
const relativePath =
|
|
4670
|
+
const relativePath = path14.relative(getProjectRoot3(), filePath);
|
|
4375
4671
|
return {
|
|
4376
4672
|
filePath: relativePath,
|
|
4377
4673
|
imports,
|
|
@@ -4382,7 +4678,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4382
4678
|
};
|
|
4383
4679
|
}
|
|
4384
4680
|
function migrateFile(project, analysis, dryRun) {
|
|
4385
|
-
const absolutePath =
|
|
4681
|
+
const absolutePath = path14.join(getProjectRoot3(), analysis.filePath);
|
|
4386
4682
|
if (!analysis.canAutoMigrate) {
|
|
4387
4683
|
return {
|
|
4388
4684
|
filePath: analysis.filePath,
|
|
@@ -4485,17 +4781,17 @@ function getSuggestion(analysis) {
|
|
|
4485
4781
|
}
|
|
4486
4782
|
|
|
4487
4783
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
4488
|
-
import
|
|
4489
|
-
import
|
|
4784
|
+
import fs17 from "fs";
|
|
4785
|
+
import path15 from "path";
|
|
4490
4786
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
4491
4787
|
const deletedFiles = [];
|
|
4492
4788
|
const errors = [];
|
|
4493
4789
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4494
|
-
const oldJsonPath =
|
|
4495
|
-
if (
|
|
4790
|
+
const oldJsonPath = path15.join(capabilitiesDir, "capabilities.json");
|
|
4791
|
+
if (fs17.existsSync(oldJsonPath)) {
|
|
4496
4792
|
try {
|
|
4497
4793
|
if (!dryRun) {
|
|
4498
|
-
|
|
4794
|
+
fs17.unlinkSync(oldJsonPath);
|
|
4499
4795
|
}
|
|
4500
4796
|
deletedFiles.push("capabilities.json");
|
|
4501
4797
|
} catch (error) {
|
|
@@ -4503,11 +4799,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4503
4799
|
}
|
|
4504
4800
|
}
|
|
4505
4801
|
for (const cap of capabilities) {
|
|
4506
|
-
const tsFilePath =
|
|
4507
|
-
if (
|
|
4802
|
+
const tsFilePath = path15.join(capabilitiesDir, `${cap.id}.ts`);
|
|
4803
|
+
if (fs17.existsSync(tsFilePath)) {
|
|
4508
4804
|
try {
|
|
4509
4805
|
if (!dryRun) {
|
|
4510
|
-
|
|
4806
|
+
fs17.unlinkSync(tsFilePath);
|
|
4511
4807
|
}
|
|
4512
4808
|
deletedFiles.push(`${cap.id}.ts`);
|
|
4513
4809
|
} catch (error) {
|
|
@@ -4523,8 +4819,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4523
4819
|
}
|
|
4524
4820
|
|
|
4525
4821
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
4526
|
-
import
|
|
4527
|
-
import
|
|
4822
|
+
import fs18 from "fs";
|
|
4823
|
+
import path16 from "path";
|
|
4528
4824
|
var REPORT_FILE = "capability-migration-report.md";
|
|
4529
4825
|
function printSummary(result) {
|
|
4530
4826
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -4687,15 +4983,15 @@ async function generateReport(result) {
|
|
|
4687
4983
|
}
|
|
4688
4984
|
lines.push("");
|
|
4689
4985
|
const logDir = process.env.LOG_DIR || "logs";
|
|
4690
|
-
if (!
|
|
4986
|
+
if (!fs18.existsSync(logDir)) {
|
|
4691
4987
|
return;
|
|
4692
4988
|
}
|
|
4693
|
-
const reportDir =
|
|
4694
|
-
if (!
|
|
4695
|
-
|
|
4989
|
+
const reportDir = path16.join(logDir, "migration");
|
|
4990
|
+
if (!fs18.existsSync(reportDir)) {
|
|
4991
|
+
fs18.mkdirSync(reportDir, { recursive: true });
|
|
4696
4992
|
}
|
|
4697
|
-
const reportPath =
|
|
4698
|
-
|
|
4993
|
+
const reportPath = path16.join(reportDir, REPORT_FILE);
|
|
4994
|
+
fs18.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
4699
4995
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
4700
4996
|
}
|
|
4701
4997
|
|
|
@@ -5227,10 +5523,10 @@ var migrationCommand = {
|
|
|
5227
5523
|
};
|
|
5228
5524
|
|
|
5229
5525
|
// src/commands/read-logs/index.ts
|
|
5230
|
-
import
|
|
5526
|
+
import path17 from "path";
|
|
5231
5527
|
|
|
5232
5528
|
// src/commands/read-logs/std-utils.ts
|
|
5233
|
-
import
|
|
5529
|
+
import fs19 from "fs";
|
|
5234
5530
|
function formatStdPrefixTime(localTime) {
|
|
5235
5531
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5236
5532
|
if (!match) return localTime;
|
|
@@ -5260,11 +5556,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5260
5556
|
return `[${time}] ${content}`;
|
|
5261
5557
|
}
|
|
5262
5558
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5263
|
-
const stat =
|
|
5559
|
+
const stat = fs19.statSync(filePath);
|
|
5264
5560
|
if (stat.size === 0) {
|
|
5265
5561
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5266
5562
|
}
|
|
5267
|
-
const fd =
|
|
5563
|
+
const fd = fs19.openSync(filePath, "r");
|
|
5268
5564
|
const chunkSize = 64 * 1024;
|
|
5269
5565
|
let position = stat.size;
|
|
5270
5566
|
let remainder = "";
|
|
@@ -5278,7 +5574,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5278
5574
|
const length = Math.min(chunkSize, position);
|
|
5279
5575
|
position -= length;
|
|
5280
5576
|
const buffer = Buffer.alloc(length);
|
|
5281
|
-
|
|
5577
|
+
fs19.readSync(fd, buffer, 0, length, position);
|
|
5282
5578
|
let chunk = buffer.toString("utf8");
|
|
5283
5579
|
if (remainder) {
|
|
5284
5580
|
chunk += remainder;
|
|
@@ -5320,7 +5616,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5320
5616
|
}
|
|
5321
5617
|
}
|
|
5322
5618
|
} finally {
|
|
5323
|
-
|
|
5619
|
+
fs19.closeSync(fd);
|
|
5324
5620
|
}
|
|
5325
5621
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5326
5622
|
}
|
|
@@ -5341,21 +5637,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5341
5637
|
}
|
|
5342
5638
|
|
|
5343
5639
|
// src/commands/read-logs/tail.ts
|
|
5344
|
-
import
|
|
5640
|
+
import fs20 from "fs";
|
|
5345
5641
|
function fileExists(filePath) {
|
|
5346
5642
|
try {
|
|
5347
|
-
|
|
5643
|
+
fs20.accessSync(filePath, fs20.constants.F_OK | fs20.constants.R_OK);
|
|
5348
5644
|
return true;
|
|
5349
5645
|
} catch {
|
|
5350
5646
|
return false;
|
|
5351
5647
|
}
|
|
5352
5648
|
}
|
|
5353
5649
|
function readFileTailLines(filePath, maxLines) {
|
|
5354
|
-
const stat =
|
|
5650
|
+
const stat = fs20.statSync(filePath);
|
|
5355
5651
|
if (stat.size === 0) {
|
|
5356
5652
|
return [];
|
|
5357
5653
|
}
|
|
5358
|
-
const fd =
|
|
5654
|
+
const fd = fs20.openSync(filePath, "r");
|
|
5359
5655
|
const chunkSize = 64 * 1024;
|
|
5360
5656
|
const chunks = [];
|
|
5361
5657
|
let position = stat.size;
|
|
@@ -5365,13 +5661,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5365
5661
|
const length = Math.min(chunkSize, position);
|
|
5366
5662
|
position -= length;
|
|
5367
5663
|
const buffer = Buffer.alloc(length);
|
|
5368
|
-
|
|
5664
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
5369
5665
|
chunks.unshift(buffer.toString("utf8"));
|
|
5370
5666
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
5371
5667
|
collectedLines += chunkLines;
|
|
5372
5668
|
}
|
|
5373
5669
|
} finally {
|
|
5374
|
-
|
|
5670
|
+
fs20.closeSync(fd);
|
|
5375
5671
|
}
|
|
5376
5672
|
const content = chunks.join("");
|
|
5377
5673
|
const allLines = content.split("\n");
|
|
@@ -5387,11 +5683,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5387
5683
|
return allLines.slice(allLines.length - maxLines);
|
|
5388
5684
|
}
|
|
5389
5685
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
5390
|
-
const stat =
|
|
5686
|
+
const stat = fs20.statSync(filePath);
|
|
5391
5687
|
if (stat.size === 0) {
|
|
5392
5688
|
return { lines: [], totalLinesCount: 0 };
|
|
5393
5689
|
}
|
|
5394
|
-
const fd =
|
|
5690
|
+
const fd = fs20.openSync(filePath, "r");
|
|
5395
5691
|
const chunkSize = 64 * 1024;
|
|
5396
5692
|
let position = stat.size;
|
|
5397
5693
|
let remainder = "";
|
|
@@ -5403,7 +5699,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5403
5699
|
const length = Math.min(chunkSize, position);
|
|
5404
5700
|
position -= length;
|
|
5405
5701
|
const buffer = Buffer.alloc(length);
|
|
5406
|
-
|
|
5702
|
+
fs20.readSync(fd, buffer, 0, length, position);
|
|
5407
5703
|
let chunk = buffer.toString("utf8");
|
|
5408
5704
|
if (remainder) {
|
|
5409
5705
|
chunk += remainder;
|
|
@@ -5434,7 +5730,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5434
5730
|
}
|
|
5435
5731
|
}
|
|
5436
5732
|
} finally {
|
|
5437
|
-
|
|
5733
|
+
fs20.closeSync(fd);
|
|
5438
5734
|
}
|
|
5439
5735
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5440
5736
|
}
|
|
@@ -5447,13 +5743,19 @@ function readClientStdSegment(filePath, maxLines, offset) {
|
|
|
5447
5743
|
function extractClientStdSegment(lines, maxLines, offset) {
|
|
5448
5744
|
const bodyLines = lines.map(stripPrefixFromStdLine);
|
|
5449
5745
|
const hotStartMarkers = [
|
|
5746
|
+
// Webpack markers
|
|
5450
5747
|
/file change detected\..*incremental compilation/i,
|
|
5451
5748
|
/starting incremental compilation/i,
|
|
5452
5749
|
/starting compilation/i,
|
|
5453
5750
|
/\bcompiling\b/i,
|
|
5454
|
-
/\brecompil/i
|
|
5751
|
+
/\brecompil/i,
|
|
5752
|
+
// Vite markers - format: "3:11:46 PM [vite] (client) hmr update ..."
|
|
5753
|
+
/VITE v[\d.]+.*ready/i,
|
|
5754
|
+
/\[vite\].*page reload/i,
|
|
5755
|
+
/\[vite\].*hmr update/i
|
|
5455
5756
|
];
|
|
5456
5757
|
const hotEndMarkers = [
|
|
5758
|
+
// Webpack markers
|
|
5457
5759
|
/file change detected\..*incremental compilation/i,
|
|
5458
5760
|
/\bwebpack compiled\b/i,
|
|
5459
5761
|
/compiled successfully/i,
|
|
@@ -5464,14 +5766,25 @@ function extractClientStdSegment(lines, maxLines, offset) {
|
|
|
5464
5766
|
/\bhmr\b/i,
|
|
5465
5767
|
/hot update/i,
|
|
5466
5768
|
/\bhot reload\b/i,
|
|
5467
|
-
/\bhmr update\b/i
|
|
5769
|
+
/\bhmr update\b/i,
|
|
5770
|
+
// Vite markers
|
|
5771
|
+
/VITE v[\d.]+.*ready/i,
|
|
5772
|
+
/\[vite\].*page reload/i,
|
|
5773
|
+
/\[vite\].*hmr update/i,
|
|
5774
|
+
/\[vite\].*hmr invalidate/i,
|
|
5775
|
+
/\[vite\].*internal server error/i,
|
|
5776
|
+
/\[vite\].*pre-transform error/i
|
|
5468
5777
|
];
|
|
5469
5778
|
const compiledMarkers = [
|
|
5779
|
+
// Webpack markers
|
|
5470
5780
|
/\bwebpack compiled\b/i,
|
|
5471
5781
|
/compiled successfully/i,
|
|
5472
5782
|
/compiled with warnings/i,
|
|
5473
5783
|
/compiled with errors/i,
|
|
5474
|
-
/failed to compile/i
|
|
5784
|
+
/failed to compile/i,
|
|
5785
|
+
// Vite markers
|
|
5786
|
+
/VITE v[\d.]+.*ready/i,
|
|
5787
|
+
/\[vite\].*hmr update/i
|
|
5475
5788
|
];
|
|
5476
5789
|
let startIndex = -1;
|
|
5477
5790
|
for (let i = bodyLines.length - 1; i >= 0; i -= 1) {
|
|
@@ -5524,14 +5837,15 @@ function extractClientStdSegment(lines, maxLines, offset) {
|
|
|
5524
5837
|
}
|
|
5525
5838
|
const segment = startIndex === -1 ? bodyLines : bodyLines.slice(startIndex);
|
|
5526
5839
|
if (segment.length === 0) {
|
|
5527
|
-
return { lines: [], totalLinesCount: 0 };
|
|
5840
|
+
return { lines: [], totalLinesCount: 0, allLines: [] };
|
|
5528
5841
|
}
|
|
5529
5842
|
const totalLinesCount = segment.length;
|
|
5530
5843
|
const endExclusive = Math.max(0, segment.length - offset);
|
|
5531
5844
|
const start = Math.max(0, endExclusive - maxLines);
|
|
5532
5845
|
return {
|
|
5533
5846
|
lines: segment.slice(start, endExclusive),
|
|
5534
|
-
totalLinesCount
|
|
5847
|
+
totalLinesCount,
|
|
5848
|
+
allLines: segment
|
|
5535
5849
|
};
|
|
5536
5850
|
}
|
|
5537
5851
|
|
|
@@ -5558,7 +5872,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
5558
5872
|
}
|
|
5559
5873
|
|
|
5560
5874
|
// src/commands/read-logs/json-lines.ts
|
|
5561
|
-
import
|
|
5875
|
+
import fs21 from "fs";
|
|
5562
5876
|
function normalizePid(value) {
|
|
5563
5877
|
if (typeof value === "number") {
|
|
5564
5878
|
return String(value);
|
|
@@ -5609,11 +5923,11 @@ function buildWantedLevelSet(levels) {
|
|
|
5609
5923
|
return set.size > 0 ? set : null;
|
|
5610
5924
|
}
|
|
5611
5925
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
5612
|
-
const stat =
|
|
5926
|
+
const stat = fs21.statSync(filePath);
|
|
5613
5927
|
if (stat.size === 0) {
|
|
5614
5928
|
return { lines: [], totalLinesCount: 0 };
|
|
5615
5929
|
}
|
|
5616
|
-
const fd =
|
|
5930
|
+
const fd = fs21.openSync(filePath, "r");
|
|
5617
5931
|
const chunkSize = 64 * 1024;
|
|
5618
5932
|
let position = stat.size;
|
|
5619
5933
|
let remainder = "";
|
|
@@ -5628,7 +5942,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
5628
5942
|
const length = Math.min(chunkSize, position);
|
|
5629
5943
|
position -= length;
|
|
5630
5944
|
const buffer = Buffer.alloc(length);
|
|
5631
|
-
|
|
5945
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
5632
5946
|
let chunk = buffer.toString("utf8");
|
|
5633
5947
|
if (remainder) {
|
|
5634
5948
|
chunk += remainder;
|
|
@@ -5690,7 +6004,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
5690
6004
|
}
|
|
5691
6005
|
}
|
|
5692
6006
|
} finally {
|
|
5693
|
-
|
|
6007
|
+
fs21.closeSync(fd);
|
|
5694
6008
|
}
|
|
5695
6009
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5696
6010
|
}
|
|
@@ -5733,11 +6047,11 @@ function extractTraceId(obj) {
|
|
|
5733
6047
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
5734
6048
|
const wanted = traceId.trim();
|
|
5735
6049
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
5736
|
-
const stat =
|
|
6050
|
+
const stat = fs21.statSync(filePath);
|
|
5737
6051
|
if (stat.size === 0) {
|
|
5738
6052
|
return { lines: [], totalLinesCount: 0 };
|
|
5739
6053
|
}
|
|
5740
|
-
const fd =
|
|
6054
|
+
const fd = fs21.openSync(filePath, "r");
|
|
5741
6055
|
const chunkSize = 64 * 1024;
|
|
5742
6056
|
let position = stat.size;
|
|
5743
6057
|
let remainder = "";
|
|
@@ -5750,7 +6064,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
5750
6064
|
const length = Math.min(chunkSize, position);
|
|
5751
6065
|
position -= length;
|
|
5752
6066
|
const buffer = Buffer.alloc(length);
|
|
5753
|
-
|
|
6067
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
5754
6068
|
let chunk = buffer.toString("utf8");
|
|
5755
6069
|
if (remainder) {
|
|
5756
6070
|
chunk += remainder;
|
|
@@ -5803,7 +6117,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
5803
6117
|
}
|
|
5804
6118
|
}
|
|
5805
6119
|
} finally {
|
|
5806
|
-
|
|
6120
|
+
fs21.closeSync(fd);
|
|
5807
6121
|
}
|
|
5808
6122
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5809
6123
|
}
|
|
@@ -5812,11 +6126,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
5812
6126
|
if (!wantedLevelSet) {
|
|
5813
6127
|
return { lines: [], totalLinesCount: 0 };
|
|
5814
6128
|
}
|
|
5815
|
-
const stat =
|
|
6129
|
+
const stat = fs21.statSync(filePath);
|
|
5816
6130
|
if (stat.size === 0) {
|
|
5817
6131
|
return { lines: [], totalLinesCount: 0 };
|
|
5818
6132
|
}
|
|
5819
|
-
const fd =
|
|
6133
|
+
const fd = fs21.openSync(filePath, "r");
|
|
5820
6134
|
const chunkSize = 64 * 1024;
|
|
5821
6135
|
let position = stat.size;
|
|
5822
6136
|
let remainder = "";
|
|
@@ -5828,7 +6142,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
5828
6142
|
const length = Math.min(chunkSize, position);
|
|
5829
6143
|
position -= length;
|
|
5830
6144
|
const buffer = Buffer.alloc(length);
|
|
5831
|
-
|
|
6145
|
+
fs21.readSync(fd, buffer, 0, length, position);
|
|
5832
6146
|
let chunk = buffer.toString("utf8");
|
|
5833
6147
|
if (remainder) {
|
|
5834
6148
|
chunk += remainder;
|
|
@@ -5875,7 +6189,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
5875
6189
|
}
|
|
5876
6190
|
}
|
|
5877
6191
|
} finally {
|
|
5878
|
-
|
|
6192
|
+
fs21.closeSync(fd);
|
|
5879
6193
|
}
|
|
5880
6194
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5881
6195
|
}
|
|
@@ -6068,12 +6382,21 @@ async function readLatestLogLinesMeta(options) {
|
|
|
6068
6382
|
return { lines: [], totalLinesCount: 0 };
|
|
6069
6383
|
}
|
|
6070
6384
|
async function readLogsJsonResult(options) {
|
|
6071
|
-
const { lines, totalLinesCount } = await readLatestLogLinesMeta(options);
|
|
6385
|
+
const { lines, totalLinesCount, allLines } = await readLatestLogLinesMeta(options);
|
|
6072
6386
|
if (options.type === "server-std" || options.type === "client-std" || options.type === "dev" || options.type === "dev-std" || options.type === "install-dep-std") {
|
|
6387
|
+
const linesForErrorCheck = allLines ?? lines;
|
|
6388
|
+
const stackTracePattern = /\bat\s+\S+\s+\([^)]+:\d+:\d+\)/;
|
|
6389
|
+
const linesToFilter = allLines ?? lines;
|
|
6390
|
+
const filteredLines = linesToFilter.filter((line) => !stackTracePattern.test(line));
|
|
6391
|
+
const maxLines = options.maxLines ?? 30;
|
|
6392
|
+
const offset = options.offset ?? 0;
|
|
6393
|
+
const endExclusive = Math.max(0, filteredLines.length - offset);
|
|
6394
|
+
const start = Math.max(0, endExclusive - maxLines);
|
|
6395
|
+
const paginatedLogs = filteredLines.slice(start, endExclusive);
|
|
6073
6396
|
return {
|
|
6074
|
-
hasError: hasErrorInStdLines(
|
|
6075
|
-
totalLinesCount,
|
|
6076
|
-
logs:
|
|
6397
|
+
hasError: hasErrorInStdLines(linesForErrorCheck),
|
|
6398
|
+
totalLinesCount: filteredLines.length,
|
|
6399
|
+
logs: paginatedLogs
|
|
6077
6400
|
};
|
|
6078
6401
|
}
|
|
6079
6402
|
const logs = [];
|
|
@@ -6100,30 +6423,30 @@ async function readLogsJsonResult(options) {
|
|
|
6100
6423
|
};
|
|
6101
6424
|
}
|
|
6102
6425
|
function resolveLogFilePath(logDir, type) {
|
|
6103
|
-
const base =
|
|
6426
|
+
const base = path17.isAbsolute(logDir) ? logDir : path17.join(process.cwd(), logDir);
|
|
6104
6427
|
if (type === "server") {
|
|
6105
|
-
return
|
|
6428
|
+
return path17.join(base, "server.log");
|
|
6106
6429
|
}
|
|
6107
6430
|
if (type === "trace") {
|
|
6108
|
-
return
|
|
6431
|
+
return path17.join(base, "trace.log");
|
|
6109
6432
|
}
|
|
6110
6433
|
if (type === "server-std") {
|
|
6111
|
-
return
|
|
6434
|
+
return path17.join(base, "server.std.log");
|
|
6112
6435
|
}
|
|
6113
6436
|
if (type === "client-std") {
|
|
6114
|
-
return
|
|
6437
|
+
return path17.join(base, "client.std.log");
|
|
6115
6438
|
}
|
|
6116
6439
|
if (type === "dev") {
|
|
6117
|
-
return
|
|
6440
|
+
return path17.join(base, "dev.log");
|
|
6118
6441
|
}
|
|
6119
6442
|
if (type === "dev-std") {
|
|
6120
|
-
return
|
|
6443
|
+
return path17.join(base, "dev.std.log");
|
|
6121
6444
|
}
|
|
6122
6445
|
if (type === "install-dep-std") {
|
|
6123
|
-
return
|
|
6446
|
+
return path17.join(base, "install-dep.std.log");
|
|
6124
6447
|
}
|
|
6125
6448
|
if (type === "browser") {
|
|
6126
|
-
return
|
|
6449
|
+
return path17.join(base, "browser.log");
|
|
6127
6450
|
}
|
|
6128
6451
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6129
6452
|
}
|
|
@@ -6185,17 +6508,18 @@ var commands = [
|
|
|
6185
6508
|
syncCommand,
|
|
6186
6509
|
actionPluginCommandGroup,
|
|
6187
6510
|
capabilityCommandGroup,
|
|
6511
|
+
componentCommandGroup,
|
|
6188
6512
|
migrationCommand,
|
|
6189
6513
|
readLogsCommand
|
|
6190
6514
|
];
|
|
6191
6515
|
|
|
6192
6516
|
// src/index.ts
|
|
6193
|
-
var envPath =
|
|
6194
|
-
if (
|
|
6517
|
+
var envPath = path18.join(process.cwd(), ".env");
|
|
6518
|
+
if (fs22.existsSync(envPath)) {
|
|
6195
6519
|
dotenvConfig({ path: envPath });
|
|
6196
6520
|
}
|
|
6197
|
-
var __dirname =
|
|
6198
|
-
var pkg = JSON.parse(
|
|
6521
|
+
var __dirname = path18.dirname(fileURLToPath4(import.meta.url));
|
|
6522
|
+
var pkg = JSON.parse(fs22.readFileSync(path18.join(__dirname, "../package.json"), "utf-8"));
|
|
6199
6523
|
var cli = new FullstackCLI(pkg.version);
|
|
6200
6524
|
cli.useAll(commands);
|
|
6201
6525
|
cli.run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.22-alpha.0",
|
|
4
4
|
"description": "CLI tool for fullstack template management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,18 +32,23 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@lark-apaas/http-client": "^0.1.2",
|
|
35
|
+
"@lydell/node-pty": "1.1.0",
|
|
35
36
|
"@vercel/nft": "^0.30.3",
|
|
36
37
|
"commander": "^13.0.0",
|
|
38
|
+
"debug": "^4.4.3",
|
|
37
39
|
"dotenv": "^16.0.0",
|
|
38
40
|
"drizzle-kit": "0.31.5",
|
|
39
41
|
"drizzle-orm": "0.44.6",
|
|
42
|
+
"es-toolkit": "^1.44.0",
|
|
40
43
|
"inflection": "^3.0.2",
|
|
41
44
|
"pinyin-pro": "^3.27.0",
|
|
42
45
|
"postgres": "^3.4.3",
|
|
46
|
+
"shadcn": "3.8.2",
|
|
43
47
|
"ts-morph": "^27.0.0",
|
|
44
48
|
"zod-to-json-schema": "^3.24.1"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
51
|
+
"@types/debug": "^4",
|
|
47
52
|
"@types/node": "^22.0.0",
|
|
48
53
|
"tsup": "^8.3.5",
|
|
49
54
|
"typescript": "^5.9.2",
|