@lark-apaas/fullstack-cli 1.1.66 → 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 +397 -311
- 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) {
|
|
@@ -4805,7 +4891,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4805
4891
|
}
|
|
4806
4892
|
async function loadPlugin(pluginKey) {
|
|
4807
4893
|
try {
|
|
4808
|
-
const userRequire = createRequire2(
|
|
4894
|
+
const userRequire = createRequire2(path15.join(getProjectRoot2(), "package.json"));
|
|
4809
4895
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4810
4896
|
const pluginModule = await import(resolvedPath);
|
|
4811
4897
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4968,8 +5054,8 @@ var capabilityCommandGroup = {
|
|
|
4968
5054
|
import { execFile } from "child_process";
|
|
4969
5055
|
|
|
4970
5056
|
// src/commands/component/registry-preparer.ts
|
|
4971
|
-
import
|
|
4972
|
-
import
|
|
5057
|
+
import fs18 from "fs";
|
|
5058
|
+
import path16 from "path";
|
|
4973
5059
|
import os from "os";
|
|
4974
5060
|
|
|
4975
5061
|
// src/commands/component/service.ts
|
|
@@ -5029,7 +5115,7 @@ async function sendInstallEvent(key) {
|
|
|
5029
5115
|
}
|
|
5030
5116
|
|
|
5031
5117
|
// src/commands/component/registry-preparer.ts
|
|
5032
|
-
var REGISTRY_TEMP_DIR =
|
|
5118
|
+
var REGISTRY_TEMP_DIR = path16.join(os.tmpdir(), "miaoda-registry");
|
|
5033
5119
|
function parseComponentKey(key) {
|
|
5034
5120
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
5035
5121
|
if (!match) {
|
|
@@ -5041,11 +5127,11 @@ function parseComponentKey(key) {
|
|
|
5041
5127
|
}
|
|
5042
5128
|
function getLocalRegistryPath(key) {
|
|
5043
5129
|
const { scope, name } = parseComponentKey(key);
|
|
5044
|
-
return
|
|
5130
|
+
return path16.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
5045
5131
|
}
|
|
5046
5132
|
function ensureDir(dirPath) {
|
|
5047
|
-
if (!
|
|
5048
|
-
|
|
5133
|
+
if (!fs18.existsSync(dirPath)) {
|
|
5134
|
+
fs18.mkdirSync(dirPath, { recursive: true });
|
|
5049
5135
|
}
|
|
5050
5136
|
}
|
|
5051
5137
|
async function prepareRecursive(key, visited) {
|
|
@@ -5078,8 +5164,8 @@ async function prepareRecursive(key, visited) {
|
|
|
5078
5164
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
5079
5165
|
};
|
|
5080
5166
|
const localPath = getLocalRegistryPath(key);
|
|
5081
|
-
ensureDir(
|
|
5082
|
-
|
|
5167
|
+
ensureDir(path16.dirname(localPath));
|
|
5168
|
+
fs18.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
5083
5169
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
5084
5170
|
}
|
|
5085
5171
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -5089,18 +5175,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
5089
5175
|
}
|
|
5090
5176
|
function cleanupTempDir() {
|
|
5091
5177
|
try {
|
|
5092
|
-
if (
|
|
5093
|
-
|
|
5178
|
+
if (fs18.existsSync(REGISTRY_TEMP_DIR)) {
|
|
5179
|
+
fs18.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
5094
5180
|
}
|
|
5095
5181
|
} catch {
|
|
5096
5182
|
}
|
|
5097
5183
|
}
|
|
5098
5184
|
function getDownloadedRegistryItem(itemId) {
|
|
5099
5185
|
const localPath = getLocalRegistryPath(itemId);
|
|
5100
|
-
if (!
|
|
5186
|
+
if (!fs18.existsSync(localPath)) {
|
|
5101
5187
|
return null;
|
|
5102
5188
|
}
|
|
5103
|
-
const content =
|
|
5189
|
+
const content = fs18.readFileSync(localPath, "utf-8");
|
|
5104
5190
|
return JSON.parse(content);
|
|
5105
5191
|
}
|
|
5106
5192
|
|
|
@@ -5268,58 +5354,58 @@ var componentCommandGroup = {
|
|
|
5268
5354
|
};
|
|
5269
5355
|
|
|
5270
5356
|
// src/commands/migration/version-manager.ts
|
|
5271
|
-
import
|
|
5272
|
-
import
|
|
5357
|
+
import fs19 from "fs";
|
|
5358
|
+
import path17 from "path";
|
|
5273
5359
|
var PACKAGE_JSON = "package.json";
|
|
5274
5360
|
var VERSION_FIELD = "migrationVersion";
|
|
5275
5361
|
function getPackageJsonPath2() {
|
|
5276
|
-
return
|
|
5362
|
+
return path17.join(process.cwd(), PACKAGE_JSON);
|
|
5277
5363
|
}
|
|
5278
5364
|
function getCurrentVersion() {
|
|
5279
5365
|
const pkgPath = getPackageJsonPath2();
|
|
5280
|
-
if (!
|
|
5366
|
+
if (!fs19.existsSync(pkgPath)) {
|
|
5281
5367
|
throw new Error("package.json not found");
|
|
5282
5368
|
}
|
|
5283
|
-
const pkg2 = JSON.parse(
|
|
5369
|
+
const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
|
|
5284
5370
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
5285
5371
|
}
|
|
5286
5372
|
function setCurrentVersion(version) {
|
|
5287
5373
|
const pkgPath = getPackageJsonPath2();
|
|
5288
|
-
const pkg2 = JSON.parse(
|
|
5374
|
+
const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
|
|
5289
5375
|
pkg2[VERSION_FIELD] = version;
|
|
5290
|
-
|
|
5376
|
+
fs19.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
5291
5377
|
}
|
|
5292
5378
|
|
|
5293
5379
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5294
|
-
import
|
|
5295
|
-
import
|
|
5380
|
+
import fs21 from "fs";
|
|
5381
|
+
import path19 from "path";
|
|
5296
5382
|
|
|
5297
5383
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
5298
|
-
import
|
|
5299
|
-
import
|
|
5384
|
+
import fs20 from "fs";
|
|
5385
|
+
import path18 from "path";
|
|
5300
5386
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
5301
5387
|
function getProjectRoot3() {
|
|
5302
5388
|
return process.cwd();
|
|
5303
5389
|
}
|
|
5304
5390
|
function getCapabilitiesDir2() {
|
|
5305
|
-
return
|
|
5391
|
+
return path18.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
5306
5392
|
}
|
|
5307
5393
|
function getPluginManifestPath2(pluginKey) {
|
|
5308
|
-
return
|
|
5394
|
+
return path18.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
5309
5395
|
}
|
|
5310
5396
|
|
|
5311
5397
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5312
5398
|
function detectJsonMigration() {
|
|
5313
5399
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5314
|
-
const oldFilePath =
|
|
5315
|
-
if (!
|
|
5400
|
+
const oldFilePath = path19.join(capabilitiesDir, "capabilities.json");
|
|
5401
|
+
if (!fs21.existsSync(oldFilePath)) {
|
|
5316
5402
|
return {
|
|
5317
5403
|
needsMigration: false,
|
|
5318
5404
|
reason: "capabilities.json not found"
|
|
5319
5405
|
};
|
|
5320
5406
|
}
|
|
5321
5407
|
try {
|
|
5322
|
-
const content =
|
|
5408
|
+
const content = fs21.readFileSync(oldFilePath, "utf-8");
|
|
5323
5409
|
const parsed = JSON.parse(content);
|
|
5324
5410
|
if (!Array.isArray(parsed)) {
|
|
5325
5411
|
return {
|
|
@@ -5370,8 +5456,8 @@ async function check(options) {
|
|
|
5370
5456
|
}
|
|
5371
5457
|
|
|
5372
5458
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5373
|
-
import
|
|
5374
|
-
import
|
|
5459
|
+
import fs22 from "fs";
|
|
5460
|
+
import path20 from "path";
|
|
5375
5461
|
|
|
5376
5462
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5377
5463
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5601,18 +5687,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5601
5687
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5602
5688
|
function loadExistingCapabilities() {
|
|
5603
5689
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5604
|
-
if (!
|
|
5690
|
+
if (!fs22.existsSync(capabilitiesDir)) {
|
|
5605
5691
|
return [];
|
|
5606
5692
|
}
|
|
5607
|
-
const files =
|
|
5693
|
+
const files = fs22.readdirSync(capabilitiesDir);
|
|
5608
5694
|
const capabilities = [];
|
|
5609
5695
|
for (const file of files) {
|
|
5610
5696
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5611
5697
|
continue;
|
|
5612
5698
|
}
|
|
5613
5699
|
try {
|
|
5614
|
-
const filePath =
|
|
5615
|
-
const content =
|
|
5700
|
+
const filePath = path20.join(capabilitiesDir, file);
|
|
5701
|
+
const content = fs22.readFileSync(filePath, "utf-8");
|
|
5616
5702
|
const capability = JSON.parse(content);
|
|
5617
5703
|
if (capability.id && capability.pluginKey) {
|
|
5618
5704
|
capabilities.push(capability);
|
|
@@ -5670,9 +5756,9 @@ async function migrateJsonFiles(options) {
|
|
|
5670
5756
|
}
|
|
5671
5757
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5672
5758
|
for (const cap of newCapabilities) {
|
|
5673
|
-
const filePath =
|
|
5759
|
+
const filePath = path20.join(capabilitiesDir, `${cap.id}.json`);
|
|
5674
5760
|
const content = JSON.stringify(cap, null, 2);
|
|
5675
|
-
|
|
5761
|
+
fs22.writeFileSync(filePath, content, "utf-8");
|
|
5676
5762
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5677
5763
|
}
|
|
5678
5764
|
return {
|
|
@@ -5684,11 +5770,11 @@ async function migrateJsonFiles(options) {
|
|
|
5684
5770
|
}
|
|
5685
5771
|
|
|
5686
5772
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5687
|
-
import
|
|
5773
|
+
import fs23 from "fs";
|
|
5688
5774
|
function isPluginInstalled2(pluginKey) {
|
|
5689
5775
|
const actionPlugins = readActionPlugins();
|
|
5690
5776
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5691
|
-
return
|
|
5777
|
+
return fs23.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5692
5778
|
}
|
|
5693
5779
|
function detectPluginsToInstall(capabilities) {
|
|
5694
5780
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5764,12 +5850,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5764
5850
|
}
|
|
5765
5851
|
|
|
5766
5852
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5767
|
-
import
|
|
5853
|
+
import path22 from "path";
|
|
5768
5854
|
import { Project as Project3 } from "ts-morph";
|
|
5769
5855
|
|
|
5770
5856
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5771
|
-
import
|
|
5772
|
-
import
|
|
5857
|
+
import fs24 from "fs";
|
|
5858
|
+
import path21 from "path";
|
|
5773
5859
|
var EXCLUDED_DIRS = [
|
|
5774
5860
|
"node_modules",
|
|
5775
5861
|
"dist",
|
|
@@ -5784,9 +5870,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5784
5870
|
/\.d\.ts$/
|
|
5785
5871
|
];
|
|
5786
5872
|
function scanDirectory(dir, files = []) {
|
|
5787
|
-
const entries =
|
|
5873
|
+
const entries = fs24.readdirSync(dir, { withFileTypes: true });
|
|
5788
5874
|
for (const entry of entries) {
|
|
5789
|
-
const fullPath =
|
|
5875
|
+
const fullPath = path21.join(dir, entry.name);
|
|
5790
5876
|
if (entry.isDirectory()) {
|
|
5791
5877
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5792
5878
|
continue;
|
|
@@ -5802,14 +5888,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5802
5888
|
return files;
|
|
5803
5889
|
}
|
|
5804
5890
|
function scanServerFiles() {
|
|
5805
|
-
const serverDir =
|
|
5806
|
-
if (!
|
|
5891
|
+
const serverDir = path21.join(getProjectRoot3(), "server");
|
|
5892
|
+
if (!fs24.existsSync(serverDir)) {
|
|
5807
5893
|
return [];
|
|
5808
5894
|
}
|
|
5809
5895
|
return scanDirectory(serverDir);
|
|
5810
5896
|
}
|
|
5811
5897
|
function hasCapabilityImport(filePath) {
|
|
5812
|
-
const content =
|
|
5898
|
+
const content = fs24.readFileSync(filePath, "utf-8");
|
|
5813
5899
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5814
5900
|
}
|
|
5815
5901
|
function scanFilesToMigrate() {
|
|
@@ -6186,7 +6272,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6186
6272
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
6187
6273
|
const classInfo = analyzeClass(sourceFile);
|
|
6188
6274
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
6189
|
-
const relativePath =
|
|
6275
|
+
const relativePath = path22.relative(getProjectRoot3(), filePath);
|
|
6190
6276
|
return {
|
|
6191
6277
|
filePath: relativePath,
|
|
6192
6278
|
imports,
|
|
@@ -6197,7 +6283,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6197
6283
|
};
|
|
6198
6284
|
}
|
|
6199
6285
|
function migrateFile(project, analysis, dryRun) {
|
|
6200
|
-
const absolutePath =
|
|
6286
|
+
const absolutePath = path22.join(getProjectRoot3(), analysis.filePath);
|
|
6201
6287
|
if (!analysis.canAutoMigrate) {
|
|
6202
6288
|
return {
|
|
6203
6289
|
filePath: analysis.filePath,
|
|
@@ -6300,17 +6386,17 @@ function getSuggestion(analysis) {
|
|
|
6300
6386
|
}
|
|
6301
6387
|
|
|
6302
6388
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
6303
|
-
import
|
|
6304
|
-
import
|
|
6389
|
+
import fs25 from "fs";
|
|
6390
|
+
import path23 from "path";
|
|
6305
6391
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
6306
6392
|
const deletedFiles = [];
|
|
6307
6393
|
const errors = [];
|
|
6308
6394
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6309
|
-
const oldJsonPath =
|
|
6310
|
-
if (
|
|
6395
|
+
const oldJsonPath = path23.join(capabilitiesDir, "capabilities.json");
|
|
6396
|
+
if (fs25.existsSync(oldJsonPath)) {
|
|
6311
6397
|
try {
|
|
6312
6398
|
if (!dryRun) {
|
|
6313
|
-
|
|
6399
|
+
fs25.unlinkSync(oldJsonPath);
|
|
6314
6400
|
}
|
|
6315
6401
|
deletedFiles.push("capabilities.json");
|
|
6316
6402
|
} catch (error) {
|
|
@@ -6318,11 +6404,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6318
6404
|
}
|
|
6319
6405
|
}
|
|
6320
6406
|
for (const cap of capabilities) {
|
|
6321
|
-
const tsFilePath =
|
|
6322
|
-
if (
|
|
6407
|
+
const tsFilePath = path23.join(capabilitiesDir, `${cap.id}.ts`);
|
|
6408
|
+
if (fs25.existsSync(tsFilePath)) {
|
|
6323
6409
|
try {
|
|
6324
6410
|
if (!dryRun) {
|
|
6325
|
-
|
|
6411
|
+
fs25.unlinkSync(tsFilePath);
|
|
6326
6412
|
}
|
|
6327
6413
|
deletedFiles.push(`${cap.id}.ts`);
|
|
6328
6414
|
} catch (error) {
|
|
@@ -6338,8 +6424,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6338
6424
|
}
|
|
6339
6425
|
|
|
6340
6426
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
6341
|
-
import
|
|
6342
|
-
import
|
|
6427
|
+
import fs26 from "fs";
|
|
6428
|
+
import path24 from "path";
|
|
6343
6429
|
var REPORT_FILE = "capability-migration-report.md";
|
|
6344
6430
|
function printSummary(result) {
|
|
6345
6431
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6502,15 +6588,15 @@ async function generateReport(result) {
|
|
|
6502
6588
|
}
|
|
6503
6589
|
lines.push("");
|
|
6504
6590
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6505
|
-
if (!
|
|
6591
|
+
if (!fs26.existsSync(logDir)) {
|
|
6506
6592
|
return;
|
|
6507
6593
|
}
|
|
6508
|
-
const reportDir =
|
|
6509
|
-
if (!
|
|
6510
|
-
|
|
6594
|
+
const reportDir = path24.join(logDir, "migration");
|
|
6595
|
+
if (!fs26.existsSync(reportDir)) {
|
|
6596
|
+
fs26.mkdirSync(reportDir, { recursive: true });
|
|
6511
6597
|
}
|
|
6512
|
-
const reportPath =
|
|
6513
|
-
|
|
6598
|
+
const reportPath = path24.join(reportDir, REPORT_FILE);
|
|
6599
|
+
fs26.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6514
6600
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6515
6601
|
}
|
|
6516
6602
|
|
|
@@ -7042,10 +7128,10 @@ var migrationCommand = {
|
|
|
7042
7128
|
};
|
|
7043
7129
|
|
|
7044
7130
|
// src/commands/read-logs/index.ts
|
|
7045
|
-
import
|
|
7131
|
+
import path25 from "path";
|
|
7046
7132
|
|
|
7047
7133
|
// src/commands/read-logs/std-utils.ts
|
|
7048
|
-
import
|
|
7134
|
+
import fs27 from "fs";
|
|
7049
7135
|
function formatStdPrefixTime(localTime) {
|
|
7050
7136
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
7051
7137
|
if (!match) return localTime;
|
|
@@ -7075,11 +7161,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
7075
7161
|
return `[${time}] ${content}`;
|
|
7076
7162
|
}
|
|
7077
7163
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
7078
|
-
const stat =
|
|
7164
|
+
const stat = fs27.statSync(filePath);
|
|
7079
7165
|
if (stat.size === 0) {
|
|
7080
7166
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
7081
7167
|
}
|
|
7082
|
-
const fd =
|
|
7168
|
+
const fd = fs27.openSync(filePath, "r");
|
|
7083
7169
|
const chunkSize = 64 * 1024;
|
|
7084
7170
|
let position = stat.size;
|
|
7085
7171
|
let remainder = "";
|
|
@@ -7093,7 +7179,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7093
7179
|
const length = Math.min(chunkSize, position);
|
|
7094
7180
|
position -= length;
|
|
7095
7181
|
const buffer = Buffer.alloc(length);
|
|
7096
|
-
|
|
7182
|
+
fs27.readSync(fd, buffer, 0, length, position);
|
|
7097
7183
|
let chunk = buffer.toString("utf8");
|
|
7098
7184
|
if (remainder) {
|
|
7099
7185
|
chunk += remainder;
|
|
@@ -7135,7 +7221,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7135
7221
|
}
|
|
7136
7222
|
}
|
|
7137
7223
|
} finally {
|
|
7138
|
-
|
|
7224
|
+
fs27.closeSync(fd);
|
|
7139
7225
|
}
|
|
7140
7226
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
7141
7227
|
}
|
|
@@ -7156,21 +7242,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
7156
7242
|
}
|
|
7157
7243
|
|
|
7158
7244
|
// src/commands/read-logs/tail.ts
|
|
7159
|
-
import
|
|
7245
|
+
import fs28 from "fs";
|
|
7160
7246
|
function fileExists(filePath) {
|
|
7161
7247
|
try {
|
|
7162
|
-
|
|
7248
|
+
fs28.accessSync(filePath, fs28.constants.F_OK | fs28.constants.R_OK);
|
|
7163
7249
|
return true;
|
|
7164
7250
|
} catch {
|
|
7165
7251
|
return false;
|
|
7166
7252
|
}
|
|
7167
7253
|
}
|
|
7168
7254
|
function readFileTailLines(filePath, maxLines) {
|
|
7169
|
-
const stat =
|
|
7255
|
+
const stat = fs28.statSync(filePath);
|
|
7170
7256
|
if (stat.size === 0) {
|
|
7171
7257
|
return [];
|
|
7172
7258
|
}
|
|
7173
|
-
const fd =
|
|
7259
|
+
const fd = fs28.openSync(filePath, "r");
|
|
7174
7260
|
const chunkSize = 64 * 1024;
|
|
7175
7261
|
const chunks = [];
|
|
7176
7262
|
let position = stat.size;
|
|
@@ -7180,13 +7266,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7180
7266
|
const length = Math.min(chunkSize, position);
|
|
7181
7267
|
position -= length;
|
|
7182
7268
|
const buffer = Buffer.alloc(length);
|
|
7183
|
-
|
|
7269
|
+
fs28.readSync(fd, buffer, 0, length, position);
|
|
7184
7270
|
chunks.unshift(buffer.toString("utf8"));
|
|
7185
7271
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
7186
7272
|
collectedLines += chunkLines;
|
|
7187
7273
|
}
|
|
7188
7274
|
} finally {
|
|
7189
|
-
|
|
7275
|
+
fs28.closeSync(fd);
|
|
7190
7276
|
}
|
|
7191
7277
|
const content = chunks.join("");
|
|
7192
7278
|
const allLines = content.split("\n");
|
|
@@ -7202,11 +7288,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7202
7288
|
return allLines.slice(allLines.length - maxLines);
|
|
7203
7289
|
}
|
|
7204
7290
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
7205
|
-
const stat =
|
|
7291
|
+
const stat = fs28.statSync(filePath);
|
|
7206
7292
|
if (stat.size === 0) {
|
|
7207
7293
|
return { lines: [], totalLinesCount: 0 };
|
|
7208
7294
|
}
|
|
7209
|
-
const fd =
|
|
7295
|
+
const fd = fs28.openSync(filePath, "r");
|
|
7210
7296
|
const chunkSize = 64 * 1024;
|
|
7211
7297
|
let position = stat.size;
|
|
7212
7298
|
let remainder = "";
|
|
@@ -7218,7 +7304,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7218
7304
|
const length = Math.min(chunkSize, position);
|
|
7219
7305
|
position -= length;
|
|
7220
7306
|
const buffer = Buffer.alloc(length);
|
|
7221
|
-
|
|
7307
|
+
fs28.readSync(fd, buffer, 0, length, position);
|
|
7222
7308
|
let chunk = buffer.toString("utf8");
|
|
7223
7309
|
if (remainder) {
|
|
7224
7310
|
chunk += remainder;
|
|
@@ -7249,7 +7335,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7249
7335
|
}
|
|
7250
7336
|
}
|
|
7251
7337
|
} finally {
|
|
7252
|
-
|
|
7338
|
+
fs28.closeSync(fd);
|
|
7253
7339
|
}
|
|
7254
7340
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7255
7341
|
}
|
|
@@ -7391,7 +7477,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7391
7477
|
}
|
|
7392
7478
|
|
|
7393
7479
|
// src/commands/read-logs/json-lines.ts
|
|
7394
|
-
import
|
|
7480
|
+
import fs29 from "fs";
|
|
7395
7481
|
|
|
7396
7482
|
// src/commands/read-logs/structured-log.ts
|
|
7397
7483
|
function normalizeLevelName(value) {
|
|
@@ -7467,11 +7553,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7467
7553
|
return set.size > 0 ? set : null;
|
|
7468
7554
|
}
|
|
7469
7555
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7470
|
-
const stat =
|
|
7556
|
+
const stat = fs29.statSync(filePath);
|
|
7471
7557
|
if (stat.size === 0) {
|
|
7472
7558
|
return { lines: [], totalLinesCount: 0 };
|
|
7473
7559
|
}
|
|
7474
|
-
const fd =
|
|
7560
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7475
7561
|
const chunkSize = 64 * 1024;
|
|
7476
7562
|
let position = stat.size;
|
|
7477
7563
|
let remainder = "";
|
|
@@ -7486,7 +7572,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7486
7572
|
const length = Math.min(chunkSize, position);
|
|
7487
7573
|
position -= length;
|
|
7488
7574
|
const buffer = Buffer.alloc(length);
|
|
7489
|
-
|
|
7575
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7490
7576
|
let chunk = buffer.toString("utf8");
|
|
7491
7577
|
if (remainder) {
|
|
7492
7578
|
chunk += remainder;
|
|
@@ -7548,7 +7634,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7548
7634
|
}
|
|
7549
7635
|
}
|
|
7550
7636
|
} finally {
|
|
7551
|
-
|
|
7637
|
+
fs29.closeSync(fd);
|
|
7552
7638
|
}
|
|
7553
7639
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7554
7640
|
}
|
|
@@ -7591,11 +7677,11 @@ function extractTraceId(obj) {
|
|
|
7591
7677
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7592
7678
|
const wanted = traceId.trim();
|
|
7593
7679
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7594
|
-
const stat =
|
|
7680
|
+
const stat = fs29.statSync(filePath);
|
|
7595
7681
|
if (stat.size === 0) {
|
|
7596
7682
|
return { lines: [], totalLinesCount: 0 };
|
|
7597
7683
|
}
|
|
7598
|
-
const fd =
|
|
7684
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7599
7685
|
const chunkSize = 64 * 1024;
|
|
7600
7686
|
let position = stat.size;
|
|
7601
7687
|
let remainder = "";
|
|
@@ -7608,7 +7694,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7608
7694
|
const length = Math.min(chunkSize, position);
|
|
7609
7695
|
position -= length;
|
|
7610
7696
|
const buffer = Buffer.alloc(length);
|
|
7611
|
-
|
|
7697
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7612
7698
|
let chunk = buffer.toString("utf8");
|
|
7613
7699
|
if (remainder) {
|
|
7614
7700
|
chunk += remainder;
|
|
@@ -7661,7 +7747,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7661
7747
|
}
|
|
7662
7748
|
}
|
|
7663
7749
|
} finally {
|
|
7664
|
-
|
|
7750
|
+
fs29.closeSync(fd);
|
|
7665
7751
|
}
|
|
7666
7752
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7667
7753
|
}
|
|
@@ -7670,11 +7756,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7670
7756
|
if (!wantedLevelSet) {
|
|
7671
7757
|
return { lines: [], totalLinesCount: 0 };
|
|
7672
7758
|
}
|
|
7673
|
-
const stat =
|
|
7759
|
+
const stat = fs29.statSync(filePath);
|
|
7674
7760
|
if (stat.size === 0) {
|
|
7675
7761
|
return { lines: [], totalLinesCount: 0 };
|
|
7676
7762
|
}
|
|
7677
|
-
const fd =
|
|
7763
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7678
7764
|
const chunkSize = 64 * 1024;
|
|
7679
7765
|
let position = stat.size;
|
|
7680
7766
|
let remainder = "";
|
|
@@ -7686,7 +7772,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7686
7772
|
const length = Math.min(chunkSize, position);
|
|
7687
7773
|
position -= length;
|
|
7688
7774
|
const buffer = Buffer.alloc(length);
|
|
7689
|
-
|
|
7775
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7690
7776
|
let chunk = buffer.toString("utf8");
|
|
7691
7777
|
if (remainder) {
|
|
7692
7778
|
chunk += remainder;
|
|
@@ -7733,7 +7819,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7733
7819
|
}
|
|
7734
7820
|
}
|
|
7735
7821
|
} finally {
|
|
7736
|
-
|
|
7822
|
+
fs29.closeSync(fd);
|
|
7737
7823
|
}
|
|
7738
7824
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7739
7825
|
}
|
|
@@ -7975,30 +8061,30 @@ async function readLogsJsonResult(options) {
|
|
|
7975
8061
|
};
|
|
7976
8062
|
}
|
|
7977
8063
|
function resolveLogFilePath(logDir, type) {
|
|
7978
|
-
const base =
|
|
8064
|
+
const base = path25.isAbsolute(logDir) ? logDir : path25.join(process.cwd(), logDir);
|
|
7979
8065
|
if (type === "server") {
|
|
7980
|
-
return
|
|
8066
|
+
return path25.join(base, "server.log");
|
|
7981
8067
|
}
|
|
7982
8068
|
if (type === "trace") {
|
|
7983
|
-
return
|
|
8069
|
+
return path25.join(base, "trace.log");
|
|
7984
8070
|
}
|
|
7985
8071
|
if (type === "server-std") {
|
|
7986
|
-
return
|
|
8072
|
+
return path25.join(base, "server.std.log");
|
|
7987
8073
|
}
|
|
7988
8074
|
if (type === "client-std") {
|
|
7989
|
-
return
|
|
8075
|
+
return path25.join(base, "client.std.log");
|
|
7990
8076
|
}
|
|
7991
8077
|
if (type === "dev") {
|
|
7992
|
-
return
|
|
8078
|
+
return path25.join(base, "dev.log");
|
|
7993
8079
|
}
|
|
7994
8080
|
if (type === "dev-std") {
|
|
7995
|
-
return
|
|
8081
|
+
return path25.join(base, "dev.std.log");
|
|
7996
8082
|
}
|
|
7997
8083
|
if (type === "install-dep-std") {
|
|
7998
|
-
return
|
|
8084
|
+
return path25.join(base, "install-dep.std.log");
|
|
7999
8085
|
}
|
|
8000
8086
|
if (type === "browser") {
|
|
8001
|
-
return
|
|
8087
|
+
return path25.join(base, "browser.log");
|
|
8002
8088
|
}
|
|
8003
8089
|
throw new Error(`Unsupported log type: ${type}`);
|
|
8004
8090
|
}
|
|
@@ -8159,9 +8245,9 @@ function camelToKebab(str) {
|
|
|
8159
8245
|
}
|
|
8160
8246
|
|
|
8161
8247
|
// src/commands/build/upload-static.handler.ts
|
|
8162
|
-
import * as
|
|
8248
|
+
import * as fs30 from "fs";
|
|
8163
8249
|
import * as os2 from "os";
|
|
8164
|
-
import * as
|
|
8250
|
+
import * as path26 from "path";
|
|
8165
8251
|
import { execFileSync } from "child_process";
|
|
8166
8252
|
function readCredentialsFromEnv() {
|
|
8167
8253
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -8185,8 +8271,8 @@ async function uploadStatic(options) {
|
|
|
8185
8271
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
8186
8272
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
8187
8273
|
} = options;
|
|
8188
|
-
const resolvedStaticDir =
|
|
8189
|
-
if (!
|
|
8274
|
+
const resolvedStaticDir = path26.resolve(staticDir);
|
|
8275
|
+
if (!fs30.existsSync(resolvedStaticDir)) {
|
|
8190
8276
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
8191
8277
|
return;
|
|
8192
8278
|
}
|
|
@@ -8219,8 +8305,8 @@ async function uploadStatic(options) {
|
|
|
8219
8305
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
8220
8306
|
}
|
|
8221
8307
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
8222
|
-
const confPath =
|
|
8223
|
-
|
|
8308
|
+
const confPath = path26.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
8309
|
+
fs30.writeFileSync(confPath, "");
|
|
8224
8310
|
try {
|
|
8225
8311
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
8226
8312
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -8234,7 +8320,7 @@ async function uploadStatic(options) {
|
|
|
8234
8320
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
8235
8321
|
} finally {
|
|
8236
8322
|
try {
|
|
8237
|
-
|
|
8323
|
+
fs30.unlinkSync(confPath);
|
|
8238
8324
|
} catch {
|
|
8239
8325
|
}
|
|
8240
8326
|
}
|
|
@@ -8254,8 +8340,8 @@ async function uploadStatic(options) {
|
|
|
8254
8340
|
}
|
|
8255
8341
|
}
|
|
8256
8342
|
function resolveTosutilPath(tosutilPath) {
|
|
8257
|
-
if (
|
|
8258
|
-
return
|
|
8343
|
+
if (path26.isAbsolute(tosutilPath)) {
|
|
8344
|
+
return fs30.existsSync(tosutilPath) ? tosutilPath : null;
|
|
8259
8345
|
}
|
|
8260
8346
|
try {
|
|
8261
8347
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -8300,7 +8386,7 @@ async function resolveBucketId(appId) {
|
|
|
8300
8386
|
return bucketId;
|
|
8301
8387
|
}
|
|
8302
8388
|
function isDirEmpty(dirPath) {
|
|
8303
|
-
const entries =
|
|
8389
|
+
const entries = fs30.readdirSync(dirPath);
|
|
8304
8390
|
return entries.length === 0;
|
|
8305
8391
|
}
|
|
8306
8392
|
|
|
@@ -8396,13 +8482,13 @@ var commands = [
|
|
|
8396
8482
|
|
|
8397
8483
|
// src/index.ts
|
|
8398
8484
|
for (const filename of [".env.local", ".env"]) {
|
|
8399
|
-
const envPath =
|
|
8400
|
-
if (
|
|
8485
|
+
const envPath = path27.join(process.cwd(), filename);
|
|
8486
|
+
if (fs31.existsSync(envPath)) {
|
|
8401
8487
|
dotenvConfig({ path: envPath });
|
|
8402
8488
|
}
|
|
8403
8489
|
}
|
|
8404
|
-
var __dirname =
|
|
8405
|
-
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"));
|
|
8406
8492
|
var cli = new FullstackCLI(pkg.version);
|
|
8407
8493
|
cli.useAll(commands);
|
|
8408
8494
|
cli.run();
|