@lark-apaas/fullstack-cli 1.1.67-alpha.20260914114352 → 1.1.67-alpha.20260915105805
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 +412 -327
- package/package.json +2 -1
- package/templates/scripts/lint.js +94 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs31 from "fs";
|
|
3
|
+
import path27 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -2478,8 +2478,8 @@ var genDbSchemaCommand = {
|
|
|
2478
2478
|
};
|
|
2479
2479
|
|
|
2480
2480
|
// src/commands/sync/run.handler.ts
|
|
2481
|
-
import
|
|
2482
|
-
import
|
|
2481
|
+
import path7 from "path";
|
|
2482
|
+
import fs9 from "fs";
|
|
2483
2483
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2484
2484
|
|
|
2485
2485
|
// src/config/sync.ts
|
|
@@ -2581,6 +2581,29 @@ function buildDefaultRules(opts) {
|
|
|
2581
2581
|
type: "file",
|
|
2582
2582
|
overwrite: true
|
|
2583
2583
|
},
|
|
2584
|
+
// UI 留在 server/mcp/ui,但使用 Agent 生成的独立浏览器配置。
|
|
2585
|
+
// 不生成 UI 目录;仅给已有 Nest 工程增量补服务端排除项。
|
|
2586
|
+
{ onlyNestjs: true, type: "typescript-exclude", to: "tsconfig.node.json", path: "server/mcp/ui" },
|
|
2587
|
+
{ onlyNestjs: true, type: "add-script", name: "type:check:mcp-ui", command: "node ./scripts/lint.js --typecheck-mcp-ui", overwrite: false },
|
|
2588
|
+
{ onlyNestjs: true, type: "add-script", name: "eslint:mcp-ui", command: "node ./scripts/lint.js --eslint-mcp-ui", overwrite: false },
|
|
2589
|
+
{
|
|
2590
|
+
onlyNestjs: true,
|
|
2591
|
+
type: "patch-script",
|
|
2592
|
+
name: "type:check",
|
|
2593
|
+
to: "node ./scripts/lint.js --typecheck",
|
|
2594
|
+
ifEquals: [
|
|
2595
|
+
'concurrently -n "server,client" -c "blue,green" "npm run type:check:server" "npm run type:check:client"',
|
|
2596
|
+
'concurrently "npm run type:check:server" "npm run type:check:client"',
|
|
2597
|
+
'concurrently "npm run type:check:client" "npm run type:check:server"'
|
|
2598
|
+
]
|
|
2599
|
+
},
|
|
2600
|
+
{
|
|
2601
|
+
onlyNestjs: true,
|
|
2602
|
+
type: "patch-script",
|
|
2603
|
+
name: "eslint",
|
|
2604
|
+
to: 'eslint . --quiet --ignore-pattern "server/mcp/ui/**"',
|
|
2605
|
+
ifEquals: ["eslint . --quiet", "eslint ."]
|
|
2606
|
+
},
|
|
2584
2607
|
// 9. 把模板版本的 lint 脚本替换为支持 --files 的 runner
|
|
2585
2608
|
// 只识别平台模板生成的 `concurrently ...` 形态,用户真正改写过的脚本保持原样
|
|
2586
2609
|
{
|
|
@@ -2750,18 +2773,86 @@ function activateGitHooks(userProjectRoot) {
|
|
|
2750
2773
|
return { action: "already-active" };
|
|
2751
2774
|
}
|
|
2752
2775
|
|
|
2776
|
+
// src/commands/sync/typescript-exclude.ts
|
|
2777
|
+
import fs7 from "fs";
|
|
2778
|
+
import path5 from "path";
|
|
2779
|
+
import ts from "typescript";
|
|
2780
|
+
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
2781
|
+
function excludeTypeScriptPath(filename, excludedPath) {
|
|
2782
|
+
if (!fs7.existsSync(filename)) return;
|
|
2783
|
+
const source = fs7.readFileSync(filename, "utf8");
|
|
2784
|
+
const errors = [];
|
|
2785
|
+
const raw = parse(source, errors, { allowTrailingComma: true });
|
|
2786
|
+
if (errors.length || !raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
2787
|
+
throw new Error(`Invalid TypeScript configuration: ${filename}`);
|
|
2788
|
+
}
|
|
2789
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(filename, {}, {
|
|
2790
|
+
...ts.sys,
|
|
2791
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
2792
|
+
throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
const diagnostics = parsed?.errors.filter((d) => d.code !== 18003 && d.code !== 18002) ?? [];
|
|
2796
|
+
if (!parsed || diagnostics.length) {
|
|
2797
|
+
throw new Error(`Cannot migrate ${filename}: ${diagnostics.map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n")).join("; ")}`);
|
|
2798
|
+
}
|
|
2799
|
+
const inherited = parsed.raw.exclude;
|
|
2800
|
+
const excludes = inherited ?? [
|
|
2801
|
+
"node_modules",
|
|
2802
|
+
"bower_components",
|
|
2803
|
+
"jspm_packages",
|
|
2804
|
+
...[parsed.options.outDir, parsed.options.declarationDir].filter((p) => Boolean(p)).map((p) => path5.relative(path5.dirname(filename), p).split(path5.sep).join("/"))
|
|
2805
|
+
];
|
|
2806
|
+
if (!Array.isArray(excludes) || excludes.some((p) => typeof p !== "string")) {
|
|
2807
|
+
throw new Error(`Invalid exclude array: ${filename}`);
|
|
2808
|
+
}
|
|
2809
|
+
if (excludes.includes(excludedPath)) return;
|
|
2810
|
+
const formattingOptions = { insertSpaces: true, tabSize: 2, eol: source.includes("\r\n") ? "\r\n" : "\n" };
|
|
2811
|
+
const edits = raw.exclude ? modify(source, ["exclude", raw.exclude.length], excludedPath, { formattingOptions, isArrayInsertion: true }) : modify(source, ["exclude"], [...excludes, excludedPath], { formattingOptions });
|
|
2812
|
+
fs7.writeFileSync(filename, applyEdits(source, edits));
|
|
2813
|
+
console.log(`[fullstack-cli] \u2713 ${path5.basename(filename)} (exclude ${excludedPath})`);
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
// src/commands/sync/resolve-stack.ts
|
|
2817
|
+
import fs8 from "fs";
|
|
2818
|
+
import path6 from "path";
|
|
2819
|
+
function resolveStack(userProjectRoot) {
|
|
2820
|
+
const sparkMetaPath = path6.join(userProjectRoot, ".spark", "meta.json");
|
|
2821
|
+
if (!fs8.existsSync(sparkMetaPath)) {
|
|
2822
|
+
return void 0;
|
|
2823
|
+
}
|
|
2824
|
+
try {
|
|
2825
|
+
const meta = JSON.parse(fs8.readFileSync(sparkMetaPath, "utf-8"));
|
|
2826
|
+
return typeof meta.stack === "string" ? meta.stack : void 0;
|
|
2827
|
+
} catch (error) {
|
|
2828
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2829
|
+
console.warn(`[fullstack-cli] \u26A0 Failed to read .spark/meta.json, fallback to default sync: ${message}`);
|
|
2830
|
+
return void 0;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
function isNestjsProject(root, stack) {
|
|
2834
|
+
if (stack === "nestjs-react-fullstack") return true;
|
|
2835
|
+
if (stack) return false;
|
|
2836
|
+
try {
|
|
2837
|
+
const pkg2 = JSON.parse(fs8.readFileSync(path6.join(root, "package.json"), "utf8"));
|
|
2838
|
+
return Boolean(pkg2.dependencies?.["@nestjs/core"]) && fs8.existsSync(path6.join(root, "tsconfig.node.json"));
|
|
2839
|
+
} catch {
|
|
2840
|
+
return false;
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2753
2844
|
// src/commands/sync/run.handler.ts
|
|
2754
2845
|
async function run2(options) {
|
|
2755
2846
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2756
2847
|
const __filename = fileURLToPath3(import.meta.url);
|
|
2757
|
-
const __dirname2 =
|
|
2758
|
-
const pluginRoot =
|
|
2848
|
+
const __dirname2 = path7.dirname(__filename);
|
|
2849
|
+
const pluginRoot = path7.resolve(__dirname2, "..");
|
|
2759
2850
|
if (userProjectRoot === pluginRoot) {
|
|
2760
2851
|
console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
|
|
2761
2852
|
process.exit(0);
|
|
2762
2853
|
}
|
|
2763
|
-
const userPackageJson =
|
|
2764
|
-
if (!
|
|
2854
|
+
const userPackageJson = path7.join(userProjectRoot, "package.json");
|
|
2855
|
+
if (!fs9.existsSync(userPackageJson)) {
|
|
2765
2856
|
console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
|
|
2766
2857
|
process.exit(0);
|
|
2767
2858
|
}
|
|
@@ -2775,7 +2866,9 @@ async function run2(options) {
|
|
|
2775
2866
|
console.warn("[fullstack-cli] No sync configuration found");
|
|
2776
2867
|
process.exit(0);
|
|
2777
2868
|
}
|
|
2869
|
+
const isNestjs = isNestjsProject(userProjectRoot, stack);
|
|
2778
2870
|
for (const rule of config.sync) {
|
|
2871
|
+
if (rule.onlyNestjs && !isNestjs) continue;
|
|
2779
2872
|
await syncRule(rule, pluginRoot, userProjectRoot);
|
|
2780
2873
|
}
|
|
2781
2874
|
if (config.permissions) {
|
|
@@ -2796,23 +2889,13 @@ async function run2(options) {
|
|
|
2796
2889
|
process.exit(1);
|
|
2797
2890
|
}
|
|
2798
2891
|
}
|
|
2799
|
-
function resolveStack(userProjectRoot) {
|
|
2800
|
-
const sparkMetaPath = path5.join(userProjectRoot, ".spark", "meta.json");
|
|
2801
|
-
if (!fs7.existsSync(sparkMetaPath)) {
|
|
2802
|
-
return void 0;
|
|
2803
|
-
}
|
|
2804
|
-
try {
|
|
2805
|
-
const meta = JSON.parse(fs7.readFileSync(sparkMetaPath, "utf-8"));
|
|
2806
|
-
return typeof meta.stack === "string" ? meta.stack : void 0;
|
|
2807
|
-
} catch (error) {
|
|
2808
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2809
|
-
console.warn(`[fullstack-cli] \u26A0 Failed to read .spark/meta.json, fallback to default sync: ${message}`);
|
|
2810
|
-
return void 0;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
2892
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2893
|
+
if (rule.type === "typescript-exclude") {
|
|
2894
|
+
excludeTypeScriptPath(path7.join(userProjectRoot, rule.to), rule.path);
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2814
2897
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2815
|
-
const destPath2 =
|
|
2898
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2816
2899
|
if (rule.type === "delete-file") {
|
|
2817
2900
|
deleteFile(destPath2);
|
|
2818
2901
|
} else {
|
|
@@ -2821,37 +2904,37 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2821
2904
|
return;
|
|
2822
2905
|
}
|
|
2823
2906
|
if (rule.type === "remove-line") {
|
|
2824
|
-
const destPath2 =
|
|
2907
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2825
2908
|
removeLineFromFile(destPath2, rule.pattern);
|
|
2826
2909
|
return;
|
|
2827
2910
|
}
|
|
2828
2911
|
if (rule.type === "add-script") {
|
|
2829
|
-
const packageJsonPath =
|
|
2912
|
+
const packageJsonPath = path7.join(userProjectRoot, "package.json");
|
|
2830
2913
|
addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
|
|
2831
2914
|
return;
|
|
2832
2915
|
}
|
|
2833
2916
|
if (rule.type === "patch-script") {
|
|
2834
|
-
const packageJsonPath =
|
|
2835
|
-
patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
|
|
2917
|
+
const packageJsonPath = path7.join(userProjectRoot, "package.json");
|
|
2918
|
+
patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith, rule.ifEquals);
|
|
2836
2919
|
return;
|
|
2837
2920
|
}
|
|
2838
2921
|
if (rule.type === "add-line") {
|
|
2839
|
-
const destPath2 =
|
|
2922
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2840
2923
|
addLineToFile(destPath2, rule.line);
|
|
2841
2924
|
return;
|
|
2842
2925
|
}
|
|
2843
2926
|
if (rule.type === "merge-json") {
|
|
2844
|
-
const srcPath2 =
|
|
2845
|
-
const destPath2 =
|
|
2927
|
+
const srcPath2 = path7.join(pluginRoot, rule.from);
|
|
2928
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2846
2929
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2847
2930
|
return;
|
|
2848
2931
|
}
|
|
2849
2932
|
if (!("from" in rule)) {
|
|
2850
2933
|
return;
|
|
2851
2934
|
}
|
|
2852
|
-
const srcPath =
|
|
2853
|
-
const destPath =
|
|
2854
|
-
if (!
|
|
2935
|
+
const srcPath = path7.join(pluginRoot, rule.from);
|
|
2936
|
+
const destPath = path7.join(userProjectRoot, rule.to);
|
|
2937
|
+
if (!fs9.existsSync(srcPath)) {
|
|
2855
2938
|
console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
|
|
2856
2939
|
return;
|
|
2857
2940
|
}
|
|
@@ -2868,68 +2951,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2868
2951
|
}
|
|
2869
2952
|
}
|
|
2870
2953
|
function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
|
|
2871
|
-
if (onlyIfExists && !
|
|
2872
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2954
|
+
if (onlyIfExists && !fs9.existsSync(dest)) {
|
|
2955
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (skipped, target not exists)`);
|
|
2873
2956
|
return;
|
|
2874
2957
|
}
|
|
2875
|
-
const destDir =
|
|
2876
|
-
if (!
|
|
2877
|
-
|
|
2958
|
+
const destDir = path7.dirname(dest);
|
|
2959
|
+
if (!fs9.existsSync(destDir)) {
|
|
2960
|
+
fs9.mkdirSync(destDir, { recursive: true });
|
|
2878
2961
|
}
|
|
2879
|
-
if (
|
|
2880
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2962
|
+
if (fs9.existsSync(dest) && !overwrite) {
|
|
2963
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (skipped, already exists)`);
|
|
2881
2964
|
return;
|
|
2882
2965
|
}
|
|
2883
|
-
|
|
2884
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2966
|
+
fs9.copyFileSync(src, dest);
|
|
2967
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dest)}`);
|
|
2885
2968
|
}
|
|
2886
2969
|
function syncDirectory(src, dest, overwrite = true) {
|
|
2887
|
-
if (!
|
|
2888
|
-
|
|
2970
|
+
if (!fs9.existsSync(dest)) {
|
|
2971
|
+
fs9.mkdirSync(dest, { recursive: true });
|
|
2889
2972
|
}
|
|
2890
|
-
const files =
|
|
2973
|
+
const files = fs9.readdirSync(src);
|
|
2891
2974
|
let count = 0;
|
|
2892
2975
|
files.forEach((file) => {
|
|
2893
|
-
const srcFile =
|
|
2894
|
-
const destFile =
|
|
2895
|
-
const stats =
|
|
2976
|
+
const srcFile = path7.join(src, file);
|
|
2977
|
+
const destFile = path7.join(dest, file);
|
|
2978
|
+
const stats = fs9.statSync(srcFile);
|
|
2896
2979
|
if (stats.isDirectory()) {
|
|
2897
2980
|
syncDirectory(srcFile, destFile, overwrite);
|
|
2898
2981
|
} else {
|
|
2899
|
-
if (overwrite || !
|
|
2900
|
-
|
|
2901
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2982
|
+
if (overwrite || !fs9.existsSync(destFile)) {
|
|
2983
|
+
fs9.copyFileSync(srcFile, destFile);
|
|
2984
|
+
console.log(`[fullstack-cli] \u2713 ${path7.relative(dest, destFile)}`);
|
|
2902
2985
|
count++;
|
|
2903
2986
|
}
|
|
2904
2987
|
}
|
|
2905
2988
|
});
|
|
2906
2989
|
if (count > 0) {
|
|
2907
|
-
console.log(`[fullstack-cli] Synced ${count} files to ${
|
|
2990
|
+
console.log(`[fullstack-cli] Synced ${count} files to ${path7.basename(dest)}/`);
|
|
2908
2991
|
}
|
|
2909
2992
|
}
|
|
2910
2993
|
function appendToFile(src, dest) {
|
|
2911
|
-
const content =
|
|
2994
|
+
const content = fs9.readFileSync(src, "utf-8");
|
|
2912
2995
|
let existingContent = "";
|
|
2913
|
-
if (
|
|
2914
|
-
existingContent =
|
|
2996
|
+
if (fs9.existsSync(dest)) {
|
|
2997
|
+
existingContent = fs9.readFileSync(dest, "utf-8");
|
|
2915
2998
|
}
|
|
2916
2999
|
if (existingContent.includes(content.trim())) {
|
|
2917
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
3000
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (already contains content)`);
|
|
2918
3001
|
return;
|
|
2919
3002
|
}
|
|
2920
|
-
|
|
2921
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
3003
|
+
fs9.appendFileSync(dest, content);
|
|
3004
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dest)} (appended)`);
|
|
2922
3005
|
}
|
|
2923
3006
|
function setPermissions(permissions, projectRoot) {
|
|
2924
3007
|
for (const [pattern, mode] of Object.entries(permissions)) {
|
|
2925
3008
|
if (pattern === "**/*.sh") {
|
|
2926
|
-
const scriptsDir =
|
|
2927
|
-
if (
|
|
2928
|
-
const files =
|
|
3009
|
+
const scriptsDir = path7.join(projectRoot, "scripts");
|
|
3010
|
+
if (fs9.existsSync(scriptsDir)) {
|
|
3011
|
+
const files = fs9.readdirSync(scriptsDir);
|
|
2929
3012
|
files.forEach((file) => {
|
|
2930
3013
|
if (file.endsWith(".sh")) {
|
|
2931
|
-
const filePath =
|
|
2932
|
-
|
|
3014
|
+
const filePath = path7.join(scriptsDir, file);
|
|
3015
|
+
fs9.chmodSync(filePath, mode);
|
|
2933
3016
|
}
|
|
2934
3017
|
});
|
|
2935
3018
|
}
|
|
@@ -2937,27 +3020,27 @@ function setPermissions(permissions, projectRoot) {
|
|
|
2937
3020
|
}
|
|
2938
3021
|
}
|
|
2939
3022
|
function deleteFile(filePath) {
|
|
2940
|
-
if (
|
|
2941
|
-
|
|
2942
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
3023
|
+
if (fs9.existsSync(filePath)) {
|
|
3024
|
+
fs9.unlinkSync(filePath);
|
|
3025
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(filePath)} (deleted)`);
|
|
2943
3026
|
} else {
|
|
2944
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
3027
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(filePath)} (not found)`);
|
|
2945
3028
|
}
|
|
2946
3029
|
}
|
|
2947
3030
|
function deleteDirectory(dirPath) {
|
|
2948
|
-
if (
|
|
2949
|
-
|
|
2950
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
3031
|
+
if (fs9.existsSync(dirPath)) {
|
|
3032
|
+
fs9.rmSync(dirPath, { recursive: true });
|
|
3033
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dirPath)} (deleted)`);
|
|
2951
3034
|
} else {
|
|
2952
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
3035
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dirPath)} (not found)`);
|
|
2953
3036
|
}
|
|
2954
3037
|
}
|
|
2955
3038
|
function addScript(packageJsonPath, name, command, overwrite) {
|
|
2956
|
-
if (!
|
|
3039
|
+
if (!fs9.existsSync(packageJsonPath)) {
|
|
2957
3040
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2958
3041
|
return;
|
|
2959
3042
|
}
|
|
2960
|
-
const content =
|
|
3043
|
+
const content = fs9.readFileSync(packageJsonPath, "utf-8");
|
|
2961
3044
|
const pkg2 = JSON.parse(content);
|
|
2962
3045
|
if (!pkg2.scripts) {
|
|
2963
3046
|
pkg2.scripts = {};
|
|
@@ -2969,16 +3052,16 @@ function addScript(packageJsonPath, name, command, overwrite) {
|
|
|
2969
3052
|
}
|
|
2970
3053
|
}
|
|
2971
3054
|
pkg2.scripts[name] = command;
|
|
2972
|
-
|
|
3055
|
+
fs9.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
2973
3056
|
console.log(`[fullstack-cli] \u2713 scripts.${name}`);
|
|
2974
3057
|
}
|
|
2975
|
-
function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
2976
|
-
if (!
|
|
3058
|
+
function patchScript(packageJsonPath, name, to, ifStartsWith, ifEquals) {
|
|
3059
|
+
if (!fs9.existsSync(packageJsonPath)) {
|
|
2977
3060
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
2978
3061
|
return;
|
|
2979
3062
|
}
|
|
2980
3063
|
try {
|
|
2981
|
-
const content =
|
|
3064
|
+
const content = fs9.readFileSync(packageJsonPath, "utf-8");
|
|
2982
3065
|
const pkg2 = JSON.parse(content);
|
|
2983
3066
|
const current = pkg2.scripts?.[name];
|
|
2984
3067
|
if (!current) {
|
|
@@ -2989,14 +3072,14 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
|
2989
3072
|
console.log(`[fullstack-cli] \u25CB scripts.${name} (already patched)`);
|
|
2990
3073
|
return;
|
|
2991
3074
|
}
|
|
2992
|
-
if (!current.startsWith(ifStartsWith)) {
|
|
3075
|
+
if (!(ifEquals ? ifEquals.includes(current) : ifStartsWith && current.startsWith(ifStartsWith))) {
|
|
2993
3076
|
console.warn(
|
|
2994
3077
|
`[fullstack-cli] \u26A0 Skipped patching scripts.${name} because it has been customized`
|
|
2995
3078
|
);
|
|
2996
3079
|
return;
|
|
2997
3080
|
}
|
|
2998
3081
|
pkg2.scripts[name] = to;
|
|
2999
|
-
|
|
3082
|
+
fs9.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
3000
3083
|
console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
|
|
3001
3084
|
} catch (error) {
|
|
3002
3085
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -3004,38 +3087,38 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
|
3004
3087
|
}
|
|
3005
3088
|
}
|
|
3006
3089
|
function addLineToFile(filePath, line) {
|
|
3007
|
-
const fileName =
|
|
3008
|
-
if (!
|
|
3090
|
+
const fileName = path7.basename(filePath);
|
|
3091
|
+
if (!fs9.existsSync(filePath)) {
|
|
3009
3092
|
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
3010
3093
|
return;
|
|
3011
3094
|
}
|
|
3012
|
-
const content =
|
|
3095
|
+
const content = fs9.readFileSync(filePath, "utf-8");
|
|
3013
3096
|
const lines = content.split("\n").map((l) => l.trim());
|
|
3014
3097
|
if (lines.includes(line)) {
|
|
3015
3098
|
console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
|
|
3016
3099
|
return;
|
|
3017
3100
|
}
|
|
3018
3101
|
const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
|
|
3019
|
-
|
|
3102
|
+
fs9.appendFileSync(filePath, appendContent);
|
|
3020
3103
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
3021
3104
|
}
|
|
3022
3105
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
3023
|
-
const fileName =
|
|
3024
|
-
if (!
|
|
3106
|
+
const fileName = path7.basename(dest);
|
|
3107
|
+
if (!fs9.existsSync(src)) {
|
|
3025
3108
|
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
3026
3109
|
return;
|
|
3027
3110
|
}
|
|
3028
|
-
const templateContent = JSON.parse(
|
|
3029
|
-
if (!
|
|
3030
|
-
const destDir =
|
|
3031
|
-
if (!
|
|
3032
|
-
|
|
3111
|
+
const templateContent = JSON.parse(fs9.readFileSync(src, "utf-8"));
|
|
3112
|
+
if (!fs9.existsSync(dest)) {
|
|
3113
|
+
const destDir = path7.dirname(dest);
|
|
3114
|
+
if (!fs9.existsSync(destDir)) {
|
|
3115
|
+
fs9.mkdirSync(destDir, { recursive: true });
|
|
3033
3116
|
}
|
|
3034
|
-
|
|
3117
|
+
fs9.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
3035
3118
|
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
3036
3119
|
return;
|
|
3037
3120
|
}
|
|
3038
|
-
const userContent = JSON.parse(
|
|
3121
|
+
const userContent = JSON.parse(fs9.readFileSync(dest, "utf-8"));
|
|
3039
3122
|
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
3040
3123
|
const userStr = JSON.stringify(userContent, null, 2);
|
|
3041
3124
|
const mergedStr = JSON.stringify(merged, null, 2);
|
|
@@ -3043,7 +3126,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
|
|
|
3043
3126
|
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
3044
3127
|
return;
|
|
3045
3128
|
}
|
|
3046
|
-
|
|
3129
|
+
fs9.writeFileSync(dest, mergedStr + "\n");
|
|
3047
3130
|
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
3048
3131
|
}
|
|
3049
3132
|
|
|
@@ -3202,12 +3285,12 @@ async function reportCreateInstanceEvent(pluginKey, version) {
|
|
|
3202
3285
|
|
|
3203
3286
|
// src/utils/git.ts
|
|
3204
3287
|
import { execSync, spawnSync as spawnSync3 } from "child_process";
|
|
3205
|
-
import
|
|
3206
|
-
import
|
|
3288
|
+
import fs10 from "fs";
|
|
3289
|
+
import path8 from "path";
|
|
3207
3290
|
function isGitRepository(cwd = process.cwd()) {
|
|
3208
3291
|
try {
|
|
3209
|
-
const gitDir =
|
|
3210
|
-
if (
|
|
3292
|
+
const gitDir = path8.join(cwd, ".git");
|
|
3293
|
+
if (fs10.existsSync(gitDir)) {
|
|
3211
3294
|
return true;
|
|
3212
3295
|
}
|
|
3213
3296
|
const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
|
|
@@ -3236,7 +3319,7 @@ function getChangedFiles(cwd = process.cwd()) {
|
|
|
3236
3319
|
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
3237
3320
|
const filteredFiles = [];
|
|
3238
3321
|
for (const filePath of filesToStage) {
|
|
3239
|
-
if (
|
|
3322
|
+
if (fs10.existsSync(path8.join(cwd, filePath))) {
|
|
3240
3323
|
filteredFiles.push(filePath);
|
|
3241
3324
|
continue;
|
|
3242
3325
|
}
|
|
@@ -3321,20 +3404,20 @@ Auto-committed by fullstack-cli`;
|
|
|
3321
3404
|
}
|
|
3322
3405
|
|
|
3323
3406
|
// src/utils/package-json.ts
|
|
3324
|
-
import
|
|
3325
|
-
import
|
|
3407
|
+
import fs11 from "fs";
|
|
3408
|
+
import path9 from "path";
|
|
3326
3409
|
function readPackageJson(cwd = process.cwd()) {
|
|
3327
|
-
const pkgPath =
|
|
3328
|
-
if (!
|
|
3410
|
+
const pkgPath = path9.join(cwd, "package.json");
|
|
3411
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
3329
3412
|
throw new Error(`package.json not found at ${pkgPath}`);
|
|
3330
3413
|
}
|
|
3331
|
-
const content =
|
|
3414
|
+
const content = fs11.readFileSync(pkgPath, "utf-8");
|
|
3332
3415
|
return JSON.parse(content);
|
|
3333
3416
|
}
|
|
3334
3417
|
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
3335
|
-
const pkgPath =
|
|
3418
|
+
const pkgPath = path9.join(cwd, "package.json");
|
|
3336
3419
|
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
3337
|
-
|
|
3420
|
+
fs11.writeFileSync(pkgPath, content, "utf-8");
|
|
3338
3421
|
}
|
|
3339
3422
|
function removeUpgradeScript(pkg2) {
|
|
3340
3423
|
if (!pkg2.scripts?.upgrade) {
|
|
@@ -3379,15 +3462,15 @@ function cleanupPackageJson(cwd = process.cwd()) {
|
|
|
3379
3462
|
}
|
|
3380
3463
|
|
|
3381
3464
|
// src/commands/upgrade/shared/utils.ts
|
|
3382
|
-
import
|
|
3383
|
-
import
|
|
3465
|
+
import path10 from "path";
|
|
3466
|
+
import fs12 from "fs";
|
|
3384
3467
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3385
3468
|
function getCliVersion() {
|
|
3386
3469
|
try {
|
|
3387
3470
|
const __filename = fileURLToPath4(import.meta.url);
|
|
3388
|
-
const __dirname2 =
|
|
3389
|
-
const pkgPath =
|
|
3390
|
-
const pkgContent =
|
|
3471
|
+
const __dirname2 = path10.dirname(__filename);
|
|
3472
|
+
const pkgPath = path10.resolve(__dirname2, "../../../package.json");
|
|
3473
|
+
const pkgContent = fs12.readFileSync(pkgPath, "utf-8");
|
|
3391
3474
|
const pkg2 = JSON.parse(pkgContent);
|
|
3392
3475
|
return pkg2.version || "unknown";
|
|
3393
3476
|
} catch {
|
|
@@ -3396,11 +3479,14 @@ function getCliVersion() {
|
|
|
3396
3479
|
}
|
|
3397
3480
|
|
|
3398
3481
|
// src/commands/upgrade/get-upgrade-files.ts
|
|
3399
|
-
function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
3400
|
-
const
|
|
3482
|
+
function getUpgradeFilesToStage(disableGenOpenapi = true, userProjectRoot = process.env.INIT_CWD || process.cwd()) {
|
|
3483
|
+
const stack = resolveStack(userProjectRoot);
|
|
3484
|
+
const isNestjs = isNestjsProject(userProjectRoot, stack);
|
|
3485
|
+
const syncConfig = genSyncConfig(stack, { disableGenOpenapi });
|
|
3401
3486
|
const filesToStage = /* @__PURE__ */ new Set();
|
|
3402
3487
|
syncConfig.sync.forEach((rule) => {
|
|
3403
|
-
if (rule.
|
|
3488
|
+
if (rule.onlyNestjs && !isNestjs) return;
|
|
3489
|
+
if (rule.type === "file" || rule.type === "directory" || rule.type === "merge-json" || rule.type === "typescript-exclude") {
|
|
3404
3490
|
filesToStage.add(rule.to);
|
|
3405
3491
|
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
3406
3492
|
filesToStage.add(rule.to);
|
|
@@ -3431,7 +3517,7 @@ async function run3(options = {}) {
|
|
|
3431
3517
|
if (shouldCommit) {
|
|
3432
3518
|
console.log("[fullstack-cli] Step 3/3: Committing changes...");
|
|
3433
3519
|
const version = getCliVersion();
|
|
3434
|
-
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
|
|
3520
|
+
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true, userProjectRoot);
|
|
3435
3521
|
autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
|
|
3436
3522
|
} else {
|
|
3437
3523
|
console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
|
|
@@ -3446,8 +3532,8 @@ async function run3(options = {}) {
|
|
|
3446
3532
|
|
|
3447
3533
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3448
3534
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
3449
|
-
import
|
|
3450
|
-
import
|
|
3535
|
+
import fs13 from "fs";
|
|
3536
|
+
import path11 from "path";
|
|
3451
3537
|
|
|
3452
3538
|
// src/utils/grayscale/config.ts
|
|
3453
3539
|
function getGrayscaleConfig(configJson) {
|
|
@@ -3695,8 +3781,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3695
3781
|
if (version) {
|
|
3696
3782
|
let current = "";
|
|
3697
3783
|
try {
|
|
3698
|
-
const installedPkgPath =
|
|
3699
|
-
const installedPkg = JSON.parse(
|
|
3784
|
+
const installedPkgPath = path11.join(cwd, "node_modules", pkg2, "package.json");
|
|
3785
|
+
const installedPkg = JSON.parse(fs13.readFileSync(installedPkgPath, "utf-8"));
|
|
3700
3786
|
current = installedPkg.version || "";
|
|
3701
3787
|
} catch (err) {
|
|
3702
3788
|
const code = err?.code;
|
|
@@ -3814,8 +3900,8 @@ var depsCommand = {
|
|
|
3814
3900
|
|
|
3815
3901
|
// src/commands/upgrade/global-deps/run.handler.ts
|
|
3816
3902
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
3817
|
-
import
|
|
3818
|
-
import
|
|
3903
|
+
import fs14 from "fs";
|
|
3904
|
+
import path12 from "path";
|
|
3819
3905
|
var MANAGED_GLOBAL_CLIS = [
|
|
3820
3906
|
"@lark-apaas/fullstack-cli",
|
|
3821
3907
|
"@lark-apaas/miaoda-cli"
|
|
@@ -3826,15 +3912,15 @@ function readGlobalInstalledVersion(pkg2) {
|
|
|
3826
3912
|
if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
|
|
3827
3913
|
candidates.push("/usr");
|
|
3828
3914
|
candidates.push("/usr/local");
|
|
3829
|
-
if (process.env.HOME) candidates.push(
|
|
3915
|
+
if (process.env.HOME) candidates.push(path12.join(process.env.HOME, ".npm-global"));
|
|
3830
3916
|
const seen = /* @__PURE__ */ new Set();
|
|
3831
3917
|
for (const prefix of candidates) {
|
|
3832
3918
|
if (seen.has(prefix)) continue;
|
|
3833
3919
|
seen.add(prefix);
|
|
3834
3920
|
try {
|
|
3835
|
-
const pkgPath =
|
|
3836
|
-
if (
|
|
3837
|
-
const meta = JSON.parse(
|
|
3921
|
+
const pkgPath = path12.join(prefix, "lib", "node_modules", pkg2, "package.json");
|
|
3922
|
+
if (fs14.existsSync(pkgPath)) {
|
|
3923
|
+
const meta = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3838
3924
|
if (meta && typeof meta.version === "string") return meta.version;
|
|
3839
3925
|
}
|
|
3840
3926
|
} catch (err) {
|
|
@@ -3931,8 +4017,8 @@ var upgradeCommand = {
|
|
|
3931
4017
|
};
|
|
3932
4018
|
|
|
3933
4019
|
// src/commands/action-plugin/utils.ts
|
|
3934
|
-
import
|
|
3935
|
-
import
|
|
4020
|
+
import fs15 from "fs";
|
|
4021
|
+
import path13 from "path";
|
|
3936
4022
|
import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
|
|
3937
4023
|
function parsePluginName(input) {
|
|
3938
4024
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3950,18 +4036,18 @@ function getProjectRoot() {
|
|
|
3950
4036
|
return process.cwd();
|
|
3951
4037
|
}
|
|
3952
4038
|
function getPackageJsonPath() {
|
|
3953
|
-
return
|
|
4039
|
+
return path13.join(getProjectRoot(), "package.json");
|
|
3954
4040
|
}
|
|
3955
4041
|
function getPluginPath(pluginName) {
|
|
3956
|
-
return
|
|
4042
|
+
return path13.join(getProjectRoot(), "node_modules", pluginName);
|
|
3957
4043
|
}
|
|
3958
4044
|
function readPackageJson2() {
|
|
3959
4045
|
const pkgPath = getPackageJsonPath();
|
|
3960
|
-
if (!
|
|
4046
|
+
if (!fs15.existsSync(pkgPath)) {
|
|
3961
4047
|
throw new Error("package.json not found in current directory");
|
|
3962
4048
|
}
|
|
3963
4049
|
try {
|
|
3964
|
-
const content =
|
|
4050
|
+
const content = fs15.readFileSync(pkgPath, "utf-8");
|
|
3965
4051
|
return JSON.parse(content);
|
|
3966
4052
|
} catch {
|
|
3967
4053
|
throw new Error("Failed to parse package.json");
|
|
@@ -3969,7 +4055,7 @@ function readPackageJson2() {
|
|
|
3969
4055
|
}
|
|
3970
4056
|
function writePackageJson2(pkg2) {
|
|
3971
4057
|
const pkgPath = getPackageJsonPath();
|
|
3972
|
-
|
|
4058
|
+
fs15.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3973
4059
|
}
|
|
3974
4060
|
function readActionPlugins() {
|
|
3975
4061
|
const pkg2 = readPackageJson2();
|
|
@@ -4002,12 +4088,12 @@ function npmInstall(tgzPath) {
|
|
|
4002
4088
|
}
|
|
4003
4089
|
}
|
|
4004
4090
|
function getPackageVersion(pluginName) {
|
|
4005
|
-
const pkgJsonPath =
|
|
4006
|
-
if (!
|
|
4091
|
+
const pkgJsonPath = path13.join(getPluginPath(pluginName), "package.json");
|
|
4092
|
+
if (!fs15.existsSync(pkgJsonPath)) {
|
|
4007
4093
|
return null;
|
|
4008
4094
|
}
|
|
4009
4095
|
try {
|
|
4010
|
-
const content =
|
|
4096
|
+
const content = fs15.readFileSync(pkgJsonPath, "utf-8");
|
|
4011
4097
|
const pkg2 = JSON.parse(content);
|
|
4012
4098
|
return pkg2.version || null;
|
|
4013
4099
|
} catch {
|
|
@@ -4015,49 +4101,49 @@ function getPackageVersion(pluginName) {
|
|
|
4015
4101
|
}
|
|
4016
4102
|
}
|
|
4017
4103
|
function readPluginPackageJson(pluginPath) {
|
|
4018
|
-
const pkgJsonPath =
|
|
4019
|
-
if (!
|
|
4104
|
+
const pkgJsonPath = path13.join(pluginPath, "package.json");
|
|
4105
|
+
if (!fs15.existsSync(pkgJsonPath)) {
|
|
4020
4106
|
return null;
|
|
4021
4107
|
}
|
|
4022
4108
|
try {
|
|
4023
|
-
const content =
|
|
4109
|
+
const content = fs15.readFileSync(pkgJsonPath, "utf-8");
|
|
4024
4110
|
return JSON.parse(content);
|
|
4025
4111
|
} catch {
|
|
4026
4112
|
return null;
|
|
4027
4113
|
}
|
|
4028
4114
|
}
|
|
4029
4115
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
4030
|
-
const nodeModulesPath =
|
|
4031
|
-
const targetDir =
|
|
4032
|
-
const scopeDir =
|
|
4033
|
-
if (!
|
|
4034
|
-
|
|
4116
|
+
const nodeModulesPath = path13.join(getProjectRoot(), "node_modules");
|
|
4117
|
+
const targetDir = path13.join(nodeModulesPath, pluginName);
|
|
4118
|
+
const scopeDir = path13.dirname(targetDir);
|
|
4119
|
+
if (!fs15.existsSync(scopeDir)) {
|
|
4120
|
+
fs15.mkdirSync(scopeDir, { recursive: true });
|
|
4035
4121
|
}
|
|
4036
|
-
if (
|
|
4037
|
-
|
|
4122
|
+
if (fs15.existsSync(targetDir)) {
|
|
4123
|
+
fs15.rmSync(targetDir, { recursive: true });
|
|
4038
4124
|
}
|
|
4039
|
-
const tempDir =
|
|
4040
|
-
if (
|
|
4041
|
-
|
|
4125
|
+
const tempDir = path13.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
4126
|
+
if (fs15.existsSync(tempDir)) {
|
|
4127
|
+
fs15.rmSync(tempDir, { recursive: true });
|
|
4042
4128
|
}
|
|
4043
|
-
|
|
4129
|
+
fs15.mkdirSync(tempDir, { recursive: true });
|
|
4044
4130
|
try {
|
|
4045
4131
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
4046
|
-
const extractedDir =
|
|
4047
|
-
if (
|
|
4048
|
-
|
|
4132
|
+
const extractedDir = path13.join(tempDir, "package");
|
|
4133
|
+
if (fs15.existsSync(extractedDir)) {
|
|
4134
|
+
fs15.renameSync(extractedDir, targetDir);
|
|
4049
4135
|
} else {
|
|
4050
|
-
const files =
|
|
4136
|
+
const files = fs15.readdirSync(tempDir);
|
|
4051
4137
|
if (files.length === 1) {
|
|
4052
|
-
|
|
4138
|
+
fs15.renameSync(path13.join(tempDir, files[0]), targetDir);
|
|
4053
4139
|
} else {
|
|
4054
4140
|
throw new Error("Unexpected tgz structure");
|
|
4055
4141
|
}
|
|
4056
4142
|
}
|
|
4057
4143
|
return targetDir;
|
|
4058
4144
|
} finally {
|
|
4059
|
-
if (
|
|
4060
|
-
|
|
4145
|
+
if (fs15.existsSync(tempDir)) {
|
|
4146
|
+
fs15.rmSync(tempDir, { recursive: true });
|
|
4061
4147
|
}
|
|
4062
4148
|
}
|
|
4063
4149
|
}
|
|
@@ -4066,10 +4152,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
4066
4152
|
return [];
|
|
4067
4153
|
}
|
|
4068
4154
|
const missing = [];
|
|
4069
|
-
const nodeModulesPath =
|
|
4155
|
+
const nodeModulesPath = path13.join(getProjectRoot(), "node_modules");
|
|
4070
4156
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
4071
|
-
const depPath =
|
|
4072
|
-
if (!
|
|
4157
|
+
const depPath = path13.join(nodeModulesPath, depName);
|
|
4158
|
+
if (!fs15.existsSync(depPath)) {
|
|
4073
4159
|
missing.push(depName);
|
|
4074
4160
|
}
|
|
4075
4161
|
}
|
|
@@ -4093,16 +4179,16 @@ function installMissingDeps(deps) {
|
|
|
4093
4179
|
}
|
|
4094
4180
|
function removePluginDirectory(pluginName) {
|
|
4095
4181
|
const pluginPath = getPluginPath(pluginName);
|
|
4096
|
-
if (
|
|
4097
|
-
|
|
4182
|
+
if (fs15.existsSync(pluginPath)) {
|
|
4183
|
+
fs15.rmSync(pluginPath, { recursive: true });
|
|
4098
4184
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
4099
4185
|
}
|
|
4100
4186
|
}
|
|
4101
4187
|
|
|
4102
4188
|
// src/commands/action-plugin/api-client.ts
|
|
4103
4189
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
4104
|
-
import
|
|
4105
|
-
import
|
|
4190
|
+
import fs16 from "fs";
|
|
4191
|
+
import path14 from "path";
|
|
4106
4192
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
4107
4193
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
4108
4194
|
const client = getHttpClient();
|
|
@@ -4167,19 +4253,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
4167
4253
|
return Buffer.from(arrayBuffer);
|
|
4168
4254
|
}
|
|
4169
4255
|
function getPluginCacheDir() {
|
|
4170
|
-
return
|
|
4256
|
+
return path14.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
4171
4257
|
}
|
|
4172
4258
|
function ensureCacheDir() {
|
|
4173
4259
|
const cacheDir = getPluginCacheDir();
|
|
4174
|
-
if (!
|
|
4175
|
-
|
|
4260
|
+
if (!fs16.existsSync(cacheDir)) {
|
|
4261
|
+
fs16.mkdirSync(cacheDir, { recursive: true });
|
|
4176
4262
|
}
|
|
4177
4263
|
}
|
|
4178
4264
|
function getTempFilePath(pluginKey, version) {
|
|
4179
4265
|
ensureCacheDir();
|
|
4180
4266
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4181
4267
|
const filename = `${safeKey}@${version}.tgz`;
|
|
4182
|
-
return
|
|
4268
|
+
return path14.join(getPluginCacheDir(), filename);
|
|
4183
4269
|
}
|
|
4184
4270
|
var MAX_RETRIES = 2;
|
|
4185
4271
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -4216,7 +4302,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
4216
4302
|
);
|
|
4217
4303
|
}
|
|
4218
4304
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
4219
|
-
|
|
4305
|
+
fs16.writeFileSync(tgzPath, tgzBuffer);
|
|
4220
4306
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
4221
4307
|
return {
|
|
4222
4308
|
tgzPath,
|
|
@@ -4230,18 +4316,18 @@ function getCachePath(pluginKey, version) {
|
|
|
4230
4316
|
ensureCacheDir();
|
|
4231
4317
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4232
4318
|
const filename = `${safeKey}@${version}.tgz`;
|
|
4233
|
-
return
|
|
4319
|
+
return path14.join(getPluginCacheDir(), filename);
|
|
4234
4320
|
}
|
|
4235
4321
|
function hasCachedPlugin(pluginKey, version) {
|
|
4236
4322
|
const cachePath = getCachePath(pluginKey, version);
|
|
4237
|
-
return
|
|
4323
|
+
return fs16.existsSync(cachePath);
|
|
4238
4324
|
}
|
|
4239
4325
|
function listCachedPlugins() {
|
|
4240
4326
|
const cacheDir = getPluginCacheDir();
|
|
4241
|
-
if (!
|
|
4327
|
+
if (!fs16.existsSync(cacheDir)) {
|
|
4242
4328
|
return [];
|
|
4243
4329
|
}
|
|
4244
|
-
const files =
|
|
4330
|
+
const files = fs16.readdirSync(cacheDir);
|
|
4245
4331
|
const result = [];
|
|
4246
4332
|
for (const file of files) {
|
|
4247
4333
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -4249,8 +4335,8 @@ function listCachedPlugins() {
|
|
|
4249
4335
|
if (!match) continue;
|
|
4250
4336
|
const [, rawName, version] = match;
|
|
4251
4337
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
4252
|
-
const filePath =
|
|
4253
|
-
const stat =
|
|
4338
|
+
const filePath = path14.join(cacheDir, file);
|
|
4339
|
+
const stat = fs16.statSync(filePath);
|
|
4254
4340
|
result.push({
|
|
4255
4341
|
name,
|
|
4256
4342
|
version,
|
|
@@ -4263,14 +4349,14 @@ function listCachedPlugins() {
|
|
|
4263
4349
|
}
|
|
4264
4350
|
function cleanAllCache() {
|
|
4265
4351
|
const cacheDir = getPluginCacheDir();
|
|
4266
|
-
if (!
|
|
4352
|
+
if (!fs16.existsSync(cacheDir)) {
|
|
4267
4353
|
return 0;
|
|
4268
4354
|
}
|
|
4269
|
-
const files =
|
|
4355
|
+
const files = fs16.readdirSync(cacheDir);
|
|
4270
4356
|
let count = 0;
|
|
4271
4357
|
for (const file of files) {
|
|
4272
4358
|
if (file.endsWith(".tgz")) {
|
|
4273
|
-
|
|
4359
|
+
fs16.unlinkSync(path14.join(cacheDir, file));
|
|
4274
4360
|
count++;
|
|
4275
4361
|
}
|
|
4276
4362
|
}
|
|
@@ -4278,21 +4364,21 @@ function cleanAllCache() {
|
|
|
4278
4364
|
}
|
|
4279
4365
|
function cleanPluginCache(pluginKey, version) {
|
|
4280
4366
|
const cacheDir = getPluginCacheDir();
|
|
4281
|
-
if (!
|
|
4367
|
+
if (!fs16.existsSync(cacheDir)) {
|
|
4282
4368
|
return 0;
|
|
4283
4369
|
}
|
|
4284
4370
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4285
|
-
const files =
|
|
4371
|
+
const files = fs16.readdirSync(cacheDir);
|
|
4286
4372
|
let count = 0;
|
|
4287
4373
|
for (const file of files) {
|
|
4288
4374
|
if (version) {
|
|
4289
4375
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
4290
|
-
|
|
4376
|
+
fs16.unlinkSync(path14.join(cacheDir, file));
|
|
4291
4377
|
count++;
|
|
4292
4378
|
}
|
|
4293
4379
|
} else {
|
|
4294
4380
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
4295
|
-
|
|
4381
|
+
fs16.unlinkSync(path14.join(cacheDir, file));
|
|
4296
4382
|
count++;
|
|
4297
4383
|
}
|
|
4298
4384
|
}
|
|
@@ -4719,45 +4805,45 @@ var actionPluginCommandGroup = {
|
|
|
4719
4805
|
};
|
|
4720
4806
|
|
|
4721
4807
|
// src/commands/capability/utils.ts
|
|
4722
|
-
import
|
|
4808
|
+
import fs17 from "fs";
|
|
4723
4809
|
import { createRequire as createRequire2 } from "module";
|
|
4724
|
-
import
|
|
4810
|
+
import path15 from "path";
|
|
4725
4811
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4726
4812
|
var SHARED_CAPABILITIES_DIR = "shared/capabilities";
|
|
4727
4813
|
function getProjectRoot2() {
|
|
4728
4814
|
return process.cwd();
|
|
4729
4815
|
}
|
|
4730
4816
|
function getCapabilitiesDir() {
|
|
4731
|
-
const sharedDir =
|
|
4732
|
-
if (
|
|
4817
|
+
const sharedDir = path15.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
|
|
4818
|
+
if (fs17.existsSync(sharedDir)) {
|
|
4733
4819
|
return sharedDir;
|
|
4734
4820
|
}
|
|
4735
|
-
return
|
|
4821
|
+
return path15.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4736
4822
|
}
|
|
4737
4823
|
function getCapabilityPath(id) {
|
|
4738
|
-
return
|
|
4824
|
+
return path15.join(getCapabilitiesDir(), `${id}.json`);
|
|
4739
4825
|
}
|
|
4740
4826
|
function getPluginManifestPath(pluginKey) {
|
|
4741
|
-
return
|
|
4827
|
+
return path15.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4742
4828
|
}
|
|
4743
4829
|
function capabilitiesDirExists() {
|
|
4744
|
-
return
|
|
4830
|
+
return fs17.existsSync(getCapabilitiesDir());
|
|
4745
4831
|
}
|
|
4746
4832
|
function listCapabilityIds() {
|
|
4747
4833
|
const dir = getCapabilitiesDir();
|
|
4748
|
-
if (!
|
|
4834
|
+
if (!fs17.existsSync(dir)) {
|
|
4749
4835
|
return [];
|
|
4750
4836
|
}
|
|
4751
|
-
const files =
|
|
4837
|
+
const files = fs17.readdirSync(dir);
|
|
4752
4838
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4753
4839
|
}
|
|
4754
4840
|
function readCapability(id) {
|
|
4755
4841
|
const filePath = getCapabilityPath(id);
|
|
4756
|
-
if (!
|
|
4842
|
+
if (!fs17.existsSync(filePath)) {
|
|
4757
4843
|
throw new Error(`Capability not found: ${id}`);
|
|
4758
4844
|
}
|
|
4759
4845
|
try {
|
|
4760
|
-
const content =
|
|
4846
|
+
const content = fs17.readFileSync(filePath, "utf-8");
|
|
4761
4847
|
return JSON.parse(content);
|
|
4762
4848
|
} catch (error) {
|
|
4763
4849
|
if (error instanceof SyntaxError) {
|
|
@@ -4784,11 +4870,11 @@ function readAllCapabilities() {
|
|
|
4784
4870
|
}
|
|
4785
4871
|
function readPluginManifest(pluginKey) {
|
|
4786
4872
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4787
|
-
if (!
|
|
4873
|
+
if (!fs17.existsSync(manifestPath)) {
|
|
4788
4874
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4789
4875
|
}
|
|
4790
4876
|
try {
|
|
4791
|
-
const content =
|
|
4877
|
+
const content = fs17.readFileSync(manifestPath, "utf-8");
|
|
4792
4878
|
return JSON.parse(content);
|
|
4793
4879
|
} catch (error) {
|
|
4794
4880
|
if (error instanceof SyntaxError) {
|
|
@@ -4803,19 +4889,9 @@ function isDynamicSchema(schema) {
|
|
|
4803
4889
|
function hasValidParamsSchema(paramsSchema) {
|
|
4804
4890
|
return paramsSchema !== void 0 && Object.keys(paramsSchema).length > 0;
|
|
4805
4891
|
}
|
|
4806
|
-
function resolveActionInputSchema(manifestAction, actionIndex, paramsSchema, pluginInstance) {
|
|
4807
|
-
if (isDynamicSchema(manifestAction.inputSchema)) {
|
|
4808
|
-
if (!pluginInstance) throw new Error("Plugin instance not available for dynamic schema");
|
|
4809
|
-
const jsonSchema = pluginInstance.getInputJsonSchema(manifestAction.key);
|
|
4810
|
-
if (!jsonSchema) throw new Error(`Failed to get input schema for action: ${manifestAction.key}`);
|
|
4811
|
-
return jsonSchema;
|
|
4812
|
-
}
|
|
4813
|
-
if (actionIndex === 0 && hasValidParamsSchema(paramsSchema)) return paramsSchema;
|
|
4814
|
-
return manifestAction.inputSchema;
|
|
4815
|
-
}
|
|
4816
4892
|
async function loadPlugin(pluginKey) {
|
|
4817
4893
|
try {
|
|
4818
|
-
const userRequire = createRequire2(
|
|
4894
|
+
const userRequire = createRequire2(path15.join(getProjectRoot2(), "package.json"));
|
|
4819
4895
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4820
4896
|
const pluginModule = await import(resolvedPath);
|
|
4821
4897
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4849,12 +4925,21 @@ async function hydrateCapability(capability) {
|
|
|
4849
4925
|
const actions = [];
|
|
4850
4926
|
for (let index = 0; index < manifest.actions.length; index++) {
|
|
4851
4927
|
const manifestAction = manifest.actions[index];
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
pluginInstance
|
|
4857
|
-
|
|
4928
|
+
let inputSchema;
|
|
4929
|
+
if (index === 0 && hasValidParamsSchema(capability.paramsSchema)) {
|
|
4930
|
+
inputSchema = capability.paramsSchema;
|
|
4931
|
+
} else if (isDynamicSchema(manifestAction.inputSchema)) {
|
|
4932
|
+
if (!pluginInstance) {
|
|
4933
|
+
throw new Error(`Plugin instance not available for dynamic schema`);
|
|
4934
|
+
}
|
|
4935
|
+
const jsonSchema = pluginInstance.getInputJsonSchema(manifestAction.key);
|
|
4936
|
+
if (!jsonSchema) {
|
|
4937
|
+
throw new Error(`Failed to get input schema for action: ${manifestAction.key}`);
|
|
4938
|
+
}
|
|
4939
|
+
inputSchema = jsonSchema;
|
|
4940
|
+
} else {
|
|
4941
|
+
inputSchema = manifestAction.inputSchema;
|
|
4942
|
+
}
|
|
4858
4943
|
let outputSchema;
|
|
4859
4944
|
if (isDynamicSchema(manifestAction.outputSchema)) {
|
|
4860
4945
|
if (!pluginInstance) {
|
|
@@ -4969,8 +5054,8 @@ var capabilityCommandGroup = {
|
|
|
4969
5054
|
import { execFile } from "child_process";
|
|
4970
5055
|
|
|
4971
5056
|
// src/commands/component/registry-preparer.ts
|
|
4972
|
-
import
|
|
4973
|
-
import
|
|
5057
|
+
import fs18 from "fs";
|
|
5058
|
+
import path16 from "path";
|
|
4974
5059
|
import os from "os";
|
|
4975
5060
|
|
|
4976
5061
|
// src/commands/component/service.ts
|
|
@@ -5030,7 +5115,7 @@ async function sendInstallEvent(key) {
|
|
|
5030
5115
|
}
|
|
5031
5116
|
|
|
5032
5117
|
// src/commands/component/registry-preparer.ts
|
|
5033
|
-
var REGISTRY_TEMP_DIR =
|
|
5118
|
+
var REGISTRY_TEMP_DIR = path16.join(os.tmpdir(), "miaoda-registry");
|
|
5034
5119
|
function parseComponentKey(key) {
|
|
5035
5120
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
5036
5121
|
if (!match) {
|
|
@@ -5042,11 +5127,11 @@ function parseComponentKey(key) {
|
|
|
5042
5127
|
}
|
|
5043
5128
|
function getLocalRegistryPath(key) {
|
|
5044
5129
|
const { scope, name } = parseComponentKey(key);
|
|
5045
|
-
return
|
|
5130
|
+
return path16.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
5046
5131
|
}
|
|
5047
5132
|
function ensureDir(dirPath) {
|
|
5048
|
-
if (!
|
|
5049
|
-
|
|
5133
|
+
if (!fs18.existsSync(dirPath)) {
|
|
5134
|
+
fs18.mkdirSync(dirPath, { recursive: true });
|
|
5050
5135
|
}
|
|
5051
5136
|
}
|
|
5052
5137
|
async function prepareRecursive(key, visited) {
|
|
@@ -5079,8 +5164,8 @@ async function prepareRecursive(key, visited) {
|
|
|
5079
5164
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
5080
5165
|
};
|
|
5081
5166
|
const localPath = getLocalRegistryPath(key);
|
|
5082
|
-
ensureDir(
|
|
5083
|
-
|
|
5167
|
+
ensureDir(path16.dirname(localPath));
|
|
5168
|
+
fs18.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
5084
5169
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
5085
5170
|
}
|
|
5086
5171
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -5090,18 +5175,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
5090
5175
|
}
|
|
5091
5176
|
function cleanupTempDir() {
|
|
5092
5177
|
try {
|
|
5093
|
-
if (
|
|
5094
|
-
|
|
5178
|
+
if (fs18.existsSync(REGISTRY_TEMP_DIR)) {
|
|
5179
|
+
fs18.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
5095
5180
|
}
|
|
5096
5181
|
} catch {
|
|
5097
5182
|
}
|
|
5098
5183
|
}
|
|
5099
5184
|
function getDownloadedRegistryItem(itemId) {
|
|
5100
5185
|
const localPath = getLocalRegistryPath(itemId);
|
|
5101
|
-
if (!
|
|
5186
|
+
if (!fs18.existsSync(localPath)) {
|
|
5102
5187
|
return null;
|
|
5103
5188
|
}
|
|
5104
|
-
const content =
|
|
5189
|
+
const content = fs18.readFileSync(localPath, "utf-8");
|
|
5105
5190
|
return JSON.parse(content);
|
|
5106
5191
|
}
|
|
5107
5192
|
|
|
@@ -5269,58 +5354,58 @@ var componentCommandGroup = {
|
|
|
5269
5354
|
};
|
|
5270
5355
|
|
|
5271
5356
|
// src/commands/migration/version-manager.ts
|
|
5272
|
-
import
|
|
5273
|
-
import
|
|
5357
|
+
import fs19 from "fs";
|
|
5358
|
+
import path17 from "path";
|
|
5274
5359
|
var PACKAGE_JSON = "package.json";
|
|
5275
5360
|
var VERSION_FIELD = "migrationVersion";
|
|
5276
5361
|
function getPackageJsonPath2() {
|
|
5277
|
-
return
|
|
5362
|
+
return path17.join(process.cwd(), PACKAGE_JSON);
|
|
5278
5363
|
}
|
|
5279
5364
|
function getCurrentVersion() {
|
|
5280
5365
|
const pkgPath = getPackageJsonPath2();
|
|
5281
|
-
if (!
|
|
5366
|
+
if (!fs19.existsSync(pkgPath)) {
|
|
5282
5367
|
throw new Error("package.json not found");
|
|
5283
5368
|
}
|
|
5284
|
-
const pkg2 = JSON.parse(
|
|
5369
|
+
const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
|
|
5285
5370
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
5286
5371
|
}
|
|
5287
5372
|
function setCurrentVersion(version) {
|
|
5288
5373
|
const pkgPath = getPackageJsonPath2();
|
|
5289
|
-
const pkg2 = JSON.parse(
|
|
5374
|
+
const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
|
|
5290
5375
|
pkg2[VERSION_FIELD] = version;
|
|
5291
|
-
|
|
5376
|
+
fs19.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
5292
5377
|
}
|
|
5293
5378
|
|
|
5294
5379
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5295
|
-
import
|
|
5296
|
-
import
|
|
5380
|
+
import fs21 from "fs";
|
|
5381
|
+
import path19 from "path";
|
|
5297
5382
|
|
|
5298
5383
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
5299
|
-
import
|
|
5300
|
-
import
|
|
5384
|
+
import fs20 from "fs";
|
|
5385
|
+
import path18 from "path";
|
|
5301
5386
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
5302
5387
|
function getProjectRoot3() {
|
|
5303
5388
|
return process.cwd();
|
|
5304
5389
|
}
|
|
5305
5390
|
function getCapabilitiesDir2() {
|
|
5306
|
-
return
|
|
5391
|
+
return path18.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
5307
5392
|
}
|
|
5308
5393
|
function getPluginManifestPath2(pluginKey) {
|
|
5309
|
-
return
|
|
5394
|
+
return path18.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
5310
5395
|
}
|
|
5311
5396
|
|
|
5312
5397
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5313
5398
|
function detectJsonMigration() {
|
|
5314
5399
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5315
|
-
const oldFilePath =
|
|
5316
|
-
if (!
|
|
5400
|
+
const oldFilePath = path19.join(capabilitiesDir, "capabilities.json");
|
|
5401
|
+
if (!fs21.existsSync(oldFilePath)) {
|
|
5317
5402
|
return {
|
|
5318
5403
|
needsMigration: false,
|
|
5319
5404
|
reason: "capabilities.json not found"
|
|
5320
5405
|
};
|
|
5321
5406
|
}
|
|
5322
5407
|
try {
|
|
5323
|
-
const content =
|
|
5408
|
+
const content = fs21.readFileSync(oldFilePath, "utf-8");
|
|
5324
5409
|
const parsed = JSON.parse(content);
|
|
5325
5410
|
if (!Array.isArray(parsed)) {
|
|
5326
5411
|
return {
|
|
@@ -5371,8 +5456,8 @@ async function check(options) {
|
|
|
5371
5456
|
}
|
|
5372
5457
|
|
|
5373
5458
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5374
|
-
import
|
|
5375
|
-
import
|
|
5459
|
+
import fs22 from "fs";
|
|
5460
|
+
import path20 from "path";
|
|
5376
5461
|
|
|
5377
5462
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5378
5463
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5602,18 +5687,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5602
5687
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5603
5688
|
function loadExistingCapabilities() {
|
|
5604
5689
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5605
|
-
if (!
|
|
5690
|
+
if (!fs22.existsSync(capabilitiesDir)) {
|
|
5606
5691
|
return [];
|
|
5607
5692
|
}
|
|
5608
|
-
const files =
|
|
5693
|
+
const files = fs22.readdirSync(capabilitiesDir);
|
|
5609
5694
|
const capabilities = [];
|
|
5610
5695
|
for (const file of files) {
|
|
5611
5696
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5612
5697
|
continue;
|
|
5613
5698
|
}
|
|
5614
5699
|
try {
|
|
5615
|
-
const filePath =
|
|
5616
|
-
const content =
|
|
5700
|
+
const filePath = path20.join(capabilitiesDir, file);
|
|
5701
|
+
const content = fs22.readFileSync(filePath, "utf-8");
|
|
5617
5702
|
const capability = JSON.parse(content);
|
|
5618
5703
|
if (capability.id && capability.pluginKey) {
|
|
5619
5704
|
capabilities.push(capability);
|
|
@@ -5671,9 +5756,9 @@ async function migrateJsonFiles(options) {
|
|
|
5671
5756
|
}
|
|
5672
5757
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5673
5758
|
for (const cap of newCapabilities) {
|
|
5674
|
-
const filePath =
|
|
5759
|
+
const filePath = path20.join(capabilitiesDir, `${cap.id}.json`);
|
|
5675
5760
|
const content = JSON.stringify(cap, null, 2);
|
|
5676
|
-
|
|
5761
|
+
fs22.writeFileSync(filePath, content, "utf-8");
|
|
5677
5762
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5678
5763
|
}
|
|
5679
5764
|
return {
|
|
@@ -5685,11 +5770,11 @@ async function migrateJsonFiles(options) {
|
|
|
5685
5770
|
}
|
|
5686
5771
|
|
|
5687
5772
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5688
|
-
import
|
|
5773
|
+
import fs23 from "fs";
|
|
5689
5774
|
function isPluginInstalled2(pluginKey) {
|
|
5690
5775
|
const actionPlugins = readActionPlugins();
|
|
5691
5776
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5692
|
-
return
|
|
5777
|
+
return fs23.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5693
5778
|
}
|
|
5694
5779
|
function detectPluginsToInstall(capabilities) {
|
|
5695
5780
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5765,12 +5850,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5765
5850
|
}
|
|
5766
5851
|
|
|
5767
5852
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5768
|
-
import
|
|
5853
|
+
import path22 from "path";
|
|
5769
5854
|
import { Project as Project3 } from "ts-morph";
|
|
5770
5855
|
|
|
5771
5856
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5772
|
-
import
|
|
5773
|
-
import
|
|
5857
|
+
import fs24 from "fs";
|
|
5858
|
+
import path21 from "path";
|
|
5774
5859
|
var EXCLUDED_DIRS = [
|
|
5775
5860
|
"node_modules",
|
|
5776
5861
|
"dist",
|
|
@@ -5785,9 +5870,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5785
5870
|
/\.d\.ts$/
|
|
5786
5871
|
];
|
|
5787
5872
|
function scanDirectory(dir, files = []) {
|
|
5788
|
-
const entries =
|
|
5873
|
+
const entries = fs24.readdirSync(dir, { withFileTypes: true });
|
|
5789
5874
|
for (const entry of entries) {
|
|
5790
|
-
const fullPath =
|
|
5875
|
+
const fullPath = path21.join(dir, entry.name);
|
|
5791
5876
|
if (entry.isDirectory()) {
|
|
5792
5877
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5793
5878
|
continue;
|
|
@@ -5803,14 +5888,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5803
5888
|
return files;
|
|
5804
5889
|
}
|
|
5805
5890
|
function scanServerFiles() {
|
|
5806
|
-
const serverDir =
|
|
5807
|
-
if (!
|
|
5891
|
+
const serverDir = path21.join(getProjectRoot3(), "server");
|
|
5892
|
+
if (!fs24.existsSync(serverDir)) {
|
|
5808
5893
|
return [];
|
|
5809
5894
|
}
|
|
5810
5895
|
return scanDirectory(serverDir);
|
|
5811
5896
|
}
|
|
5812
5897
|
function hasCapabilityImport(filePath) {
|
|
5813
|
-
const content =
|
|
5898
|
+
const content = fs24.readFileSync(filePath, "utf-8");
|
|
5814
5899
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5815
5900
|
}
|
|
5816
5901
|
function scanFilesToMigrate() {
|
|
@@ -6187,7 +6272,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6187
6272
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
6188
6273
|
const classInfo = analyzeClass(sourceFile);
|
|
6189
6274
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
6190
|
-
const relativePath =
|
|
6275
|
+
const relativePath = path22.relative(getProjectRoot3(), filePath);
|
|
6191
6276
|
return {
|
|
6192
6277
|
filePath: relativePath,
|
|
6193
6278
|
imports,
|
|
@@ -6198,7 +6283,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6198
6283
|
};
|
|
6199
6284
|
}
|
|
6200
6285
|
function migrateFile(project, analysis, dryRun) {
|
|
6201
|
-
const absolutePath =
|
|
6286
|
+
const absolutePath = path22.join(getProjectRoot3(), analysis.filePath);
|
|
6202
6287
|
if (!analysis.canAutoMigrate) {
|
|
6203
6288
|
return {
|
|
6204
6289
|
filePath: analysis.filePath,
|
|
@@ -6301,17 +6386,17 @@ function getSuggestion(analysis) {
|
|
|
6301
6386
|
}
|
|
6302
6387
|
|
|
6303
6388
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
6304
|
-
import
|
|
6305
|
-
import
|
|
6389
|
+
import fs25 from "fs";
|
|
6390
|
+
import path23 from "path";
|
|
6306
6391
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
6307
6392
|
const deletedFiles = [];
|
|
6308
6393
|
const errors = [];
|
|
6309
6394
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6310
|
-
const oldJsonPath =
|
|
6311
|
-
if (
|
|
6395
|
+
const oldJsonPath = path23.join(capabilitiesDir, "capabilities.json");
|
|
6396
|
+
if (fs25.existsSync(oldJsonPath)) {
|
|
6312
6397
|
try {
|
|
6313
6398
|
if (!dryRun) {
|
|
6314
|
-
|
|
6399
|
+
fs25.unlinkSync(oldJsonPath);
|
|
6315
6400
|
}
|
|
6316
6401
|
deletedFiles.push("capabilities.json");
|
|
6317
6402
|
} catch (error) {
|
|
@@ -6319,11 +6404,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6319
6404
|
}
|
|
6320
6405
|
}
|
|
6321
6406
|
for (const cap of capabilities) {
|
|
6322
|
-
const tsFilePath =
|
|
6323
|
-
if (
|
|
6407
|
+
const tsFilePath = path23.join(capabilitiesDir, `${cap.id}.ts`);
|
|
6408
|
+
if (fs25.existsSync(tsFilePath)) {
|
|
6324
6409
|
try {
|
|
6325
6410
|
if (!dryRun) {
|
|
6326
|
-
|
|
6411
|
+
fs25.unlinkSync(tsFilePath);
|
|
6327
6412
|
}
|
|
6328
6413
|
deletedFiles.push(`${cap.id}.ts`);
|
|
6329
6414
|
} catch (error) {
|
|
@@ -6339,8 +6424,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6339
6424
|
}
|
|
6340
6425
|
|
|
6341
6426
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
6342
|
-
import
|
|
6343
|
-
import
|
|
6427
|
+
import fs26 from "fs";
|
|
6428
|
+
import path24 from "path";
|
|
6344
6429
|
var REPORT_FILE = "capability-migration-report.md";
|
|
6345
6430
|
function printSummary(result) {
|
|
6346
6431
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6503,15 +6588,15 @@ async function generateReport(result) {
|
|
|
6503
6588
|
}
|
|
6504
6589
|
lines.push("");
|
|
6505
6590
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6506
|
-
if (!
|
|
6591
|
+
if (!fs26.existsSync(logDir)) {
|
|
6507
6592
|
return;
|
|
6508
6593
|
}
|
|
6509
|
-
const reportDir =
|
|
6510
|
-
if (!
|
|
6511
|
-
|
|
6594
|
+
const reportDir = path24.join(logDir, "migration");
|
|
6595
|
+
if (!fs26.existsSync(reportDir)) {
|
|
6596
|
+
fs26.mkdirSync(reportDir, { recursive: true });
|
|
6512
6597
|
}
|
|
6513
|
-
const reportPath =
|
|
6514
|
-
|
|
6598
|
+
const reportPath = path24.join(reportDir, REPORT_FILE);
|
|
6599
|
+
fs26.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6515
6600
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6516
6601
|
}
|
|
6517
6602
|
|
|
@@ -7043,10 +7128,10 @@ var migrationCommand = {
|
|
|
7043
7128
|
};
|
|
7044
7129
|
|
|
7045
7130
|
// src/commands/read-logs/index.ts
|
|
7046
|
-
import
|
|
7131
|
+
import path25 from "path";
|
|
7047
7132
|
|
|
7048
7133
|
// src/commands/read-logs/std-utils.ts
|
|
7049
|
-
import
|
|
7134
|
+
import fs27 from "fs";
|
|
7050
7135
|
function formatStdPrefixTime(localTime) {
|
|
7051
7136
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
7052
7137
|
if (!match) return localTime;
|
|
@@ -7076,11 +7161,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
7076
7161
|
return `[${time}] ${content}`;
|
|
7077
7162
|
}
|
|
7078
7163
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
7079
|
-
const stat =
|
|
7164
|
+
const stat = fs27.statSync(filePath);
|
|
7080
7165
|
if (stat.size === 0) {
|
|
7081
7166
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
7082
7167
|
}
|
|
7083
|
-
const fd =
|
|
7168
|
+
const fd = fs27.openSync(filePath, "r");
|
|
7084
7169
|
const chunkSize = 64 * 1024;
|
|
7085
7170
|
let position = stat.size;
|
|
7086
7171
|
let remainder = "";
|
|
@@ -7094,7 +7179,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7094
7179
|
const length = Math.min(chunkSize, position);
|
|
7095
7180
|
position -= length;
|
|
7096
7181
|
const buffer = Buffer.alloc(length);
|
|
7097
|
-
|
|
7182
|
+
fs27.readSync(fd, buffer, 0, length, position);
|
|
7098
7183
|
let chunk = buffer.toString("utf8");
|
|
7099
7184
|
if (remainder) {
|
|
7100
7185
|
chunk += remainder;
|
|
@@ -7136,7 +7221,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7136
7221
|
}
|
|
7137
7222
|
}
|
|
7138
7223
|
} finally {
|
|
7139
|
-
|
|
7224
|
+
fs27.closeSync(fd);
|
|
7140
7225
|
}
|
|
7141
7226
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
7142
7227
|
}
|
|
@@ -7157,21 +7242,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
7157
7242
|
}
|
|
7158
7243
|
|
|
7159
7244
|
// src/commands/read-logs/tail.ts
|
|
7160
|
-
import
|
|
7245
|
+
import fs28 from "fs";
|
|
7161
7246
|
function fileExists(filePath) {
|
|
7162
7247
|
try {
|
|
7163
|
-
|
|
7248
|
+
fs28.accessSync(filePath, fs28.constants.F_OK | fs28.constants.R_OK);
|
|
7164
7249
|
return true;
|
|
7165
7250
|
} catch {
|
|
7166
7251
|
return false;
|
|
7167
7252
|
}
|
|
7168
7253
|
}
|
|
7169
7254
|
function readFileTailLines(filePath, maxLines) {
|
|
7170
|
-
const stat =
|
|
7255
|
+
const stat = fs28.statSync(filePath);
|
|
7171
7256
|
if (stat.size === 0) {
|
|
7172
7257
|
return [];
|
|
7173
7258
|
}
|
|
7174
|
-
const fd =
|
|
7259
|
+
const fd = fs28.openSync(filePath, "r");
|
|
7175
7260
|
const chunkSize = 64 * 1024;
|
|
7176
7261
|
const chunks = [];
|
|
7177
7262
|
let position = stat.size;
|
|
@@ -7181,13 +7266,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7181
7266
|
const length = Math.min(chunkSize, position);
|
|
7182
7267
|
position -= length;
|
|
7183
7268
|
const buffer = Buffer.alloc(length);
|
|
7184
|
-
|
|
7269
|
+
fs28.readSync(fd, buffer, 0, length, position);
|
|
7185
7270
|
chunks.unshift(buffer.toString("utf8"));
|
|
7186
7271
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
7187
7272
|
collectedLines += chunkLines;
|
|
7188
7273
|
}
|
|
7189
7274
|
} finally {
|
|
7190
|
-
|
|
7275
|
+
fs28.closeSync(fd);
|
|
7191
7276
|
}
|
|
7192
7277
|
const content = chunks.join("");
|
|
7193
7278
|
const allLines = content.split("\n");
|
|
@@ -7203,11 +7288,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7203
7288
|
return allLines.slice(allLines.length - maxLines);
|
|
7204
7289
|
}
|
|
7205
7290
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
7206
|
-
const stat =
|
|
7291
|
+
const stat = fs28.statSync(filePath);
|
|
7207
7292
|
if (stat.size === 0) {
|
|
7208
7293
|
return { lines: [], totalLinesCount: 0 };
|
|
7209
7294
|
}
|
|
7210
|
-
const fd =
|
|
7295
|
+
const fd = fs28.openSync(filePath, "r");
|
|
7211
7296
|
const chunkSize = 64 * 1024;
|
|
7212
7297
|
let position = stat.size;
|
|
7213
7298
|
let remainder = "";
|
|
@@ -7219,7 +7304,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7219
7304
|
const length = Math.min(chunkSize, position);
|
|
7220
7305
|
position -= length;
|
|
7221
7306
|
const buffer = Buffer.alloc(length);
|
|
7222
|
-
|
|
7307
|
+
fs28.readSync(fd, buffer, 0, length, position);
|
|
7223
7308
|
let chunk = buffer.toString("utf8");
|
|
7224
7309
|
if (remainder) {
|
|
7225
7310
|
chunk += remainder;
|
|
@@ -7250,7 +7335,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7250
7335
|
}
|
|
7251
7336
|
}
|
|
7252
7337
|
} finally {
|
|
7253
|
-
|
|
7338
|
+
fs28.closeSync(fd);
|
|
7254
7339
|
}
|
|
7255
7340
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7256
7341
|
}
|
|
@@ -7392,7 +7477,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7392
7477
|
}
|
|
7393
7478
|
|
|
7394
7479
|
// src/commands/read-logs/json-lines.ts
|
|
7395
|
-
import
|
|
7480
|
+
import fs29 from "fs";
|
|
7396
7481
|
|
|
7397
7482
|
// src/commands/read-logs/structured-log.ts
|
|
7398
7483
|
function normalizeLevelName(value) {
|
|
@@ -7468,11 +7553,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7468
7553
|
return set.size > 0 ? set : null;
|
|
7469
7554
|
}
|
|
7470
7555
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7471
|
-
const stat =
|
|
7556
|
+
const stat = fs29.statSync(filePath);
|
|
7472
7557
|
if (stat.size === 0) {
|
|
7473
7558
|
return { lines: [], totalLinesCount: 0 };
|
|
7474
7559
|
}
|
|
7475
|
-
const fd =
|
|
7560
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7476
7561
|
const chunkSize = 64 * 1024;
|
|
7477
7562
|
let position = stat.size;
|
|
7478
7563
|
let remainder = "";
|
|
@@ -7487,7 +7572,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7487
7572
|
const length = Math.min(chunkSize, position);
|
|
7488
7573
|
position -= length;
|
|
7489
7574
|
const buffer = Buffer.alloc(length);
|
|
7490
|
-
|
|
7575
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7491
7576
|
let chunk = buffer.toString("utf8");
|
|
7492
7577
|
if (remainder) {
|
|
7493
7578
|
chunk += remainder;
|
|
@@ -7549,7 +7634,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7549
7634
|
}
|
|
7550
7635
|
}
|
|
7551
7636
|
} finally {
|
|
7552
|
-
|
|
7637
|
+
fs29.closeSync(fd);
|
|
7553
7638
|
}
|
|
7554
7639
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7555
7640
|
}
|
|
@@ -7592,11 +7677,11 @@ function extractTraceId(obj) {
|
|
|
7592
7677
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7593
7678
|
const wanted = traceId.trim();
|
|
7594
7679
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7595
|
-
const stat =
|
|
7680
|
+
const stat = fs29.statSync(filePath);
|
|
7596
7681
|
if (stat.size === 0) {
|
|
7597
7682
|
return { lines: [], totalLinesCount: 0 };
|
|
7598
7683
|
}
|
|
7599
|
-
const fd =
|
|
7684
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7600
7685
|
const chunkSize = 64 * 1024;
|
|
7601
7686
|
let position = stat.size;
|
|
7602
7687
|
let remainder = "";
|
|
@@ -7609,7 +7694,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7609
7694
|
const length = Math.min(chunkSize, position);
|
|
7610
7695
|
position -= length;
|
|
7611
7696
|
const buffer = Buffer.alloc(length);
|
|
7612
|
-
|
|
7697
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7613
7698
|
let chunk = buffer.toString("utf8");
|
|
7614
7699
|
if (remainder) {
|
|
7615
7700
|
chunk += remainder;
|
|
@@ -7662,7 +7747,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7662
7747
|
}
|
|
7663
7748
|
}
|
|
7664
7749
|
} finally {
|
|
7665
|
-
|
|
7750
|
+
fs29.closeSync(fd);
|
|
7666
7751
|
}
|
|
7667
7752
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7668
7753
|
}
|
|
@@ -7671,11 +7756,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7671
7756
|
if (!wantedLevelSet) {
|
|
7672
7757
|
return { lines: [], totalLinesCount: 0 };
|
|
7673
7758
|
}
|
|
7674
|
-
const stat =
|
|
7759
|
+
const stat = fs29.statSync(filePath);
|
|
7675
7760
|
if (stat.size === 0) {
|
|
7676
7761
|
return { lines: [], totalLinesCount: 0 };
|
|
7677
7762
|
}
|
|
7678
|
-
const fd =
|
|
7763
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7679
7764
|
const chunkSize = 64 * 1024;
|
|
7680
7765
|
let position = stat.size;
|
|
7681
7766
|
let remainder = "";
|
|
@@ -7687,7 +7772,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7687
7772
|
const length = Math.min(chunkSize, position);
|
|
7688
7773
|
position -= length;
|
|
7689
7774
|
const buffer = Buffer.alloc(length);
|
|
7690
|
-
|
|
7775
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7691
7776
|
let chunk = buffer.toString("utf8");
|
|
7692
7777
|
if (remainder) {
|
|
7693
7778
|
chunk += remainder;
|
|
@@ -7734,7 +7819,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7734
7819
|
}
|
|
7735
7820
|
}
|
|
7736
7821
|
} finally {
|
|
7737
|
-
|
|
7822
|
+
fs29.closeSync(fd);
|
|
7738
7823
|
}
|
|
7739
7824
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7740
7825
|
}
|
|
@@ -7976,30 +8061,30 @@ async function readLogsJsonResult(options) {
|
|
|
7976
8061
|
};
|
|
7977
8062
|
}
|
|
7978
8063
|
function resolveLogFilePath(logDir, type) {
|
|
7979
|
-
const base =
|
|
8064
|
+
const base = path25.isAbsolute(logDir) ? logDir : path25.join(process.cwd(), logDir);
|
|
7980
8065
|
if (type === "server") {
|
|
7981
|
-
return
|
|
8066
|
+
return path25.join(base, "server.log");
|
|
7982
8067
|
}
|
|
7983
8068
|
if (type === "trace") {
|
|
7984
|
-
return
|
|
8069
|
+
return path25.join(base, "trace.log");
|
|
7985
8070
|
}
|
|
7986
8071
|
if (type === "server-std") {
|
|
7987
|
-
return
|
|
8072
|
+
return path25.join(base, "server.std.log");
|
|
7988
8073
|
}
|
|
7989
8074
|
if (type === "client-std") {
|
|
7990
|
-
return
|
|
8075
|
+
return path25.join(base, "client.std.log");
|
|
7991
8076
|
}
|
|
7992
8077
|
if (type === "dev") {
|
|
7993
|
-
return
|
|
8078
|
+
return path25.join(base, "dev.log");
|
|
7994
8079
|
}
|
|
7995
8080
|
if (type === "dev-std") {
|
|
7996
|
-
return
|
|
8081
|
+
return path25.join(base, "dev.std.log");
|
|
7997
8082
|
}
|
|
7998
8083
|
if (type === "install-dep-std") {
|
|
7999
|
-
return
|
|
8084
|
+
return path25.join(base, "install-dep.std.log");
|
|
8000
8085
|
}
|
|
8001
8086
|
if (type === "browser") {
|
|
8002
|
-
return
|
|
8087
|
+
return path25.join(base, "browser.log");
|
|
8003
8088
|
}
|
|
8004
8089
|
throw new Error(`Unsupported log type: ${type}`);
|
|
8005
8090
|
}
|
|
@@ -8160,9 +8245,9 @@ function camelToKebab(str) {
|
|
|
8160
8245
|
}
|
|
8161
8246
|
|
|
8162
8247
|
// src/commands/build/upload-static.handler.ts
|
|
8163
|
-
import * as
|
|
8248
|
+
import * as fs30 from "fs";
|
|
8164
8249
|
import * as os2 from "os";
|
|
8165
|
-
import * as
|
|
8250
|
+
import * as path26 from "path";
|
|
8166
8251
|
import { execFileSync } from "child_process";
|
|
8167
8252
|
function readCredentialsFromEnv() {
|
|
8168
8253
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -8186,8 +8271,8 @@ async function uploadStatic(options) {
|
|
|
8186
8271
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
8187
8272
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
8188
8273
|
} = options;
|
|
8189
|
-
const resolvedStaticDir =
|
|
8190
|
-
if (!
|
|
8274
|
+
const resolvedStaticDir = path26.resolve(staticDir);
|
|
8275
|
+
if (!fs30.existsSync(resolvedStaticDir)) {
|
|
8191
8276
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
8192
8277
|
return;
|
|
8193
8278
|
}
|
|
@@ -8220,8 +8305,8 @@ async function uploadStatic(options) {
|
|
|
8220
8305
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
8221
8306
|
}
|
|
8222
8307
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
8223
|
-
const confPath =
|
|
8224
|
-
|
|
8308
|
+
const confPath = path26.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
8309
|
+
fs30.writeFileSync(confPath, "");
|
|
8225
8310
|
try {
|
|
8226
8311
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
8227
8312
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -8235,7 +8320,7 @@ async function uploadStatic(options) {
|
|
|
8235
8320
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
8236
8321
|
} finally {
|
|
8237
8322
|
try {
|
|
8238
|
-
|
|
8323
|
+
fs30.unlinkSync(confPath);
|
|
8239
8324
|
} catch {
|
|
8240
8325
|
}
|
|
8241
8326
|
}
|
|
@@ -8255,8 +8340,8 @@ async function uploadStatic(options) {
|
|
|
8255
8340
|
}
|
|
8256
8341
|
}
|
|
8257
8342
|
function resolveTosutilPath(tosutilPath) {
|
|
8258
|
-
if (
|
|
8259
|
-
return
|
|
8343
|
+
if (path26.isAbsolute(tosutilPath)) {
|
|
8344
|
+
return fs30.existsSync(tosutilPath) ? tosutilPath : null;
|
|
8260
8345
|
}
|
|
8261
8346
|
try {
|
|
8262
8347
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -8301,7 +8386,7 @@ async function resolveBucketId(appId) {
|
|
|
8301
8386
|
return bucketId;
|
|
8302
8387
|
}
|
|
8303
8388
|
function isDirEmpty(dirPath) {
|
|
8304
|
-
const entries =
|
|
8389
|
+
const entries = fs30.readdirSync(dirPath);
|
|
8305
8390
|
return entries.length === 0;
|
|
8306
8391
|
}
|
|
8307
8392
|
|
|
@@ -8397,13 +8482,13 @@ var commands = [
|
|
|
8397
8482
|
|
|
8398
8483
|
// src/index.ts
|
|
8399
8484
|
for (const filename of [".env.local", ".env"]) {
|
|
8400
|
-
const envPath =
|
|
8401
|
-
if (
|
|
8485
|
+
const envPath = path27.join(process.cwd(), filename);
|
|
8486
|
+
if (fs31.existsSync(envPath)) {
|
|
8402
8487
|
dotenvConfig({ path: envPath });
|
|
8403
8488
|
}
|
|
8404
8489
|
}
|
|
8405
|
-
var __dirname =
|
|
8406
|
-
var pkg = JSON.parse(
|
|
8490
|
+
var __dirname = path27.dirname(fileURLToPath5(import.meta.url));
|
|
8491
|
+
var pkg = JSON.parse(fs31.readFileSync(path27.join(__dirname, "../package.json"), "utf-8"));
|
|
8407
8492
|
var cli = new FullstackCLI(pkg.version);
|
|
8408
8493
|
cli.useAll(commands);
|
|
8409
8494
|
cli.run();
|