@lark-apaas/fullstack-cli 1.1.40-alpha.0 → 1.1.40-alpha.1
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 +210 -299
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs27 from "fs";
|
|
3
|
+
import path23 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -3106,112 +3106,27 @@ async function run3(options = {}) {
|
|
|
3106
3106
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3107
3107
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
3108
3108
|
|
|
3109
|
-
// src/utils/grayscale/
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
var CACHE_PATH = path8.join(os.homedir(), ".fullstack", "grayscale-cache.json");
|
|
3114
|
-
var NORMAL_TTL_MS = 30 * 60 * 1e3;
|
|
3115
|
-
var FALLBACK_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
3116
|
-
function readLocalCache(fallback = false) {
|
|
3117
|
-
try {
|
|
3118
|
-
if (!fs10.existsSync(CACHE_PATH)) {
|
|
3119
|
-
return null;
|
|
3120
|
-
}
|
|
3121
|
-
const content = fs10.readFileSync(CACHE_PATH, "utf-8");
|
|
3122
|
-
const entry = JSON.parse(content);
|
|
3123
|
-
if (!entry.config || !entry.timestamp) {
|
|
3124
|
-
return null;
|
|
3125
|
-
}
|
|
3126
|
-
const ttl = fallback ? FALLBACK_TTL_MS : NORMAL_TTL_MS;
|
|
3127
|
-
const age = Date.now() - entry.timestamp;
|
|
3128
|
-
if (age > ttl) {
|
|
3129
|
-
return null;
|
|
3130
|
-
}
|
|
3131
|
-
return entry.config;
|
|
3132
|
-
} catch {
|
|
3109
|
+
// src/utils/grayscale/config.ts
|
|
3110
|
+
function getGrayscaleConfig() {
|
|
3111
|
+
const raw = process.env.GRAYSCALE_CONFIG;
|
|
3112
|
+
if (!raw) {
|
|
3133
3113
|
return null;
|
|
3134
3114
|
}
|
|
3135
|
-
}
|
|
3136
|
-
function writeLocalCache(config) {
|
|
3137
3115
|
try {
|
|
3138
|
-
const
|
|
3139
|
-
if (!
|
|
3140
|
-
|
|
3116
|
+
const config = JSON.parse(raw);
|
|
3117
|
+
if (!config.enabled) {
|
|
3118
|
+
return null;
|
|
3141
3119
|
}
|
|
3142
|
-
|
|
3143
|
-
config,
|
|
3144
|
-
timestamp: Date.now()
|
|
3145
|
-
};
|
|
3146
|
-
fs10.writeFileSync(CACHE_PATH, JSON.stringify(entry, null, 2), "utf-8");
|
|
3120
|
+
return config;
|
|
3147
3121
|
} catch {
|
|
3148
|
-
|
|
3149
|
-
}
|
|
3150
|
-
|
|
3151
|
-
// src/utils/grayscale/config.ts
|
|
3152
|
-
var memoryCache = null;
|
|
3153
|
-
var MEMORY_TTL_MS = 60 * 1e3;
|
|
3154
|
-
var API_TIMEOUT_MS = 3e3;
|
|
3155
|
-
async function fetchFromApi() {
|
|
3156
|
-
try {
|
|
3157
|
-
const client = getHttpClient();
|
|
3158
|
-
const controller = new AbortController();
|
|
3159
|
-
const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
|
|
3160
|
-
try {
|
|
3161
|
-
const response = await client.post(
|
|
3162
|
-
"/api/v1/studio/innerapi/get_grayscale_config",
|
|
3163
|
-
{},
|
|
3164
|
-
{ signal: controller.signal }
|
|
3165
|
-
);
|
|
3166
|
-
if (!response.ok) {
|
|
3167
|
-
console.warn(`[grayscale] API request failed: ${response.status} ${response.statusText}`);
|
|
3168
|
-
return null;
|
|
3169
|
-
}
|
|
3170
|
-
const result = await response.json();
|
|
3171
|
-
if (result.status_code !== "0") {
|
|
3172
|
-
console.warn(`[grayscale] API error: ${result.message}`);
|
|
3173
|
-
return null;
|
|
3174
|
-
}
|
|
3175
|
-
return result.data?.config ?? null;
|
|
3176
|
-
} finally {
|
|
3177
|
-
clearTimeout(timer);
|
|
3178
|
-
}
|
|
3179
|
-
} catch (error) {
|
|
3180
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
3181
|
-
console.warn(`[grayscale] Failed to fetch config from API: ${message}`);
|
|
3122
|
+
console.warn("[grayscale] Failed to parse GRAYSCALE_CONFIG env");
|
|
3182
3123
|
return null;
|
|
3183
3124
|
}
|
|
3184
3125
|
}
|
|
3185
|
-
async function getGrayscaleConfig() {
|
|
3186
|
-
if (memoryCache) {
|
|
3187
|
-
const age = Date.now() - memoryCache.timestamp;
|
|
3188
|
-
if (age <= MEMORY_TTL_MS) {
|
|
3189
|
-
return memoryCache.config;
|
|
3190
|
-
}
|
|
3191
|
-
memoryCache = null;
|
|
3192
|
-
}
|
|
3193
|
-
const localNormal = readLocalCache(false);
|
|
3194
|
-
if (localNormal) {
|
|
3195
|
-
memoryCache = { config: localNormal, timestamp: Date.now() };
|
|
3196
|
-
return localNormal;
|
|
3197
|
-
}
|
|
3198
|
-
const apiConfig = await fetchFromApi();
|
|
3199
|
-
if (apiConfig) {
|
|
3200
|
-
memoryCache = { config: apiConfig, timestamp: Date.now() };
|
|
3201
|
-
writeLocalCache(apiConfig);
|
|
3202
|
-
return apiConfig;
|
|
3203
|
-
}
|
|
3204
|
-
const localFallback = readLocalCache(true);
|
|
3205
|
-
if (localFallback) {
|
|
3206
|
-
memoryCache = { config: localFallback, timestamp: Date.now() };
|
|
3207
|
-
return localFallback;
|
|
3208
|
-
}
|
|
3209
|
-
return null;
|
|
3210
|
-
}
|
|
3211
3126
|
|
|
3212
3127
|
// src/utils/grayscale/identity.ts
|
|
3213
|
-
import
|
|
3214
|
-
import
|
|
3128
|
+
import fs10 from "fs";
|
|
3129
|
+
import path8 from "path";
|
|
3215
3130
|
function readFromEnvVars() {
|
|
3216
3131
|
const appId = process.env.app_id || process.env.APP_ID;
|
|
3217
3132
|
const tenantId = process.env.tenant_id || process.env.TENANT_ID;
|
|
@@ -3219,11 +3134,11 @@ function readFromEnvVars() {
|
|
|
3219
3134
|
}
|
|
3220
3135
|
function parseEnvFile(filePath) {
|
|
3221
3136
|
const result = {};
|
|
3222
|
-
if (!
|
|
3137
|
+
if (!fs10.existsSync(filePath)) {
|
|
3223
3138
|
return result;
|
|
3224
3139
|
}
|
|
3225
3140
|
try {
|
|
3226
|
-
const content =
|
|
3141
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
3227
3142
|
const lines = content.split("\n");
|
|
3228
3143
|
for (const line of lines) {
|
|
3229
3144
|
const trimmed = line.trim();
|
|
@@ -3240,7 +3155,7 @@ function parseEnvFile(filePath) {
|
|
|
3240
3155
|
return result;
|
|
3241
3156
|
}
|
|
3242
3157
|
function readFromForceEnvFile(cwd) {
|
|
3243
|
-
const envPath2 =
|
|
3158
|
+
const envPath2 = path8.join(cwd, ".force", "environment", "env");
|
|
3244
3159
|
const vars = parseEnvFile(envPath2);
|
|
3245
3160
|
return {
|
|
3246
3161
|
appId: vars.app_id || vars.APP_ID,
|
|
@@ -3263,7 +3178,7 @@ function readFromClientBasePath() {
|
|
|
3263
3178
|
return {};
|
|
3264
3179
|
}
|
|
3265
3180
|
function readFromDotEnv(cwd) {
|
|
3266
|
-
const envPath2 =
|
|
3181
|
+
const envPath2 = path8.join(cwd, ".env");
|
|
3267
3182
|
const vars = parseEnvFile(envPath2);
|
|
3268
3183
|
return {
|
|
3269
3184
|
appId: vars.app_id || vars.APP_ID,
|
|
@@ -3271,12 +3186,12 @@ function readFromDotEnv(cwd) {
|
|
|
3271
3186
|
};
|
|
3272
3187
|
}
|
|
3273
3188
|
function readFromPackageJson(cwd) {
|
|
3274
|
-
const pkgPath =
|
|
3275
|
-
if (!
|
|
3189
|
+
const pkgPath = path8.join(cwd, "package.json");
|
|
3190
|
+
if (!fs10.existsSync(pkgPath)) {
|
|
3276
3191
|
return {};
|
|
3277
3192
|
}
|
|
3278
3193
|
try {
|
|
3279
|
-
const content =
|
|
3194
|
+
const content = fs10.readFileSync(pkgPath, "utf-8");
|
|
3280
3195
|
const pkg2 = JSON.parse(content);
|
|
3281
3196
|
const appId = pkg2?.fullstack?.appId;
|
|
3282
3197
|
return appId ? { appId } : {};
|
|
@@ -3379,16 +3294,12 @@ function resolveTargetVersions(config, identity) {
|
|
|
3379
3294
|
}
|
|
3380
3295
|
|
|
3381
3296
|
// src/utils/grayscale/index.ts
|
|
3382
|
-
|
|
3383
|
-
const config =
|
|
3297
|
+
function resolveGrayscaleVersions(cwd) {
|
|
3298
|
+
const config = getGrayscaleConfig();
|
|
3384
3299
|
if (!config) {
|
|
3385
3300
|
console.log("[grayscale] Config not available, skipping grayscale");
|
|
3386
3301
|
return null;
|
|
3387
3302
|
}
|
|
3388
|
-
if (!config.enabled) {
|
|
3389
|
-
console.log("[grayscale] Grayscale is disabled");
|
|
3390
|
-
return null;
|
|
3391
|
-
}
|
|
3392
3303
|
const identity = readProjectIdentity(cwd);
|
|
3393
3304
|
if (!identity.appId && !identity.tenantId) {
|
|
3394
3305
|
console.log("[grayscale] No app_id or tenant_id found, skipping grayscale");
|
|
@@ -3507,7 +3418,7 @@ async function run4(options = {}) {
|
|
|
3507
3418
|
if (!options.skipGrayscale && !options.version) {
|
|
3508
3419
|
console.log("[fullstack-cli] Step 2/3: Checking grayscale config...");
|
|
3509
3420
|
try {
|
|
3510
|
-
const grayscaleVersions =
|
|
3421
|
+
const grayscaleVersions = resolveGrayscaleVersions(cwd);
|
|
3511
3422
|
if (grayscaleVersions) {
|
|
3512
3423
|
console.log("[fullstack-cli] Step 3/3: Applying grayscale versions...");
|
|
3513
3424
|
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun);
|
|
@@ -3567,8 +3478,8 @@ var upgradeCommand = {
|
|
|
3567
3478
|
};
|
|
3568
3479
|
|
|
3569
3480
|
// src/commands/action-plugin/utils.ts
|
|
3570
|
-
import
|
|
3571
|
-
import
|
|
3481
|
+
import fs11 from "fs";
|
|
3482
|
+
import path9 from "path";
|
|
3572
3483
|
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
3573
3484
|
function parsePluginName(input) {
|
|
3574
3485
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3586,18 +3497,18 @@ function getProjectRoot() {
|
|
|
3586
3497
|
return process.cwd();
|
|
3587
3498
|
}
|
|
3588
3499
|
function getPackageJsonPath() {
|
|
3589
|
-
return
|
|
3500
|
+
return path9.join(getProjectRoot(), "package.json");
|
|
3590
3501
|
}
|
|
3591
3502
|
function getPluginPath(pluginName) {
|
|
3592
|
-
return
|
|
3503
|
+
return path9.join(getProjectRoot(), "node_modules", pluginName);
|
|
3593
3504
|
}
|
|
3594
3505
|
function readPackageJson2() {
|
|
3595
3506
|
const pkgPath = getPackageJsonPath();
|
|
3596
|
-
if (!
|
|
3507
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
3597
3508
|
throw new Error("package.json not found in current directory");
|
|
3598
3509
|
}
|
|
3599
3510
|
try {
|
|
3600
|
-
const content =
|
|
3511
|
+
const content = fs11.readFileSync(pkgPath, "utf-8");
|
|
3601
3512
|
return JSON.parse(content);
|
|
3602
3513
|
} catch {
|
|
3603
3514
|
throw new Error("Failed to parse package.json");
|
|
@@ -3605,7 +3516,7 @@ function readPackageJson2() {
|
|
|
3605
3516
|
}
|
|
3606
3517
|
function writePackageJson2(pkg2) {
|
|
3607
3518
|
const pkgPath = getPackageJsonPath();
|
|
3608
|
-
|
|
3519
|
+
fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3609
3520
|
}
|
|
3610
3521
|
function readActionPlugins() {
|
|
3611
3522
|
const pkg2 = readPackageJson2();
|
|
@@ -3638,12 +3549,12 @@ function npmInstall(tgzPath) {
|
|
|
3638
3549
|
}
|
|
3639
3550
|
}
|
|
3640
3551
|
function getPackageVersion(pluginName) {
|
|
3641
|
-
const pkgJsonPath =
|
|
3642
|
-
if (!
|
|
3552
|
+
const pkgJsonPath = path9.join(getPluginPath(pluginName), "package.json");
|
|
3553
|
+
if (!fs11.existsSync(pkgJsonPath)) {
|
|
3643
3554
|
return null;
|
|
3644
3555
|
}
|
|
3645
3556
|
try {
|
|
3646
|
-
const content =
|
|
3557
|
+
const content = fs11.readFileSync(pkgJsonPath, "utf-8");
|
|
3647
3558
|
const pkg2 = JSON.parse(content);
|
|
3648
3559
|
return pkg2.version || null;
|
|
3649
3560
|
} catch {
|
|
@@ -3651,49 +3562,49 @@ function getPackageVersion(pluginName) {
|
|
|
3651
3562
|
}
|
|
3652
3563
|
}
|
|
3653
3564
|
function readPluginPackageJson(pluginPath) {
|
|
3654
|
-
const pkgJsonPath =
|
|
3655
|
-
if (!
|
|
3565
|
+
const pkgJsonPath = path9.join(pluginPath, "package.json");
|
|
3566
|
+
if (!fs11.existsSync(pkgJsonPath)) {
|
|
3656
3567
|
return null;
|
|
3657
3568
|
}
|
|
3658
3569
|
try {
|
|
3659
|
-
const content =
|
|
3570
|
+
const content = fs11.readFileSync(pkgJsonPath, "utf-8");
|
|
3660
3571
|
return JSON.parse(content);
|
|
3661
3572
|
} catch {
|
|
3662
3573
|
return null;
|
|
3663
3574
|
}
|
|
3664
3575
|
}
|
|
3665
3576
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3666
|
-
const nodeModulesPath =
|
|
3667
|
-
const targetDir =
|
|
3668
|
-
const scopeDir =
|
|
3669
|
-
if (!
|
|
3670
|
-
|
|
3577
|
+
const nodeModulesPath = path9.join(getProjectRoot(), "node_modules");
|
|
3578
|
+
const targetDir = path9.join(nodeModulesPath, pluginName);
|
|
3579
|
+
const scopeDir = path9.dirname(targetDir);
|
|
3580
|
+
if (!fs11.existsSync(scopeDir)) {
|
|
3581
|
+
fs11.mkdirSync(scopeDir, { recursive: true });
|
|
3671
3582
|
}
|
|
3672
|
-
if (
|
|
3673
|
-
|
|
3583
|
+
if (fs11.existsSync(targetDir)) {
|
|
3584
|
+
fs11.rmSync(targetDir, { recursive: true });
|
|
3674
3585
|
}
|
|
3675
|
-
const tempDir =
|
|
3676
|
-
if (
|
|
3677
|
-
|
|
3586
|
+
const tempDir = path9.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3587
|
+
if (fs11.existsSync(tempDir)) {
|
|
3588
|
+
fs11.rmSync(tempDir, { recursive: true });
|
|
3678
3589
|
}
|
|
3679
|
-
|
|
3590
|
+
fs11.mkdirSync(tempDir, { recursive: true });
|
|
3680
3591
|
try {
|
|
3681
3592
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3682
|
-
const extractedDir =
|
|
3683
|
-
if (
|
|
3684
|
-
|
|
3593
|
+
const extractedDir = path9.join(tempDir, "package");
|
|
3594
|
+
if (fs11.existsSync(extractedDir)) {
|
|
3595
|
+
fs11.renameSync(extractedDir, targetDir);
|
|
3685
3596
|
} else {
|
|
3686
|
-
const files =
|
|
3597
|
+
const files = fs11.readdirSync(tempDir);
|
|
3687
3598
|
if (files.length === 1) {
|
|
3688
|
-
|
|
3599
|
+
fs11.renameSync(path9.join(tempDir, files[0]), targetDir);
|
|
3689
3600
|
} else {
|
|
3690
3601
|
throw new Error("Unexpected tgz structure");
|
|
3691
3602
|
}
|
|
3692
3603
|
}
|
|
3693
3604
|
return targetDir;
|
|
3694
3605
|
} finally {
|
|
3695
|
-
if (
|
|
3696
|
-
|
|
3606
|
+
if (fs11.existsSync(tempDir)) {
|
|
3607
|
+
fs11.rmSync(tempDir, { recursive: true });
|
|
3697
3608
|
}
|
|
3698
3609
|
}
|
|
3699
3610
|
}
|
|
@@ -3702,10 +3613,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3702
3613
|
return [];
|
|
3703
3614
|
}
|
|
3704
3615
|
const missing = [];
|
|
3705
|
-
const nodeModulesPath =
|
|
3616
|
+
const nodeModulesPath = path9.join(getProjectRoot(), "node_modules");
|
|
3706
3617
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3707
|
-
const depPath =
|
|
3708
|
-
if (!
|
|
3618
|
+
const depPath = path9.join(nodeModulesPath, depName);
|
|
3619
|
+
if (!fs11.existsSync(depPath)) {
|
|
3709
3620
|
missing.push(depName);
|
|
3710
3621
|
}
|
|
3711
3622
|
}
|
|
@@ -3729,16 +3640,16 @@ function installMissingDeps(deps) {
|
|
|
3729
3640
|
}
|
|
3730
3641
|
function removePluginDirectory(pluginName) {
|
|
3731
3642
|
const pluginPath = getPluginPath(pluginName);
|
|
3732
|
-
if (
|
|
3733
|
-
|
|
3643
|
+
if (fs11.existsSync(pluginPath)) {
|
|
3644
|
+
fs11.rmSync(pluginPath, { recursive: true });
|
|
3734
3645
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3735
3646
|
}
|
|
3736
3647
|
}
|
|
3737
3648
|
|
|
3738
3649
|
// src/commands/action-plugin/api-client.ts
|
|
3739
3650
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3740
|
-
import
|
|
3741
|
-
import
|
|
3651
|
+
import fs12 from "fs";
|
|
3652
|
+
import path10 from "path";
|
|
3742
3653
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3743
3654
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3744
3655
|
const client = getHttpClient();
|
|
@@ -3802,19 +3713,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3802
3713
|
return Buffer.from(arrayBuffer);
|
|
3803
3714
|
}
|
|
3804
3715
|
function getPluginCacheDir() {
|
|
3805
|
-
return
|
|
3716
|
+
return path10.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3806
3717
|
}
|
|
3807
3718
|
function ensureCacheDir() {
|
|
3808
3719
|
const cacheDir = getPluginCacheDir();
|
|
3809
|
-
if (!
|
|
3810
|
-
|
|
3720
|
+
if (!fs12.existsSync(cacheDir)) {
|
|
3721
|
+
fs12.mkdirSync(cacheDir, { recursive: true });
|
|
3811
3722
|
}
|
|
3812
3723
|
}
|
|
3813
3724
|
function getTempFilePath(pluginKey, version) {
|
|
3814
3725
|
ensureCacheDir();
|
|
3815
3726
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3816
3727
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3817
|
-
return
|
|
3728
|
+
return path10.join(getPluginCacheDir(), filename);
|
|
3818
3729
|
}
|
|
3819
3730
|
var MAX_RETRIES = 2;
|
|
3820
3731
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3851,7 +3762,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3851
3762
|
);
|
|
3852
3763
|
}
|
|
3853
3764
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3854
|
-
|
|
3765
|
+
fs12.writeFileSync(tgzPath, tgzBuffer);
|
|
3855
3766
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3856
3767
|
return {
|
|
3857
3768
|
tgzPath,
|
|
@@ -3865,18 +3776,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3865
3776
|
ensureCacheDir();
|
|
3866
3777
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3867
3778
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3868
|
-
return
|
|
3779
|
+
return path10.join(getPluginCacheDir(), filename);
|
|
3869
3780
|
}
|
|
3870
3781
|
function hasCachedPlugin(pluginKey, version) {
|
|
3871
3782
|
const cachePath = getCachePath(pluginKey, version);
|
|
3872
|
-
return
|
|
3783
|
+
return fs12.existsSync(cachePath);
|
|
3873
3784
|
}
|
|
3874
3785
|
function listCachedPlugins() {
|
|
3875
3786
|
const cacheDir = getPluginCacheDir();
|
|
3876
|
-
if (!
|
|
3787
|
+
if (!fs12.existsSync(cacheDir)) {
|
|
3877
3788
|
return [];
|
|
3878
3789
|
}
|
|
3879
|
-
const files =
|
|
3790
|
+
const files = fs12.readdirSync(cacheDir);
|
|
3880
3791
|
const result = [];
|
|
3881
3792
|
for (const file of files) {
|
|
3882
3793
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3884,8 +3795,8 @@ function listCachedPlugins() {
|
|
|
3884
3795
|
if (!match) continue;
|
|
3885
3796
|
const [, rawName, version] = match;
|
|
3886
3797
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3887
|
-
const filePath =
|
|
3888
|
-
const stat =
|
|
3798
|
+
const filePath = path10.join(cacheDir, file);
|
|
3799
|
+
const stat = fs12.statSync(filePath);
|
|
3889
3800
|
result.push({
|
|
3890
3801
|
name,
|
|
3891
3802
|
version,
|
|
@@ -3898,14 +3809,14 @@ function listCachedPlugins() {
|
|
|
3898
3809
|
}
|
|
3899
3810
|
function cleanAllCache() {
|
|
3900
3811
|
const cacheDir = getPluginCacheDir();
|
|
3901
|
-
if (!
|
|
3812
|
+
if (!fs12.existsSync(cacheDir)) {
|
|
3902
3813
|
return 0;
|
|
3903
3814
|
}
|
|
3904
|
-
const files =
|
|
3815
|
+
const files = fs12.readdirSync(cacheDir);
|
|
3905
3816
|
let count = 0;
|
|
3906
3817
|
for (const file of files) {
|
|
3907
3818
|
if (file.endsWith(".tgz")) {
|
|
3908
|
-
|
|
3819
|
+
fs12.unlinkSync(path10.join(cacheDir, file));
|
|
3909
3820
|
count++;
|
|
3910
3821
|
}
|
|
3911
3822
|
}
|
|
@@ -3913,21 +3824,21 @@ function cleanAllCache() {
|
|
|
3913
3824
|
}
|
|
3914
3825
|
function cleanPluginCache(pluginKey, version) {
|
|
3915
3826
|
const cacheDir = getPluginCacheDir();
|
|
3916
|
-
if (!
|
|
3827
|
+
if (!fs12.existsSync(cacheDir)) {
|
|
3917
3828
|
return 0;
|
|
3918
3829
|
}
|
|
3919
3830
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3920
|
-
const files =
|
|
3831
|
+
const files = fs12.readdirSync(cacheDir);
|
|
3921
3832
|
let count = 0;
|
|
3922
3833
|
for (const file of files) {
|
|
3923
3834
|
if (version) {
|
|
3924
3835
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3925
|
-
|
|
3836
|
+
fs12.unlinkSync(path10.join(cacheDir, file));
|
|
3926
3837
|
count++;
|
|
3927
3838
|
}
|
|
3928
3839
|
} else {
|
|
3929
3840
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3930
|
-
|
|
3841
|
+
fs12.unlinkSync(path10.join(cacheDir, file));
|
|
3931
3842
|
count++;
|
|
3932
3843
|
}
|
|
3933
3844
|
}
|
|
@@ -4354,40 +4265,40 @@ var actionPluginCommandGroup = {
|
|
|
4354
4265
|
};
|
|
4355
4266
|
|
|
4356
4267
|
// src/commands/capability/utils.ts
|
|
4357
|
-
import
|
|
4268
|
+
import fs13 from "fs";
|
|
4358
4269
|
import { createRequire as createRequire2 } from "module";
|
|
4359
|
-
import
|
|
4270
|
+
import path11 from "path";
|
|
4360
4271
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4361
4272
|
function getProjectRoot2() {
|
|
4362
4273
|
return process.cwd();
|
|
4363
4274
|
}
|
|
4364
4275
|
function getCapabilitiesDir() {
|
|
4365
|
-
return
|
|
4276
|
+
return path11.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4366
4277
|
}
|
|
4367
4278
|
function getCapabilityPath(id) {
|
|
4368
|
-
return
|
|
4279
|
+
return path11.join(getCapabilitiesDir(), `${id}.json`);
|
|
4369
4280
|
}
|
|
4370
4281
|
function getPluginManifestPath(pluginKey) {
|
|
4371
|
-
return
|
|
4282
|
+
return path11.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4372
4283
|
}
|
|
4373
4284
|
function capabilitiesDirExists() {
|
|
4374
|
-
return
|
|
4285
|
+
return fs13.existsSync(getCapabilitiesDir());
|
|
4375
4286
|
}
|
|
4376
4287
|
function listCapabilityIds() {
|
|
4377
4288
|
const dir = getCapabilitiesDir();
|
|
4378
|
-
if (!
|
|
4289
|
+
if (!fs13.existsSync(dir)) {
|
|
4379
4290
|
return [];
|
|
4380
4291
|
}
|
|
4381
|
-
const files =
|
|
4292
|
+
const files = fs13.readdirSync(dir);
|
|
4382
4293
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4383
4294
|
}
|
|
4384
4295
|
function readCapability(id) {
|
|
4385
4296
|
const filePath = getCapabilityPath(id);
|
|
4386
|
-
if (!
|
|
4297
|
+
if (!fs13.existsSync(filePath)) {
|
|
4387
4298
|
throw new Error(`Capability not found: ${id}`);
|
|
4388
4299
|
}
|
|
4389
4300
|
try {
|
|
4390
|
-
const content =
|
|
4301
|
+
const content = fs13.readFileSync(filePath, "utf-8");
|
|
4391
4302
|
return JSON.parse(content);
|
|
4392
4303
|
} catch (error) {
|
|
4393
4304
|
if (error instanceof SyntaxError) {
|
|
@@ -4414,11 +4325,11 @@ function readAllCapabilities() {
|
|
|
4414
4325
|
}
|
|
4415
4326
|
function readPluginManifest(pluginKey) {
|
|
4416
4327
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4417
|
-
if (!
|
|
4328
|
+
if (!fs13.existsSync(manifestPath)) {
|
|
4418
4329
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4419
4330
|
}
|
|
4420
4331
|
try {
|
|
4421
|
-
const content =
|
|
4332
|
+
const content = fs13.readFileSync(manifestPath, "utf-8");
|
|
4422
4333
|
return JSON.parse(content);
|
|
4423
4334
|
} catch (error) {
|
|
4424
4335
|
if (error instanceof SyntaxError) {
|
|
@@ -4435,7 +4346,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4435
4346
|
}
|
|
4436
4347
|
async function loadPlugin(pluginKey) {
|
|
4437
4348
|
try {
|
|
4438
|
-
const userRequire = createRequire2(
|
|
4349
|
+
const userRequire = createRequire2(path11.join(getProjectRoot2(), "package.json"));
|
|
4439
4350
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4440
4351
|
const pluginModule = await import(resolvedPath);
|
|
4441
4352
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4598,9 +4509,9 @@ var capabilityCommandGroup = {
|
|
|
4598
4509
|
import { execFile } from "child_process";
|
|
4599
4510
|
|
|
4600
4511
|
// src/commands/component/registry-preparer.ts
|
|
4601
|
-
import
|
|
4602
|
-
import
|
|
4603
|
-
import
|
|
4512
|
+
import fs14 from "fs";
|
|
4513
|
+
import path12 from "path";
|
|
4514
|
+
import os from "os";
|
|
4604
4515
|
|
|
4605
4516
|
// src/commands/component/service.ts
|
|
4606
4517
|
import { mapValues } from "es-toolkit";
|
|
@@ -4655,7 +4566,7 @@ async function sendInstallEvent(key) {
|
|
|
4655
4566
|
}
|
|
4656
4567
|
|
|
4657
4568
|
// src/commands/component/registry-preparer.ts
|
|
4658
|
-
var REGISTRY_TEMP_DIR =
|
|
4569
|
+
var REGISTRY_TEMP_DIR = path12.join(os.tmpdir(), "miaoda-registry");
|
|
4659
4570
|
function parseComponentKey(key) {
|
|
4660
4571
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4661
4572
|
if (!match) {
|
|
@@ -4667,11 +4578,11 @@ function parseComponentKey(key) {
|
|
|
4667
4578
|
}
|
|
4668
4579
|
function getLocalRegistryPath(key) {
|
|
4669
4580
|
const { scope, name } = parseComponentKey(key);
|
|
4670
|
-
return
|
|
4581
|
+
return path12.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4671
4582
|
}
|
|
4672
4583
|
function ensureDir(dirPath) {
|
|
4673
|
-
if (!
|
|
4674
|
-
|
|
4584
|
+
if (!fs14.existsSync(dirPath)) {
|
|
4585
|
+
fs14.mkdirSync(dirPath, { recursive: true });
|
|
4675
4586
|
}
|
|
4676
4587
|
}
|
|
4677
4588
|
async function prepareRecursive(key, visited) {
|
|
@@ -4704,8 +4615,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4704
4615
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4705
4616
|
};
|
|
4706
4617
|
const localPath = getLocalRegistryPath(key);
|
|
4707
|
-
ensureDir(
|
|
4708
|
-
|
|
4618
|
+
ensureDir(path12.dirname(localPath));
|
|
4619
|
+
fs14.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4709
4620
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4710
4621
|
}
|
|
4711
4622
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4715,18 +4626,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4715
4626
|
}
|
|
4716
4627
|
function cleanupTempDir() {
|
|
4717
4628
|
try {
|
|
4718
|
-
if (
|
|
4719
|
-
|
|
4629
|
+
if (fs14.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4630
|
+
fs14.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4720
4631
|
}
|
|
4721
4632
|
} catch {
|
|
4722
4633
|
}
|
|
4723
4634
|
}
|
|
4724
4635
|
function getDownloadedRegistryItem(itemId) {
|
|
4725
4636
|
const localPath = getLocalRegistryPath(itemId);
|
|
4726
|
-
if (!
|
|
4637
|
+
if (!fs14.existsSync(localPath)) {
|
|
4727
4638
|
return null;
|
|
4728
4639
|
}
|
|
4729
|
-
const content =
|
|
4640
|
+
const content = fs14.readFileSync(localPath, "utf-8");
|
|
4730
4641
|
return JSON.parse(content);
|
|
4731
4642
|
}
|
|
4732
4643
|
|
|
@@ -4894,58 +4805,58 @@ var componentCommandGroup = {
|
|
|
4894
4805
|
};
|
|
4895
4806
|
|
|
4896
4807
|
// src/commands/migration/version-manager.ts
|
|
4897
|
-
import
|
|
4898
|
-
import
|
|
4808
|
+
import fs15 from "fs";
|
|
4809
|
+
import path13 from "path";
|
|
4899
4810
|
var PACKAGE_JSON = "package.json";
|
|
4900
4811
|
var VERSION_FIELD = "migrationVersion";
|
|
4901
4812
|
function getPackageJsonPath2() {
|
|
4902
|
-
return
|
|
4813
|
+
return path13.join(process.cwd(), PACKAGE_JSON);
|
|
4903
4814
|
}
|
|
4904
4815
|
function getCurrentVersion() {
|
|
4905
4816
|
const pkgPath = getPackageJsonPath2();
|
|
4906
|
-
if (!
|
|
4817
|
+
if (!fs15.existsSync(pkgPath)) {
|
|
4907
4818
|
throw new Error("package.json not found");
|
|
4908
4819
|
}
|
|
4909
|
-
const pkg2 = JSON.parse(
|
|
4820
|
+
const pkg2 = JSON.parse(fs15.readFileSync(pkgPath, "utf-8"));
|
|
4910
4821
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4911
4822
|
}
|
|
4912
4823
|
function setCurrentVersion(version) {
|
|
4913
4824
|
const pkgPath = getPackageJsonPath2();
|
|
4914
|
-
const pkg2 = JSON.parse(
|
|
4825
|
+
const pkg2 = JSON.parse(fs15.readFileSync(pkgPath, "utf-8"));
|
|
4915
4826
|
pkg2[VERSION_FIELD] = version;
|
|
4916
|
-
|
|
4827
|
+
fs15.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4917
4828
|
}
|
|
4918
4829
|
|
|
4919
4830
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4920
|
-
import fs18 from "fs";
|
|
4921
|
-
import path16 from "path";
|
|
4922
|
-
|
|
4923
|
-
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4924
4831
|
import fs17 from "fs";
|
|
4925
4832
|
import path15 from "path";
|
|
4833
|
+
|
|
4834
|
+
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4835
|
+
import fs16 from "fs";
|
|
4836
|
+
import path14 from "path";
|
|
4926
4837
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4927
4838
|
function getProjectRoot3() {
|
|
4928
4839
|
return process.cwd();
|
|
4929
4840
|
}
|
|
4930
4841
|
function getCapabilitiesDir2() {
|
|
4931
|
-
return
|
|
4842
|
+
return path14.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4932
4843
|
}
|
|
4933
4844
|
function getPluginManifestPath2(pluginKey) {
|
|
4934
|
-
return
|
|
4845
|
+
return path14.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4935
4846
|
}
|
|
4936
4847
|
|
|
4937
4848
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4938
4849
|
function detectJsonMigration() {
|
|
4939
4850
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4940
|
-
const oldFilePath =
|
|
4941
|
-
if (!
|
|
4851
|
+
const oldFilePath = path15.join(capabilitiesDir, "capabilities.json");
|
|
4852
|
+
if (!fs17.existsSync(oldFilePath)) {
|
|
4942
4853
|
return {
|
|
4943
4854
|
needsMigration: false,
|
|
4944
4855
|
reason: "capabilities.json not found"
|
|
4945
4856
|
};
|
|
4946
4857
|
}
|
|
4947
4858
|
try {
|
|
4948
|
-
const content =
|
|
4859
|
+
const content = fs17.readFileSync(oldFilePath, "utf-8");
|
|
4949
4860
|
const parsed = JSON.parse(content);
|
|
4950
4861
|
if (!Array.isArray(parsed)) {
|
|
4951
4862
|
return {
|
|
@@ -4996,8 +4907,8 @@ async function check(options) {
|
|
|
4996
4907
|
}
|
|
4997
4908
|
|
|
4998
4909
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4999
|
-
import
|
|
5000
|
-
import
|
|
4910
|
+
import fs18 from "fs";
|
|
4911
|
+
import path16 from "path";
|
|
5001
4912
|
|
|
5002
4913
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5003
4914
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5227,18 +5138,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5227
5138
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5228
5139
|
function loadExistingCapabilities() {
|
|
5229
5140
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5230
|
-
if (!
|
|
5141
|
+
if (!fs18.existsSync(capabilitiesDir)) {
|
|
5231
5142
|
return [];
|
|
5232
5143
|
}
|
|
5233
|
-
const files =
|
|
5144
|
+
const files = fs18.readdirSync(capabilitiesDir);
|
|
5234
5145
|
const capabilities = [];
|
|
5235
5146
|
for (const file of files) {
|
|
5236
5147
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5237
5148
|
continue;
|
|
5238
5149
|
}
|
|
5239
5150
|
try {
|
|
5240
|
-
const filePath =
|
|
5241
|
-
const content =
|
|
5151
|
+
const filePath = path16.join(capabilitiesDir, file);
|
|
5152
|
+
const content = fs18.readFileSync(filePath, "utf-8");
|
|
5242
5153
|
const capability = JSON.parse(content);
|
|
5243
5154
|
if (capability.id && capability.pluginKey) {
|
|
5244
5155
|
capabilities.push(capability);
|
|
@@ -5296,9 +5207,9 @@ async function migrateJsonFiles(options) {
|
|
|
5296
5207
|
}
|
|
5297
5208
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5298
5209
|
for (const cap of newCapabilities) {
|
|
5299
|
-
const filePath =
|
|
5210
|
+
const filePath = path16.join(capabilitiesDir, `${cap.id}.json`);
|
|
5300
5211
|
const content = JSON.stringify(cap, null, 2);
|
|
5301
|
-
|
|
5212
|
+
fs18.writeFileSync(filePath, content, "utf-8");
|
|
5302
5213
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5303
5214
|
}
|
|
5304
5215
|
return {
|
|
@@ -5310,11 +5221,11 @@ async function migrateJsonFiles(options) {
|
|
|
5310
5221
|
}
|
|
5311
5222
|
|
|
5312
5223
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5313
|
-
import
|
|
5224
|
+
import fs19 from "fs";
|
|
5314
5225
|
function isPluginInstalled2(pluginKey) {
|
|
5315
5226
|
const actionPlugins = readActionPlugins();
|
|
5316
5227
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5317
|
-
return
|
|
5228
|
+
return fs19.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5318
5229
|
}
|
|
5319
5230
|
function detectPluginsToInstall(capabilities) {
|
|
5320
5231
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5390,12 +5301,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5390
5301
|
}
|
|
5391
5302
|
|
|
5392
5303
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5393
|
-
import
|
|
5304
|
+
import path18 from "path";
|
|
5394
5305
|
import { Project as Project3 } from "ts-morph";
|
|
5395
5306
|
|
|
5396
5307
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5397
|
-
import
|
|
5398
|
-
import
|
|
5308
|
+
import fs20 from "fs";
|
|
5309
|
+
import path17 from "path";
|
|
5399
5310
|
var EXCLUDED_DIRS = [
|
|
5400
5311
|
"node_modules",
|
|
5401
5312
|
"dist",
|
|
@@ -5410,9 +5321,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5410
5321
|
/\.d\.ts$/
|
|
5411
5322
|
];
|
|
5412
5323
|
function scanDirectory(dir, files = []) {
|
|
5413
|
-
const entries =
|
|
5324
|
+
const entries = fs20.readdirSync(dir, { withFileTypes: true });
|
|
5414
5325
|
for (const entry of entries) {
|
|
5415
|
-
const fullPath =
|
|
5326
|
+
const fullPath = path17.join(dir, entry.name);
|
|
5416
5327
|
if (entry.isDirectory()) {
|
|
5417
5328
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5418
5329
|
continue;
|
|
@@ -5428,14 +5339,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5428
5339
|
return files;
|
|
5429
5340
|
}
|
|
5430
5341
|
function scanServerFiles() {
|
|
5431
|
-
const serverDir =
|
|
5432
|
-
if (!
|
|
5342
|
+
const serverDir = path17.join(getProjectRoot3(), "server");
|
|
5343
|
+
if (!fs20.existsSync(serverDir)) {
|
|
5433
5344
|
return [];
|
|
5434
5345
|
}
|
|
5435
5346
|
return scanDirectory(serverDir);
|
|
5436
5347
|
}
|
|
5437
5348
|
function hasCapabilityImport(filePath) {
|
|
5438
|
-
const content =
|
|
5349
|
+
const content = fs20.readFileSync(filePath, "utf-8");
|
|
5439
5350
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5440
5351
|
}
|
|
5441
5352
|
function scanFilesToMigrate() {
|
|
@@ -5812,7 +5723,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5812
5723
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5813
5724
|
const classInfo = analyzeClass(sourceFile);
|
|
5814
5725
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5815
|
-
const relativePath =
|
|
5726
|
+
const relativePath = path18.relative(getProjectRoot3(), filePath);
|
|
5816
5727
|
return {
|
|
5817
5728
|
filePath: relativePath,
|
|
5818
5729
|
imports,
|
|
@@ -5823,7 +5734,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5823
5734
|
};
|
|
5824
5735
|
}
|
|
5825
5736
|
function migrateFile(project, analysis, dryRun) {
|
|
5826
|
-
const absolutePath =
|
|
5737
|
+
const absolutePath = path18.join(getProjectRoot3(), analysis.filePath);
|
|
5827
5738
|
if (!analysis.canAutoMigrate) {
|
|
5828
5739
|
return {
|
|
5829
5740
|
filePath: analysis.filePath,
|
|
@@ -5926,17 +5837,17 @@ function getSuggestion(analysis) {
|
|
|
5926
5837
|
}
|
|
5927
5838
|
|
|
5928
5839
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5929
|
-
import
|
|
5930
|
-
import
|
|
5840
|
+
import fs21 from "fs";
|
|
5841
|
+
import path19 from "path";
|
|
5931
5842
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5932
5843
|
const deletedFiles = [];
|
|
5933
5844
|
const errors = [];
|
|
5934
5845
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5935
|
-
const oldJsonPath =
|
|
5936
|
-
if (
|
|
5846
|
+
const oldJsonPath = path19.join(capabilitiesDir, "capabilities.json");
|
|
5847
|
+
if (fs21.existsSync(oldJsonPath)) {
|
|
5937
5848
|
try {
|
|
5938
5849
|
if (!dryRun) {
|
|
5939
|
-
|
|
5850
|
+
fs21.unlinkSync(oldJsonPath);
|
|
5940
5851
|
}
|
|
5941
5852
|
deletedFiles.push("capabilities.json");
|
|
5942
5853
|
} catch (error) {
|
|
@@ -5944,11 +5855,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5944
5855
|
}
|
|
5945
5856
|
}
|
|
5946
5857
|
for (const cap of capabilities) {
|
|
5947
|
-
const tsFilePath =
|
|
5948
|
-
if (
|
|
5858
|
+
const tsFilePath = path19.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5859
|
+
if (fs21.existsSync(tsFilePath)) {
|
|
5949
5860
|
try {
|
|
5950
5861
|
if (!dryRun) {
|
|
5951
|
-
|
|
5862
|
+
fs21.unlinkSync(tsFilePath);
|
|
5952
5863
|
}
|
|
5953
5864
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5954
5865
|
} catch (error) {
|
|
@@ -5964,8 +5875,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5964
5875
|
}
|
|
5965
5876
|
|
|
5966
5877
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5967
|
-
import
|
|
5968
|
-
import
|
|
5878
|
+
import fs22 from "fs";
|
|
5879
|
+
import path20 from "path";
|
|
5969
5880
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5970
5881
|
function printSummary(result) {
|
|
5971
5882
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6128,15 +6039,15 @@ async function generateReport(result) {
|
|
|
6128
6039
|
}
|
|
6129
6040
|
lines.push("");
|
|
6130
6041
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6131
|
-
if (!
|
|
6042
|
+
if (!fs22.existsSync(logDir)) {
|
|
6132
6043
|
return;
|
|
6133
6044
|
}
|
|
6134
|
-
const reportDir =
|
|
6135
|
-
if (!
|
|
6136
|
-
|
|
6045
|
+
const reportDir = path20.join(logDir, "migration");
|
|
6046
|
+
if (!fs22.existsSync(reportDir)) {
|
|
6047
|
+
fs22.mkdirSync(reportDir, { recursive: true });
|
|
6137
6048
|
}
|
|
6138
|
-
const reportPath =
|
|
6139
|
-
|
|
6049
|
+
const reportPath = path20.join(reportDir, REPORT_FILE);
|
|
6050
|
+
fs22.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6140
6051
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6141
6052
|
}
|
|
6142
6053
|
|
|
@@ -6668,10 +6579,10 @@ var migrationCommand = {
|
|
|
6668
6579
|
};
|
|
6669
6580
|
|
|
6670
6581
|
// src/commands/read-logs/index.ts
|
|
6671
|
-
import
|
|
6582
|
+
import path21 from "path";
|
|
6672
6583
|
|
|
6673
6584
|
// src/commands/read-logs/std-utils.ts
|
|
6674
|
-
import
|
|
6585
|
+
import fs23 from "fs";
|
|
6675
6586
|
function formatStdPrefixTime(localTime) {
|
|
6676
6587
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6677
6588
|
if (!match) return localTime;
|
|
@@ -6701,11 +6612,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6701
6612
|
return `[${time}] ${content}`;
|
|
6702
6613
|
}
|
|
6703
6614
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6704
|
-
const stat =
|
|
6615
|
+
const stat = fs23.statSync(filePath);
|
|
6705
6616
|
if (stat.size === 0) {
|
|
6706
6617
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6707
6618
|
}
|
|
6708
|
-
const fd =
|
|
6619
|
+
const fd = fs23.openSync(filePath, "r");
|
|
6709
6620
|
const chunkSize = 64 * 1024;
|
|
6710
6621
|
let position = stat.size;
|
|
6711
6622
|
let remainder = "";
|
|
@@ -6719,7 +6630,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6719
6630
|
const length = Math.min(chunkSize, position);
|
|
6720
6631
|
position -= length;
|
|
6721
6632
|
const buffer = Buffer.alloc(length);
|
|
6722
|
-
|
|
6633
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
6723
6634
|
let chunk = buffer.toString("utf8");
|
|
6724
6635
|
if (remainder) {
|
|
6725
6636
|
chunk += remainder;
|
|
@@ -6761,7 +6672,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6761
6672
|
}
|
|
6762
6673
|
}
|
|
6763
6674
|
} finally {
|
|
6764
|
-
|
|
6675
|
+
fs23.closeSync(fd);
|
|
6765
6676
|
}
|
|
6766
6677
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6767
6678
|
}
|
|
@@ -6782,21 +6693,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6782
6693
|
}
|
|
6783
6694
|
|
|
6784
6695
|
// src/commands/read-logs/tail.ts
|
|
6785
|
-
import
|
|
6696
|
+
import fs24 from "fs";
|
|
6786
6697
|
function fileExists(filePath) {
|
|
6787
6698
|
try {
|
|
6788
|
-
|
|
6699
|
+
fs24.accessSync(filePath, fs24.constants.F_OK | fs24.constants.R_OK);
|
|
6789
6700
|
return true;
|
|
6790
6701
|
} catch {
|
|
6791
6702
|
return false;
|
|
6792
6703
|
}
|
|
6793
6704
|
}
|
|
6794
6705
|
function readFileTailLines(filePath, maxLines) {
|
|
6795
|
-
const stat =
|
|
6706
|
+
const stat = fs24.statSync(filePath);
|
|
6796
6707
|
if (stat.size === 0) {
|
|
6797
6708
|
return [];
|
|
6798
6709
|
}
|
|
6799
|
-
const fd =
|
|
6710
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6800
6711
|
const chunkSize = 64 * 1024;
|
|
6801
6712
|
const chunks = [];
|
|
6802
6713
|
let position = stat.size;
|
|
@@ -6806,13 +6717,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6806
6717
|
const length = Math.min(chunkSize, position);
|
|
6807
6718
|
position -= length;
|
|
6808
6719
|
const buffer = Buffer.alloc(length);
|
|
6809
|
-
|
|
6720
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6810
6721
|
chunks.unshift(buffer.toString("utf8"));
|
|
6811
6722
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6812
6723
|
collectedLines += chunkLines;
|
|
6813
6724
|
}
|
|
6814
6725
|
} finally {
|
|
6815
|
-
|
|
6726
|
+
fs24.closeSync(fd);
|
|
6816
6727
|
}
|
|
6817
6728
|
const content = chunks.join("");
|
|
6818
6729
|
const allLines = content.split("\n");
|
|
@@ -6828,11 +6739,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6828
6739
|
return allLines.slice(allLines.length - maxLines);
|
|
6829
6740
|
}
|
|
6830
6741
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6831
|
-
const stat =
|
|
6742
|
+
const stat = fs24.statSync(filePath);
|
|
6832
6743
|
if (stat.size === 0) {
|
|
6833
6744
|
return { lines: [], totalLinesCount: 0 };
|
|
6834
6745
|
}
|
|
6835
|
-
const fd =
|
|
6746
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6836
6747
|
const chunkSize = 64 * 1024;
|
|
6837
6748
|
let position = stat.size;
|
|
6838
6749
|
let remainder = "";
|
|
@@ -6844,7 +6755,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6844
6755
|
const length = Math.min(chunkSize, position);
|
|
6845
6756
|
position -= length;
|
|
6846
6757
|
const buffer = Buffer.alloc(length);
|
|
6847
|
-
|
|
6758
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6848
6759
|
let chunk = buffer.toString("utf8");
|
|
6849
6760
|
if (remainder) {
|
|
6850
6761
|
chunk += remainder;
|
|
@@ -6875,7 +6786,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6875
6786
|
}
|
|
6876
6787
|
}
|
|
6877
6788
|
} finally {
|
|
6878
|
-
|
|
6789
|
+
fs24.closeSync(fd);
|
|
6879
6790
|
}
|
|
6880
6791
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6881
6792
|
}
|
|
@@ -7017,7 +6928,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7017
6928
|
}
|
|
7018
6929
|
|
|
7019
6930
|
// src/commands/read-logs/json-lines.ts
|
|
7020
|
-
import
|
|
6931
|
+
import fs25 from "fs";
|
|
7021
6932
|
function normalizePid(value) {
|
|
7022
6933
|
if (typeof value === "number") {
|
|
7023
6934
|
return String(value);
|
|
@@ -7068,11 +6979,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7068
6979
|
return set.size > 0 ? set : null;
|
|
7069
6980
|
}
|
|
7070
6981
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7071
|
-
const stat =
|
|
6982
|
+
const stat = fs25.statSync(filePath);
|
|
7072
6983
|
if (stat.size === 0) {
|
|
7073
6984
|
return { lines: [], totalLinesCount: 0 };
|
|
7074
6985
|
}
|
|
7075
|
-
const fd =
|
|
6986
|
+
const fd = fs25.openSync(filePath, "r");
|
|
7076
6987
|
const chunkSize = 64 * 1024;
|
|
7077
6988
|
let position = stat.size;
|
|
7078
6989
|
let remainder = "";
|
|
@@ -7087,7 +6998,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7087
6998
|
const length = Math.min(chunkSize, position);
|
|
7088
6999
|
position -= length;
|
|
7089
7000
|
const buffer = Buffer.alloc(length);
|
|
7090
|
-
|
|
7001
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
7091
7002
|
let chunk = buffer.toString("utf8");
|
|
7092
7003
|
if (remainder) {
|
|
7093
7004
|
chunk += remainder;
|
|
@@ -7149,7 +7060,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7149
7060
|
}
|
|
7150
7061
|
}
|
|
7151
7062
|
} finally {
|
|
7152
|
-
|
|
7063
|
+
fs25.closeSync(fd);
|
|
7153
7064
|
}
|
|
7154
7065
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7155
7066
|
}
|
|
@@ -7192,11 +7103,11 @@ function extractTraceId(obj) {
|
|
|
7192
7103
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7193
7104
|
const wanted = traceId.trim();
|
|
7194
7105
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7195
|
-
const stat =
|
|
7106
|
+
const stat = fs25.statSync(filePath);
|
|
7196
7107
|
if (stat.size === 0) {
|
|
7197
7108
|
return { lines: [], totalLinesCount: 0 };
|
|
7198
7109
|
}
|
|
7199
|
-
const fd =
|
|
7110
|
+
const fd = fs25.openSync(filePath, "r");
|
|
7200
7111
|
const chunkSize = 64 * 1024;
|
|
7201
7112
|
let position = stat.size;
|
|
7202
7113
|
let remainder = "";
|
|
@@ -7209,7 +7120,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7209
7120
|
const length = Math.min(chunkSize, position);
|
|
7210
7121
|
position -= length;
|
|
7211
7122
|
const buffer = Buffer.alloc(length);
|
|
7212
|
-
|
|
7123
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
7213
7124
|
let chunk = buffer.toString("utf8");
|
|
7214
7125
|
if (remainder) {
|
|
7215
7126
|
chunk += remainder;
|
|
@@ -7262,7 +7173,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7262
7173
|
}
|
|
7263
7174
|
}
|
|
7264
7175
|
} finally {
|
|
7265
|
-
|
|
7176
|
+
fs25.closeSync(fd);
|
|
7266
7177
|
}
|
|
7267
7178
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7268
7179
|
}
|
|
@@ -7271,11 +7182,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7271
7182
|
if (!wantedLevelSet) {
|
|
7272
7183
|
return { lines: [], totalLinesCount: 0 };
|
|
7273
7184
|
}
|
|
7274
|
-
const stat =
|
|
7185
|
+
const stat = fs25.statSync(filePath);
|
|
7275
7186
|
if (stat.size === 0) {
|
|
7276
7187
|
return { lines: [], totalLinesCount: 0 };
|
|
7277
7188
|
}
|
|
7278
|
-
const fd =
|
|
7189
|
+
const fd = fs25.openSync(filePath, "r");
|
|
7279
7190
|
const chunkSize = 64 * 1024;
|
|
7280
7191
|
let position = stat.size;
|
|
7281
7192
|
let remainder = "";
|
|
@@ -7287,7 +7198,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7287
7198
|
const length = Math.min(chunkSize, position);
|
|
7288
7199
|
position -= length;
|
|
7289
7200
|
const buffer = Buffer.alloc(length);
|
|
7290
|
-
|
|
7201
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
7291
7202
|
let chunk = buffer.toString("utf8");
|
|
7292
7203
|
if (remainder) {
|
|
7293
7204
|
chunk += remainder;
|
|
@@ -7334,7 +7245,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7334
7245
|
}
|
|
7335
7246
|
}
|
|
7336
7247
|
} finally {
|
|
7337
|
-
|
|
7248
|
+
fs25.closeSync(fd);
|
|
7338
7249
|
}
|
|
7339
7250
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7340
7251
|
}
|
|
@@ -7568,30 +7479,30 @@ async function readLogsJsonResult(options) {
|
|
|
7568
7479
|
};
|
|
7569
7480
|
}
|
|
7570
7481
|
function resolveLogFilePath(logDir, type) {
|
|
7571
|
-
const base =
|
|
7482
|
+
const base = path21.isAbsolute(logDir) ? logDir : path21.join(process.cwd(), logDir);
|
|
7572
7483
|
if (type === "server") {
|
|
7573
|
-
return
|
|
7484
|
+
return path21.join(base, "server.log");
|
|
7574
7485
|
}
|
|
7575
7486
|
if (type === "trace") {
|
|
7576
|
-
return
|
|
7487
|
+
return path21.join(base, "trace.log");
|
|
7577
7488
|
}
|
|
7578
7489
|
if (type === "server-std") {
|
|
7579
|
-
return
|
|
7490
|
+
return path21.join(base, "server.std.log");
|
|
7580
7491
|
}
|
|
7581
7492
|
if (type === "client-std") {
|
|
7582
|
-
return
|
|
7493
|
+
return path21.join(base, "client.std.log");
|
|
7583
7494
|
}
|
|
7584
7495
|
if (type === "dev") {
|
|
7585
|
-
return
|
|
7496
|
+
return path21.join(base, "dev.log");
|
|
7586
7497
|
}
|
|
7587
7498
|
if (type === "dev-std") {
|
|
7588
|
-
return
|
|
7499
|
+
return path21.join(base, "dev.std.log");
|
|
7589
7500
|
}
|
|
7590
7501
|
if (type === "install-dep-std") {
|
|
7591
|
-
return
|
|
7502
|
+
return path21.join(base, "install-dep.std.log");
|
|
7592
7503
|
}
|
|
7593
7504
|
if (type === "browser") {
|
|
7594
|
-
return
|
|
7505
|
+
return path21.join(base, "browser.log");
|
|
7595
7506
|
}
|
|
7596
7507
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7597
7508
|
}
|
|
@@ -7768,9 +7679,9 @@ function camelToKebab(str) {
|
|
|
7768
7679
|
}
|
|
7769
7680
|
|
|
7770
7681
|
// src/commands/build/upload-static.handler.ts
|
|
7771
|
-
import * as
|
|
7772
|
-
import * as
|
|
7773
|
-
import * as
|
|
7682
|
+
import * as fs26 from "fs";
|
|
7683
|
+
import * as os2 from "os";
|
|
7684
|
+
import * as path22 from "path";
|
|
7774
7685
|
import { execFileSync } from "child_process";
|
|
7775
7686
|
function readCredentialsFromEnv() {
|
|
7776
7687
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7794,8 +7705,8 @@ async function uploadStatic(options) {
|
|
|
7794
7705
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7795
7706
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7796
7707
|
} = options;
|
|
7797
|
-
const resolvedStaticDir =
|
|
7798
|
-
if (!
|
|
7708
|
+
const resolvedStaticDir = path22.resolve(staticDir);
|
|
7709
|
+
if (!fs26.existsSync(resolvedStaticDir)) {
|
|
7799
7710
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7800
7711
|
return;
|
|
7801
7712
|
}
|
|
@@ -7828,8 +7739,8 @@ async function uploadStatic(options) {
|
|
|
7828
7739
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7829
7740
|
}
|
|
7830
7741
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7831
|
-
const confPath =
|
|
7832
|
-
|
|
7742
|
+
const confPath = path22.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7743
|
+
fs26.writeFileSync(confPath, "");
|
|
7833
7744
|
try {
|
|
7834
7745
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7835
7746
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7843,7 +7754,7 @@ async function uploadStatic(options) {
|
|
|
7843
7754
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7844
7755
|
} finally {
|
|
7845
7756
|
try {
|
|
7846
|
-
|
|
7757
|
+
fs26.unlinkSync(confPath);
|
|
7847
7758
|
} catch {
|
|
7848
7759
|
}
|
|
7849
7760
|
}
|
|
@@ -7863,8 +7774,8 @@ async function uploadStatic(options) {
|
|
|
7863
7774
|
}
|
|
7864
7775
|
}
|
|
7865
7776
|
function resolveTosutilPath(tosutilPath) {
|
|
7866
|
-
if (
|
|
7867
|
-
return
|
|
7777
|
+
if (path22.isAbsolute(tosutilPath)) {
|
|
7778
|
+
return fs26.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7868
7779
|
}
|
|
7869
7780
|
try {
|
|
7870
7781
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -7909,7 +7820,7 @@ async function resolveBucketId(appId) {
|
|
|
7909
7820
|
return bucketId;
|
|
7910
7821
|
}
|
|
7911
7822
|
function isDirEmpty(dirPath) {
|
|
7912
|
-
const entries =
|
|
7823
|
+
const entries = fs26.readdirSync(dirPath);
|
|
7913
7824
|
return entries.length === 0;
|
|
7914
7825
|
}
|
|
7915
7826
|
|
|
@@ -8004,12 +7915,12 @@ var commands = [
|
|
|
8004
7915
|
];
|
|
8005
7916
|
|
|
8006
7917
|
// src/index.ts
|
|
8007
|
-
var envPath =
|
|
8008
|
-
if (
|
|
7918
|
+
var envPath = path23.join(process.cwd(), ".env");
|
|
7919
|
+
if (fs27.existsSync(envPath)) {
|
|
8009
7920
|
dotenvConfig({ path: envPath });
|
|
8010
7921
|
}
|
|
8011
|
-
var __dirname =
|
|
8012
|
-
var pkg = JSON.parse(
|
|
7922
|
+
var __dirname = path23.dirname(fileURLToPath5(import.meta.url));
|
|
7923
|
+
var pkg = JSON.parse(fs27.readFileSync(path23.join(__dirname, "../package.json"), "utf-8"));
|
|
8013
7924
|
var cli = new FullstackCLI(pkg.version);
|
|
8014
7925
|
cli.useAll(commands);
|
|
8015
7926
|
cli.run();
|