@lark-apaas/fullstack-cli 1.1.39 → 1.1.40-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +555 -192
- 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 fs28 from "fs";
|
|
3
|
+
import path24 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -3105,6 +3105,309 @@ async function run3(options = {}) {
|
|
|
3105
3105
|
|
|
3106
3106
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3107
3107
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
3108
|
+
|
|
3109
|
+
// src/utils/grayscale/cache.ts
|
|
3110
|
+
import fs10 from "fs";
|
|
3111
|
+
import path8 from "path";
|
|
3112
|
+
import os from "os";
|
|
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 {
|
|
3133
|
+
return null;
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
function writeLocalCache(config) {
|
|
3137
|
+
try {
|
|
3138
|
+
const dir = path8.dirname(CACHE_PATH);
|
|
3139
|
+
if (!fs10.existsSync(dir)) {
|
|
3140
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
3141
|
+
}
|
|
3142
|
+
const entry = {
|
|
3143
|
+
config,
|
|
3144
|
+
timestamp: Date.now()
|
|
3145
|
+
};
|
|
3146
|
+
fs10.writeFileSync(CACHE_PATH, JSON.stringify(entry, null, 2), "utf-8");
|
|
3147
|
+
} 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}`);
|
|
3182
|
+
return null;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
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
|
+
|
|
3212
|
+
// src/utils/grayscale/identity.ts
|
|
3213
|
+
import fs11 from "fs";
|
|
3214
|
+
import path9 from "path";
|
|
3215
|
+
function readFromEnvVars() {
|
|
3216
|
+
const appId = process.env.app_id || process.env.APP_ID;
|
|
3217
|
+
const tenantId = process.env.tenant_id || process.env.TENANT_ID;
|
|
3218
|
+
return { appId, tenantId };
|
|
3219
|
+
}
|
|
3220
|
+
function parseEnvFile(filePath) {
|
|
3221
|
+
const result = {};
|
|
3222
|
+
if (!fs11.existsSync(filePath)) {
|
|
3223
|
+
return result;
|
|
3224
|
+
}
|
|
3225
|
+
try {
|
|
3226
|
+
const content = fs11.readFileSync(filePath, "utf-8");
|
|
3227
|
+
const lines = content.split("\n");
|
|
3228
|
+
for (const line of lines) {
|
|
3229
|
+
const trimmed = line.trim();
|
|
3230
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
3231
|
+
continue;
|
|
3232
|
+
}
|
|
3233
|
+
const match = trimmed.match(/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=["']?(.+?)["']?$/);
|
|
3234
|
+
if (match) {
|
|
3235
|
+
result[match[1]] = match[2];
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
} catch {
|
|
3239
|
+
}
|
|
3240
|
+
return result;
|
|
3241
|
+
}
|
|
3242
|
+
function readFromForceEnvFile(cwd) {
|
|
3243
|
+
const envPath2 = path9.join(cwd, ".force", "environment", "env");
|
|
3244
|
+
const vars = parseEnvFile(envPath2);
|
|
3245
|
+
return {
|
|
3246
|
+
appId: vars.app_id || vars.APP_ID,
|
|
3247
|
+
tenantId: vars.tenant_id || vars.TENANT_ID
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
function readFromClientBasePath() {
|
|
3251
|
+
const basePath = process.env.CLIENT_BASE_PATH;
|
|
3252
|
+
if (!basePath) {
|
|
3253
|
+
return {};
|
|
3254
|
+
}
|
|
3255
|
+
const afMatch = basePath.match(/\/af\/p\/([^/]+)/);
|
|
3256
|
+
if (afMatch) {
|
|
3257
|
+
return { appId: afMatch[1] };
|
|
3258
|
+
}
|
|
3259
|
+
const appMatch = basePath.match(/\/app\/([^/]+)/);
|
|
3260
|
+
if (appMatch) {
|
|
3261
|
+
return { appId: appMatch[1] };
|
|
3262
|
+
}
|
|
3263
|
+
return {};
|
|
3264
|
+
}
|
|
3265
|
+
function readFromDotEnv(cwd) {
|
|
3266
|
+
const envPath2 = path9.join(cwd, ".env");
|
|
3267
|
+
const vars = parseEnvFile(envPath2);
|
|
3268
|
+
return {
|
|
3269
|
+
appId: vars.app_id || vars.APP_ID,
|
|
3270
|
+
tenantId: vars.tenant_id || vars.TENANT_ID
|
|
3271
|
+
};
|
|
3272
|
+
}
|
|
3273
|
+
function readFromPackageJson(cwd) {
|
|
3274
|
+
const pkgPath = path9.join(cwd, "package.json");
|
|
3275
|
+
if (!fs11.existsSync(pkgPath)) {
|
|
3276
|
+
return {};
|
|
3277
|
+
}
|
|
3278
|
+
try {
|
|
3279
|
+
const content = fs11.readFileSync(pkgPath, "utf-8");
|
|
3280
|
+
const pkg2 = JSON.parse(content);
|
|
3281
|
+
const appId = pkg2?.fullstack?.appId;
|
|
3282
|
+
return appId ? { appId } : {};
|
|
3283
|
+
} catch {
|
|
3284
|
+
return {};
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
function readProjectIdentity(cwd) {
|
|
3288
|
+
const sources = [
|
|
3289
|
+
() => readFromEnvVars(),
|
|
3290
|
+
() => readFromForceEnvFile(cwd),
|
|
3291
|
+
() => readFromClientBasePath(),
|
|
3292
|
+
() => readFromDotEnv(cwd),
|
|
3293
|
+
() => readFromPackageJson(cwd)
|
|
3294
|
+
];
|
|
3295
|
+
const merged = {};
|
|
3296
|
+
for (const source of sources) {
|
|
3297
|
+
const identity = source();
|
|
3298
|
+
if (!merged.appId && identity.appId) {
|
|
3299
|
+
merged.appId = identity.appId;
|
|
3300
|
+
}
|
|
3301
|
+
if (!merged.tenantId && identity.tenantId) {
|
|
3302
|
+
merged.tenantId = identity.tenantId;
|
|
3303
|
+
}
|
|
3304
|
+
if (merged.appId && merged.tenantId) {
|
|
3305
|
+
break;
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
return merged;
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
// src/utils/grayscale/rules.ts
|
|
3312
|
+
import { createHash } from "crypto";
|
|
3313
|
+
function isInPercentage(key, percentage) {
|
|
3314
|
+
if (percentage <= 0) return false;
|
|
3315
|
+
if (percentage >= 100) return true;
|
|
3316
|
+
const hash = createHash("md5").update(`grayscale:${key}`).digest("hex");
|
|
3317
|
+
const value = parseInt(hash.substring(0, 8), 16) % 1e4;
|
|
3318
|
+
const threshold = Math.floor(percentage * 100);
|
|
3319
|
+
return value < threshold;
|
|
3320
|
+
}
|
|
3321
|
+
function matchConditions(rule, identity) {
|
|
3322
|
+
const { conditions } = rule;
|
|
3323
|
+
if (conditions.tenant_ids && conditions.tenant_ids.length > 0) {
|
|
3324
|
+
if (identity.tenantId && conditions.tenant_ids.includes(identity.tenantId)) {
|
|
3325
|
+
return true;
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
if (conditions.app_ids && conditions.app_ids.length > 0) {
|
|
3329
|
+
if (identity.appId && conditions.app_ids.includes(identity.appId)) {
|
|
3330
|
+
return true;
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
if (conditions.percentage != null && conditions.percentage > 0) {
|
|
3334
|
+
const hashKey = conditions.hash_key || "app_id";
|
|
3335
|
+
const hashValue = hashKey === "tenant_id" ? identity.tenantId : identity.appId;
|
|
3336
|
+
if (hashValue && isInPercentage(hashValue, conditions.percentage)) {
|
|
3337
|
+
return true;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
const hasConditions = conditions.tenant_ids && conditions.tenant_ids.length > 0 || conditions.app_ids && conditions.app_ids.length > 0 || conditions.percentage != null && conditions.percentage > 0;
|
|
3341
|
+
return !hasConditions;
|
|
3342
|
+
}
|
|
3343
|
+
function evaluateRules(config, identity) {
|
|
3344
|
+
const enabledRules = config.rules.filter((rule) => rule.enabled).sort((a, b) => b.priority - a.priority);
|
|
3345
|
+
for (const rule of enabledRules) {
|
|
3346
|
+
if (matchConditions(rule, identity)) {
|
|
3347
|
+
return rule;
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
return null;
|
|
3351
|
+
}
|
|
3352
|
+
function resolveTargetVersions(config, identity) {
|
|
3353
|
+
const matchedRule = evaluateRules(config, identity);
|
|
3354
|
+
const channelName = matchedRule?.channel || config.default_channel;
|
|
3355
|
+
const channel = config.channels[channelName];
|
|
3356
|
+
if (!channel) {
|
|
3357
|
+
console.warn(`[grayscale] Channel "${channelName}" not found in config`);
|
|
3358
|
+
return null;
|
|
3359
|
+
}
|
|
3360
|
+
const versions = /* @__PURE__ */ new Map();
|
|
3361
|
+
for (const [pkgName, version] of Object.entries(channel.versions)) {
|
|
3362
|
+
if (config.blocked_versions?.includes(version)) {
|
|
3363
|
+
console.warn(`[grayscale] Version ${version} of ${pkgName} is blocked, skipping`);
|
|
3364
|
+
continue;
|
|
3365
|
+
}
|
|
3366
|
+
versions.set(pkgName, version);
|
|
3367
|
+
}
|
|
3368
|
+
if (config.force_versions) {
|
|
3369
|
+
for (const [pkgName, version] of Object.entries(config.force_versions)) {
|
|
3370
|
+
versions.set(pkgName, version);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
if (matchedRule) {
|
|
3374
|
+
console.log(`[grayscale] Matched rule: "${matchedRule.name}" (id: ${matchedRule.id}), channel: ${channelName}`);
|
|
3375
|
+
} else {
|
|
3376
|
+
console.log(`[grayscale] No rule matched, using default channel: ${channelName}`);
|
|
3377
|
+
}
|
|
3378
|
+
return versions;
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
// src/utils/grayscale/index.ts
|
|
3382
|
+
async function resolveGrayscaleVersions(cwd) {
|
|
3383
|
+
const config = await getGrayscaleConfig();
|
|
3384
|
+
if (!config) {
|
|
3385
|
+
console.log("[grayscale] Config not available, skipping grayscale");
|
|
3386
|
+
return null;
|
|
3387
|
+
}
|
|
3388
|
+
if (!config.enabled) {
|
|
3389
|
+
console.log("[grayscale] Grayscale is disabled");
|
|
3390
|
+
return null;
|
|
3391
|
+
}
|
|
3392
|
+
const identity = readProjectIdentity(cwd);
|
|
3393
|
+
if (!identity.appId && !identity.tenantId) {
|
|
3394
|
+
console.log("[grayscale] No app_id or tenant_id found, skipping grayscale");
|
|
3395
|
+
return null;
|
|
3396
|
+
}
|
|
3397
|
+
console.log(`[grayscale] Project identity: appId=${identity.appId || "N/A"}, tenantId=${identity.tenantId || "N/A"}`);
|
|
3398
|
+
const versions = resolveTargetVersions(config, identity);
|
|
3399
|
+
if (!versions || versions.size === 0) {
|
|
3400
|
+
console.log("[grayscale] No target versions resolved");
|
|
3401
|
+
return null;
|
|
3402
|
+
}
|
|
3403
|
+
console.log(`[grayscale] Resolved ${versions.size} package version(s):`);
|
|
3404
|
+
for (const [pkg2, ver] of versions) {
|
|
3405
|
+
console.log(`[grayscale] ${pkg2} -> ${ver}`);
|
|
3406
|
+
}
|
|
3407
|
+
return versions;
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
// src/commands/upgrade/deps/run.handler.ts
|
|
3108
3411
|
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
3109
3412
|
const pkg2 = readPackageJson(cwd);
|
|
3110
3413
|
const allPackages = /* @__PURE__ */ new Set();
|
|
@@ -3157,11 +3460,43 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3157
3460
|
});
|
|
3158
3461
|
}
|
|
3159
3462
|
}
|
|
3463
|
+
function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun) {
|
|
3464
|
+
const upgradePlan = [];
|
|
3465
|
+
for (const pkg2 of packages) {
|
|
3466
|
+
const version = grayscaleVersions.get(pkg2);
|
|
3467
|
+
if (version) {
|
|
3468
|
+
upgradePlan.push({ pkg: pkg2, version });
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
if (upgradePlan.length === 0) {
|
|
3472
|
+
console.log("[fullstack-cli] No grayscale versions matched current packages");
|
|
3473
|
+
return;
|
|
3474
|
+
}
|
|
3475
|
+
console.log(`[fullstack-cli] Grayscale upgrade plan (${upgradePlan.length} package(s)):`);
|
|
3476
|
+
upgradePlan.forEach(({ pkg: pkg2, version }) => {
|
|
3477
|
+
console.log(` - ${pkg2} -> ${version}`);
|
|
3478
|
+
});
|
|
3479
|
+
if (dryRun) {
|
|
3480
|
+
console.log("[fullstack-cli] Dry run mode, skipping actual installation");
|
|
3481
|
+
return;
|
|
3482
|
+
}
|
|
3483
|
+
for (const { pkg: pkg2, version } of upgradePlan) {
|
|
3484
|
+
const target = `${pkg2}@${version}`;
|
|
3485
|
+
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
3486
|
+
const result = spawnSync3("npm", ["install", target], {
|
|
3487
|
+
cwd,
|
|
3488
|
+
stdio: "inherit"
|
|
3489
|
+
});
|
|
3490
|
+
if (result.error || result.status !== 0) {
|
|
3491
|
+
throw new Error(`Failed to install ${target}`);
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
}
|
|
3160
3495
|
async function run4(options = {}) {
|
|
3161
3496
|
const cwd = process.env.INIT_CWD || process.cwd();
|
|
3162
3497
|
console.log("[fullstack-cli] Starting dependencies upgrade...");
|
|
3163
3498
|
try {
|
|
3164
|
-
console.log("[fullstack-cli] Step 1/
|
|
3499
|
+
console.log("[fullstack-cli] Step 1/3: Scanning @lark-apaas dependencies...");
|
|
3165
3500
|
const packages = findLarkAapaasPackages(cwd, options.packages);
|
|
3166
3501
|
if (packages.length === 0) {
|
|
3167
3502
|
console.log("[fullstack-cli] No @lark-apaas packages found");
|
|
@@ -3169,7 +3504,35 @@ async function run4(options = {}) {
|
|
|
3169
3504
|
}
|
|
3170
3505
|
console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
|
|
3171
3506
|
packages.forEach((p) => console.log(` - ${p}`));
|
|
3172
|
-
|
|
3507
|
+
if (!options.skipGrayscale && !options.version) {
|
|
3508
|
+
console.log("[fullstack-cli] Step 2/3: Checking grayscale config...");
|
|
3509
|
+
try {
|
|
3510
|
+
const grayscaleVersions = await resolveGrayscaleVersions(cwd);
|
|
3511
|
+
if (grayscaleVersions) {
|
|
3512
|
+
console.log("[fullstack-cli] Step 3/3: Applying grayscale versions...");
|
|
3513
|
+
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun);
|
|
3514
|
+
if (!options.dryRun) {
|
|
3515
|
+
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s) via grayscale`);
|
|
3516
|
+
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
3517
|
+
}
|
|
3518
|
+
return;
|
|
3519
|
+
}
|
|
3520
|
+
console.log("[fullstack-cli] Grayscale not available, falling back to default upgrade");
|
|
3521
|
+
} catch (error) {
|
|
3522
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
3523
|
+
console.warn(`[fullstack-cli] Grayscale check failed: ${msg}, falling back to default upgrade`);
|
|
3524
|
+
}
|
|
3525
|
+
} else if (options.skipGrayscale) {
|
|
3526
|
+
console.log("[fullstack-cli] Step 2/3: Skipping grayscale check (--skip-grayscale)");
|
|
3527
|
+
} else {
|
|
3528
|
+
console.log("[fullstack-cli] Step 2/3: Skipping grayscale check (explicit --version provided)");
|
|
3529
|
+
}
|
|
3530
|
+
if (options.dryRun) {
|
|
3531
|
+
console.log("[fullstack-cli] Dry run mode: would upgrade via npm update (no grayscale)");
|
|
3532
|
+
packages.forEach((p) => console.log(` - ${p} -> ${options.version || "latest compatible"}`));
|
|
3533
|
+
return;
|
|
3534
|
+
}
|
|
3535
|
+
console.log("[fullstack-cli] Step 3/3: Upgrading packages...");
|
|
3173
3536
|
upgradePackages(packages, options.version, cwd);
|
|
3174
3537
|
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
|
|
3175
3538
|
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
@@ -3185,7 +3548,7 @@ var depsCommand = {
|
|
|
3185
3548
|
name: "deps",
|
|
3186
3549
|
description: "Upgrade @lark-apaas dependencies",
|
|
3187
3550
|
register(parentCommand) {
|
|
3188
|
-
parentCommand.command(this.name).description(this.description).option("--version <version>", "Upgrade to specific version").option("--packages <packages>", "Only upgrade specific packages (comma-separated)").action(async (options) => {
|
|
3551
|
+
parentCommand.command(this.name).description(this.description).option("--version <version>", "Upgrade to specific version").option("--packages <packages>", "Only upgrade specific packages (comma-separated)").option("--skip-grayscale", "Skip grayscale version check").option("--dry-run", "Show upgrade plan without executing").action(async (options) => {
|
|
3189
3552
|
await run4(options);
|
|
3190
3553
|
});
|
|
3191
3554
|
}
|
|
@@ -3204,8 +3567,8 @@ var upgradeCommand = {
|
|
|
3204
3567
|
};
|
|
3205
3568
|
|
|
3206
3569
|
// src/commands/action-plugin/utils.ts
|
|
3207
|
-
import
|
|
3208
|
-
import
|
|
3570
|
+
import fs12 from "fs";
|
|
3571
|
+
import path10 from "path";
|
|
3209
3572
|
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
3210
3573
|
function parsePluginName(input) {
|
|
3211
3574
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3223,18 +3586,18 @@ function getProjectRoot() {
|
|
|
3223
3586
|
return process.cwd();
|
|
3224
3587
|
}
|
|
3225
3588
|
function getPackageJsonPath() {
|
|
3226
|
-
return
|
|
3589
|
+
return path10.join(getProjectRoot(), "package.json");
|
|
3227
3590
|
}
|
|
3228
3591
|
function getPluginPath(pluginName) {
|
|
3229
|
-
return
|
|
3592
|
+
return path10.join(getProjectRoot(), "node_modules", pluginName);
|
|
3230
3593
|
}
|
|
3231
3594
|
function readPackageJson2() {
|
|
3232
3595
|
const pkgPath = getPackageJsonPath();
|
|
3233
|
-
if (!
|
|
3596
|
+
if (!fs12.existsSync(pkgPath)) {
|
|
3234
3597
|
throw new Error("package.json not found in current directory");
|
|
3235
3598
|
}
|
|
3236
3599
|
try {
|
|
3237
|
-
const content =
|
|
3600
|
+
const content = fs12.readFileSync(pkgPath, "utf-8");
|
|
3238
3601
|
return JSON.parse(content);
|
|
3239
3602
|
} catch {
|
|
3240
3603
|
throw new Error("Failed to parse package.json");
|
|
@@ -3242,7 +3605,7 @@ function readPackageJson2() {
|
|
|
3242
3605
|
}
|
|
3243
3606
|
function writePackageJson2(pkg2) {
|
|
3244
3607
|
const pkgPath = getPackageJsonPath();
|
|
3245
|
-
|
|
3608
|
+
fs12.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3246
3609
|
}
|
|
3247
3610
|
function readActionPlugins() {
|
|
3248
3611
|
const pkg2 = readPackageJson2();
|
|
@@ -3275,12 +3638,12 @@ function npmInstall(tgzPath) {
|
|
|
3275
3638
|
}
|
|
3276
3639
|
}
|
|
3277
3640
|
function getPackageVersion(pluginName) {
|
|
3278
|
-
const pkgJsonPath =
|
|
3279
|
-
if (!
|
|
3641
|
+
const pkgJsonPath = path10.join(getPluginPath(pluginName), "package.json");
|
|
3642
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3280
3643
|
return null;
|
|
3281
3644
|
}
|
|
3282
3645
|
try {
|
|
3283
|
-
const content =
|
|
3646
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3284
3647
|
const pkg2 = JSON.parse(content);
|
|
3285
3648
|
return pkg2.version || null;
|
|
3286
3649
|
} catch {
|
|
@@ -3288,49 +3651,49 @@ function getPackageVersion(pluginName) {
|
|
|
3288
3651
|
}
|
|
3289
3652
|
}
|
|
3290
3653
|
function readPluginPackageJson(pluginPath) {
|
|
3291
|
-
const pkgJsonPath =
|
|
3292
|
-
if (!
|
|
3654
|
+
const pkgJsonPath = path10.join(pluginPath, "package.json");
|
|
3655
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3293
3656
|
return null;
|
|
3294
3657
|
}
|
|
3295
3658
|
try {
|
|
3296
|
-
const content =
|
|
3659
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3297
3660
|
return JSON.parse(content);
|
|
3298
3661
|
} catch {
|
|
3299
3662
|
return null;
|
|
3300
3663
|
}
|
|
3301
3664
|
}
|
|
3302
3665
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3303
|
-
const nodeModulesPath =
|
|
3304
|
-
const targetDir =
|
|
3305
|
-
const scopeDir =
|
|
3306
|
-
if (!
|
|
3307
|
-
|
|
3666
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3667
|
+
const targetDir = path10.join(nodeModulesPath, pluginName);
|
|
3668
|
+
const scopeDir = path10.dirname(targetDir);
|
|
3669
|
+
if (!fs12.existsSync(scopeDir)) {
|
|
3670
|
+
fs12.mkdirSync(scopeDir, { recursive: true });
|
|
3308
3671
|
}
|
|
3309
|
-
if (
|
|
3310
|
-
|
|
3672
|
+
if (fs12.existsSync(targetDir)) {
|
|
3673
|
+
fs12.rmSync(targetDir, { recursive: true });
|
|
3311
3674
|
}
|
|
3312
|
-
const tempDir =
|
|
3313
|
-
if (
|
|
3314
|
-
|
|
3675
|
+
const tempDir = path10.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3676
|
+
if (fs12.existsSync(tempDir)) {
|
|
3677
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3315
3678
|
}
|
|
3316
|
-
|
|
3679
|
+
fs12.mkdirSync(tempDir, { recursive: true });
|
|
3317
3680
|
try {
|
|
3318
3681
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3319
|
-
const extractedDir =
|
|
3320
|
-
if (
|
|
3321
|
-
|
|
3682
|
+
const extractedDir = path10.join(tempDir, "package");
|
|
3683
|
+
if (fs12.existsSync(extractedDir)) {
|
|
3684
|
+
fs12.renameSync(extractedDir, targetDir);
|
|
3322
3685
|
} else {
|
|
3323
|
-
const files =
|
|
3686
|
+
const files = fs12.readdirSync(tempDir);
|
|
3324
3687
|
if (files.length === 1) {
|
|
3325
|
-
|
|
3688
|
+
fs12.renameSync(path10.join(tempDir, files[0]), targetDir);
|
|
3326
3689
|
} else {
|
|
3327
3690
|
throw new Error("Unexpected tgz structure");
|
|
3328
3691
|
}
|
|
3329
3692
|
}
|
|
3330
3693
|
return targetDir;
|
|
3331
3694
|
} finally {
|
|
3332
|
-
if (
|
|
3333
|
-
|
|
3695
|
+
if (fs12.existsSync(tempDir)) {
|
|
3696
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3334
3697
|
}
|
|
3335
3698
|
}
|
|
3336
3699
|
}
|
|
@@ -3339,10 +3702,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3339
3702
|
return [];
|
|
3340
3703
|
}
|
|
3341
3704
|
const missing = [];
|
|
3342
|
-
const nodeModulesPath =
|
|
3705
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3343
3706
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3344
|
-
const depPath =
|
|
3345
|
-
if (!
|
|
3707
|
+
const depPath = path10.join(nodeModulesPath, depName);
|
|
3708
|
+
if (!fs12.existsSync(depPath)) {
|
|
3346
3709
|
missing.push(depName);
|
|
3347
3710
|
}
|
|
3348
3711
|
}
|
|
@@ -3366,16 +3729,16 @@ function installMissingDeps(deps) {
|
|
|
3366
3729
|
}
|
|
3367
3730
|
function removePluginDirectory(pluginName) {
|
|
3368
3731
|
const pluginPath = getPluginPath(pluginName);
|
|
3369
|
-
if (
|
|
3370
|
-
|
|
3732
|
+
if (fs12.existsSync(pluginPath)) {
|
|
3733
|
+
fs12.rmSync(pluginPath, { recursive: true });
|
|
3371
3734
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3372
3735
|
}
|
|
3373
3736
|
}
|
|
3374
3737
|
|
|
3375
3738
|
// src/commands/action-plugin/api-client.ts
|
|
3376
3739
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3377
|
-
import
|
|
3378
|
-
import
|
|
3740
|
+
import fs13 from "fs";
|
|
3741
|
+
import path11 from "path";
|
|
3379
3742
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3380
3743
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3381
3744
|
const client = getHttpClient();
|
|
@@ -3439,19 +3802,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3439
3802
|
return Buffer.from(arrayBuffer);
|
|
3440
3803
|
}
|
|
3441
3804
|
function getPluginCacheDir() {
|
|
3442
|
-
return
|
|
3805
|
+
return path11.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3443
3806
|
}
|
|
3444
3807
|
function ensureCacheDir() {
|
|
3445
3808
|
const cacheDir = getPluginCacheDir();
|
|
3446
|
-
if (!
|
|
3447
|
-
|
|
3809
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3810
|
+
fs13.mkdirSync(cacheDir, { recursive: true });
|
|
3448
3811
|
}
|
|
3449
3812
|
}
|
|
3450
3813
|
function getTempFilePath(pluginKey, version) {
|
|
3451
3814
|
ensureCacheDir();
|
|
3452
3815
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3453
3816
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3454
|
-
return
|
|
3817
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3455
3818
|
}
|
|
3456
3819
|
var MAX_RETRIES = 2;
|
|
3457
3820
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3488,7 +3851,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3488
3851
|
);
|
|
3489
3852
|
}
|
|
3490
3853
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3491
|
-
|
|
3854
|
+
fs13.writeFileSync(tgzPath, tgzBuffer);
|
|
3492
3855
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3493
3856
|
return {
|
|
3494
3857
|
tgzPath,
|
|
@@ -3502,18 +3865,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3502
3865
|
ensureCacheDir();
|
|
3503
3866
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3504
3867
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3505
|
-
return
|
|
3868
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3506
3869
|
}
|
|
3507
3870
|
function hasCachedPlugin(pluginKey, version) {
|
|
3508
3871
|
const cachePath = getCachePath(pluginKey, version);
|
|
3509
|
-
return
|
|
3872
|
+
return fs13.existsSync(cachePath);
|
|
3510
3873
|
}
|
|
3511
3874
|
function listCachedPlugins() {
|
|
3512
3875
|
const cacheDir = getPluginCacheDir();
|
|
3513
|
-
if (!
|
|
3876
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3514
3877
|
return [];
|
|
3515
3878
|
}
|
|
3516
|
-
const files =
|
|
3879
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3517
3880
|
const result = [];
|
|
3518
3881
|
for (const file of files) {
|
|
3519
3882
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3521,8 +3884,8 @@ function listCachedPlugins() {
|
|
|
3521
3884
|
if (!match) continue;
|
|
3522
3885
|
const [, rawName, version] = match;
|
|
3523
3886
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3524
|
-
const filePath =
|
|
3525
|
-
const stat =
|
|
3887
|
+
const filePath = path11.join(cacheDir, file);
|
|
3888
|
+
const stat = fs13.statSync(filePath);
|
|
3526
3889
|
result.push({
|
|
3527
3890
|
name,
|
|
3528
3891
|
version,
|
|
@@ -3535,14 +3898,14 @@ function listCachedPlugins() {
|
|
|
3535
3898
|
}
|
|
3536
3899
|
function cleanAllCache() {
|
|
3537
3900
|
const cacheDir = getPluginCacheDir();
|
|
3538
|
-
if (!
|
|
3901
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3539
3902
|
return 0;
|
|
3540
3903
|
}
|
|
3541
|
-
const files =
|
|
3904
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3542
3905
|
let count = 0;
|
|
3543
3906
|
for (const file of files) {
|
|
3544
3907
|
if (file.endsWith(".tgz")) {
|
|
3545
|
-
|
|
3908
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3546
3909
|
count++;
|
|
3547
3910
|
}
|
|
3548
3911
|
}
|
|
@@ -3550,21 +3913,21 @@ function cleanAllCache() {
|
|
|
3550
3913
|
}
|
|
3551
3914
|
function cleanPluginCache(pluginKey, version) {
|
|
3552
3915
|
const cacheDir = getPluginCacheDir();
|
|
3553
|
-
if (!
|
|
3916
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3554
3917
|
return 0;
|
|
3555
3918
|
}
|
|
3556
3919
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3557
|
-
const files =
|
|
3920
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3558
3921
|
let count = 0;
|
|
3559
3922
|
for (const file of files) {
|
|
3560
3923
|
if (version) {
|
|
3561
3924
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3562
|
-
|
|
3925
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3563
3926
|
count++;
|
|
3564
3927
|
}
|
|
3565
3928
|
} else {
|
|
3566
3929
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3567
|
-
|
|
3930
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3568
3931
|
count++;
|
|
3569
3932
|
}
|
|
3570
3933
|
}
|
|
@@ -3991,40 +4354,40 @@ var actionPluginCommandGroup = {
|
|
|
3991
4354
|
};
|
|
3992
4355
|
|
|
3993
4356
|
// src/commands/capability/utils.ts
|
|
3994
|
-
import
|
|
4357
|
+
import fs14 from "fs";
|
|
3995
4358
|
import { createRequire as createRequire2 } from "module";
|
|
3996
|
-
import
|
|
4359
|
+
import path12 from "path";
|
|
3997
4360
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
3998
4361
|
function getProjectRoot2() {
|
|
3999
4362
|
return process.cwd();
|
|
4000
4363
|
}
|
|
4001
4364
|
function getCapabilitiesDir() {
|
|
4002
|
-
return
|
|
4365
|
+
return path12.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4003
4366
|
}
|
|
4004
4367
|
function getCapabilityPath(id) {
|
|
4005
|
-
return
|
|
4368
|
+
return path12.join(getCapabilitiesDir(), `${id}.json`);
|
|
4006
4369
|
}
|
|
4007
4370
|
function getPluginManifestPath(pluginKey) {
|
|
4008
|
-
return
|
|
4371
|
+
return path12.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4009
4372
|
}
|
|
4010
4373
|
function capabilitiesDirExists() {
|
|
4011
|
-
return
|
|
4374
|
+
return fs14.existsSync(getCapabilitiesDir());
|
|
4012
4375
|
}
|
|
4013
4376
|
function listCapabilityIds() {
|
|
4014
4377
|
const dir = getCapabilitiesDir();
|
|
4015
|
-
if (!
|
|
4378
|
+
if (!fs14.existsSync(dir)) {
|
|
4016
4379
|
return [];
|
|
4017
4380
|
}
|
|
4018
|
-
const files =
|
|
4381
|
+
const files = fs14.readdirSync(dir);
|
|
4019
4382
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4020
4383
|
}
|
|
4021
4384
|
function readCapability(id) {
|
|
4022
4385
|
const filePath = getCapabilityPath(id);
|
|
4023
|
-
if (!
|
|
4386
|
+
if (!fs14.existsSync(filePath)) {
|
|
4024
4387
|
throw new Error(`Capability not found: ${id}`);
|
|
4025
4388
|
}
|
|
4026
4389
|
try {
|
|
4027
|
-
const content =
|
|
4390
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4028
4391
|
return JSON.parse(content);
|
|
4029
4392
|
} catch (error) {
|
|
4030
4393
|
if (error instanceof SyntaxError) {
|
|
@@ -4051,11 +4414,11 @@ function readAllCapabilities() {
|
|
|
4051
4414
|
}
|
|
4052
4415
|
function readPluginManifest(pluginKey) {
|
|
4053
4416
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4054
|
-
if (!
|
|
4417
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
4055
4418
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4056
4419
|
}
|
|
4057
4420
|
try {
|
|
4058
|
-
const content =
|
|
4421
|
+
const content = fs14.readFileSync(manifestPath, "utf-8");
|
|
4059
4422
|
return JSON.parse(content);
|
|
4060
4423
|
} catch (error) {
|
|
4061
4424
|
if (error instanceof SyntaxError) {
|
|
@@ -4072,7 +4435,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4072
4435
|
}
|
|
4073
4436
|
async function loadPlugin(pluginKey) {
|
|
4074
4437
|
try {
|
|
4075
|
-
const userRequire = createRequire2(
|
|
4438
|
+
const userRequire = createRequire2(path12.join(getProjectRoot2(), "package.json"));
|
|
4076
4439
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4077
4440
|
const pluginModule = await import(resolvedPath);
|
|
4078
4441
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4235,9 +4598,9 @@ var capabilityCommandGroup = {
|
|
|
4235
4598
|
import { execFile } from "child_process";
|
|
4236
4599
|
|
|
4237
4600
|
// src/commands/component/registry-preparer.ts
|
|
4238
|
-
import
|
|
4239
|
-
import
|
|
4240
|
-
import
|
|
4601
|
+
import fs15 from "fs";
|
|
4602
|
+
import path13 from "path";
|
|
4603
|
+
import os2 from "os";
|
|
4241
4604
|
|
|
4242
4605
|
// src/commands/component/service.ts
|
|
4243
4606
|
import { mapValues } from "es-toolkit";
|
|
@@ -4292,7 +4655,7 @@ async function sendInstallEvent(key) {
|
|
|
4292
4655
|
}
|
|
4293
4656
|
|
|
4294
4657
|
// src/commands/component/registry-preparer.ts
|
|
4295
|
-
var REGISTRY_TEMP_DIR =
|
|
4658
|
+
var REGISTRY_TEMP_DIR = path13.join(os2.tmpdir(), "miaoda-registry");
|
|
4296
4659
|
function parseComponentKey(key) {
|
|
4297
4660
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4298
4661
|
if (!match) {
|
|
@@ -4304,11 +4667,11 @@ function parseComponentKey(key) {
|
|
|
4304
4667
|
}
|
|
4305
4668
|
function getLocalRegistryPath(key) {
|
|
4306
4669
|
const { scope, name } = parseComponentKey(key);
|
|
4307
|
-
return
|
|
4670
|
+
return path13.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4308
4671
|
}
|
|
4309
4672
|
function ensureDir(dirPath) {
|
|
4310
|
-
if (!
|
|
4311
|
-
|
|
4673
|
+
if (!fs15.existsSync(dirPath)) {
|
|
4674
|
+
fs15.mkdirSync(dirPath, { recursive: true });
|
|
4312
4675
|
}
|
|
4313
4676
|
}
|
|
4314
4677
|
async function prepareRecursive(key, visited) {
|
|
@@ -4341,8 +4704,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4341
4704
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4342
4705
|
};
|
|
4343
4706
|
const localPath = getLocalRegistryPath(key);
|
|
4344
|
-
ensureDir(
|
|
4345
|
-
|
|
4707
|
+
ensureDir(path13.dirname(localPath));
|
|
4708
|
+
fs15.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4346
4709
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4347
4710
|
}
|
|
4348
4711
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4352,18 +4715,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4352
4715
|
}
|
|
4353
4716
|
function cleanupTempDir() {
|
|
4354
4717
|
try {
|
|
4355
|
-
if (
|
|
4356
|
-
|
|
4718
|
+
if (fs15.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4719
|
+
fs15.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4357
4720
|
}
|
|
4358
4721
|
} catch {
|
|
4359
4722
|
}
|
|
4360
4723
|
}
|
|
4361
4724
|
function getDownloadedRegistryItem(itemId) {
|
|
4362
4725
|
const localPath = getLocalRegistryPath(itemId);
|
|
4363
|
-
if (!
|
|
4726
|
+
if (!fs15.existsSync(localPath)) {
|
|
4364
4727
|
return null;
|
|
4365
4728
|
}
|
|
4366
|
-
const content =
|
|
4729
|
+
const content = fs15.readFileSync(localPath, "utf-8");
|
|
4367
4730
|
return JSON.parse(content);
|
|
4368
4731
|
}
|
|
4369
4732
|
|
|
@@ -4531,58 +4894,58 @@ var componentCommandGroup = {
|
|
|
4531
4894
|
};
|
|
4532
4895
|
|
|
4533
4896
|
// src/commands/migration/version-manager.ts
|
|
4534
|
-
import
|
|
4535
|
-
import
|
|
4897
|
+
import fs16 from "fs";
|
|
4898
|
+
import path14 from "path";
|
|
4536
4899
|
var PACKAGE_JSON = "package.json";
|
|
4537
4900
|
var VERSION_FIELD = "migrationVersion";
|
|
4538
4901
|
function getPackageJsonPath2() {
|
|
4539
|
-
return
|
|
4902
|
+
return path14.join(process.cwd(), PACKAGE_JSON);
|
|
4540
4903
|
}
|
|
4541
4904
|
function getCurrentVersion() {
|
|
4542
4905
|
const pkgPath = getPackageJsonPath2();
|
|
4543
|
-
if (!
|
|
4906
|
+
if (!fs16.existsSync(pkgPath)) {
|
|
4544
4907
|
throw new Error("package.json not found");
|
|
4545
4908
|
}
|
|
4546
|
-
const pkg2 = JSON.parse(
|
|
4909
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4547
4910
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4548
4911
|
}
|
|
4549
4912
|
function setCurrentVersion(version) {
|
|
4550
4913
|
const pkgPath = getPackageJsonPath2();
|
|
4551
|
-
const pkg2 = JSON.parse(
|
|
4914
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4552
4915
|
pkg2[VERSION_FIELD] = version;
|
|
4553
|
-
|
|
4916
|
+
fs16.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4554
4917
|
}
|
|
4555
4918
|
|
|
4556
4919
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4557
|
-
import
|
|
4558
|
-
import
|
|
4920
|
+
import fs18 from "fs";
|
|
4921
|
+
import path16 from "path";
|
|
4559
4922
|
|
|
4560
4923
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4561
|
-
import
|
|
4562
|
-
import
|
|
4924
|
+
import fs17 from "fs";
|
|
4925
|
+
import path15 from "path";
|
|
4563
4926
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4564
4927
|
function getProjectRoot3() {
|
|
4565
4928
|
return process.cwd();
|
|
4566
4929
|
}
|
|
4567
4930
|
function getCapabilitiesDir2() {
|
|
4568
|
-
return
|
|
4931
|
+
return path15.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4569
4932
|
}
|
|
4570
4933
|
function getPluginManifestPath2(pluginKey) {
|
|
4571
|
-
return
|
|
4934
|
+
return path15.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4572
4935
|
}
|
|
4573
4936
|
|
|
4574
4937
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4575
4938
|
function detectJsonMigration() {
|
|
4576
4939
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4577
|
-
const oldFilePath =
|
|
4578
|
-
if (!
|
|
4940
|
+
const oldFilePath = path16.join(capabilitiesDir, "capabilities.json");
|
|
4941
|
+
if (!fs18.existsSync(oldFilePath)) {
|
|
4579
4942
|
return {
|
|
4580
4943
|
needsMigration: false,
|
|
4581
4944
|
reason: "capabilities.json not found"
|
|
4582
4945
|
};
|
|
4583
4946
|
}
|
|
4584
4947
|
try {
|
|
4585
|
-
const content =
|
|
4948
|
+
const content = fs18.readFileSync(oldFilePath, "utf-8");
|
|
4586
4949
|
const parsed = JSON.parse(content);
|
|
4587
4950
|
if (!Array.isArray(parsed)) {
|
|
4588
4951
|
return {
|
|
@@ -4633,8 +4996,8 @@ async function check(options) {
|
|
|
4633
4996
|
}
|
|
4634
4997
|
|
|
4635
4998
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4636
|
-
import
|
|
4637
|
-
import
|
|
4999
|
+
import fs19 from "fs";
|
|
5000
|
+
import path17 from "path";
|
|
4638
5001
|
|
|
4639
5002
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
4640
5003
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4864,18 +5227,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4864
5227
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4865
5228
|
function loadExistingCapabilities() {
|
|
4866
5229
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4867
|
-
if (!
|
|
5230
|
+
if (!fs19.existsSync(capabilitiesDir)) {
|
|
4868
5231
|
return [];
|
|
4869
5232
|
}
|
|
4870
|
-
const files =
|
|
5233
|
+
const files = fs19.readdirSync(capabilitiesDir);
|
|
4871
5234
|
const capabilities = [];
|
|
4872
5235
|
for (const file of files) {
|
|
4873
5236
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4874
5237
|
continue;
|
|
4875
5238
|
}
|
|
4876
5239
|
try {
|
|
4877
|
-
const filePath =
|
|
4878
|
-
const content =
|
|
5240
|
+
const filePath = path17.join(capabilitiesDir, file);
|
|
5241
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
4879
5242
|
const capability = JSON.parse(content);
|
|
4880
5243
|
if (capability.id && capability.pluginKey) {
|
|
4881
5244
|
capabilities.push(capability);
|
|
@@ -4933,9 +5296,9 @@ async function migrateJsonFiles(options) {
|
|
|
4933
5296
|
}
|
|
4934
5297
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4935
5298
|
for (const cap of newCapabilities) {
|
|
4936
|
-
const filePath =
|
|
5299
|
+
const filePath = path17.join(capabilitiesDir, `${cap.id}.json`);
|
|
4937
5300
|
const content = JSON.stringify(cap, null, 2);
|
|
4938
|
-
|
|
5301
|
+
fs19.writeFileSync(filePath, content, "utf-8");
|
|
4939
5302
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4940
5303
|
}
|
|
4941
5304
|
return {
|
|
@@ -4947,11 +5310,11 @@ async function migrateJsonFiles(options) {
|
|
|
4947
5310
|
}
|
|
4948
5311
|
|
|
4949
5312
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4950
|
-
import
|
|
5313
|
+
import fs20 from "fs";
|
|
4951
5314
|
function isPluginInstalled2(pluginKey) {
|
|
4952
5315
|
const actionPlugins = readActionPlugins();
|
|
4953
5316
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4954
|
-
return
|
|
5317
|
+
return fs20.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4955
5318
|
}
|
|
4956
5319
|
function detectPluginsToInstall(capabilities) {
|
|
4957
5320
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5027,12 +5390,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5027
5390
|
}
|
|
5028
5391
|
|
|
5029
5392
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5030
|
-
import
|
|
5393
|
+
import path19 from "path";
|
|
5031
5394
|
import { Project as Project3 } from "ts-morph";
|
|
5032
5395
|
|
|
5033
5396
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5034
|
-
import
|
|
5035
|
-
import
|
|
5397
|
+
import fs21 from "fs";
|
|
5398
|
+
import path18 from "path";
|
|
5036
5399
|
var EXCLUDED_DIRS = [
|
|
5037
5400
|
"node_modules",
|
|
5038
5401
|
"dist",
|
|
@@ -5047,9 +5410,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5047
5410
|
/\.d\.ts$/
|
|
5048
5411
|
];
|
|
5049
5412
|
function scanDirectory(dir, files = []) {
|
|
5050
|
-
const entries =
|
|
5413
|
+
const entries = fs21.readdirSync(dir, { withFileTypes: true });
|
|
5051
5414
|
for (const entry of entries) {
|
|
5052
|
-
const fullPath =
|
|
5415
|
+
const fullPath = path18.join(dir, entry.name);
|
|
5053
5416
|
if (entry.isDirectory()) {
|
|
5054
5417
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5055
5418
|
continue;
|
|
@@ -5065,14 +5428,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5065
5428
|
return files;
|
|
5066
5429
|
}
|
|
5067
5430
|
function scanServerFiles() {
|
|
5068
|
-
const serverDir =
|
|
5069
|
-
if (!
|
|
5431
|
+
const serverDir = path18.join(getProjectRoot3(), "server");
|
|
5432
|
+
if (!fs21.existsSync(serverDir)) {
|
|
5070
5433
|
return [];
|
|
5071
5434
|
}
|
|
5072
5435
|
return scanDirectory(serverDir);
|
|
5073
5436
|
}
|
|
5074
5437
|
function hasCapabilityImport(filePath) {
|
|
5075
|
-
const content =
|
|
5438
|
+
const content = fs21.readFileSync(filePath, "utf-8");
|
|
5076
5439
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5077
5440
|
}
|
|
5078
5441
|
function scanFilesToMigrate() {
|
|
@@ -5449,7 +5812,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5449
5812
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5450
5813
|
const classInfo = analyzeClass(sourceFile);
|
|
5451
5814
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5452
|
-
const relativePath =
|
|
5815
|
+
const relativePath = path19.relative(getProjectRoot3(), filePath);
|
|
5453
5816
|
return {
|
|
5454
5817
|
filePath: relativePath,
|
|
5455
5818
|
imports,
|
|
@@ -5460,7 +5823,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5460
5823
|
};
|
|
5461
5824
|
}
|
|
5462
5825
|
function migrateFile(project, analysis, dryRun) {
|
|
5463
|
-
const absolutePath =
|
|
5826
|
+
const absolutePath = path19.join(getProjectRoot3(), analysis.filePath);
|
|
5464
5827
|
if (!analysis.canAutoMigrate) {
|
|
5465
5828
|
return {
|
|
5466
5829
|
filePath: analysis.filePath,
|
|
@@ -5563,17 +5926,17 @@ function getSuggestion(analysis) {
|
|
|
5563
5926
|
}
|
|
5564
5927
|
|
|
5565
5928
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5566
|
-
import
|
|
5567
|
-
import
|
|
5929
|
+
import fs22 from "fs";
|
|
5930
|
+
import path20 from "path";
|
|
5568
5931
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5569
5932
|
const deletedFiles = [];
|
|
5570
5933
|
const errors = [];
|
|
5571
5934
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5572
|
-
const oldJsonPath =
|
|
5573
|
-
if (
|
|
5935
|
+
const oldJsonPath = path20.join(capabilitiesDir, "capabilities.json");
|
|
5936
|
+
if (fs22.existsSync(oldJsonPath)) {
|
|
5574
5937
|
try {
|
|
5575
5938
|
if (!dryRun) {
|
|
5576
|
-
|
|
5939
|
+
fs22.unlinkSync(oldJsonPath);
|
|
5577
5940
|
}
|
|
5578
5941
|
deletedFiles.push("capabilities.json");
|
|
5579
5942
|
} catch (error) {
|
|
@@ -5581,11 +5944,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5581
5944
|
}
|
|
5582
5945
|
}
|
|
5583
5946
|
for (const cap of capabilities) {
|
|
5584
|
-
const tsFilePath =
|
|
5585
|
-
if (
|
|
5947
|
+
const tsFilePath = path20.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5948
|
+
if (fs22.existsSync(tsFilePath)) {
|
|
5586
5949
|
try {
|
|
5587
5950
|
if (!dryRun) {
|
|
5588
|
-
|
|
5951
|
+
fs22.unlinkSync(tsFilePath);
|
|
5589
5952
|
}
|
|
5590
5953
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5591
5954
|
} catch (error) {
|
|
@@ -5601,8 +5964,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5601
5964
|
}
|
|
5602
5965
|
|
|
5603
5966
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5604
|
-
import
|
|
5605
|
-
import
|
|
5967
|
+
import fs23 from "fs";
|
|
5968
|
+
import path21 from "path";
|
|
5606
5969
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5607
5970
|
function printSummary(result) {
|
|
5608
5971
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -5765,15 +6128,15 @@ async function generateReport(result) {
|
|
|
5765
6128
|
}
|
|
5766
6129
|
lines.push("");
|
|
5767
6130
|
const logDir = process.env.LOG_DIR || "logs";
|
|
5768
|
-
if (!
|
|
6131
|
+
if (!fs23.existsSync(logDir)) {
|
|
5769
6132
|
return;
|
|
5770
6133
|
}
|
|
5771
|
-
const reportDir =
|
|
5772
|
-
if (!
|
|
5773
|
-
|
|
6134
|
+
const reportDir = path21.join(logDir, "migration");
|
|
6135
|
+
if (!fs23.existsSync(reportDir)) {
|
|
6136
|
+
fs23.mkdirSync(reportDir, { recursive: true });
|
|
5774
6137
|
}
|
|
5775
|
-
const reportPath =
|
|
5776
|
-
|
|
6138
|
+
const reportPath = path21.join(reportDir, REPORT_FILE);
|
|
6139
|
+
fs23.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
5777
6140
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
5778
6141
|
}
|
|
5779
6142
|
|
|
@@ -6305,10 +6668,10 @@ var migrationCommand = {
|
|
|
6305
6668
|
};
|
|
6306
6669
|
|
|
6307
6670
|
// src/commands/read-logs/index.ts
|
|
6308
|
-
import
|
|
6671
|
+
import path22 from "path";
|
|
6309
6672
|
|
|
6310
6673
|
// src/commands/read-logs/std-utils.ts
|
|
6311
|
-
import
|
|
6674
|
+
import fs24 from "fs";
|
|
6312
6675
|
function formatStdPrefixTime(localTime) {
|
|
6313
6676
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6314
6677
|
if (!match) return localTime;
|
|
@@ -6338,11 +6701,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6338
6701
|
return `[${time}] ${content}`;
|
|
6339
6702
|
}
|
|
6340
6703
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6341
|
-
const stat =
|
|
6704
|
+
const stat = fs24.statSync(filePath);
|
|
6342
6705
|
if (stat.size === 0) {
|
|
6343
6706
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6344
6707
|
}
|
|
6345
|
-
const fd =
|
|
6708
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6346
6709
|
const chunkSize = 64 * 1024;
|
|
6347
6710
|
let position = stat.size;
|
|
6348
6711
|
let remainder = "";
|
|
@@ -6356,7 +6719,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6356
6719
|
const length = Math.min(chunkSize, position);
|
|
6357
6720
|
position -= length;
|
|
6358
6721
|
const buffer = Buffer.alloc(length);
|
|
6359
|
-
|
|
6722
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6360
6723
|
let chunk = buffer.toString("utf8");
|
|
6361
6724
|
if (remainder) {
|
|
6362
6725
|
chunk += remainder;
|
|
@@ -6398,7 +6761,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6398
6761
|
}
|
|
6399
6762
|
}
|
|
6400
6763
|
} finally {
|
|
6401
|
-
|
|
6764
|
+
fs24.closeSync(fd);
|
|
6402
6765
|
}
|
|
6403
6766
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6404
6767
|
}
|
|
@@ -6419,21 +6782,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6419
6782
|
}
|
|
6420
6783
|
|
|
6421
6784
|
// src/commands/read-logs/tail.ts
|
|
6422
|
-
import
|
|
6785
|
+
import fs25 from "fs";
|
|
6423
6786
|
function fileExists(filePath) {
|
|
6424
6787
|
try {
|
|
6425
|
-
|
|
6788
|
+
fs25.accessSync(filePath, fs25.constants.F_OK | fs25.constants.R_OK);
|
|
6426
6789
|
return true;
|
|
6427
6790
|
} catch {
|
|
6428
6791
|
return false;
|
|
6429
6792
|
}
|
|
6430
6793
|
}
|
|
6431
6794
|
function readFileTailLines(filePath, maxLines) {
|
|
6432
|
-
const stat =
|
|
6795
|
+
const stat = fs25.statSync(filePath);
|
|
6433
6796
|
if (stat.size === 0) {
|
|
6434
6797
|
return [];
|
|
6435
6798
|
}
|
|
6436
|
-
const fd =
|
|
6799
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6437
6800
|
const chunkSize = 64 * 1024;
|
|
6438
6801
|
const chunks = [];
|
|
6439
6802
|
let position = stat.size;
|
|
@@ -6443,13 +6806,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6443
6806
|
const length = Math.min(chunkSize, position);
|
|
6444
6807
|
position -= length;
|
|
6445
6808
|
const buffer = Buffer.alloc(length);
|
|
6446
|
-
|
|
6809
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6447
6810
|
chunks.unshift(buffer.toString("utf8"));
|
|
6448
6811
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6449
6812
|
collectedLines += chunkLines;
|
|
6450
6813
|
}
|
|
6451
6814
|
} finally {
|
|
6452
|
-
|
|
6815
|
+
fs25.closeSync(fd);
|
|
6453
6816
|
}
|
|
6454
6817
|
const content = chunks.join("");
|
|
6455
6818
|
const allLines = content.split("\n");
|
|
@@ -6465,11 +6828,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6465
6828
|
return allLines.slice(allLines.length - maxLines);
|
|
6466
6829
|
}
|
|
6467
6830
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6468
|
-
const stat =
|
|
6831
|
+
const stat = fs25.statSync(filePath);
|
|
6469
6832
|
if (stat.size === 0) {
|
|
6470
6833
|
return { lines: [], totalLinesCount: 0 };
|
|
6471
6834
|
}
|
|
6472
|
-
const fd =
|
|
6835
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6473
6836
|
const chunkSize = 64 * 1024;
|
|
6474
6837
|
let position = stat.size;
|
|
6475
6838
|
let remainder = "";
|
|
@@ -6481,7 +6844,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6481
6844
|
const length = Math.min(chunkSize, position);
|
|
6482
6845
|
position -= length;
|
|
6483
6846
|
const buffer = Buffer.alloc(length);
|
|
6484
|
-
|
|
6847
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6485
6848
|
let chunk = buffer.toString("utf8");
|
|
6486
6849
|
if (remainder) {
|
|
6487
6850
|
chunk += remainder;
|
|
@@ -6512,7 +6875,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6512
6875
|
}
|
|
6513
6876
|
}
|
|
6514
6877
|
} finally {
|
|
6515
|
-
|
|
6878
|
+
fs25.closeSync(fd);
|
|
6516
6879
|
}
|
|
6517
6880
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6518
6881
|
}
|
|
@@ -6654,7 +7017,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
6654
7017
|
}
|
|
6655
7018
|
|
|
6656
7019
|
// src/commands/read-logs/json-lines.ts
|
|
6657
|
-
import
|
|
7020
|
+
import fs26 from "fs";
|
|
6658
7021
|
function normalizePid(value) {
|
|
6659
7022
|
if (typeof value === "number") {
|
|
6660
7023
|
return String(value);
|
|
@@ -6705,11 +7068,11 @@ function buildWantedLevelSet(levels) {
|
|
|
6705
7068
|
return set.size > 0 ? set : null;
|
|
6706
7069
|
}
|
|
6707
7070
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
6708
|
-
const stat =
|
|
7071
|
+
const stat = fs26.statSync(filePath);
|
|
6709
7072
|
if (stat.size === 0) {
|
|
6710
7073
|
return { lines: [], totalLinesCount: 0 };
|
|
6711
7074
|
}
|
|
6712
|
-
const fd =
|
|
7075
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6713
7076
|
const chunkSize = 64 * 1024;
|
|
6714
7077
|
let position = stat.size;
|
|
6715
7078
|
let remainder = "";
|
|
@@ -6724,7 +7087,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6724
7087
|
const length = Math.min(chunkSize, position);
|
|
6725
7088
|
position -= length;
|
|
6726
7089
|
const buffer = Buffer.alloc(length);
|
|
6727
|
-
|
|
7090
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6728
7091
|
let chunk = buffer.toString("utf8");
|
|
6729
7092
|
if (remainder) {
|
|
6730
7093
|
chunk += remainder;
|
|
@@ -6786,7 +7149,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6786
7149
|
}
|
|
6787
7150
|
}
|
|
6788
7151
|
} finally {
|
|
6789
|
-
|
|
7152
|
+
fs26.closeSync(fd);
|
|
6790
7153
|
}
|
|
6791
7154
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6792
7155
|
}
|
|
@@ -6829,11 +7192,11 @@ function extractTraceId(obj) {
|
|
|
6829
7192
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6830
7193
|
const wanted = traceId.trim();
|
|
6831
7194
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6832
|
-
const stat =
|
|
7195
|
+
const stat = fs26.statSync(filePath);
|
|
6833
7196
|
if (stat.size === 0) {
|
|
6834
7197
|
return { lines: [], totalLinesCount: 0 };
|
|
6835
7198
|
}
|
|
6836
|
-
const fd =
|
|
7199
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6837
7200
|
const chunkSize = 64 * 1024;
|
|
6838
7201
|
let position = stat.size;
|
|
6839
7202
|
let remainder = "";
|
|
@@ -6846,7 +7209,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6846
7209
|
const length = Math.min(chunkSize, position);
|
|
6847
7210
|
position -= length;
|
|
6848
7211
|
const buffer = Buffer.alloc(length);
|
|
6849
|
-
|
|
7212
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6850
7213
|
let chunk = buffer.toString("utf8");
|
|
6851
7214
|
if (remainder) {
|
|
6852
7215
|
chunk += remainder;
|
|
@@ -6899,7 +7262,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6899
7262
|
}
|
|
6900
7263
|
}
|
|
6901
7264
|
} finally {
|
|
6902
|
-
|
|
7265
|
+
fs26.closeSync(fd);
|
|
6903
7266
|
}
|
|
6904
7267
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6905
7268
|
}
|
|
@@ -6908,11 +7271,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6908
7271
|
if (!wantedLevelSet) {
|
|
6909
7272
|
return { lines: [], totalLinesCount: 0 };
|
|
6910
7273
|
}
|
|
6911
|
-
const stat =
|
|
7274
|
+
const stat = fs26.statSync(filePath);
|
|
6912
7275
|
if (stat.size === 0) {
|
|
6913
7276
|
return { lines: [], totalLinesCount: 0 };
|
|
6914
7277
|
}
|
|
6915
|
-
const fd =
|
|
7278
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6916
7279
|
const chunkSize = 64 * 1024;
|
|
6917
7280
|
let position = stat.size;
|
|
6918
7281
|
let remainder = "";
|
|
@@ -6924,7 +7287,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6924
7287
|
const length = Math.min(chunkSize, position);
|
|
6925
7288
|
position -= length;
|
|
6926
7289
|
const buffer = Buffer.alloc(length);
|
|
6927
|
-
|
|
7290
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6928
7291
|
let chunk = buffer.toString("utf8");
|
|
6929
7292
|
if (remainder) {
|
|
6930
7293
|
chunk += remainder;
|
|
@@ -6971,7 +7334,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6971
7334
|
}
|
|
6972
7335
|
}
|
|
6973
7336
|
} finally {
|
|
6974
|
-
|
|
7337
|
+
fs26.closeSync(fd);
|
|
6975
7338
|
}
|
|
6976
7339
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6977
7340
|
}
|
|
@@ -7205,30 +7568,30 @@ async function readLogsJsonResult(options) {
|
|
|
7205
7568
|
};
|
|
7206
7569
|
}
|
|
7207
7570
|
function resolveLogFilePath(logDir, type) {
|
|
7208
|
-
const base =
|
|
7571
|
+
const base = path22.isAbsolute(logDir) ? logDir : path22.join(process.cwd(), logDir);
|
|
7209
7572
|
if (type === "server") {
|
|
7210
|
-
return
|
|
7573
|
+
return path22.join(base, "server.log");
|
|
7211
7574
|
}
|
|
7212
7575
|
if (type === "trace") {
|
|
7213
|
-
return
|
|
7576
|
+
return path22.join(base, "trace.log");
|
|
7214
7577
|
}
|
|
7215
7578
|
if (type === "server-std") {
|
|
7216
|
-
return
|
|
7579
|
+
return path22.join(base, "server.std.log");
|
|
7217
7580
|
}
|
|
7218
7581
|
if (type === "client-std") {
|
|
7219
|
-
return
|
|
7582
|
+
return path22.join(base, "client.std.log");
|
|
7220
7583
|
}
|
|
7221
7584
|
if (type === "dev") {
|
|
7222
|
-
return
|
|
7585
|
+
return path22.join(base, "dev.log");
|
|
7223
7586
|
}
|
|
7224
7587
|
if (type === "dev-std") {
|
|
7225
|
-
return
|
|
7588
|
+
return path22.join(base, "dev.std.log");
|
|
7226
7589
|
}
|
|
7227
7590
|
if (type === "install-dep-std") {
|
|
7228
|
-
return
|
|
7591
|
+
return path22.join(base, "install-dep.std.log");
|
|
7229
7592
|
}
|
|
7230
7593
|
if (type === "browser") {
|
|
7231
|
-
return
|
|
7594
|
+
return path22.join(base, "browser.log");
|
|
7232
7595
|
}
|
|
7233
7596
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7234
7597
|
}
|
|
@@ -7405,9 +7768,9 @@ function camelToKebab(str) {
|
|
|
7405
7768
|
}
|
|
7406
7769
|
|
|
7407
7770
|
// src/commands/build/upload-static.handler.ts
|
|
7408
|
-
import * as
|
|
7409
|
-
import * as
|
|
7410
|
-
import * as
|
|
7771
|
+
import * as fs27 from "fs";
|
|
7772
|
+
import * as os3 from "os";
|
|
7773
|
+
import * as path23 from "path";
|
|
7411
7774
|
import { execFileSync } from "child_process";
|
|
7412
7775
|
function readCredentialsFromEnv() {
|
|
7413
7776
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7431,8 +7794,8 @@ async function uploadStatic(options) {
|
|
|
7431
7794
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7432
7795
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7433
7796
|
} = options;
|
|
7434
|
-
const resolvedStaticDir =
|
|
7435
|
-
if (!
|
|
7797
|
+
const resolvedStaticDir = path23.resolve(staticDir);
|
|
7798
|
+
if (!fs27.existsSync(resolvedStaticDir)) {
|
|
7436
7799
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7437
7800
|
return;
|
|
7438
7801
|
}
|
|
@@ -7465,8 +7828,8 @@ async function uploadStatic(options) {
|
|
|
7465
7828
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7466
7829
|
}
|
|
7467
7830
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7468
|
-
const confPath =
|
|
7469
|
-
|
|
7831
|
+
const confPath = path23.join(os3.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7832
|
+
fs27.writeFileSync(confPath, "");
|
|
7470
7833
|
try {
|
|
7471
7834
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7472
7835
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7480,7 +7843,7 @@ async function uploadStatic(options) {
|
|
|
7480
7843
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7481
7844
|
} finally {
|
|
7482
7845
|
try {
|
|
7483
|
-
|
|
7846
|
+
fs27.unlinkSync(confPath);
|
|
7484
7847
|
} catch {
|
|
7485
7848
|
}
|
|
7486
7849
|
}
|
|
@@ -7500,8 +7863,8 @@ async function uploadStatic(options) {
|
|
|
7500
7863
|
}
|
|
7501
7864
|
}
|
|
7502
7865
|
function resolveTosutilPath(tosutilPath) {
|
|
7503
|
-
if (
|
|
7504
|
-
return
|
|
7866
|
+
if (path23.isAbsolute(tosutilPath)) {
|
|
7867
|
+
return fs27.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7505
7868
|
}
|
|
7506
7869
|
try {
|
|
7507
7870
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -7546,7 +7909,7 @@ async function resolveBucketId(appId) {
|
|
|
7546
7909
|
return bucketId;
|
|
7547
7910
|
}
|
|
7548
7911
|
function isDirEmpty(dirPath) {
|
|
7549
|
-
const entries =
|
|
7912
|
+
const entries = fs27.readdirSync(dirPath);
|
|
7550
7913
|
return entries.length === 0;
|
|
7551
7914
|
}
|
|
7552
7915
|
|
|
@@ -7641,12 +8004,12 @@ var commands = [
|
|
|
7641
8004
|
];
|
|
7642
8005
|
|
|
7643
8006
|
// src/index.ts
|
|
7644
|
-
var envPath =
|
|
7645
|
-
if (
|
|
8007
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
8008
|
+
if (fs28.existsSync(envPath)) {
|
|
7646
8009
|
dotenvConfig({ path: envPath });
|
|
7647
8010
|
}
|
|
7648
|
-
var __dirname =
|
|
7649
|
-
var pkg = JSON.parse(
|
|
8011
|
+
var __dirname = path24.dirname(fileURLToPath5(import.meta.url));
|
|
8012
|
+
var pkg = JSON.parse(fs28.readFileSync(path24.join(__dirname, "../package.json"), "utf-8"));
|
|
7650
8013
|
var cli = new FullstackCLI(pkg.version);
|
|
7651
8014
|
cli.useAll(commands);
|
|
7652
8015
|
cli.run();
|