@lark-apaas/fullstack-cli 1.1.70 → 1.1.71-alpha.20261102142155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/index.js +321 -304
- package/package.json +1 -1
- package/templates/scripts/build.sh +2 -37
- package/templates/helper/gen-openapi.ts +0 -34
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs32 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,12 +2478,12 @@ 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 fs10 from "fs";
|
|
2483
2483
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2484
2484
|
|
|
2485
2485
|
// src/config/sync.ts
|
|
2486
|
-
function buildDefaultRules(
|
|
2486
|
+
function buildDefaultRules() {
|
|
2487
2487
|
const rules = [
|
|
2488
2488
|
// 1. 派生 scripts 目录(总是覆盖;递归同步,包含 scripts/hooks/run-precommit.js)
|
|
2489
2489
|
{
|
|
@@ -2593,19 +2593,12 @@ function buildDefaultRules(opts) {
|
|
|
2593
2593
|
ifStartsWith: "concurrently "
|
|
2594
2594
|
}
|
|
2595
2595
|
];
|
|
2596
|
-
if (!opts.disableGenOpenapi) {
|
|
2597
|
-
rules.push({
|
|
2598
|
-
from: "templates/helper/gen-openapi.ts",
|
|
2599
|
-
to: "scripts/gen-openapi.ts",
|
|
2600
|
-
type: "file",
|
|
2601
|
-
overwrite: true
|
|
2602
|
-
});
|
|
2603
|
-
}
|
|
2604
2596
|
return rules;
|
|
2605
2597
|
}
|
|
2606
|
-
function defaultProfile(
|
|
2598
|
+
function defaultProfile() {
|
|
2607
2599
|
return {
|
|
2608
|
-
sync: buildDefaultRules(
|
|
2600
|
+
sync: buildDefaultRules(),
|
|
2601
|
+
retireLegacyOpenapi: true,
|
|
2609
2602
|
// 文件权限设置(所有 .sh 文件设置为可执行:'**/*.sh': 0o755)
|
|
2610
2603
|
permissions: {},
|
|
2611
2604
|
activateGitHooks: true
|
|
@@ -2803,18 +2796,39 @@ function isNestjsProject(root, stack) {
|
|
|
2803
2796
|
}
|
|
2804
2797
|
}
|
|
2805
2798
|
|
|
2799
|
+
// src/commands/sync/retire-openapi.ts
|
|
2800
|
+
import fs9 from "fs";
|
|
2801
|
+
import path6 from "path";
|
|
2802
|
+
var generatedHeader = "// This file is auto-generated by @lark-apaas/fullstack-cli";
|
|
2803
|
+
var legacyImport = /import\s*\{[^}]*\bDevToolsV2Module\b[^}]*\}\s*from\s*['"]@lark-apaas\/fullstack-nestjs-core['"]/;
|
|
2804
|
+
function retireLegacyOpenapiGenerator(root) {
|
|
2805
|
+
const file = path6.join(root, "scripts/gen-openapi.ts");
|
|
2806
|
+
if (!fs9.existsSync(file)) return;
|
|
2807
|
+
const source = fs9.readFileSync(file, "utf8");
|
|
2808
|
+
if (!source.startsWith(generatedHeader) || !legacyImport.test(source)) return;
|
|
2809
|
+
fs9.writeFileSync(
|
|
2810
|
+
file,
|
|
2811
|
+
`${generatedHeader}
|
|
2812
|
+
// OpenAPI/client SDK generation is retired. Compatibility entry for existing applications.
|
|
2813
|
+
console.info('[fullstack-cli] OpenAPI/client SDK generation is retired; skipping.');
|
|
2814
|
+
export {};
|
|
2815
|
+
`
|
|
2816
|
+
);
|
|
2817
|
+
console.log("[fullstack-cli] \u2713 Retired legacy scripts/gen-openapi.ts");
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2806
2820
|
// src/commands/sync/run.handler.ts
|
|
2807
2821
|
async function run2(options) {
|
|
2808
2822
|
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2809
2823
|
const __filename = fileURLToPath3(import.meta.url);
|
|
2810
|
-
const __dirname2 =
|
|
2811
|
-
const pluginRoot =
|
|
2824
|
+
const __dirname2 = path7.dirname(__filename);
|
|
2825
|
+
const pluginRoot = path7.resolve(__dirname2, "..");
|
|
2812
2826
|
if (userProjectRoot === pluginRoot) {
|
|
2813
2827
|
console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
|
|
2814
2828
|
process.exit(0);
|
|
2815
2829
|
}
|
|
2816
|
-
const userPackageJson =
|
|
2817
|
-
if (!
|
|
2830
|
+
const userPackageJson = path7.join(userProjectRoot, "package.json");
|
|
2831
|
+
if (!fs10.existsSync(userPackageJson)) {
|
|
2818
2832
|
console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
|
|
2819
2833
|
process.exit(0);
|
|
2820
2834
|
}
|
|
@@ -2833,6 +2847,9 @@ async function run2(options) {
|
|
|
2833
2847
|
if (rule.onlyNestjs && !isNestjs) continue;
|
|
2834
2848
|
await syncRule(rule, pluginRoot, userProjectRoot);
|
|
2835
2849
|
}
|
|
2850
|
+
if (config.retireLegacyOpenapi) {
|
|
2851
|
+
retireLegacyOpenapiGenerator(userProjectRoot);
|
|
2852
|
+
}
|
|
2836
2853
|
if (config.permissions) {
|
|
2837
2854
|
setPermissions(config.permissions, userProjectRoot);
|
|
2838
2855
|
}
|
|
@@ -2853,11 +2870,11 @@ async function run2(options) {
|
|
|
2853
2870
|
}
|
|
2854
2871
|
async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
2855
2872
|
if (rule.type === "typescript-exclude") {
|
|
2856
|
-
excludeTypeScriptPath(
|
|
2873
|
+
excludeTypeScriptPath(path7.join(userProjectRoot, rule.to), rule.path);
|
|
2857
2874
|
return;
|
|
2858
2875
|
}
|
|
2859
2876
|
if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2860
|
-
const destPath2 =
|
|
2877
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2861
2878
|
if (rule.type === "delete-file") {
|
|
2862
2879
|
deleteFile(destPath2);
|
|
2863
2880
|
} else {
|
|
@@ -2866,37 +2883,37 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2866
2883
|
return;
|
|
2867
2884
|
}
|
|
2868
2885
|
if (rule.type === "remove-line") {
|
|
2869
|
-
const destPath2 =
|
|
2886
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2870
2887
|
removeLineFromFile(destPath2, rule.pattern);
|
|
2871
2888
|
return;
|
|
2872
2889
|
}
|
|
2873
2890
|
if (rule.type === "add-script") {
|
|
2874
|
-
const packageJsonPath =
|
|
2891
|
+
const packageJsonPath = path7.join(userProjectRoot, "package.json");
|
|
2875
2892
|
addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
|
|
2876
2893
|
return;
|
|
2877
2894
|
}
|
|
2878
2895
|
if (rule.type === "patch-script") {
|
|
2879
|
-
const packageJsonPath =
|
|
2896
|
+
const packageJsonPath = path7.join(userProjectRoot, "package.json");
|
|
2880
2897
|
patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
|
|
2881
2898
|
return;
|
|
2882
2899
|
}
|
|
2883
2900
|
if (rule.type === "add-line") {
|
|
2884
|
-
const destPath2 =
|
|
2901
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2885
2902
|
addLineToFile(destPath2, rule.line);
|
|
2886
2903
|
return;
|
|
2887
2904
|
}
|
|
2888
2905
|
if (rule.type === "merge-json") {
|
|
2889
|
-
const srcPath2 =
|
|
2890
|
-
const destPath2 =
|
|
2906
|
+
const srcPath2 = path7.join(pluginRoot, rule.from);
|
|
2907
|
+
const destPath2 = path7.join(userProjectRoot, rule.to);
|
|
2891
2908
|
mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
|
|
2892
2909
|
return;
|
|
2893
2910
|
}
|
|
2894
2911
|
if (!("from" in rule)) {
|
|
2895
2912
|
return;
|
|
2896
2913
|
}
|
|
2897
|
-
const srcPath =
|
|
2898
|
-
const destPath =
|
|
2899
|
-
if (!
|
|
2914
|
+
const srcPath = path7.join(pluginRoot, rule.from);
|
|
2915
|
+
const destPath = path7.join(userProjectRoot, rule.to);
|
|
2916
|
+
if (!fs10.existsSync(srcPath)) {
|
|
2900
2917
|
console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
|
|
2901
2918
|
return;
|
|
2902
2919
|
}
|
|
@@ -2913,68 +2930,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
|
|
|
2913
2930
|
}
|
|
2914
2931
|
}
|
|
2915
2932
|
function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
|
|
2916
|
-
if (onlyIfExists && !
|
|
2917
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2933
|
+
if (onlyIfExists && !fs10.existsSync(dest)) {
|
|
2934
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (skipped, target not exists)`);
|
|
2918
2935
|
return;
|
|
2919
2936
|
}
|
|
2920
|
-
const destDir =
|
|
2921
|
-
if (!
|
|
2922
|
-
|
|
2937
|
+
const destDir = path7.dirname(dest);
|
|
2938
|
+
if (!fs10.existsSync(destDir)) {
|
|
2939
|
+
fs10.mkdirSync(destDir, { recursive: true });
|
|
2923
2940
|
}
|
|
2924
|
-
if (
|
|
2925
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2941
|
+
if (fs10.existsSync(dest) && !overwrite) {
|
|
2942
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (skipped, already exists)`);
|
|
2926
2943
|
return;
|
|
2927
2944
|
}
|
|
2928
|
-
|
|
2929
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2945
|
+
fs10.copyFileSync(src, dest);
|
|
2946
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dest)}`);
|
|
2930
2947
|
}
|
|
2931
2948
|
function syncDirectory(src, dest, overwrite = true) {
|
|
2932
|
-
if (!
|
|
2933
|
-
|
|
2949
|
+
if (!fs10.existsSync(dest)) {
|
|
2950
|
+
fs10.mkdirSync(dest, { recursive: true });
|
|
2934
2951
|
}
|
|
2935
|
-
const files =
|
|
2952
|
+
const files = fs10.readdirSync(src);
|
|
2936
2953
|
let count = 0;
|
|
2937
2954
|
files.forEach((file) => {
|
|
2938
|
-
const srcFile =
|
|
2939
|
-
const destFile =
|
|
2940
|
-
const stats =
|
|
2955
|
+
const srcFile = path7.join(src, file);
|
|
2956
|
+
const destFile = path7.join(dest, file);
|
|
2957
|
+
const stats = fs10.statSync(srcFile);
|
|
2941
2958
|
if (stats.isDirectory()) {
|
|
2942
2959
|
syncDirectory(srcFile, destFile, overwrite);
|
|
2943
2960
|
} else {
|
|
2944
|
-
if (overwrite || !
|
|
2945
|
-
|
|
2946
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2961
|
+
if (overwrite || !fs10.existsSync(destFile)) {
|
|
2962
|
+
fs10.copyFileSync(srcFile, destFile);
|
|
2963
|
+
console.log(`[fullstack-cli] \u2713 ${path7.relative(dest, destFile)}`);
|
|
2947
2964
|
count++;
|
|
2948
2965
|
}
|
|
2949
2966
|
}
|
|
2950
2967
|
});
|
|
2951
2968
|
if (count > 0) {
|
|
2952
|
-
console.log(`[fullstack-cli] Synced ${count} files to ${
|
|
2969
|
+
console.log(`[fullstack-cli] Synced ${count} files to ${path7.basename(dest)}/`);
|
|
2953
2970
|
}
|
|
2954
2971
|
}
|
|
2955
2972
|
function appendToFile(src, dest) {
|
|
2956
|
-
const content =
|
|
2973
|
+
const content = fs10.readFileSync(src, "utf-8");
|
|
2957
2974
|
let existingContent = "";
|
|
2958
|
-
if (
|
|
2959
|
-
existingContent =
|
|
2975
|
+
if (fs10.existsSync(dest)) {
|
|
2976
|
+
existingContent = fs10.readFileSync(dest, "utf-8");
|
|
2960
2977
|
}
|
|
2961
2978
|
if (existingContent.includes(content.trim())) {
|
|
2962
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
2979
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dest)} (already contains content)`);
|
|
2963
2980
|
return;
|
|
2964
2981
|
}
|
|
2965
|
-
|
|
2966
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
2982
|
+
fs10.appendFileSync(dest, content);
|
|
2983
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dest)} (appended)`);
|
|
2967
2984
|
}
|
|
2968
2985
|
function setPermissions(permissions, projectRoot) {
|
|
2969
2986
|
for (const [pattern, mode] of Object.entries(permissions)) {
|
|
2970
2987
|
if (pattern === "**/*.sh") {
|
|
2971
|
-
const scriptsDir =
|
|
2972
|
-
if (
|
|
2973
|
-
const files =
|
|
2988
|
+
const scriptsDir = path7.join(projectRoot, "scripts");
|
|
2989
|
+
if (fs10.existsSync(scriptsDir)) {
|
|
2990
|
+
const files = fs10.readdirSync(scriptsDir);
|
|
2974
2991
|
files.forEach((file) => {
|
|
2975
2992
|
if (file.endsWith(".sh")) {
|
|
2976
|
-
const filePath =
|
|
2977
|
-
|
|
2993
|
+
const filePath = path7.join(scriptsDir, file);
|
|
2994
|
+
fs10.chmodSync(filePath, mode);
|
|
2978
2995
|
}
|
|
2979
2996
|
});
|
|
2980
2997
|
}
|
|
@@ -2982,27 +2999,27 @@ function setPermissions(permissions, projectRoot) {
|
|
|
2982
2999
|
}
|
|
2983
3000
|
}
|
|
2984
3001
|
function deleteFile(filePath) {
|
|
2985
|
-
if (
|
|
2986
|
-
|
|
2987
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
3002
|
+
if (fs10.existsSync(filePath)) {
|
|
3003
|
+
fs10.unlinkSync(filePath);
|
|
3004
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(filePath)} (deleted)`);
|
|
2988
3005
|
} else {
|
|
2989
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
3006
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(filePath)} (not found)`);
|
|
2990
3007
|
}
|
|
2991
3008
|
}
|
|
2992
3009
|
function deleteDirectory(dirPath) {
|
|
2993
|
-
if (
|
|
2994
|
-
|
|
2995
|
-
console.log(`[fullstack-cli] \u2713 ${
|
|
3010
|
+
if (fs10.existsSync(dirPath)) {
|
|
3011
|
+
fs10.rmSync(dirPath, { recursive: true });
|
|
3012
|
+
console.log(`[fullstack-cli] \u2713 ${path7.basename(dirPath)} (deleted)`);
|
|
2996
3013
|
} else {
|
|
2997
|
-
console.log(`[fullstack-cli] \u25CB ${
|
|
3014
|
+
console.log(`[fullstack-cli] \u25CB ${path7.basename(dirPath)} (not found)`);
|
|
2998
3015
|
}
|
|
2999
3016
|
}
|
|
3000
3017
|
function addScript(packageJsonPath, name, command, overwrite) {
|
|
3001
|
-
if (!
|
|
3018
|
+
if (!fs10.existsSync(packageJsonPath)) {
|
|
3002
3019
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
3003
3020
|
return;
|
|
3004
3021
|
}
|
|
3005
|
-
const content =
|
|
3022
|
+
const content = fs10.readFileSync(packageJsonPath, "utf-8");
|
|
3006
3023
|
const pkg2 = JSON.parse(content);
|
|
3007
3024
|
if (!pkg2.scripts) {
|
|
3008
3025
|
pkg2.scripts = {};
|
|
@@ -3014,16 +3031,16 @@ function addScript(packageJsonPath, name, command, overwrite) {
|
|
|
3014
3031
|
}
|
|
3015
3032
|
}
|
|
3016
3033
|
pkg2.scripts[name] = command;
|
|
3017
|
-
|
|
3034
|
+
fs10.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
3018
3035
|
console.log(`[fullstack-cli] \u2713 scripts.${name}`);
|
|
3019
3036
|
}
|
|
3020
3037
|
function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
3021
|
-
if (!
|
|
3038
|
+
if (!fs10.existsSync(packageJsonPath)) {
|
|
3022
3039
|
console.log(`[fullstack-cli] \u25CB package.json (not found)`);
|
|
3023
3040
|
return;
|
|
3024
3041
|
}
|
|
3025
3042
|
try {
|
|
3026
|
-
const content =
|
|
3043
|
+
const content = fs10.readFileSync(packageJsonPath, "utf-8");
|
|
3027
3044
|
const pkg2 = JSON.parse(content);
|
|
3028
3045
|
const current = pkg2.scripts?.[name];
|
|
3029
3046
|
if (!current) {
|
|
@@ -3041,7 +3058,7 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
|
3041
3058
|
return;
|
|
3042
3059
|
}
|
|
3043
3060
|
pkg2.scripts[name] = to;
|
|
3044
|
-
|
|
3061
|
+
fs10.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
|
|
3045
3062
|
console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
|
|
3046
3063
|
} catch (error) {
|
|
3047
3064
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -3049,38 +3066,38 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
|
|
|
3049
3066
|
}
|
|
3050
3067
|
}
|
|
3051
3068
|
function addLineToFile(filePath, line) {
|
|
3052
|
-
const fileName =
|
|
3053
|
-
if (!
|
|
3069
|
+
const fileName = path7.basename(filePath);
|
|
3070
|
+
if (!fs10.existsSync(filePath)) {
|
|
3054
3071
|
console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
|
|
3055
3072
|
return;
|
|
3056
3073
|
}
|
|
3057
|
-
const content =
|
|
3074
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
3058
3075
|
const lines = content.split("\n").map((l) => l.trim());
|
|
3059
3076
|
if (lines.includes(line)) {
|
|
3060
3077
|
console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
|
|
3061
3078
|
return;
|
|
3062
3079
|
}
|
|
3063
3080
|
const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
|
|
3064
|
-
|
|
3081
|
+
fs10.appendFileSync(filePath, appendContent);
|
|
3065
3082
|
console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
|
|
3066
3083
|
}
|
|
3067
3084
|
function mergeJsonFile(src, dest, arrayMerge) {
|
|
3068
|
-
const fileName =
|
|
3069
|
-
if (!
|
|
3085
|
+
const fileName = path7.basename(dest);
|
|
3086
|
+
if (!fs10.existsSync(src)) {
|
|
3070
3087
|
console.warn(`[fullstack-cli] Source not found: ${src}`);
|
|
3071
3088
|
return;
|
|
3072
3089
|
}
|
|
3073
|
-
const templateContent = JSON.parse(
|
|
3074
|
-
if (!
|
|
3075
|
-
const destDir =
|
|
3076
|
-
if (!
|
|
3077
|
-
|
|
3090
|
+
const templateContent = JSON.parse(fs10.readFileSync(src, "utf-8"));
|
|
3091
|
+
if (!fs10.existsSync(dest)) {
|
|
3092
|
+
const destDir = path7.dirname(dest);
|
|
3093
|
+
if (!fs10.existsSync(destDir)) {
|
|
3094
|
+
fs10.mkdirSync(destDir, { recursive: true });
|
|
3078
3095
|
}
|
|
3079
|
-
|
|
3096
|
+
fs10.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
|
|
3080
3097
|
console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
|
|
3081
3098
|
return;
|
|
3082
3099
|
}
|
|
3083
|
-
const userContent = JSON.parse(
|
|
3100
|
+
const userContent = JSON.parse(fs10.readFileSync(dest, "utf-8"));
|
|
3084
3101
|
const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
|
|
3085
3102
|
const userStr = JSON.stringify(userContent, null, 2);
|
|
3086
3103
|
const mergedStr = JSON.stringify(merged, null, 2);
|
|
@@ -3088,7 +3105,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
|
|
|
3088
3105
|
console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
|
|
3089
3106
|
return;
|
|
3090
3107
|
}
|
|
3091
|
-
|
|
3108
|
+
fs10.writeFileSync(dest, mergedStr + "\n");
|
|
3092
3109
|
console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
|
|
3093
3110
|
}
|
|
3094
3111
|
|
|
@@ -3097,7 +3114,7 @@ var syncCommand = {
|
|
|
3097
3114
|
name: "sync",
|
|
3098
3115
|
description: "Sync template files (scripts, configs) to user project",
|
|
3099
3116
|
register(program) {
|
|
3100
|
-
program.command(this.name).description(this.description).option("--disable-gen-openapi", "
|
|
3117
|
+
program.command(this.name).description(this.description).option("--disable-gen-openapi", "Deprecated compatibility option; OpenAPI generation is retired").action(async (options) => {
|
|
3101
3118
|
await run2(options);
|
|
3102
3119
|
});
|
|
3103
3120
|
}
|
|
@@ -3247,12 +3264,12 @@ async function reportCreateInstanceEvent(pluginKey, version) {
|
|
|
3247
3264
|
|
|
3248
3265
|
// src/utils/git.ts
|
|
3249
3266
|
import { execSync, spawnSync as spawnSync3 } from "child_process";
|
|
3250
|
-
import
|
|
3251
|
-
import
|
|
3267
|
+
import fs11 from "fs";
|
|
3268
|
+
import path8 from "path";
|
|
3252
3269
|
function isGitRepository(cwd = process.cwd()) {
|
|
3253
3270
|
try {
|
|
3254
|
-
const gitDir =
|
|
3255
|
-
if (
|
|
3271
|
+
const gitDir = path8.join(cwd, ".git");
|
|
3272
|
+
if (fs11.existsSync(gitDir)) {
|
|
3256
3273
|
return true;
|
|
3257
3274
|
}
|
|
3258
3275
|
const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
|
|
@@ -3281,7 +3298,7 @@ function getChangedFiles(cwd = process.cwd()) {
|
|
|
3281
3298
|
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
3282
3299
|
const filteredFiles = [];
|
|
3283
3300
|
for (const filePath of filesToStage) {
|
|
3284
|
-
if (
|
|
3301
|
+
if (fs11.existsSync(path8.join(cwd, filePath))) {
|
|
3285
3302
|
filteredFiles.push(filePath);
|
|
3286
3303
|
continue;
|
|
3287
3304
|
}
|
|
@@ -3366,20 +3383,20 @@ Auto-committed by fullstack-cli`;
|
|
|
3366
3383
|
}
|
|
3367
3384
|
|
|
3368
3385
|
// src/utils/package-json.ts
|
|
3369
|
-
import
|
|
3370
|
-
import
|
|
3386
|
+
import fs12 from "fs";
|
|
3387
|
+
import path9 from "path";
|
|
3371
3388
|
function readPackageJson(cwd = process.cwd()) {
|
|
3372
|
-
const pkgPath =
|
|
3373
|
-
if (!
|
|
3389
|
+
const pkgPath = path9.join(cwd, "package.json");
|
|
3390
|
+
if (!fs12.existsSync(pkgPath)) {
|
|
3374
3391
|
throw new Error(`package.json not found at ${pkgPath}`);
|
|
3375
3392
|
}
|
|
3376
|
-
const content =
|
|
3393
|
+
const content = fs12.readFileSync(pkgPath, "utf-8");
|
|
3377
3394
|
return JSON.parse(content);
|
|
3378
3395
|
}
|
|
3379
3396
|
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
3380
|
-
const pkgPath =
|
|
3397
|
+
const pkgPath = path9.join(cwd, "package.json");
|
|
3381
3398
|
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
3382
|
-
|
|
3399
|
+
fs12.writeFileSync(pkgPath, content, "utf-8");
|
|
3383
3400
|
}
|
|
3384
3401
|
function removeUpgradeScript(pkg2) {
|
|
3385
3402
|
if (!pkg2.scripts?.upgrade) {
|
|
@@ -3424,15 +3441,15 @@ function cleanupPackageJson(cwd = process.cwd()) {
|
|
|
3424
3441
|
}
|
|
3425
3442
|
|
|
3426
3443
|
// src/commands/upgrade/shared/utils.ts
|
|
3427
|
-
import
|
|
3428
|
-
import
|
|
3444
|
+
import path10 from "path";
|
|
3445
|
+
import fs13 from "fs";
|
|
3429
3446
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3430
3447
|
function getCliVersion() {
|
|
3431
3448
|
try {
|
|
3432
3449
|
const __filename = fileURLToPath4(import.meta.url);
|
|
3433
|
-
const __dirname2 =
|
|
3434
|
-
const pkgPath =
|
|
3435
|
-
const pkgContent =
|
|
3450
|
+
const __dirname2 = path10.dirname(__filename);
|
|
3451
|
+
const pkgPath = path10.resolve(__dirname2, "../../../package.json");
|
|
3452
|
+
const pkgContent = fs13.readFileSync(pkgPath, "utf-8");
|
|
3436
3453
|
const pkg2 = JSON.parse(pkgContent);
|
|
3437
3454
|
return pkg2.version || "unknown";
|
|
3438
3455
|
} catch {
|
|
@@ -3494,8 +3511,8 @@ async function run3(options = {}) {
|
|
|
3494
3511
|
|
|
3495
3512
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3496
3513
|
import { spawnSync as spawnSync4 } from "child_process";
|
|
3497
|
-
import
|
|
3498
|
-
import
|
|
3514
|
+
import fs14 from "fs";
|
|
3515
|
+
import path11 from "path";
|
|
3499
3516
|
|
|
3500
3517
|
// src/utils/grayscale/config.ts
|
|
3501
3518
|
function getGrayscaleConfig(configJson) {
|
|
@@ -3743,8 +3760,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
|
|
|
3743
3760
|
if (version) {
|
|
3744
3761
|
let current = "";
|
|
3745
3762
|
try {
|
|
3746
|
-
const installedPkgPath =
|
|
3747
|
-
const installedPkg = JSON.parse(
|
|
3763
|
+
const installedPkgPath = path11.join(cwd, "node_modules", pkg2, "package.json");
|
|
3764
|
+
const installedPkg = JSON.parse(fs14.readFileSync(installedPkgPath, "utf-8"));
|
|
3748
3765
|
current = installedPkg.version || "";
|
|
3749
3766
|
} catch (err) {
|
|
3750
3767
|
const code = err?.code;
|
|
@@ -3862,8 +3879,8 @@ var depsCommand = {
|
|
|
3862
3879
|
|
|
3863
3880
|
// src/commands/upgrade/global-deps/run.handler.ts
|
|
3864
3881
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
3865
|
-
import
|
|
3866
|
-
import
|
|
3882
|
+
import fs15 from "fs";
|
|
3883
|
+
import path12 from "path";
|
|
3867
3884
|
var MANAGED_GLOBAL_CLIS = [
|
|
3868
3885
|
"@lark-apaas/fullstack-cli",
|
|
3869
3886
|
"@lark-apaas/miaoda-cli"
|
|
@@ -3874,15 +3891,15 @@ function readGlobalInstalledVersion(pkg2) {
|
|
|
3874
3891
|
if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
|
|
3875
3892
|
candidates.push("/usr");
|
|
3876
3893
|
candidates.push("/usr/local");
|
|
3877
|
-
if (process.env.HOME) candidates.push(
|
|
3894
|
+
if (process.env.HOME) candidates.push(path12.join(process.env.HOME, ".npm-global"));
|
|
3878
3895
|
const seen = /* @__PURE__ */ new Set();
|
|
3879
3896
|
for (const prefix of candidates) {
|
|
3880
3897
|
if (seen.has(prefix)) continue;
|
|
3881
3898
|
seen.add(prefix);
|
|
3882
3899
|
try {
|
|
3883
|
-
const pkgPath =
|
|
3884
|
-
if (
|
|
3885
|
-
const meta = JSON.parse(
|
|
3900
|
+
const pkgPath = path12.join(prefix, "lib", "node_modules", pkg2, "package.json");
|
|
3901
|
+
if (fs15.existsSync(pkgPath)) {
|
|
3902
|
+
const meta = JSON.parse(fs15.readFileSync(pkgPath, "utf-8"));
|
|
3886
3903
|
if (meta && typeof meta.version === "string") return meta.version;
|
|
3887
3904
|
}
|
|
3888
3905
|
} catch (err) {
|
|
@@ -3970,7 +3987,7 @@ var upgradeCommand = {
|
|
|
3970
3987
|
name: "upgrade",
|
|
3971
3988
|
description: "Upgrade template files and auto-commit changes",
|
|
3972
3989
|
register(program) {
|
|
3973
|
-
const upgradeCmd = program.command(this.name).description(this.description).option("--disable-gen-openapi", "
|
|
3990
|
+
const upgradeCmd = program.command(this.name).description(this.description).option("--disable-gen-openapi", "Deprecated compatibility option; OpenAPI generation is retired").option("--no-commit", "Skip auto-commit changes").action(async (options) => {
|
|
3974
3991
|
await run3(options);
|
|
3975
3992
|
});
|
|
3976
3993
|
depsCommand.register(upgradeCmd);
|
|
@@ -3979,8 +3996,8 @@ var upgradeCommand = {
|
|
|
3979
3996
|
};
|
|
3980
3997
|
|
|
3981
3998
|
// src/commands/action-plugin/utils.ts
|
|
3982
|
-
import
|
|
3983
|
-
import
|
|
3999
|
+
import fs16 from "fs";
|
|
4000
|
+
import path13 from "path";
|
|
3984
4001
|
import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
|
|
3985
4002
|
function parsePluginName(input) {
|
|
3986
4003
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3998,18 +4015,18 @@ function getProjectRoot() {
|
|
|
3998
4015
|
return process.cwd();
|
|
3999
4016
|
}
|
|
4000
4017
|
function getPackageJsonPath() {
|
|
4001
|
-
return
|
|
4018
|
+
return path13.join(getProjectRoot(), "package.json");
|
|
4002
4019
|
}
|
|
4003
4020
|
function getPluginPath(pluginName) {
|
|
4004
|
-
return
|
|
4021
|
+
return path13.join(getProjectRoot(), "node_modules", pluginName);
|
|
4005
4022
|
}
|
|
4006
4023
|
function readPackageJson2() {
|
|
4007
4024
|
const pkgPath = getPackageJsonPath();
|
|
4008
|
-
if (!
|
|
4025
|
+
if (!fs16.existsSync(pkgPath)) {
|
|
4009
4026
|
throw new Error("package.json not found in current directory");
|
|
4010
4027
|
}
|
|
4011
4028
|
try {
|
|
4012
|
-
const content =
|
|
4029
|
+
const content = fs16.readFileSync(pkgPath, "utf-8");
|
|
4013
4030
|
return JSON.parse(content);
|
|
4014
4031
|
} catch {
|
|
4015
4032
|
throw new Error("Failed to parse package.json");
|
|
@@ -4017,7 +4034,7 @@ function readPackageJson2() {
|
|
|
4017
4034
|
}
|
|
4018
4035
|
function writePackageJson2(pkg2) {
|
|
4019
4036
|
const pkgPath = getPackageJsonPath();
|
|
4020
|
-
|
|
4037
|
+
fs16.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4021
4038
|
}
|
|
4022
4039
|
function readActionPlugins() {
|
|
4023
4040
|
const pkg2 = readPackageJson2();
|
|
@@ -4050,12 +4067,12 @@ function npmInstall(tgzPath) {
|
|
|
4050
4067
|
}
|
|
4051
4068
|
}
|
|
4052
4069
|
function getPackageVersion(pluginName) {
|
|
4053
|
-
const pkgJsonPath =
|
|
4054
|
-
if (!
|
|
4070
|
+
const pkgJsonPath = path13.join(getPluginPath(pluginName), "package.json");
|
|
4071
|
+
if (!fs16.existsSync(pkgJsonPath)) {
|
|
4055
4072
|
return null;
|
|
4056
4073
|
}
|
|
4057
4074
|
try {
|
|
4058
|
-
const content =
|
|
4075
|
+
const content = fs16.readFileSync(pkgJsonPath, "utf-8");
|
|
4059
4076
|
const pkg2 = JSON.parse(content);
|
|
4060
4077
|
return pkg2.version || null;
|
|
4061
4078
|
} catch {
|
|
@@ -4063,49 +4080,49 @@ function getPackageVersion(pluginName) {
|
|
|
4063
4080
|
}
|
|
4064
4081
|
}
|
|
4065
4082
|
function readPluginPackageJson(pluginPath) {
|
|
4066
|
-
const pkgJsonPath =
|
|
4067
|
-
if (!
|
|
4083
|
+
const pkgJsonPath = path13.join(pluginPath, "package.json");
|
|
4084
|
+
if (!fs16.existsSync(pkgJsonPath)) {
|
|
4068
4085
|
return null;
|
|
4069
4086
|
}
|
|
4070
4087
|
try {
|
|
4071
|
-
const content =
|
|
4088
|
+
const content = fs16.readFileSync(pkgJsonPath, "utf-8");
|
|
4072
4089
|
return JSON.parse(content);
|
|
4073
4090
|
} catch {
|
|
4074
4091
|
return null;
|
|
4075
4092
|
}
|
|
4076
4093
|
}
|
|
4077
4094
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
4078
|
-
const nodeModulesPath =
|
|
4079
|
-
const targetDir =
|
|
4080
|
-
const scopeDir =
|
|
4081
|
-
if (!
|
|
4082
|
-
|
|
4095
|
+
const nodeModulesPath = path13.join(getProjectRoot(), "node_modules");
|
|
4096
|
+
const targetDir = path13.join(nodeModulesPath, pluginName);
|
|
4097
|
+
const scopeDir = path13.dirname(targetDir);
|
|
4098
|
+
if (!fs16.existsSync(scopeDir)) {
|
|
4099
|
+
fs16.mkdirSync(scopeDir, { recursive: true });
|
|
4083
4100
|
}
|
|
4084
|
-
if (
|
|
4085
|
-
|
|
4101
|
+
if (fs16.existsSync(targetDir)) {
|
|
4102
|
+
fs16.rmSync(targetDir, { recursive: true });
|
|
4086
4103
|
}
|
|
4087
|
-
const tempDir =
|
|
4088
|
-
if (
|
|
4089
|
-
|
|
4104
|
+
const tempDir = path13.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
4105
|
+
if (fs16.existsSync(tempDir)) {
|
|
4106
|
+
fs16.rmSync(tempDir, { recursive: true });
|
|
4090
4107
|
}
|
|
4091
|
-
|
|
4108
|
+
fs16.mkdirSync(tempDir, { recursive: true });
|
|
4092
4109
|
try {
|
|
4093
4110
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
4094
|
-
const extractedDir =
|
|
4095
|
-
if (
|
|
4096
|
-
|
|
4111
|
+
const extractedDir = path13.join(tempDir, "package");
|
|
4112
|
+
if (fs16.existsSync(extractedDir)) {
|
|
4113
|
+
fs16.renameSync(extractedDir, targetDir);
|
|
4097
4114
|
} else {
|
|
4098
|
-
const files =
|
|
4115
|
+
const files = fs16.readdirSync(tempDir);
|
|
4099
4116
|
if (files.length === 1) {
|
|
4100
|
-
|
|
4117
|
+
fs16.renameSync(path13.join(tempDir, files[0]), targetDir);
|
|
4101
4118
|
} else {
|
|
4102
4119
|
throw new Error("Unexpected tgz structure");
|
|
4103
4120
|
}
|
|
4104
4121
|
}
|
|
4105
4122
|
return targetDir;
|
|
4106
4123
|
} finally {
|
|
4107
|
-
if (
|
|
4108
|
-
|
|
4124
|
+
if (fs16.existsSync(tempDir)) {
|
|
4125
|
+
fs16.rmSync(tempDir, { recursive: true });
|
|
4109
4126
|
}
|
|
4110
4127
|
}
|
|
4111
4128
|
}
|
|
@@ -4114,10 +4131,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
4114
4131
|
return [];
|
|
4115
4132
|
}
|
|
4116
4133
|
const missing = [];
|
|
4117
|
-
const nodeModulesPath =
|
|
4134
|
+
const nodeModulesPath = path13.join(getProjectRoot(), "node_modules");
|
|
4118
4135
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
4119
|
-
const depPath =
|
|
4120
|
-
if (!
|
|
4136
|
+
const depPath = path13.join(nodeModulesPath, depName);
|
|
4137
|
+
if (!fs16.existsSync(depPath)) {
|
|
4121
4138
|
missing.push(depName);
|
|
4122
4139
|
}
|
|
4123
4140
|
}
|
|
@@ -4141,16 +4158,16 @@ function installMissingDeps(deps) {
|
|
|
4141
4158
|
}
|
|
4142
4159
|
function removePluginDirectory(pluginName) {
|
|
4143
4160
|
const pluginPath = getPluginPath(pluginName);
|
|
4144
|
-
if (
|
|
4145
|
-
|
|
4161
|
+
if (fs16.existsSync(pluginPath)) {
|
|
4162
|
+
fs16.rmSync(pluginPath, { recursive: true });
|
|
4146
4163
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
4147
4164
|
}
|
|
4148
4165
|
}
|
|
4149
4166
|
|
|
4150
4167
|
// src/commands/action-plugin/api-client.ts
|
|
4151
4168
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
4152
|
-
import
|
|
4153
|
-
import
|
|
4169
|
+
import fs17 from "fs";
|
|
4170
|
+
import path14 from "path";
|
|
4154
4171
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
4155
4172
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
4156
4173
|
const client = getHttpClient();
|
|
@@ -4215,19 +4232,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
4215
4232
|
return Buffer.from(arrayBuffer);
|
|
4216
4233
|
}
|
|
4217
4234
|
function getPluginCacheDir() {
|
|
4218
|
-
return
|
|
4235
|
+
return path14.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
4219
4236
|
}
|
|
4220
4237
|
function ensureCacheDir() {
|
|
4221
4238
|
const cacheDir = getPluginCacheDir();
|
|
4222
|
-
if (!
|
|
4223
|
-
|
|
4239
|
+
if (!fs17.existsSync(cacheDir)) {
|
|
4240
|
+
fs17.mkdirSync(cacheDir, { recursive: true });
|
|
4224
4241
|
}
|
|
4225
4242
|
}
|
|
4226
4243
|
function getTempFilePath(pluginKey, version) {
|
|
4227
4244
|
ensureCacheDir();
|
|
4228
4245
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4229
4246
|
const filename = `${safeKey}@${version}.tgz`;
|
|
4230
|
-
return
|
|
4247
|
+
return path14.join(getPluginCacheDir(), filename);
|
|
4231
4248
|
}
|
|
4232
4249
|
var MAX_RETRIES = 2;
|
|
4233
4250
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -4264,7 +4281,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
4264
4281
|
);
|
|
4265
4282
|
}
|
|
4266
4283
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
4267
|
-
|
|
4284
|
+
fs17.writeFileSync(tgzPath, tgzBuffer);
|
|
4268
4285
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
4269
4286
|
return {
|
|
4270
4287
|
tgzPath,
|
|
@@ -4278,18 +4295,18 @@ function getCachePath(pluginKey, version) {
|
|
|
4278
4295
|
ensureCacheDir();
|
|
4279
4296
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4280
4297
|
const filename = `${safeKey}@${version}.tgz`;
|
|
4281
|
-
return
|
|
4298
|
+
return path14.join(getPluginCacheDir(), filename);
|
|
4282
4299
|
}
|
|
4283
4300
|
function hasCachedPlugin(pluginKey, version) {
|
|
4284
4301
|
const cachePath = getCachePath(pluginKey, version);
|
|
4285
|
-
return
|
|
4302
|
+
return fs17.existsSync(cachePath);
|
|
4286
4303
|
}
|
|
4287
4304
|
function listCachedPlugins() {
|
|
4288
4305
|
const cacheDir = getPluginCacheDir();
|
|
4289
|
-
if (!
|
|
4306
|
+
if (!fs17.existsSync(cacheDir)) {
|
|
4290
4307
|
return [];
|
|
4291
4308
|
}
|
|
4292
|
-
const files =
|
|
4309
|
+
const files = fs17.readdirSync(cacheDir);
|
|
4293
4310
|
const result = [];
|
|
4294
4311
|
for (const file of files) {
|
|
4295
4312
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -4297,8 +4314,8 @@ function listCachedPlugins() {
|
|
|
4297
4314
|
if (!match) continue;
|
|
4298
4315
|
const [, rawName, version] = match;
|
|
4299
4316
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
4300
|
-
const filePath =
|
|
4301
|
-
const stat =
|
|
4317
|
+
const filePath = path14.join(cacheDir, file);
|
|
4318
|
+
const stat = fs17.statSync(filePath);
|
|
4302
4319
|
result.push({
|
|
4303
4320
|
name,
|
|
4304
4321
|
version,
|
|
@@ -4311,14 +4328,14 @@ function listCachedPlugins() {
|
|
|
4311
4328
|
}
|
|
4312
4329
|
function cleanAllCache() {
|
|
4313
4330
|
const cacheDir = getPluginCacheDir();
|
|
4314
|
-
if (!
|
|
4331
|
+
if (!fs17.existsSync(cacheDir)) {
|
|
4315
4332
|
return 0;
|
|
4316
4333
|
}
|
|
4317
|
-
const files =
|
|
4334
|
+
const files = fs17.readdirSync(cacheDir);
|
|
4318
4335
|
let count = 0;
|
|
4319
4336
|
for (const file of files) {
|
|
4320
4337
|
if (file.endsWith(".tgz")) {
|
|
4321
|
-
|
|
4338
|
+
fs17.unlinkSync(path14.join(cacheDir, file));
|
|
4322
4339
|
count++;
|
|
4323
4340
|
}
|
|
4324
4341
|
}
|
|
@@ -4326,21 +4343,21 @@ function cleanAllCache() {
|
|
|
4326
4343
|
}
|
|
4327
4344
|
function cleanPluginCache(pluginKey, version) {
|
|
4328
4345
|
const cacheDir = getPluginCacheDir();
|
|
4329
|
-
if (!
|
|
4346
|
+
if (!fs17.existsSync(cacheDir)) {
|
|
4330
4347
|
return 0;
|
|
4331
4348
|
}
|
|
4332
4349
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
4333
|
-
const files =
|
|
4350
|
+
const files = fs17.readdirSync(cacheDir);
|
|
4334
4351
|
let count = 0;
|
|
4335
4352
|
for (const file of files) {
|
|
4336
4353
|
if (version) {
|
|
4337
4354
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
4338
|
-
|
|
4355
|
+
fs17.unlinkSync(path14.join(cacheDir, file));
|
|
4339
4356
|
count++;
|
|
4340
4357
|
}
|
|
4341
4358
|
} else {
|
|
4342
4359
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
4343
|
-
|
|
4360
|
+
fs17.unlinkSync(path14.join(cacheDir, file));
|
|
4344
4361
|
count++;
|
|
4345
4362
|
}
|
|
4346
4363
|
}
|
|
@@ -4767,45 +4784,45 @@ var actionPluginCommandGroup = {
|
|
|
4767
4784
|
};
|
|
4768
4785
|
|
|
4769
4786
|
// src/commands/capability/utils.ts
|
|
4770
|
-
import
|
|
4787
|
+
import fs18 from "fs";
|
|
4771
4788
|
import { createRequire as createRequire2 } from "module";
|
|
4772
|
-
import
|
|
4789
|
+
import path15 from "path";
|
|
4773
4790
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4774
4791
|
var SHARED_CAPABILITIES_DIR = "shared/capabilities";
|
|
4775
4792
|
function getProjectRoot2() {
|
|
4776
4793
|
return process.cwd();
|
|
4777
4794
|
}
|
|
4778
4795
|
function getCapabilitiesDir() {
|
|
4779
|
-
const sharedDir =
|
|
4780
|
-
if (
|
|
4796
|
+
const sharedDir = path15.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
|
|
4797
|
+
if (fs18.existsSync(sharedDir)) {
|
|
4781
4798
|
return sharedDir;
|
|
4782
4799
|
}
|
|
4783
|
-
return
|
|
4800
|
+
return path15.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4784
4801
|
}
|
|
4785
4802
|
function getCapabilityPath(id) {
|
|
4786
|
-
return
|
|
4803
|
+
return path15.join(getCapabilitiesDir(), `${id}.json`);
|
|
4787
4804
|
}
|
|
4788
4805
|
function getPluginManifestPath(pluginKey) {
|
|
4789
|
-
return
|
|
4806
|
+
return path15.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4790
4807
|
}
|
|
4791
4808
|
function capabilitiesDirExists() {
|
|
4792
|
-
return
|
|
4809
|
+
return fs18.existsSync(getCapabilitiesDir());
|
|
4793
4810
|
}
|
|
4794
4811
|
function listCapabilityIds() {
|
|
4795
4812
|
const dir = getCapabilitiesDir();
|
|
4796
|
-
if (!
|
|
4813
|
+
if (!fs18.existsSync(dir)) {
|
|
4797
4814
|
return [];
|
|
4798
4815
|
}
|
|
4799
|
-
const files =
|
|
4816
|
+
const files = fs18.readdirSync(dir);
|
|
4800
4817
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4801
4818
|
}
|
|
4802
4819
|
function readCapability(id) {
|
|
4803
4820
|
const filePath = getCapabilityPath(id);
|
|
4804
|
-
if (!
|
|
4821
|
+
if (!fs18.existsSync(filePath)) {
|
|
4805
4822
|
throw new Error(`Capability not found: ${id}`);
|
|
4806
4823
|
}
|
|
4807
4824
|
try {
|
|
4808
|
-
const content =
|
|
4825
|
+
const content = fs18.readFileSync(filePath, "utf-8");
|
|
4809
4826
|
return JSON.parse(content);
|
|
4810
4827
|
} catch (error) {
|
|
4811
4828
|
if (error instanceof SyntaxError) {
|
|
@@ -4832,11 +4849,11 @@ function readAllCapabilities() {
|
|
|
4832
4849
|
}
|
|
4833
4850
|
function readPluginManifest(pluginKey) {
|
|
4834
4851
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4835
|
-
if (!
|
|
4852
|
+
if (!fs18.existsSync(manifestPath)) {
|
|
4836
4853
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4837
4854
|
}
|
|
4838
4855
|
try {
|
|
4839
|
-
const content =
|
|
4856
|
+
const content = fs18.readFileSync(manifestPath, "utf-8");
|
|
4840
4857
|
return JSON.parse(content);
|
|
4841
4858
|
} catch (error) {
|
|
4842
4859
|
if (error instanceof SyntaxError) {
|
|
@@ -4853,7 +4870,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4853
4870
|
}
|
|
4854
4871
|
async function loadPlugin(pluginKey) {
|
|
4855
4872
|
try {
|
|
4856
|
-
const userRequire = createRequire2(
|
|
4873
|
+
const userRequire = createRequire2(path15.join(getProjectRoot2(), "package.json"));
|
|
4857
4874
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4858
4875
|
const pluginModule = await import(resolvedPath);
|
|
4859
4876
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -5016,8 +5033,8 @@ var capabilityCommandGroup = {
|
|
|
5016
5033
|
import { execFile } from "child_process";
|
|
5017
5034
|
|
|
5018
5035
|
// src/commands/component/registry-preparer.ts
|
|
5019
|
-
import
|
|
5020
|
-
import
|
|
5036
|
+
import fs19 from "fs";
|
|
5037
|
+
import path16 from "path";
|
|
5021
5038
|
import os from "os";
|
|
5022
5039
|
|
|
5023
5040
|
// src/commands/component/service.ts
|
|
@@ -5077,7 +5094,7 @@ async function sendInstallEvent(key) {
|
|
|
5077
5094
|
}
|
|
5078
5095
|
|
|
5079
5096
|
// src/commands/component/registry-preparer.ts
|
|
5080
|
-
var REGISTRY_TEMP_DIR =
|
|
5097
|
+
var REGISTRY_TEMP_DIR = path16.join(os.tmpdir(), "miaoda-registry");
|
|
5081
5098
|
function parseComponentKey(key) {
|
|
5082
5099
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
5083
5100
|
if (!match) {
|
|
@@ -5089,11 +5106,11 @@ function parseComponentKey(key) {
|
|
|
5089
5106
|
}
|
|
5090
5107
|
function getLocalRegistryPath(key) {
|
|
5091
5108
|
const { scope, name } = parseComponentKey(key);
|
|
5092
|
-
return
|
|
5109
|
+
return path16.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
5093
5110
|
}
|
|
5094
5111
|
function ensureDir(dirPath) {
|
|
5095
|
-
if (!
|
|
5096
|
-
|
|
5112
|
+
if (!fs19.existsSync(dirPath)) {
|
|
5113
|
+
fs19.mkdirSync(dirPath, { recursive: true });
|
|
5097
5114
|
}
|
|
5098
5115
|
}
|
|
5099
5116
|
async function prepareRecursive(key, visited) {
|
|
@@ -5126,8 +5143,8 @@ async function prepareRecursive(key, visited) {
|
|
|
5126
5143
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
5127
5144
|
};
|
|
5128
5145
|
const localPath = getLocalRegistryPath(key);
|
|
5129
|
-
ensureDir(
|
|
5130
|
-
|
|
5146
|
+
ensureDir(path16.dirname(localPath));
|
|
5147
|
+
fs19.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
5131
5148
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
5132
5149
|
}
|
|
5133
5150
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -5137,18 +5154,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
5137
5154
|
}
|
|
5138
5155
|
function cleanupTempDir() {
|
|
5139
5156
|
try {
|
|
5140
|
-
if (
|
|
5141
|
-
|
|
5157
|
+
if (fs19.existsSync(REGISTRY_TEMP_DIR)) {
|
|
5158
|
+
fs19.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
5142
5159
|
}
|
|
5143
5160
|
} catch {
|
|
5144
5161
|
}
|
|
5145
5162
|
}
|
|
5146
5163
|
function getDownloadedRegistryItem(itemId) {
|
|
5147
5164
|
const localPath = getLocalRegistryPath(itemId);
|
|
5148
|
-
if (!
|
|
5165
|
+
if (!fs19.existsSync(localPath)) {
|
|
5149
5166
|
return null;
|
|
5150
5167
|
}
|
|
5151
|
-
const content =
|
|
5168
|
+
const content = fs19.readFileSync(localPath, "utf-8");
|
|
5152
5169
|
return JSON.parse(content);
|
|
5153
5170
|
}
|
|
5154
5171
|
|
|
@@ -5316,58 +5333,58 @@ var componentCommandGroup = {
|
|
|
5316
5333
|
};
|
|
5317
5334
|
|
|
5318
5335
|
// src/commands/migration/version-manager.ts
|
|
5319
|
-
import
|
|
5320
|
-
import
|
|
5336
|
+
import fs20 from "fs";
|
|
5337
|
+
import path17 from "path";
|
|
5321
5338
|
var PACKAGE_JSON = "package.json";
|
|
5322
5339
|
var VERSION_FIELD = "migrationVersion";
|
|
5323
5340
|
function getPackageJsonPath2() {
|
|
5324
|
-
return
|
|
5341
|
+
return path17.join(process.cwd(), PACKAGE_JSON);
|
|
5325
5342
|
}
|
|
5326
5343
|
function getCurrentVersion() {
|
|
5327
5344
|
const pkgPath = getPackageJsonPath2();
|
|
5328
|
-
if (!
|
|
5345
|
+
if (!fs20.existsSync(pkgPath)) {
|
|
5329
5346
|
throw new Error("package.json not found");
|
|
5330
5347
|
}
|
|
5331
|
-
const pkg2 = JSON.parse(
|
|
5348
|
+
const pkg2 = JSON.parse(fs20.readFileSync(pkgPath, "utf-8"));
|
|
5332
5349
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
5333
5350
|
}
|
|
5334
5351
|
function setCurrentVersion(version) {
|
|
5335
5352
|
const pkgPath = getPackageJsonPath2();
|
|
5336
|
-
const pkg2 = JSON.parse(
|
|
5353
|
+
const pkg2 = JSON.parse(fs20.readFileSync(pkgPath, "utf-8"));
|
|
5337
5354
|
pkg2[VERSION_FIELD] = version;
|
|
5338
|
-
|
|
5355
|
+
fs20.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
5339
5356
|
}
|
|
5340
5357
|
|
|
5341
5358
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5342
|
-
import
|
|
5343
|
-
import
|
|
5359
|
+
import fs22 from "fs";
|
|
5360
|
+
import path19 from "path";
|
|
5344
5361
|
|
|
5345
5362
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
5346
|
-
import
|
|
5347
|
-
import
|
|
5363
|
+
import fs21 from "fs";
|
|
5364
|
+
import path18 from "path";
|
|
5348
5365
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
5349
5366
|
function getProjectRoot3() {
|
|
5350
5367
|
return process.cwd();
|
|
5351
5368
|
}
|
|
5352
5369
|
function getCapabilitiesDir2() {
|
|
5353
|
-
return
|
|
5370
|
+
return path18.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
5354
5371
|
}
|
|
5355
5372
|
function getPluginManifestPath2(pluginKey) {
|
|
5356
|
-
return
|
|
5373
|
+
return path18.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
5357
5374
|
}
|
|
5358
5375
|
|
|
5359
5376
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5360
5377
|
function detectJsonMigration() {
|
|
5361
5378
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5362
|
-
const oldFilePath =
|
|
5363
|
-
if (!
|
|
5379
|
+
const oldFilePath = path19.join(capabilitiesDir, "capabilities.json");
|
|
5380
|
+
if (!fs22.existsSync(oldFilePath)) {
|
|
5364
5381
|
return {
|
|
5365
5382
|
needsMigration: false,
|
|
5366
5383
|
reason: "capabilities.json not found"
|
|
5367
5384
|
};
|
|
5368
5385
|
}
|
|
5369
5386
|
try {
|
|
5370
|
-
const content =
|
|
5387
|
+
const content = fs22.readFileSync(oldFilePath, "utf-8");
|
|
5371
5388
|
const parsed = JSON.parse(content);
|
|
5372
5389
|
if (!Array.isArray(parsed)) {
|
|
5373
5390
|
return {
|
|
@@ -5418,8 +5435,8 @@ async function check(options) {
|
|
|
5418
5435
|
}
|
|
5419
5436
|
|
|
5420
5437
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5421
|
-
import
|
|
5422
|
-
import
|
|
5438
|
+
import fs23 from "fs";
|
|
5439
|
+
import path20 from "path";
|
|
5423
5440
|
|
|
5424
5441
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5425
5442
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5649,18 +5666,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5649
5666
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5650
5667
|
function loadExistingCapabilities() {
|
|
5651
5668
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5652
|
-
if (!
|
|
5669
|
+
if (!fs23.existsSync(capabilitiesDir)) {
|
|
5653
5670
|
return [];
|
|
5654
5671
|
}
|
|
5655
|
-
const files =
|
|
5672
|
+
const files = fs23.readdirSync(capabilitiesDir);
|
|
5656
5673
|
const capabilities = [];
|
|
5657
5674
|
for (const file of files) {
|
|
5658
5675
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5659
5676
|
continue;
|
|
5660
5677
|
}
|
|
5661
5678
|
try {
|
|
5662
|
-
const filePath =
|
|
5663
|
-
const content =
|
|
5679
|
+
const filePath = path20.join(capabilitiesDir, file);
|
|
5680
|
+
const content = fs23.readFileSync(filePath, "utf-8");
|
|
5664
5681
|
const capability = JSON.parse(content);
|
|
5665
5682
|
if (capability.id && capability.pluginKey) {
|
|
5666
5683
|
capabilities.push(capability);
|
|
@@ -5718,9 +5735,9 @@ async function migrateJsonFiles(options) {
|
|
|
5718
5735
|
}
|
|
5719
5736
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5720
5737
|
for (const cap of newCapabilities) {
|
|
5721
|
-
const filePath =
|
|
5738
|
+
const filePath = path20.join(capabilitiesDir, `${cap.id}.json`);
|
|
5722
5739
|
const content = JSON.stringify(cap, null, 2);
|
|
5723
|
-
|
|
5740
|
+
fs23.writeFileSync(filePath, content, "utf-8");
|
|
5724
5741
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5725
5742
|
}
|
|
5726
5743
|
return {
|
|
@@ -5732,11 +5749,11 @@ async function migrateJsonFiles(options) {
|
|
|
5732
5749
|
}
|
|
5733
5750
|
|
|
5734
5751
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5735
|
-
import
|
|
5752
|
+
import fs24 from "fs";
|
|
5736
5753
|
function isPluginInstalled2(pluginKey) {
|
|
5737
5754
|
const actionPlugins = readActionPlugins();
|
|
5738
5755
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5739
|
-
return
|
|
5756
|
+
return fs24.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5740
5757
|
}
|
|
5741
5758
|
function detectPluginsToInstall(capabilities) {
|
|
5742
5759
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5812,12 +5829,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5812
5829
|
}
|
|
5813
5830
|
|
|
5814
5831
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5815
|
-
import
|
|
5832
|
+
import path22 from "path";
|
|
5816
5833
|
import { Project as Project3 } from "ts-morph";
|
|
5817
5834
|
|
|
5818
5835
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5819
|
-
import
|
|
5820
|
-
import
|
|
5836
|
+
import fs25 from "fs";
|
|
5837
|
+
import path21 from "path";
|
|
5821
5838
|
var EXCLUDED_DIRS = [
|
|
5822
5839
|
"node_modules",
|
|
5823
5840
|
"dist",
|
|
@@ -5832,9 +5849,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5832
5849
|
/\.d\.ts$/
|
|
5833
5850
|
];
|
|
5834
5851
|
function scanDirectory(dir, files = []) {
|
|
5835
|
-
const entries =
|
|
5852
|
+
const entries = fs25.readdirSync(dir, { withFileTypes: true });
|
|
5836
5853
|
for (const entry of entries) {
|
|
5837
|
-
const fullPath =
|
|
5854
|
+
const fullPath = path21.join(dir, entry.name);
|
|
5838
5855
|
if (entry.isDirectory()) {
|
|
5839
5856
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5840
5857
|
continue;
|
|
@@ -5850,14 +5867,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5850
5867
|
return files;
|
|
5851
5868
|
}
|
|
5852
5869
|
function scanServerFiles() {
|
|
5853
|
-
const serverDir =
|
|
5854
|
-
if (!
|
|
5870
|
+
const serverDir = path21.join(getProjectRoot3(), "server");
|
|
5871
|
+
if (!fs25.existsSync(serverDir)) {
|
|
5855
5872
|
return [];
|
|
5856
5873
|
}
|
|
5857
5874
|
return scanDirectory(serverDir);
|
|
5858
5875
|
}
|
|
5859
5876
|
function hasCapabilityImport(filePath) {
|
|
5860
|
-
const content =
|
|
5877
|
+
const content = fs25.readFileSync(filePath, "utf-8");
|
|
5861
5878
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5862
5879
|
}
|
|
5863
5880
|
function scanFilesToMigrate() {
|
|
@@ -6234,7 +6251,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6234
6251
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
6235
6252
|
const classInfo = analyzeClass(sourceFile);
|
|
6236
6253
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
6237
|
-
const relativePath =
|
|
6254
|
+
const relativePath = path22.relative(getProjectRoot3(), filePath);
|
|
6238
6255
|
return {
|
|
6239
6256
|
filePath: relativePath,
|
|
6240
6257
|
imports,
|
|
@@ -6245,7 +6262,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6245
6262
|
};
|
|
6246
6263
|
}
|
|
6247
6264
|
function migrateFile(project, analysis, dryRun) {
|
|
6248
|
-
const absolutePath =
|
|
6265
|
+
const absolutePath = path22.join(getProjectRoot3(), analysis.filePath);
|
|
6249
6266
|
if (!analysis.canAutoMigrate) {
|
|
6250
6267
|
return {
|
|
6251
6268
|
filePath: analysis.filePath,
|
|
@@ -6348,17 +6365,17 @@ function getSuggestion(analysis) {
|
|
|
6348
6365
|
}
|
|
6349
6366
|
|
|
6350
6367
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
6351
|
-
import
|
|
6352
|
-
import
|
|
6368
|
+
import fs26 from "fs";
|
|
6369
|
+
import path23 from "path";
|
|
6353
6370
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
6354
6371
|
const deletedFiles = [];
|
|
6355
6372
|
const errors = [];
|
|
6356
6373
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6357
|
-
const oldJsonPath =
|
|
6358
|
-
if (
|
|
6374
|
+
const oldJsonPath = path23.join(capabilitiesDir, "capabilities.json");
|
|
6375
|
+
if (fs26.existsSync(oldJsonPath)) {
|
|
6359
6376
|
try {
|
|
6360
6377
|
if (!dryRun) {
|
|
6361
|
-
|
|
6378
|
+
fs26.unlinkSync(oldJsonPath);
|
|
6362
6379
|
}
|
|
6363
6380
|
deletedFiles.push("capabilities.json");
|
|
6364
6381
|
} catch (error) {
|
|
@@ -6366,11 +6383,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6366
6383
|
}
|
|
6367
6384
|
}
|
|
6368
6385
|
for (const cap of capabilities) {
|
|
6369
|
-
const tsFilePath =
|
|
6370
|
-
if (
|
|
6386
|
+
const tsFilePath = path23.join(capabilitiesDir, `${cap.id}.ts`);
|
|
6387
|
+
if (fs26.existsSync(tsFilePath)) {
|
|
6371
6388
|
try {
|
|
6372
6389
|
if (!dryRun) {
|
|
6373
|
-
|
|
6390
|
+
fs26.unlinkSync(tsFilePath);
|
|
6374
6391
|
}
|
|
6375
6392
|
deletedFiles.push(`${cap.id}.ts`);
|
|
6376
6393
|
} catch (error) {
|
|
@@ -6386,8 +6403,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6386
6403
|
}
|
|
6387
6404
|
|
|
6388
6405
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
6389
|
-
import
|
|
6390
|
-
import
|
|
6406
|
+
import fs27 from "fs";
|
|
6407
|
+
import path24 from "path";
|
|
6391
6408
|
var REPORT_FILE = "capability-migration-report.md";
|
|
6392
6409
|
function printSummary(result) {
|
|
6393
6410
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6550,15 +6567,15 @@ async function generateReport(result) {
|
|
|
6550
6567
|
}
|
|
6551
6568
|
lines.push("");
|
|
6552
6569
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6553
|
-
if (!
|
|
6570
|
+
if (!fs27.existsSync(logDir)) {
|
|
6554
6571
|
return;
|
|
6555
6572
|
}
|
|
6556
|
-
const reportDir =
|
|
6557
|
-
if (!
|
|
6558
|
-
|
|
6573
|
+
const reportDir = path24.join(logDir, "migration");
|
|
6574
|
+
if (!fs27.existsSync(reportDir)) {
|
|
6575
|
+
fs27.mkdirSync(reportDir, { recursive: true });
|
|
6559
6576
|
}
|
|
6560
|
-
const reportPath =
|
|
6561
|
-
|
|
6577
|
+
const reportPath = path24.join(reportDir, REPORT_FILE);
|
|
6578
|
+
fs27.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6562
6579
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6563
6580
|
}
|
|
6564
6581
|
|
|
@@ -7090,10 +7107,10 @@ var migrationCommand = {
|
|
|
7090
7107
|
};
|
|
7091
7108
|
|
|
7092
7109
|
// src/commands/read-logs/index.ts
|
|
7093
|
-
import
|
|
7110
|
+
import path25 from "path";
|
|
7094
7111
|
|
|
7095
7112
|
// src/commands/read-logs/std-utils.ts
|
|
7096
|
-
import
|
|
7113
|
+
import fs28 from "fs";
|
|
7097
7114
|
function formatStdPrefixTime(localTime) {
|
|
7098
7115
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
7099
7116
|
if (!match) return localTime;
|
|
@@ -7123,11 +7140,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
7123
7140
|
return `[${time}] ${content}`;
|
|
7124
7141
|
}
|
|
7125
7142
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
7126
|
-
const stat =
|
|
7143
|
+
const stat = fs28.statSync(filePath);
|
|
7127
7144
|
if (stat.size === 0) {
|
|
7128
7145
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
7129
7146
|
}
|
|
7130
|
-
const fd =
|
|
7147
|
+
const fd = fs28.openSync(filePath, "r");
|
|
7131
7148
|
const chunkSize = 64 * 1024;
|
|
7132
7149
|
let position = stat.size;
|
|
7133
7150
|
let remainder = "";
|
|
@@ -7141,7 +7158,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7141
7158
|
const length = Math.min(chunkSize, position);
|
|
7142
7159
|
position -= length;
|
|
7143
7160
|
const buffer = Buffer.alloc(length);
|
|
7144
|
-
|
|
7161
|
+
fs28.readSync(fd, buffer, 0, length, position);
|
|
7145
7162
|
let chunk = buffer.toString("utf8");
|
|
7146
7163
|
if (remainder) {
|
|
7147
7164
|
chunk += remainder;
|
|
@@ -7183,7 +7200,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7183
7200
|
}
|
|
7184
7201
|
}
|
|
7185
7202
|
} finally {
|
|
7186
|
-
|
|
7203
|
+
fs28.closeSync(fd);
|
|
7187
7204
|
}
|
|
7188
7205
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
7189
7206
|
}
|
|
@@ -7204,21 +7221,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
7204
7221
|
}
|
|
7205
7222
|
|
|
7206
7223
|
// src/commands/read-logs/tail.ts
|
|
7207
|
-
import
|
|
7224
|
+
import fs29 from "fs";
|
|
7208
7225
|
function fileExists(filePath) {
|
|
7209
7226
|
try {
|
|
7210
|
-
|
|
7227
|
+
fs29.accessSync(filePath, fs29.constants.F_OK | fs29.constants.R_OK);
|
|
7211
7228
|
return true;
|
|
7212
7229
|
} catch {
|
|
7213
7230
|
return false;
|
|
7214
7231
|
}
|
|
7215
7232
|
}
|
|
7216
7233
|
function readFileTailLines(filePath, maxLines) {
|
|
7217
|
-
const stat =
|
|
7234
|
+
const stat = fs29.statSync(filePath);
|
|
7218
7235
|
if (stat.size === 0) {
|
|
7219
7236
|
return [];
|
|
7220
7237
|
}
|
|
7221
|
-
const fd =
|
|
7238
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7222
7239
|
const chunkSize = 64 * 1024;
|
|
7223
7240
|
const chunks = [];
|
|
7224
7241
|
let position = stat.size;
|
|
@@ -7228,13 +7245,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7228
7245
|
const length = Math.min(chunkSize, position);
|
|
7229
7246
|
position -= length;
|
|
7230
7247
|
const buffer = Buffer.alloc(length);
|
|
7231
|
-
|
|
7248
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7232
7249
|
chunks.unshift(buffer.toString("utf8"));
|
|
7233
7250
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
7234
7251
|
collectedLines += chunkLines;
|
|
7235
7252
|
}
|
|
7236
7253
|
} finally {
|
|
7237
|
-
|
|
7254
|
+
fs29.closeSync(fd);
|
|
7238
7255
|
}
|
|
7239
7256
|
const content = chunks.join("");
|
|
7240
7257
|
const allLines = content.split("\n");
|
|
@@ -7250,11 +7267,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7250
7267
|
return allLines.slice(allLines.length - maxLines);
|
|
7251
7268
|
}
|
|
7252
7269
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
7253
|
-
const stat =
|
|
7270
|
+
const stat = fs29.statSync(filePath);
|
|
7254
7271
|
if (stat.size === 0) {
|
|
7255
7272
|
return { lines: [], totalLinesCount: 0 };
|
|
7256
7273
|
}
|
|
7257
|
-
const fd =
|
|
7274
|
+
const fd = fs29.openSync(filePath, "r");
|
|
7258
7275
|
const chunkSize = 64 * 1024;
|
|
7259
7276
|
let position = stat.size;
|
|
7260
7277
|
let remainder = "";
|
|
@@ -7266,7 +7283,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7266
7283
|
const length = Math.min(chunkSize, position);
|
|
7267
7284
|
position -= length;
|
|
7268
7285
|
const buffer = Buffer.alloc(length);
|
|
7269
|
-
|
|
7286
|
+
fs29.readSync(fd, buffer, 0, length, position);
|
|
7270
7287
|
let chunk = buffer.toString("utf8");
|
|
7271
7288
|
if (remainder) {
|
|
7272
7289
|
chunk += remainder;
|
|
@@ -7297,7 +7314,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7297
7314
|
}
|
|
7298
7315
|
}
|
|
7299
7316
|
} finally {
|
|
7300
|
-
|
|
7317
|
+
fs29.closeSync(fd);
|
|
7301
7318
|
}
|
|
7302
7319
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7303
7320
|
}
|
|
@@ -7439,7 +7456,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7439
7456
|
}
|
|
7440
7457
|
|
|
7441
7458
|
// src/commands/read-logs/json-lines.ts
|
|
7442
|
-
import
|
|
7459
|
+
import fs30 from "fs";
|
|
7443
7460
|
|
|
7444
7461
|
// src/commands/read-logs/structured-log.ts
|
|
7445
7462
|
function normalizeLevelName(value) {
|
|
@@ -7515,11 +7532,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7515
7532
|
return set.size > 0 ? set : null;
|
|
7516
7533
|
}
|
|
7517
7534
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7518
|
-
const stat =
|
|
7535
|
+
const stat = fs30.statSync(filePath);
|
|
7519
7536
|
if (stat.size === 0) {
|
|
7520
7537
|
return { lines: [], totalLinesCount: 0 };
|
|
7521
7538
|
}
|
|
7522
|
-
const fd =
|
|
7539
|
+
const fd = fs30.openSync(filePath, "r");
|
|
7523
7540
|
const chunkSize = 64 * 1024;
|
|
7524
7541
|
let position = stat.size;
|
|
7525
7542
|
let remainder = "";
|
|
@@ -7534,7 +7551,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7534
7551
|
const length = Math.min(chunkSize, position);
|
|
7535
7552
|
position -= length;
|
|
7536
7553
|
const buffer = Buffer.alloc(length);
|
|
7537
|
-
|
|
7554
|
+
fs30.readSync(fd, buffer, 0, length, position);
|
|
7538
7555
|
let chunk = buffer.toString("utf8");
|
|
7539
7556
|
if (remainder) {
|
|
7540
7557
|
chunk += remainder;
|
|
@@ -7596,7 +7613,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7596
7613
|
}
|
|
7597
7614
|
}
|
|
7598
7615
|
} finally {
|
|
7599
|
-
|
|
7616
|
+
fs30.closeSync(fd);
|
|
7600
7617
|
}
|
|
7601
7618
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7602
7619
|
}
|
|
@@ -7639,11 +7656,11 @@ function extractTraceId(obj) {
|
|
|
7639
7656
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7640
7657
|
const wanted = traceId.trim();
|
|
7641
7658
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7642
|
-
const stat =
|
|
7659
|
+
const stat = fs30.statSync(filePath);
|
|
7643
7660
|
if (stat.size === 0) {
|
|
7644
7661
|
return { lines: [], totalLinesCount: 0 };
|
|
7645
7662
|
}
|
|
7646
|
-
const fd =
|
|
7663
|
+
const fd = fs30.openSync(filePath, "r");
|
|
7647
7664
|
const chunkSize = 64 * 1024;
|
|
7648
7665
|
let position = stat.size;
|
|
7649
7666
|
let remainder = "";
|
|
@@ -7656,7 +7673,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7656
7673
|
const length = Math.min(chunkSize, position);
|
|
7657
7674
|
position -= length;
|
|
7658
7675
|
const buffer = Buffer.alloc(length);
|
|
7659
|
-
|
|
7676
|
+
fs30.readSync(fd, buffer, 0, length, position);
|
|
7660
7677
|
let chunk = buffer.toString("utf8");
|
|
7661
7678
|
if (remainder) {
|
|
7662
7679
|
chunk += remainder;
|
|
@@ -7709,7 +7726,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7709
7726
|
}
|
|
7710
7727
|
}
|
|
7711
7728
|
} finally {
|
|
7712
|
-
|
|
7729
|
+
fs30.closeSync(fd);
|
|
7713
7730
|
}
|
|
7714
7731
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7715
7732
|
}
|
|
@@ -7718,11 +7735,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7718
7735
|
if (!wantedLevelSet) {
|
|
7719
7736
|
return { lines: [], totalLinesCount: 0 };
|
|
7720
7737
|
}
|
|
7721
|
-
const stat =
|
|
7738
|
+
const stat = fs30.statSync(filePath);
|
|
7722
7739
|
if (stat.size === 0) {
|
|
7723
7740
|
return { lines: [], totalLinesCount: 0 };
|
|
7724
7741
|
}
|
|
7725
|
-
const fd =
|
|
7742
|
+
const fd = fs30.openSync(filePath, "r");
|
|
7726
7743
|
const chunkSize = 64 * 1024;
|
|
7727
7744
|
let position = stat.size;
|
|
7728
7745
|
let remainder = "";
|
|
@@ -7734,7 +7751,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7734
7751
|
const length = Math.min(chunkSize, position);
|
|
7735
7752
|
position -= length;
|
|
7736
7753
|
const buffer = Buffer.alloc(length);
|
|
7737
|
-
|
|
7754
|
+
fs30.readSync(fd, buffer, 0, length, position);
|
|
7738
7755
|
let chunk = buffer.toString("utf8");
|
|
7739
7756
|
if (remainder) {
|
|
7740
7757
|
chunk += remainder;
|
|
@@ -7781,7 +7798,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7781
7798
|
}
|
|
7782
7799
|
}
|
|
7783
7800
|
} finally {
|
|
7784
|
-
|
|
7801
|
+
fs30.closeSync(fd);
|
|
7785
7802
|
}
|
|
7786
7803
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7787
7804
|
}
|
|
@@ -8274,30 +8291,30 @@ async function readLogsJsonResult(options) {
|
|
|
8274
8291
|
};
|
|
8275
8292
|
}
|
|
8276
8293
|
function resolveLogFilePath(logDir, type) {
|
|
8277
|
-
const base =
|
|
8294
|
+
const base = path25.isAbsolute(logDir) ? logDir : path25.join(process.cwd(), logDir);
|
|
8278
8295
|
if (type === "server") {
|
|
8279
|
-
return
|
|
8296
|
+
return path25.join(base, "server.log");
|
|
8280
8297
|
}
|
|
8281
8298
|
if (type === "trace") {
|
|
8282
|
-
return
|
|
8299
|
+
return path25.join(base, "trace.log");
|
|
8283
8300
|
}
|
|
8284
8301
|
if (type === "server-std") {
|
|
8285
|
-
return
|
|
8302
|
+
return path25.join(base, "server.std.log");
|
|
8286
8303
|
}
|
|
8287
8304
|
if (type === "client-std") {
|
|
8288
|
-
return
|
|
8305
|
+
return path25.join(base, "client.std.log");
|
|
8289
8306
|
}
|
|
8290
8307
|
if (type === "dev") {
|
|
8291
|
-
return
|
|
8308
|
+
return path25.join(base, "dev.log");
|
|
8292
8309
|
}
|
|
8293
8310
|
if (type === "dev-std") {
|
|
8294
|
-
return
|
|
8311
|
+
return path25.join(base, "dev.std.log");
|
|
8295
8312
|
}
|
|
8296
8313
|
if (type === "install-dep-std") {
|
|
8297
|
-
return
|
|
8314
|
+
return path25.join(base, "install-dep.std.log");
|
|
8298
8315
|
}
|
|
8299
8316
|
if (type === "browser") {
|
|
8300
|
-
return
|
|
8317
|
+
return path25.join(base, "browser.log");
|
|
8301
8318
|
}
|
|
8302
8319
|
throw new Error(`Unsupported log type: ${type}`);
|
|
8303
8320
|
}
|
|
@@ -8467,9 +8484,9 @@ function camelToKebab(str) {
|
|
|
8467
8484
|
}
|
|
8468
8485
|
|
|
8469
8486
|
// src/commands/build/upload-static.handler.ts
|
|
8470
|
-
import * as
|
|
8487
|
+
import * as fs31 from "fs";
|
|
8471
8488
|
import * as os2 from "os";
|
|
8472
|
-
import * as
|
|
8489
|
+
import * as path26 from "path";
|
|
8473
8490
|
import { execFileSync } from "child_process";
|
|
8474
8491
|
function readCredentialsFromEnv() {
|
|
8475
8492
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -8493,8 +8510,8 @@ async function uploadStatic(options) {
|
|
|
8493
8510
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
8494
8511
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
8495
8512
|
} = options;
|
|
8496
|
-
const resolvedStaticDir =
|
|
8497
|
-
if (!
|
|
8513
|
+
const resolvedStaticDir = path26.resolve(staticDir);
|
|
8514
|
+
if (!fs31.existsSync(resolvedStaticDir)) {
|
|
8498
8515
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
8499
8516
|
return;
|
|
8500
8517
|
}
|
|
@@ -8527,8 +8544,8 @@ async function uploadStatic(options) {
|
|
|
8527
8544
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
8528
8545
|
}
|
|
8529
8546
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
8530
|
-
const confPath =
|
|
8531
|
-
|
|
8547
|
+
const confPath = path26.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
8548
|
+
fs31.writeFileSync(confPath, "");
|
|
8532
8549
|
try {
|
|
8533
8550
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
8534
8551
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -8542,7 +8559,7 @@ async function uploadStatic(options) {
|
|
|
8542
8559
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
8543
8560
|
} finally {
|
|
8544
8561
|
try {
|
|
8545
|
-
|
|
8562
|
+
fs31.unlinkSync(confPath);
|
|
8546
8563
|
} catch {
|
|
8547
8564
|
}
|
|
8548
8565
|
}
|
|
@@ -8562,8 +8579,8 @@ async function uploadStatic(options) {
|
|
|
8562
8579
|
}
|
|
8563
8580
|
}
|
|
8564
8581
|
function resolveTosutilPath(tosutilPath) {
|
|
8565
|
-
if (
|
|
8566
|
-
return
|
|
8582
|
+
if (path26.isAbsolute(tosutilPath)) {
|
|
8583
|
+
return fs31.existsSync(tosutilPath) ? tosutilPath : null;
|
|
8567
8584
|
}
|
|
8568
8585
|
try {
|
|
8569
8586
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -8608,7 +8625,7 @@ async function resolveBucketId(appId) {
|
|
|
8608
8625
|
return bucketId;
|
|
8609
8626
|
}
|
|
8610
8627
|
function isDirEmpty(dirPath) {
|
|
8611
|
-
const entries =
|
|
8628
|
+
const entries = fs31.readdirSync(dirPath);
|
|
8612
8629
|
return entries.length === 0;
|
|
8613
8630
|
}
|
|
8614
8631
|
|
|
@@ -8704,13 +8721,13 @@ var commands = [
|
|
|
8704
8721
|
|
|
8705
8722
|
// src/index.ts
|
|
8706
8723
|
for (const filename of [".env.local", ".env"]) {
|
|
8707
|
-
const envPath =
|
|
8708
|
-
if (
|
|
8724
|
+
const envPath = path27.join(process.cwd(), filename);
|
|
8725
|
+
if (fs32.existsSync(envPath)) {
|
|
8709
8726
|
dotenvConfig({ path: envPath });
|
|
8710
8727
|
}
|
|
8711
8728
|
}
|
|
8712
|
-
var __dirname =
|
|
8713
|
-
var pkg = JSON.parse(
|
|
8729
|
+
var __dirname = path27.dirname(fileURLToPath5(import.meta.url));
|
|
8730
|
+
var pkg = JSON.parse(fs32.readFileSync(path27.join(__dirname, "../package.json"), "utf-8"));
|
|
8714
8731
|
var cli = new FullstackCLI(pkg.version);
|
|
8715
8732
|
cli.useAll(commands);
|
|
8716
8733
|
cli.run();
|