@lark-apaas/fullstack-cli 1.1.40-alpha.3 → 1.1.40-alpha.5
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 +328 -254
- 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,8 @@ 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
|
+
import fs11 from "fs";
|
|
3109
|
+
import path9 from "path";
|
|
3108
3110
|
|
|
3109
3111
|
// src/utils/grayscale/config.ts
|
|
3110
3112
|
function getGrayscaleConfig(configJson) {
|
|
@@ -3116,10 +3118,11 @@ function getGrayscaleConfig(configJson) {
|
|
|
3116
3118
|
const parsed = JSON.parse(raw);
|
|
3117
3119
|
const config = parsed.config || parsed;
|
|
3118
3120
|
const tenantId = parsed.tenant_id != null ? String(parsed.tenant_id) : void 0;
|
|
3121
|
+
const xTtEnv = parsed.x_tt_env || void 0;
|
|
3119
3122
|
if (!config.enabled) {
|
|
3120
3123
|
return null;
|
|
3121
3124
|
}
|
|
3122
|
-
return { config, tenantId };
|
|
3125
|
+
return { config, tenantId, xTtEnv };
|
|
3123
3126
|
} catch {
|
|
3124
3127
|
console.warn("[grayscale] Failed to parse grayscale config");
|
|
3125
3128
|
return null;
|
|
@@ -3132,7 +3135,8 @@ import path8 from "path";
|
|
|
3132
3135
|
function readFromEnvVars() {
|
|
3133
3136
|
const appId = process.env.app_id || process.env.APP_ID;
|
|
3134
3137
|
const tenantId = process.env.tenant_id || process.env.TENANT_ID;
|
|
3135
|
-
|
|
3138
|
+
const xTtEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV || process.env.x_tt_env;
|
|
3139
|
+
return { appId, tenantId, xTtEnv };
|
|
3136
3140
|
}
|
|
3137
3141
|
function parseEnvFile(filePath) {
|
|
3138
3142
|
const result = {};
|
|
@@ -3161,7 +3165,8 @@ function readFromForceEnvFile(cwd) {
|
|
|
3161
3165
|
const vars = parseEnvFile(envPath2);
|
|
3162
3166
|
return {
|
|
3163
3167
|
appId: vars.app_id || vars.APP_ID,
|
|
3164
|
-
tenantId: vars.tenant_id || vars.TENANT_ID
|
|
3168
|
+
tenantId: vars.tenant_id || vars.TENANT_ID,
|
|
3169
|
+
xTtEnv: vars.FORCE_FRAMEWORK_CLI_CANARY_ENV || vars.x_tt_env
|
|
3165
3170
|
};
|
|
3166
3171
|
}
|
|
3167
3172
|
function readFromClientBasePath() {
|
|
@@ -3184,7 +3189,8 @@ function readFromDotEnv(cwd) {
|
|
|
3184
3189
|
const vars = parseEnvFile(envPath2);
|
|
3185
3190
|
return {
|
|
3186
3191
|
appId: vars.app_id || vars.APP_ID,
|
|
3187
|
-
tenantId: vars.tenant_id || vars.TENANT_ID
|
|
3192
|
+
tenantId: vars.tenant_id || vars.TENANT_ID,
|
|
3193
|
+
xTtEnv: vars.FORCE_FRAMEWORK_CLI_CANARY_ENV || vars.x_tt_env
|
|
3188
3194
|
};
|
|
3189
3195
|
}
|
|
3190
3196
|
function readFromPackageJson(cwd) {
|
|
@@ -3218,8 +3224,8 @@ function readProjectIdentity(cwd) {
|
|
|
3218
3224
|
if (!merged.tenantId && identity.tenantId) {
|
|
3219
3225
|
merged.tenantId = identity.tenantId;
|
|
3220
3226
|
}
|
|
3221
|
-
if (merged.
|
|
3222
|
-
|
|
3227
|
+
if (!merged.xTtEnv && identity.xTtEnv) {
|
|
3228
|
+
merged.xTtEnv = identity.xTtEnv;
|
|
3223
3229
|
}
|
|
3224
3230
|
}
|
|
3225
3231
|
return merged;
|
|
@@ -3233,63 +3239,68 @@ function isInPercentage(tenantId, percentage) {
|
|
|
3233
3239
|
if (isNaN(id)) return false;
|
|
3234
3240
|
return id % 100 < percentage;
|
|
3235
3241
|
}
|
|
3236
|
-
function
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3242
|
+
function matchRule(rule, identity) {
|
|
3243
|
+
switch (rule.type) {
|
|
3244
|
+
case "whitelist": {
|
|
3245
|
+
const tenantMatch = rule.tenant_ids && rule.tenant_ids.length > 0 ? !!identity.tenantId && rule.tenant_ids.includes(identity.tenantId) : false;
|
|
3246
|
+
const appMatch = rule.app_ids && rule.app_ids.length > 0 ? !!identity.appId && rule.app_ids.includes(identity.appId) : false;
|
|
3247
|
+
return tenantMatch || appMatch;
|
|
3241
3248
|
}
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
if (identity.appId && conditions.app_ids.includes(identity.appId)) {
|
|
3245
|
-
return true;
|
|
3249
|
+
case "header": {
|
|
3250
|
+
return identity.xTtEnv === rule["x-tt-env"];
|
|
3246
3251
|
}
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
return
|
|
3252
|
+
case "percentage": {
|
|
3253
|
+
if (rule.value >= 100) return true;
|
|
3254
|
+
if (rule.value <= 0) return false;
|
|
3255
|
+
if (!identity.tenantId) return false;
|
|
3256
|
+
return isInPercentage(identity.tenantId, rule.value);
|
|
3252
3257
|
}
|
|
3258
|
+
default:
|
|
3259
|
+
return false;
|
|
3253
3260
|
}
|
|
3254
|
-
const hasConditions = conditions.tenant_ids && conditions.tenant_ids.length > 0 || conditions.app_ids && conditions.app_ids.length > 0 || conditions.percentage != null && conditions.percentage > 0;
|
|
3255
|
-
return !hasConditions;
|
|
3256
3261
|
}
|
|
3257
|
-
function
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3262
|
+
function matchChannel(channel, identity) {
|
|
3263
|
+
if (!channel.rules || channel.rules.length === 0) return false;
|
|
3264
|
+
return channel.rules.some((rule) => matchRule(rule, identity));
|
|
3265
|
+
}
|
|
3266
|
+
function isBlocked(config, identity) {
|
|
3267
|
+
if (identity.tenantId && config.blocklist?.tenant_ids?.includes(identity.tenantId)) {
|
|
3268
|
+
return true;
|
|
3263
3269
|
}
|
|
3264
|
-
|
|
3270
|
+
if (identity.appId && config.blocklist?.app_ids?.includes(identity.appId)) {
|
|
3271
|
+
return true;
|
|
3272
|
+
}
|
|
3273
|
+
return false;
|
|
3265
3274
|
}
|
|
3266
3275
|
function resolveTargetVersions(config, identity) {
|
|
3267
|
-
const
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3276
|
+
const stableVersions = config.stable?.versions || {};
|
|
3277
|
+
let matchedChannel;
|
|
3278
|
+
if (isBlocked(config, identity)) {
|
|
3279
|
+
console.log("[grayscale] Tenant/app is in blocklist, use stable");
|
|
3280
|
+
} else {
|
|
3281
|
+
matchedChannel = (config.channels || []).find((ch) => matchChannel(ch, identity));
|
|
3273
3282
|
}
|
|
3274
|
-
const
|
|
3275
|
-
for (const [
|
|
3276
|
-
if (config.
|
|
3277
|
-
console.warn(`[grayscale]
|
|
3283
|
+
const merged = /* @__PURE__ */ new Map();
|
|
3284
|
+
for (const [pkg2, version] of Object.entries(stableVersions)) {
|
|
3285
|
+
if (config.blocklist?.versions?.includes(version)) {
|
|
3286
|
+
console.warn(`[grayscale] stable version ${version} of ${pkg2} is blocked, skipping`);
|
|
3278
3287
|
continue;
|
|
3279
3288
|
}
|
|
3280
|
-
|
|
3289
|
+
merged.set(pkg2, version);
|
|
3281
3290
|
}
|
|
3282
|
-
if (
|
|
3283
|
-
|
|
3284
|
-
|
|
3291
|
+
if (matchedChannel) {
|
|
3292
|
+
console.log(`[grayscale] Matched channel: ${matchedChannel.name}`);
|
|
3293
|
+
for (const [pkg2, version] of Object.entries(matchedChannel.versions || {})) {
|
|
3294
|
+
if (config.blocklist?.versions?.includes(version)) {
|
|
3295
|
+
console.warn(`[grayscale] channel version ${version} of ${pkg2} is blocked, skipping`);
|
|
3296
|
+
continue;
|
|
3297
|
+
}
|
|
3298
|
+
merged.set(pkg2, version);
|
|
3285
3299
|
}
|
|
3300
|
+
} else if (!isBlocked(config, identity)) {
|
|
3301
|
+
console.log("[grayscale] No channel matched, use stable");
|
|
3286
3302
|
}
|
|
3287
|
-
|
|
3288
|
-
console.log(`[grayscale] Matched rule: "${matchedRule.name}" (id: ${matchedRule.id}), channel: ${channelName}`);
|
|
3289
|
-
} else {
|
|
3290
|
-
console.log(`[grayscale] No rule matched, using default channel: ${channelName}`);
|
|
3291
|
-
}
|
|
3292
|
-
return versions;
|
|
3303
|
+
return merged.size > 0 ? merged : null;
|
|
3293
3304
|
}
|
|
3294
3305
|
|
|
3295
3306
|
// src/utils/grayscale/index.ts
|
|
@@ -3299,12 +3310,17 @@ function resolveGrayscaleVersions(cwd, configJson) {
|
|
|
3299
3310
|
console.log("[grayscale] Config not available, skipping grayscale");
|
|
3300
3311
|
return null;
|
|
3301
3312
|
}
|
|
3302
|
-
const { config, tenantId: payloadTenantId } = result;
|
|
3313
|
+
const { config, tenantId: payloadTenantId, xTtEnv: payloadXTtEnv } = result;
|
|
3303
3314
|
const identity = readProjectIdentity(cwd);
|
|
3304
3315
|
if (payloadTenantId) {
|
|
3305
3316
|
identity.tenantId = payloadTenantId;
|
|
3306
3317
|
}
|
|
3307
|
-
|
|
3318
|
+
if (payloadXTtEnv) {
|
|
3319
|
+
identity.xTtEnv = payloadXTtEnv;
|
|
3320
|
+
}
|
|
3321
|
+
console.log(
|
|
3322
|
+
`[grayscale] Project identity: appId=${identity.appId || "N/A"}, tenantId=${identity.tenantId || "N/A"}, xTtEnv=${identity.xTtEnv || "N/A"}`
|
|
3323
|
+
);
|
|
3308
3324
|
const versions = resolveTargetVersions(config, identity);
|
|
3309
3325
|
if (!versions || versions.size === 0) {
|
|
3310
3326
|
console.log("[grayscale] No target versions resolved");
|
|
@@ -3318,6 +3334,33 @@ function resolveGrayscaleVersions(cwd, configJson) {
|
|
|
3318
3334
|
}
|
|
3319
3335
|
|
|
3320
3336
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3337
|
+
function parseSemver(version) {
|
|
3338
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
3339
|
+
if (!match) return null;
|
|
3340
|
+
return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)];
|
|
3341
|
+
}
|
|
3342
|
+
function compareSemver(a, b) {
|
|
3343
|
+
const va = parseSemver(a);
|
|
3344
|
+
const vb = parseSemver(b);
|
|
3345
|
+
if (!va || !vb) return 0;
|
|
3346
|
+
for (let i = 0; i < 3; i++) {
|
|
3347
|
+
if (va[i] < vb[i]) return -1;
|
|
3348
|
+
if (va[i] > vb[i]) return 1;
|
|
3349
|
+
}
|
|
3350
|
+
return 0;
|
|
3351
|
+
}
|
|
3352
|
+
function satisfiesCaret(installed, range) {
|
|
3353
|
+
const baseVersion = range.slice(1);
|
|
3354
|
+
const base = parseSemver(baseVersion);
|
|
3355
|
+
const inst = parseSemver(installed);
|
|
3356
|
+
if (!base || !inst) return false;
|
|
3357
|
+
if (compareSemver(installed, baseVersion) < 0) return false;
|
|
3358
|
+
if (inst[0] > base[0]) return false;
|
|
3359
|
+
return true;
|
|
3360
|
+
}
|
|
3361
|
+
function isRangeVersion(version) {
|
|
3362
|
+
return version.startsWith("^");
|
|
3363
|
+
}
|
|
3321
3364
|
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
3322
3365
|
const pkg2 = readPackageJson(cwd);
|
|
3323
3366
|
const allPackages = /* @__PURE__ */ new Set();
|
|
@@ -3370,12 +3413,37 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3370
3413
|
});
|
|
3371
3414
|
}
|
|
3372
3415
|
}
|
|
3373
|
-
function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun) {
|
|
3416
|
+
function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode) {
|
|
3374
3417
|
const upgradePlan = [];
|
|
3375
3418
|
for (const pkg2 of packages) {
|
|
3376
3419
|
const version = grayscaleVersions.get(pkg2);
|
|
3377
3420
|
if (version) {
|
|
3378
|
-
|
|
3421
|
+
let current = "";
|
|
3422
|
+
try {
|
|
3423
|
+
const installedPkgPath = path9.join(cwd, "node_modules", pkg2, "package.json");
|
|
3424
|
+
const installedPkg = JSON.parse(fs11.readFileSync(installedPkgPath, "utf-8"));
|
|
3425
|
+
current = installedPkg.version || "";
|
|
3426
|
+
} catch {
|
|
3427
|
+
}
|
|
3428
|
+
if (mode === "destroy") {
|
|
3429
|
+
if (!isRangeVersion(version) && current === version) {
|
|
3430
|
+
console.log(`[fullstack-cli] ${pkg2}@${version} (already installed, skip)`);
|
|
3431
|
+
continue;
|
|
3432
|
+
}
|
|
3433
|
+
} else {
|
|
3434
|
+
if (isRangeVersion(version)) {
|
|
3435
|
+
if (current && satisfiesCaret(current, version)) {
|
|
3436
|
+
console.log(`[fullstack-cli] ${pkg2}@${current} satisfies ${version} (skip)`);
|
|
3437
|
+
continue;
|
|
3438
|
+
}
|
|
3439
|
+
} else {
|
|
3440
|
+
if (current === version) {
|
|
3441
|
+
console.log(`[fullstack-cli] ${pkg2}@${version} (already installed, skip)`);
|
|
3442
|
+
continue;
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
upgradePlan.push({ pkg: pkg2, version, current });
|
|
3379
3447
|
}
|
|
3380
3448
|
}
|
|
3381
3449
|
if (upgradePlan.length === 0) {
|
|
@@ -3383,23 +3451,21 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun) {
|
|
|
3383
3451
|
return;
|
|
3384
3452
|
}
|
|
3385
3453
|
console.log(`[fullstack-cli] Grayscale upgrade plan (${upgradePlan.length} package(s)):`);
|
|
3386
|
-
upgradePlan.forEach(({ pkg: pkg2, version }) => {
|
|
3387
|
-
console.log(` - ${pkg2} -> ${version}`);
|
|
3454
|
+
upgradePlan.forEach(({ pkg: pkg2, version, current }) => {
|
|
3455
|
+
console.log(` - ${pkg2} ${current} -> ${version}`);
|
|
3388
3456
|
});
|
|
3389
3457
|
if (dryRun) {
|
|
3390
3458
|
console.log("[fullstack-cli] Dry run mode, skipping actual installation");
|
|
3391
3459
|
return;
|
|
3392
3460
|
}
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
throw new Error(`Failed to install ${target}`);
|
|
3402
|
-
}
|
|
3461
|
+
const targets = upgradePlan.map(({ pkg: pkg2, version }) => `${pkg2}@${version}`);
|
|
3462
|
+
console.log(`[fullstack-cli] Installing ${targets.join(" ")}...`);
|
|
3463
|
+
const result = spawnSync3("npm", ["install", ...targets], {
|
|
3464
|
+
cwd,
|
|
3465
|
+
stdio: "inherit"
|
|
3466
|
+
});
|
|
3467
|
+
if (result.error || result.status !== 0) {
|
|
3468
|
+
console.warn(`[fullstack-cli] npm install failed`);
|
|
3403
3469
|
}
|
|
3404
3470
|
}
|
|
3405
3471
|
async function run4(options = {}) {
|
|
@@ -3420,16 +3486,24 @@ async function run4(options = {}) {
|
|
|
3420
3486
|
const grayscaleVersions = resolveGrayscaleVersions(cwd, options.grayscaleConfig);
|
|
3421
3487
|
if (grayscaleVersions) {
|
|
3422
3488
|
console.log("[fullstack-cli] Step 3/3: Applying grayscale versions...");
|
|
3423
|
-
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun);
|
|
3489
|
+
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun, options.mode || "rebuild");
|
|
3424
3490
|
if (!options.dryRun) {
|
|
3425
3491
|
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s) via grayscale`);
|
|
3426
3492
|
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
3427
3493
|
}
|
|
3428
3494
|
return;
|
|
3429
3495
|
}
|
|
3496
|
+
if (options.grayscaleConfig) {
|
|
3497
|
+
console.log("[fullstack-cli] Grayscale config provided but not available, skip upgrade");
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3430
3500
|
console.log("[fullstack-cli] Grayscale not available, falling back to default upgrade");
|
|
3431
3501
|
} catch (error) {
|
|
3432
3502
|
const msg = error instanceof Error ? error.message : String(error);
|
|
3503
|
+
if (options.grayscaleConfig) {
|
|
3504
|
+
console.warn(`[fullstack-cli] Grayscale check failed: ${msg}, skip upgrade`);
|
|
3505
|
+
return;
|
|
3506
|
+
}
|
|
3433
3507
|
console.warn(`[fullstack-cli] Grayscale check failed: ${msg}, falling back to default upgrade`);
|
|
3434
3508
|
}
|
|
3435
3509
|
} else if (options.skipGrayscale) {
|
|
@@ -3458,7 +3532,7 @@ var depsCommand = {
|
|
|
3458
3532
|
name: "deps",
|
|
3459
3533
|
description: "Upgrade @lark-apaas dependencies",
|
|
3460
3534
|
register(parentCommand) {
|
|
3461
|
-
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("--grayscale-config <json>", "Grayscale config JSON (injected by sandbox_console)").option("--dry-run", "Show upgrade plan without executing").action(async (options) => {
|
|
3535
|
+
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("--grayscale-config <json>", "Grayscale config JSON (injected by sandbox_console)").option("--dry-run", "Show upgrade plan without executing").option("--mode <mode>", "Execution mode: rebuild (default) or destroy", "rebuild").action(async (options) => {
|
|
3462
3536
|
await run4(options);
|
|
3463
3537
|
});
|
|
3464
3538
|
}
|
|
@@ -3477,8 +3551,8 @@ var upgradeCommand = {
|
|
|
3477
3551
|
};
|
|
3478
3552
|
|
|
3479
3553
|
// src/commands/action-plugin/utils.ts
|
|
3480
|
-
import
|
|
3481
|
-
import
|
|
3554
|
+
import fs12 from "fs";
|
|
3555
|
+
import path10 from "path";
|
|
3482
3556
|
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
3483
3557
|
function parsePluginName(input) {
|
|
3484
3558
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3496,18 +3570,18 @@ function getProjectRoot() {
|
|
|
3496
3570
|
return process.cwd();
|
|
3497
3571
|
}
|
|
3498
3572
|
function getPackageJsonPath() {
|
|
3499
|
-
return
|
|
3573
|
+
return path10.join(getProjectRoot(), "package.json");
|
|
3500
3574
|
}
|
|
3501
3575
|
function getPluginPath(pluginName) {
|
|
3502
|
-
return
|
|
3576
|
+
return path10.join(getProjectRoot(), "node_modules", pluginName);
|
|
3503
3577
|
}
|
|
3504
3578
|
function readPackageJson2() {
|
|
3505
3579
|
const pkgPath = getPackageJsonPath();
|
|
3506
|
-
if (!
|
|
3580
|
+
if (!fs12.existsSync(pkgPath)) {
|
|
3507
3581
|
throw new Error("package.json not found in current directory");
|
|
3508
3582
|
}
|
|
3509
3583
|
try {
|
|
3510
|
-
const content =
|
|
3584
|
+
const content = fs12.readFileSync(pkgPath, "utf-8");
|
|
3511
3585
|
return JSON.parse(content);
|
|
3512
3586
|
} catch {
|
|
3513
3587
|
throw new Error("Failed to parse package.json");
|
|
@@ -3515,7 +3589,7 @@ function readPackageJson2() {
|
|
|
3515
3589
|
}
|
|
3516
3590
|
function writePackageJson2(pkg2) {
|
|
3517
3591
|
const pkgPath = getPackageJsonPath();
|
|
3518
|
-
|
|
3592
|
+
fs12.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3519
3593
|
}
|
|
3520
3594
|
function readActionPlugins() {
|
|
3521
3595
|
const pkg2 = readPackageJson2();
|
|
@@ -3548,12 +3622,12 @@ function npmInstall(tgzPath) {
|
|
|
3548
3622
|
}
|
|
3549
3623
|
}
|
|
3550
3624
|
function getPackageVersion(pluginName) {
|
|
3551
|
-
const pkgJsonPath =
|
|
3552
|
-
if (!
|
|
3625
|
+
const pkgJsonPath = path10.join(getPluginPath(pluginName), "package.json");
|
|
3626
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3553
3627
|
return null;
|
|
3554
3628
|
}
|
|
3555
3629
|
try {
|
|
3556
|
-
const content =
|
|
3630
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3557
3631
|
const pkg2 = JSON.parse(content);
|
|
3558
3632
|
return pkg2.version || null;
|
|
3559
3633
|
} catch {
|
|
@@ -3561,49 +3635,49 @@ function getPackageVersion(pluginName) {
|
|
|
3561
3635
|
}
|
|
3562
3636
|
}
|
|
3563
3637
|
function readPluginPackageJson(pluginPath) {
|
|
3564
|
-
const pkgJsonPath =
|
|
3565
|
-
if (!
|
|
3638
|
+
const pkgJsonPath = path10.join(pluginPath, "package.json");
|
|
3639
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3566
3640
|
return null;
|
|
3567
3641
|
}
|
|
3568
3642
|
try {
|
|
3569
|
-
const content =
|
|
3643
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3570
3644
|
return JSON.parse(content);
|
|
3571
3645
|
} catch {
|
|
3572
3646
|
return null;
|
|
3573
3647
|
}
|
|
3574
3648
|
}
|
|
3575
3649
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3576
|
-
const nodeModulesPath =
|
|
3577
|
-
const targetDir =
|
|
3578
|
-
const scopeDir =
|
|
3579
|
-
if (!
|
|
3580
|
-
|
|
3650
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3651
|
+
const targetDir = path10.join(nodeModulesPath, pluginName);
|
|
3652
|
+
const scopeDir = path10.dirname(targetDir);
|
|
3653
|
+
if (!fs12.existsSync(scopeDir)) {
|
|
3654
|
+
fs12.mkdirSync(scopeDir, { recursive: true });
|
|
3581
3655
|
}
|
|
3582
|
-
if (
|
|
3583
|
-
|
|
3656
|
+
if (fs12.existsSync(targetDir)) {
|
|
3657
|
+
fs12.rmSync(targetDir, { recursive: true });
|
|
3584
3658
|
}
|
|
3585
|
-
const tempDir =
|
|
3586
|
-
if (
|
|
3587
|
-
|
|
3659
|
+
const tempDir = path10.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3660
|
+
if (fs12.existsSync(tempDir)) {
|
|
3661
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3588
3662
|
}
|
|
3589
|
-
|
|
3663
|
+
fs12.mkdirSync(tempDir, { recursive: true });
|
|
3590
3664
|
try {
|
|
3591
3665
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3592
|
-
const extractedDir =
|
|
3593
|
-
if (
|
|
3594
|
-
|
|
3666
|
+
const extractedDir = path10.join(tempDir, "package");
|
|
3667
|
+
if (fs12.existsSync(extractedDir)) {
|
|
3668
|
+
fs12.renameSync(extractedDir, targetDir);
|
|
3595
3669
|
} else {
|
|
3596
|
-
const files =
|
|
3670
|
+
const files = fs12.readdirSync(tempDir);
|
|
3597
3671
|
if (files.length === 1) {
|
|
3598
|
-
|
|
3672
|
+
fs12.renameSync(path10.join(tempDir, files[0]), targetDir);
|
|
3599
3673
|
} else {
|
|
3600
3674
|
throw new Error("Unexpected tgz structure");
|
|
3601
3675
|
}
|
|
3602
3676
|
}
|
|
3603
3677
|
return targetDir;
|
|
3604
3678
|
} finally {
|
|
3605
|
-
if (
|
|
3606
|
-
|
|
3679
|
+
if (fs12.existsSync(tempDir)) {
|
|
3680
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3607
3681
|
}
|
|
3608
3682
|
}
|
|
3609
3683
|
}
|
|
@@ -3612,10 +3686,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3612
3686
|
return [];
|
|
3613
3687
|
}
|
|
3614
3688
|
const missing = [];
|
|
3615
|
-
const nodeModulesPath =
|
|
3689
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3616
3690
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3617
|
-
const depPath =
|
|
3618
|
-
if (!
|
|
3691
|
+
const depPath = path10.join(nodeModulesPath, depName);
|
|
3692
|
+
if (!fs12.existsSync(depPath)) {
|
|
3619
3693
|
missing.push(depName);
|
|
3620
3694
|
}
|
|
3621
3695
|
}
|
|
@@ -3639,16 +3713,16 @@ function installMissingDeps(deps) {
|
|
|
3639
3713
|
}
|
|
3640
3714
|
function removePluginDirectory(pluginName) {
|
|
3641
3715
|
const pluginPath = getPluginPath(pluginName);
|
|
3642
|
-
if (
|
|
3643
|
-
|
|
3716
|
+
if (fs12.existsSync(pluginPath)) {
|
|
3717
|
+
fs12.rmSync(pluginPath, { recursive: true });
|
|
3644
3718
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3645
3719
|
}
|
|
3646
3720
|
}
|
|
3647
3721
|
|
|
3648
3722
|
// src/commands/action-plugin/api-client.ts
|
|
3649
3723
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3650
|
-
import
|
|
3651
|
-
import
|
|
3724
|
+
import fs13 from "fs";
|
|
3725
|
+
import path11 from "path";
|
|
3652
3726
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3653
3727
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3654
3728
|
const client = getHttpClient();
|
|
@@ -3712,19 +3786,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3712
3786
|
return Buffer.from(arrayBuffer);
|
|
3713
3787
|
}
|
|
3714
3788
|
function getPluginCacheDir() {
|
|
3715
|
-
return
|
|
3789
|
+
return path11.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3716
3790
|
}
|
|
3717
3791
|
function ensureCacheDir() {
|
|
3718
3792
|
const cacheDir = getPluginCacheDir();
|
|
3719
|
-
if (!
|
|
3720
|
-
|
|
3793
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3794
|
+
fs13.mkdirSync(cacheDir, { recursive: true });
|
|
3721
3795
|
}
|
|
3722
3796
|
}
|
|
3723
3797
|
function getTempFilePath(pluginKey, version) {
|
|
3724
3798
|
ensureCacheDir();
|
|
3725
3799
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3726
3800
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3727
|
-
return
|
|
3801
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3728
3802
|
}
|
|
3729
3803
|
var MAX_RETRIES = 2;
|
|
3730
3804
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3761,7 +3835,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3761
3835
|
);
|
|
3762
3836
|
}
|
|
3763
3837
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3764
|
-
|
|
3838
|
+
fs13.writeFileSync(tgzPath, tgzBuffer);
|
|
3765
3839
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3766
3840
|
return {
|
|
3767
3841
|
tgzPath,
|
|
@@ -3775,18 +3849,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3775
3849
|
ensureCacheDir();
|
|
3776
3850
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3777
3851
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3778
|
-
return
|
|
3852
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3779
3853
|
}
|
|
3780
3854
|
function hasCachedPlugin(pluginKey, version) {
|
|
3781
3855
|
const cachePath = getCachePath(pluginKey, version);
|
|
3782
|
-
return
|
|
3856
|
+
return fs13.existsSync(cachePath);
|
|
3783
3857
|
}
|
|
3784
3858
|
function listCachedPlugins() {
|
|
3785
3859
|
const cacheDir = getPluginCacheDir();
|
|
3786
|
-
if (!
|
|
3860
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3787
3861
|
return [];
|
|
3788
3862
|
}
|
|
3789
|
-
const files =
|
|
3863
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3790
3864
|
const result = [];
|
|
3791
3865
|
for (const file of files) {
|
|
3792
3866
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3794,8 +3868,8 @@ function listCachedPlugins() {
|
|
|
3794
3868
|
if (!match) continue;
|
|
3795
3869
|
const [, rawName, version] = match;
|
|
3796
3870
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3797
|
-
const filePath =
|
|
3798
|
-
const stat =
|
|
3871
|
+
const filePath = path11.join(cacheDir, file);
|
|
3872
|
+
const stat = fs13.statSync(filePath);
|
|
3799
3873
|
result.push({
|
|
3800
3874
|
name,
|
|
3801
3875
|
version,
|
|
@@ -3808,14 +3882,14 @@ function listCachedPlugins() {
|
|
|
3808
3882
|
}
|
|
3809
3883
|
function cleanAllCache() {
|
|
3810
3884
|
const cacheDir = getPluginCacheDir();
|
|
3811
|
-
if (!
|
|
3885
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3812
3886
|
return 0;
|
|
3813
3887
|
}
|
|
3814
|
-
const files =
|
|
3888
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3815
3889
|
let count = 0;
|
|
3816
3890
|
for (const file of files) {
|
|
3817
3891
|
if (file.endsWith(".tgz")) {
|
|
3818
|
-
|
|
3892
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3819
3893
|
count++;
|
|
3820
3894
|
}
|
|
3821
3895
|
}
|
|
@@ -3823,21 +3897,21 @@ function cleanAllCache() {
|
|
|
3823
3897
|
}
|
|
3824
3898
|
function cleanPluginCache(pluginKey, version) {
|
|
3825
3899
|
const cacheDir = getPluginCacheDir();
|
|
3826
|
-
if (!
|
|
3900
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3827
3901
|
return 0;
|
|
3828
3902
|
}
|
|
3829
3903
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3830
|
-
const files =
|
|
3904
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3831
3905
|
let count = 0;
|
|
3832
3906
|
for (const file of files) {
|
|
3833
3907
|
if (version) {
|
|
3834
3908
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3835
|
-
|
|
3909
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3836
3910
|
count++;
|
|
3837
3911
|
}
|
|
3838
3912
|
} else {
|
|
3839
3913
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3840
|
-
|
|
3914
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3841
3915
|
count++;
|
|
3842
3916
|
}
|
|
3843
3917
|
}
|
|
@@ -4264,40 +4338,40 @@ var actionPluginCommandGroup = {
|
|
|
4264
4338
|
};
|
|
4265
4339
|
|
|
4266
4340
|
// src/commands/capability/utils.ts
|
|
4267
|
-
import
|
|
4341
|
+
import fs14 from "fs";
|
|
4268
4342
|
import { createRequire as createRequire2 } from "module";
|
|
4269
|
-
import
|
|
4343
|
+
import path12 from "path";
|
|
4270
4344
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4271
4345
|
function getProjectRoot2() {
|
|
4272
4346
|
return process.cwd();
|
|
4273
4347
|
}
|
|
4274
4348
|
function getCapabilitiesDir() {
|
|
4275
|
-
return
|
|
4349
|
+
return path12.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4276
4350
|
}
|
|
4277
4351
|
function getCapabilityPath(id) {
|
|
4278
|
-
return
|
|
4352
|
+
return path12.join(getCapabilitiesDir(), `${id}.json`);
|
|
4279
4353
|
}
|
|
4280
4354
|
function getPluginManifestPath(pluginKey) {
|
|
4281
|
-
return
|
|
4355
|
+
return path12.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4282
4356
|
}
|
|
4283
4357
|
function capabilitiesDirExists() {
|
|
4284
|
-
return
|
|
4358
|
+
return fs14.existsSync(getCapabilitiesDir());
|
|
4285
4359
|
}
|
|
4286
4360
|
function listCapabilityIds() {
|
|
4287
4361
|
const dir = getCapabilitiesDir();
|
|
4288
|
-
if (!
|
|
4362
|
+
if (!fs14.existsSync(dir)) {
|
|
4289
4363
|
return [];
|
|
4290
4364
|
}
|
|
4291
|
-
const files =
|
|
4365
|
+
const files = fs14.readdirSync(dir);
|
|
4292
4366
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4293
4367
|
}
|
|
4294
4368
|
function readCapability(id) {
|
|
4295
4369
|
const filePath = getCapabilityPath(id);
|
|
4296
|
-
if (!
|
|
4370
|
+
if (!fs14.existsSync(filePath)) {
|
|
4297
4371
|
throw new Error(`Capability not found: ${id}`);
|
|
4298
4372
|
}
|
|
4299
4373
|
try {
|
|
4300
|
-
const content =
|
|
4374
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4301
4375
|
return JSON.parse(content);
|
|
4302
4376
|
} catch (error) {
|
|
4303
4377
|
if (error instanceof SyntaxError) {
|
|
@@ -4324,11 +4398,11 @@ function readAllCapabilities() {
|
|
|
4324
4398
|
}
|
|
4325
4399
|
function readPluginManifest(pluginKey) {
|
|
4326
4400
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4327
|
-
if (!
|
|
4401
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
4328
4402
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4329
4403
|
}
|
|
4330
4404
|
try {
|
|
4331
|
-
const content =
|
|
4405
|
+
const content = fs14.readFileSync(manifestPath, "utf-8");
|
|
4332
4406
|
return JSON.parse(content);
|
|
4333
4407
|
} catch (error) {
|
|
4334
4408
|
if (error instanceof SyntaxError) {
|
|
@@ -4345,7 +4419,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4345
4419
|
}
|
|
4346
4420
|
async function loadPlugin(pluginKey) {
|
|
4347
4421
|
try {
|
|
4348
|
-
const userRequire = createRequire2(
|
|
4422
|
+
const userRequire = createRequire2(path12.join(getProjectRoot2(), "package.json"));
|
|
4349
4423
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4350
4424
|
const pluginModule = await import(resolvedPath);
|
|
4351
4425
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4508,8 +4582,8 @@ var capabilityCommandGroup = {
|
|
|
4508
4582
|
import { execFile } from "child_process";
|
|
4509
4583
|
|
|
4510
4584
|
// src/commands/component/registry-preparer.ts
|
|
4511
|
-
import
|
|
4512
|
-
import
|
|
4585
|
+
import fs15 from "fs";
|
|
4586
|
+
import path13 from "path";
|
|
4513
4587
|
import os from "os";
|
|
4514
4588
|
|
|
4515
4589
|
// src/commands/component/service.ts
|
|
@@ -4565,7 +4639,7 @@ async function sendInstallEvent(key) {
|
|
|
4565
4639
|
}
|
|
4566
4640
|
|
|
4567
4641
|
// src/commands/component/registry-preparer.ts
|
|
4568
|
-
var REGISTRY_TEMP_DIR =
|
|
4642
|
+
var REGISTRY_TEMP_DIR = path13.join(os.tmpdir(), "miaoda-registry");
|
|
4569
4643
|
function parseComponentKey(key) {
|
|
4570
4644
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4571
4645
|
if (!match) {
|
|
@@ -4577,11 +4651,11 @@ function parseComponentKey(key) {
|
|
|
4577
4651
|
}
|
|
4578
4652
|
function getLocalRegistryPath(key) {
|
|
4579
4653
|
const { scope, name } = parseComponentKey(key);
|
|
4580
|
-
return
|
|
4654
|
+
return path13.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4581
4655
|
}
|
|
4582
4656
|
function ensureDir(dirPath) {
|
|
4583
|
-
if (!
|
|
4584
|
-
|
|
4657
|
+
if (!fs15.existsSync(dirPath)) {
|
|
4658
|
+
fs15.mkdirSync(dirPath, { recursive: true });
|
|
4585
4659
|
}
|
|
4586
4660
|
}
|
|
4587
4661
|
async function prepareRecursive(key, visited) {
|
|
@@ -4614,8 +4688,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4614
4688
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4615
4689
|
};
|
|
4616
4690
|
const localPath = getLocalRegistryPath(key);
|
|
4617
|
-
ensureDir(
|
|
4618
|
-
|
|
4691
|
+
ensureDir(path13.dirname(localPath));
|
|
4692
|
+
fs15.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4619
4693
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4620
4694
|
}
|
|
4621
4695
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4625,18 +4699,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4625
4699
|
}
|
|
4626
4700
|
function cleanupTempDir() {
|
|
4627
4701
|
try {
|
|
4628
|
-
if (
|
|
4629
|
-
|
|
4702
|
+
if (fs15.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4703
|
+
fs15.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4630
4704
|
}
|
|
4631
4705
|
} catch {
|
|
4632
4706
|
}
|
|
4633
4707
|
}
|
|
4634
4708
|
function getDownloadedRegistryItem(itemId) {
|
|
4635
4709
|
const localPath = getLocalRegistryPath(itemId);
|
|
4636
|
-
if (!
|
|
4710
|
+
if (!fs15.existsSync(localPath)) {
|
|
4637
4711
|
return null;
|
|
4638
4712
|
}
|
|
4639
|
-
const content =
|
|
4713
|
+
const content = fs15.readFileSync(localPath, "utf-8");
|
|
4640
4714
|
return JSON.parse(content);
|
|
4641
4715
|
}
|
|
4642
4716
|
|
|
@@ -4804,58 +4878,58 @@ var componentCommandGroup = {
|
|
|
4804
4878
|
};
|
|
4805
4879
|
|
|
4806
4880
|
// src/commands/migration/version-manager.ts
|
|
4807
|
-
import
|
|
4808
|
-
import
|
|
4881
|
+
import fs16 from "fs";
|
|
4882
|
+
import path14 from "path";
|
|
4809
4883
|
var PACKAGE_JSON = "package.json";
|
|
4810
4884
|
var VERSION_FIELD = "migrationVersion";
|
|
4811
4885
|
function getPackageJsonPath2() {
|
|
4812
|
-
return
|
|
4886
|
+
return path14.join(process.cwd(), PACKAGE_JSON);
|
|
4813
4887
|
}
|
|
4814
4888
|
function getCurrentVersion() {
|
|
4815
4889
|
const pkgPath = getPackageJsonPath2();
|
|
4816
|
-
if (!
|
|
4890
|
+
if (!fs16.existsSync(pkgPath)) {
|
|
4817
4891
|
throw new Error("package.json not found");
|
|
4818
4892
|
}
|
|
4819
|
-
const pkg2 = JSON.parse(
|
|
4893
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4820
4894
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4821
4895
|
}
|
|
4822
4896
|
function setCurrentVersion(version) {
|
|
4823
4897
|
const pkgPath = getPackageJsonPath2();
|
|
4824
|
-
const pkg2 = JSON.parse(
|
|
4898
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4825
4899
|
pkg2[VERSION_FIELD] = version;
|
|
4826
|
-
|
|
4900
|
+
fs16.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4827
4901
|
}
|
|
4828
4902
|
|
|
4829
4903
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4830
|
-
import
|
|
4831
|
-
import
|
|
4904
|
+
import fs18 from "fs";
|
|
4905
|
+
import path16 from "path";
|
|
4832
4906
|
|
|
4833
4907
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4834
|
-
import
|
|
4835
|
-
import
|
|
4908
|
+
import fs17 from "fs";
|
|
4909
|
+
import path15 from "path";
|
|
4836
4910
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4837
4911
|
function getProjectRoot3() {
|
|
4838
4912
|
return process.cwd();
|
|
4839
4913
|
}
|
|
4840
4914
|
function getCapabilitiesDir2() {
|
|
4841
|
-
return
|
|
4915
|
+
return path15.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4842
4916
|
}
|
|
4843
4917
|
function getPluginManifestPath2(pluginKey) {
|
|
4844
|
-
return
|
|
4918
|
+
return path15.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4845
4919
|
}
|
|
4846
4920
|
|
|
4847
4921
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4848
4922
|
function detectJsonMigration() {
|
|
4849
4923
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4850
|
-
const oldFilePath =
|
|
4851
|
-
if (!
|
|
4924
|
+
const oldFilePath = path16.join(capabilitiesDir, "capabilities.json");
|
|
4925
|
+
if (!fs18.existsSync(oldFilePath)) {
|
|
4852
4926
|
return {
|
|
4853
4927
|
needsMigration: false,
|
|
4854
4928
|
reason: "capabilities.json not found"
|
|
4855
4929
|
};
|
|
4856
4930
|
}
|
|
4857
4931
|
try {
|
|
4858
|
-
const content =
|
|
4932
|
+
const content = fs18.readFileSync(oldFilePath, "utf-8");
|
|
4859
4933
|
const parsed = JSON.parse(content);
|
|
4860
4934
|
if (!Array.isArray(parsed)) {
|
|
4861
4935
|
return {
|
|
@@ -4906,8 +4980,8 @@ async function check(options) {
|
|
|
4906
4980
|
}
|
|
4907
4981
|
|
|
4908
4982
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4909
|
-
import
|
|
4910
|
-
import
|
|
4983
|
+
import fs19 from "fs";
|
|
4984
|
+
import path17 from "path";
|
|
4911
4985
|
|
|
4912
4986
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
4913
4987
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5137,18 +5211,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5137
5211
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5138
5212
|
function loadExistingCapabilities() {
|
|
5139
5213
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5140
|
-
if (!
|
|
5214
|
+
if (!fs19.existsSync(capabilitiesDir)) {
|
|
5141
5215
|
return [];
|
|
5142
5216
|
}
|
|
5143
|
-
const files =
|
|
5217
|
+
const files = fs19.readdirSync(capabilitiesDir);
|
|
5144
5218
|
const capabilities = [];
|
|
5145
5219
|
for (const file of files) {
|
|
5146
5220
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5147
5221
|
continue;
|
|
5148
5222
|
}
|
|
5149
5223
|
try {
|
|
5150
|
-
const filePath =
|
|
5151
|
-
const content =
|
|
5224
|
+
const filePath = path17.join(capabilitiesDir, file);
|
|
5225
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
5152
5226
|
const capability = JSON.parse(content);
|
|
5153
5227
|
if (capability.id && capability.pluginKey) {
|
|
5154
5228
|
capabilities.push(capability);
|
|
@@ -5206,9 +5280,9 @@ async function migrateJsonFiles(options) {
|
|
|
5206
5280
|
}
|
|
5207
5281
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5208
5282
|
for (const cap of newCapabilities) {
|
|
5209
|
-
const filePath =
|
|
5283
|
+
const filePath = path17.join(capabilitiesDir, `${cap.id}.json`);
|
|
5210
5284
|
const content = JSON.stringify(cap, null, 2);
|
|
5211
|
-
|
|
5285
|
+
fs19.writeFileSync(filePath, content, "utf-8");
|
|
5212
5286
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5213
5287
|
}
|
|
5214
5288
|
return {
|
|
@@ -5220,11 +5294,11 @@ async function migrateJsonFiles(options) {
|
|
|
5220
5294
|
}
|
|
5221
5295
|
|
|
5222
5296
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5223
|
-
import
|
|
5297
|
+
import fs20 from "fs";
|
|
5224
5298
|
function isPluginInstalled2(pluginKey) {
|
|
5225
5299
|
const actionPlugins = readActionPlugins();
|
|
5226
5300
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5227
|
-
return
|
|
5301
|
+
return fs20.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5228
5302
|
}
|
|
5229
5303
|
function detectPluginsToInstall(capabilities) {
|
|
5230
5304
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5300,12 +5374,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5300
5374
|
}
|
|
5301
5375
|
|
|
5302
5376
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5303
|
-
import
|
|
5377
|
+
import path19 from "path";
|
|
5304
5378
|
import { Project as Project3 } from "ts-morph";
|
|
5305
5379
|
|
|
5306
5380
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5307
|
-
import
|
|
5308
|
-
import
|
|
5381
|
+
import fs21 from "fs";
|
|
5382
|
+
import path18 from "path";
|
|
5309
5383
|
var EXCLUDED_DIRS = [
|
|
5310
5384
|
"node_modules",
|
|
5311
5385
|
"dist",
|
|
@@ -5320,9 +5394,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5320
5394
|
/\.d\.ts$/
|
|
5321
5395
|
];
|
|
5322
5396
|
function scanDirectory(dir, files = []) {
|
|
5323
|
-
const entries =
|
|
5397
|
+
const entries = fs21.readdirSync(dir, { withFileTypes: true });
|
|
5324
5398
|
for (const entry of entries) {
|
|
5325
|
-
const fullPath =
|
|
5399
|
+
const fullPath = path18.join(dir, entry.name);
|
|
5326
5400
|
if (entry.isDirectory()) {
|
|
5327
5401
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5328
5402
|
continue;
|
|
@@ -5338,14 +5412,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5338
5412
|
return files;
|
|
5339
5413
|
}
|
|
5340
5414
|
function scanServerFiles() {
|
|
5341
|
-
const serverDir =
|
|
5342
|
-
if (!
|
|
5415
|
+
const serverDir = path18.join(getProjectRoot3(), "server");
|
|
5416
|
+
if (!fs21.existsSync(serverDir)) {
|
|
5343
5417
|
return [];
|
|
5344
5418
|
}
|
|
5345
5419
|
return scanDirectory(serverDir);
|
|
5346
5420
|
}
|
|
5347
5421
|
function hasCapabilityImport(filePath) {
|
|
5348
|
-
const content =
|
|
5422
|
+
const content = fs21.readFileSync(filePath, "utf-8");
|
|
5349
5423
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5350
5424
|
}
|
|
5351
5425
|
function scanFilesToMigrate() {
|
|
@@ -5722,7 +5796,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5722
5796
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5723
5797
|
const classInfo = analyzeClass(sourceFile);
|
|
5724
5798
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5725
|
-
const relativePath =
|
|
5799
|
+
const relativePath = path19.relative(getProjectRoot3(), filePath);
|
|
5726
5800
|
return {
|
|
5727
5801
|
filePath: relativePath,
|
|
5728
5802
|
imports,
|
|
@@ -5733,7 +5807,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5733
5807
|
};
|
|
5734
5808
|
}
|
|
5735
5809
|
function migrateFile(project, analysis, dryRun) {
|
|
5736
|
-
const absolutePath =
|
|
5810
|
+
const absolutePath = path19.join(getProjectRoot3(), analysis.filePath);
|
|
5737
5811
|
if (!analysis.canAutoMigrate) {
|
|
5738
5812
|
return {
|
|
5739
5813
|
filePath: analysis.filePath,
|
|
@@ -5836,17 +5910,17 @@ function getSuggestion(analysis) {
|
|
|
5836
5910
|
}
|
|
5837
5911
|
|
|
5838
5912
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5839
|
-
import
|
|
5840
|
-
import
|
|
5913
|
+
import fs22 from "fs";
|
|
5914
|
+
import path20 from "path";
|
|
5841
5915
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5842
5916
|
const deletedFiles = [];
|
|
5843
5917
|
const errors = [];
|
|
5844
5918
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5845
|
-
const oldJsonPath =
|
|
5846
|
-
if (
|
|
5919
|
+
const oldJsonPath = path20.join(capabilitiesDir, "capabilities.json");
|
|
5920
|
+
if (fs22.existsSync(oldJsonPath)) {
|
|
5847
5921
|
try {
|
|
5848
5922
|
if (!dryRun) {
|
|
5849
|
-
|
|
5923
|
+
fs22.unlinkSync(oldJsonPath);
|
|
5850
5924
|
}
|
|
5851
5925
|
deletedFiles.push("capabilities.json");
|
|
5852
5926
|
} catch (error) {
|
|
@@ -5854,11 +5928,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5854
5928
|
}
|
|
5855
5929
|
}
|
|
5856
5930
|
for (const cap of capabilities) {
|
|
5857
|
-
const tsFilePath =
|
|
5858
|
-
if (
|
|
5931
|
+
const tsFilePath = path20.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5932
|
+
if (fs22.existsSync(tsFilePath)) {
|
|
5859
5933
|
try {
|
|
5860
5934
|
if (!dryRun) {
|
|
5861
|
-
|
|
5935
|
+
fs22.unlinkSync(tsFilePath);
|
|
5862
5936
|
}
|
|
5863
5937
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5864
5938
|
} catch (error) {
|
|
@@ -5874,8 +5948,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5874
5948
|
}
|
|
5875
5949
|
|
|
5876
5950
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5877
|
-
import
|
|
5878
|
-
import
|
|
5951
|
+
import fs23 from "fs";
|
|
5952
|
+
import path21 from "path";
|
|
5879
5953
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5880
5954
|
function printSummary(result) {
|
|
5881
5955
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6038,15 +6112,15 @@ async function generateReport(result) {
|
|
|
6038
6112
|
}
|
|
6039
6113
|
lines.push("");
|
|
6040
6114
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6041
|
-
if (!
|
|
6115
|
+
if (!fs23.existsSync(logDir)) {
|
|
6042
6116
|
return;
|
|
6043
6117
|
}
|
|
6044
|
-
const reportDir =
|
|
6045
|
-
if (!
|
|
6046
|
-
|
|
6118
|
+
const reportDir = path21.join(logDir, "migration");
|
|
6119
|
+
if (!fs23.existsSync(reportDir)) {
|
|
6120
|
+
fs23.mkdirSync(reportDir, { recursive: true });
|
|
6047
6121
|
}
|
|
6048
|
-
const reportPath =
|
|
6049
|
-
|
|
6122
|
+
const reportPath = path21.join(reportDir, REPORT_FILE);
|
|
6123
|
+
fs23.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6050
6124
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6051
6125
|
}
|
|
6052
6126
|
|
|
@@ -6578,10 +6652,10 @@ var migrationCommand = {
|
|
|
6578
6652
|
};
|
|
6579
6653
|
|
|
6580
6654
|
// src/commands/read-logs/index.ts
|
|
6581
|
-
import
|
|
6655
|
+
import path22 from "path";
|
|
6582
6656
|
|
|
6583
6657
|
// src/commands/read-logs/std-utils.ts
|
|
6584
|
-
import
|
|
6658
|
+
import fs24 from "fs";
|
|
6585
6659
|
function formatStdPrefixTime(localTime) {
|
|
6586
6660
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6587
6661
|
if (!match) return localTime;
|
|
@@ -6611,11 +6685,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6611
6685
|
return `[${time}] ${content}`;
|
|
6612
6686
|
}
|
|
6613
6687
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6614
|
-
const stat =
|
|
6688
|
+
const stat = fs24.statSync(filePath);
|
|
6615
6689
|
if (stat.size === 0) {
|
|
6616
6690
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6617
6691
|
}
|
|
6618
|
-
const fd =
|
|
6692
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6619
6693
|
const chunkSize = 64 * 1024;
|
|
6620
6694
|
let position = stat.size;
|
|
6621
6695
|
let remainder = "";
|
|
@@ -6629,7 +6703,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6629
6703
|
const length = Math.min(chunkSize, position);
|
|
6630
6704
|
position -= length;
|
|
6631
6705
|
const buffer = Buffer.alloc(length);
|
|
6632
|
-
|
|
6706
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6633
6707
|
let chunk = buffer.toString("utf8");
|
|
6634
6708
|
if (remainder) {
|
|
6635
6709
|
chunk += remainder;
|
|
@@ -6671,7 +6745,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6671
6745
|
}
|
|
6672
6746
|
}
|
|
6673
6747
|
} finally {
|
|
6674
|
-
|
|
6748
|
+
fs24.closeSync(fd);
|
|
6675
6749
|
}
|
|
6676
6750
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6677
6751
|
}
|
|
@@ -6692,21 +6766,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6692
6766
|
}
|
|
6693
6767
|
|
|
6694
6768
|
// src/commands/read-logs/tail.ts
|
|
6695
|
-
import
|
|
6769
|
+
import fs25 from "fs";
|
|
6696
6770
|
function fileExists(filePath) {
|
|
6697
6771
|
try {
|
|
6698
|
-
|
|
6772
|
+
fs25.accessSync(filePath, fs25.constants.F_OK | fs25.constants.R_OK);
|
|
6699
6773
|
return true;
|
|
6700
6774
|
} catch {
|
|
6701
6775
|
return false;
|
|
6702
6776
|
}
|
|
6703
6777
|
}
|
|
6704
6778
|
function readFileTailLines(filePath, maxLines) {
|
|
6705
|
-
const stat =
|
|
6779
|
+
const stat = fs25.statSync(filePath);
|
|
6706
6780
|
if (stat.size === 0) {
|
|
6707
6781
|
return [];
|
|
6708
6782
|
}
|
|
6709
|
-
const fd =
|
|
6783
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6710
6784
|
const chunkSize = 64 * 1024;
|
|
6711
6785
|
const chunks = [];
|
|
6712
6786
|
let position = stat.size;
|
|
@@ -6716,13 +6790,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6716
6790
|
const length = Math.min(chunkSize, position);
|
|
6717
6791
|
position -= length;
|
|
6718
6792
|
const buffer = Buffer.alloc(length);
|
|
6719
|
-
|
|
6793
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6720
6794
|
chunks.unshift(buffer.toString("utf8"));
|
|
6721
6795
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6722
6796
|
collectedLines += chunkLines;
|
|
6723
6797
|
}
|
|
6724
6798
|
} finally {
|
|
6725
|
-
|
|
6799
|
+
fs25.closeSync(fd);
|
|
6726
6800
|
}
|
|
6727
6801
|
const content = chunks.join("");
|
|
6728
6802
|
const allLines = content.split("\n");
|
|
@@ -6738,11 +6812,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6738
6812
|
return allLines.slice(allLines.length - maxLines);
|
|
6739
6813
|
}
|
|
6740
6814
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6741
|
-
const stat =
|
|
6815
|
+
const stat = fs25.statSync(filePath);
|
|
6742
6816
|
if (stat.size === 0) {
|
|
6743
6817
|
return { lines: [], totalLinesCount: 0 };
|
|
6744
6818
|
}
|
|
6745
|
-
const fd =
|
|
6819
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6746
6820
|
const chunkSize = 64 * 1024;
|
|
6747
6821
|
let position = stat.size;
|
|
6748
6822
|
let remainder = "";
|
|
@@ -6754,7 +6828,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6754
6828
|
const length = Math.min(chunkSize, position);
|
|
6755
6829
|
position -= length;
|
|
6756
6830
|
const buffer = Buffer.alloc(length);
|
|
6757
|
-
|
|
6831
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6758
6832
|
let chunk = buffer.toString("utf8");
|
|
6759
6833
|
if (remainder) {
|
|
6760
6834
|
chunk += remainder;
|
|
@@ -6785,7 +6859,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6785
6859
|
}
|
|
6786
6860
|
}
|
|
6787
6861
|
} finally {
|
|
6788
|
-
|
|
6862
|
+
fs25.closeSync(fd);
|
|
6789
6863
|
}
|
|
6790
6864
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6791
6865
|
}
|
|
@@ -6927,7 +7001,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
6927
7001
|
}
|
|
6928
7002
|
|
|
6929
7003
|
// src/commands/read-logs/json-lines.ts
|
|
6930
|
-
import
|
|
7004
|
+
import fs26 from "fs";
|
|
6931
7005
|
function normalizePid(value) {
|
|
6932
7006
|
if (typeof value === "number") {
|
|
6933
7007
|
return String(value);
|
|
@@ -6978,11 +7052,11 @@ function buildWantedLevelSet(levels) {
|
|
|
6978
7052
|
return set.size > 0 ? set : null;
|
|
6979
7053
|
}
|
|
6980
7054
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
6981
|
-
const stat =
|
|
7055
|
+
const stat = fs26.statSync(filePath);
|
|
6982
7056
|
if (stat.size === 0) {
|
|
6983
7057
|
return { lines: [], totalLinesCount: 0 };
|
|
6984
7058
|
}
|
|
6985
|
-
const fd =
|
|
7059
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6986
7060
|
const chunkSize = 64 * 1024;
|
|
6987
7061
|
let position = stat.size;
|
|
6988
7062
|
let remainder = "";
|
|
@@ -6997,7 +7071,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6997
7071
|
const length = Math.min(chunkSize, position);
|
|
6998
7072
|
position -= length;
|
|
6999
7073
|
const buffer = Buffer.alloc(length);
|
|
7000
|
-
|
|
7074
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7001
7075
|
let chunk = buffer.toString("utf8");
|
|
7002
7076
|
if (remainder) {
|
|
7003
7077
|
chunk += remainder;
|
|
@@ -7059,7 +7133,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7059
7133
|
}
|
|
7060
7134
|
}
|
|
7061
7135
|
} finally {
|
|
7062
|
-
|
|
7136
|
+
fs26.closeSync(fd);
|
|
7063
7137
|
}
|
|
7064
7138
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7065
7139
|
}
|
|
@@ -7102,11 +7176,11 @@ function extractTraceId(obj) {
|
|
|
7102
7176
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7103
7177
|
const wanted = traceId.trim();
|
|
7104
7178
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7105
|
-
const stat =
|
|
7179
|
+
const stat = fs26.statSync(filePath);
|
|
7106
7180
|
if (stat.size === 0) {
|
|
7107
7181
|
return { lines: [], totalLinesCount: 0 };
|
|
7108
7182
|
}
|
|
7109
|
-
const fd =
|
|
7183
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7110
7184
|
const chunkSize = 64 * 1024;
|
|
7111
7185
|
let position = stat.size;
|
|
7112
7186
|
let remainder = "";
|
|
@@ -7119,7 +7193,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7119
7193
|
const length = Math.min(chunkSize, position);
|
|
7120
7194
|
position -= length;
|
|
7121
7195
|
const buffer = Buffer.alloc(length);
|
|
7122
|
-
|
|
7196
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7123
7197
|
let chunk = buffer.toString("utf8");
|
|
7124
7198
|
if (remainder) {
|
|
7125
7199
|
chunk += remainder;
|
|
@@ -7172,7 +7246,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7172
7246
|
}
|
|
7173
7247
|
}
|
|
7174
7248
|
} finally {
|
|
7175
|
-
|
|
7249
|
+
fs26.closeSync(fd);
|
|
7176
7250
|
}
|
|
7177
7251
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7178
7252
|
}
|
|
@@ -7181,11 +7255,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7181
7255
|
if (!wantedLevelSet) {
|
|
7182
7256
|
return { lines: [], totalLinesCount: 0 };
|
|
7183
7257
|
}
|
|
7184
|
-
const stat =
|
|
7258
|
+
const stat = fs26.statSync(filePath);
|
|
7185
7259
|
if (stat.size === 0) {
|
|
7186
7260
|
return { lines: [], totalLinesCount: 0 };
|
|
7187
7261
|
}
|
|
7188
|
-
const fd =
|
|
7262
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7189
7263
|
const chunkSize = 64 * 1024;
|
|
7190
7264
|
let position = stat.size;
|
|
7191
7265
|
let remainder = "";
|
|
@@ -7197,7 +7271,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7197
7271
|
const length = Math.min(chunkSize, position);
|
|
7198
7272
|
position -= length;
|
|
7199
7273
|
const buffer = Buffer.alloc(length);
|
|
7200
|
-
|
|
7274
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7201
7275
|
let chunk = buffer.toString("utf8");
|
|
7202
7276
|
if (remainder) {
|
|
7203
7277
|
chunk += remainder;
|
|
@@ -7244,7 +7318,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7244
7318
|
}
|
|
7245
7319
|
}
|
|
7246
7320
|
} finally {
|
|
7247
|
-
|
|
7321
|
+
fs26.closeSync(fd);
|
|
7248
7322
|
}
|
|
7249
7323
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7250
7324
|
}
|
|
@@ -7478,30 +7552,30 @@ async function readLogsJsonResult(options) {
|
|
|
7478
7552
|
};
|
|
7479
7553
|
}
|
|
7480
7554
|
function resolveLogFilePath(logDir, type) {
|
|
7481
|
-
const base =
|
|
7555
|
+
const base = path22.isAbsolute(logDir) ? logDir : path22.join(process.cwd(), logDir);
|
|
7482
7556
|
if (type === "server") {
|
|
7483
|
-
return
|
|
7557
|
+
return path22.join(base, "server.log");
|
|
7484
7558
|
}
|
|
7485
7559
|
if (type === "trace") {
|
|
7486
|
-
return
|
|
7560
|
+
return path22.join(base, "trace.log");
|
|
7487
7561
|
}
|
|
7488
7562
|
if (type === "server-std") {
|
|
7489
|
-
return
|
|
7563
|
+
return path22.join(base, "server.std.log");
|
|
7490
7564
|
}
|
|
7491
7565
|
if (type === "client-std") {
|
|
7492
|
-
return
|
|
7566
|
+
return path22.join(base, "client.std.log");
|
|
7493
7567
|
}
|
|
7494
7568
|
if (type === "dev") {
|
|
7495
|
-
return
|
|
7569
|
+
return path22.join(base, "dev.log");
|
|
7496
7570
|
}
|
|
7497
7571
|
if (type === "dev-std") {
|
|
7498
|
-
return
|
|
7572
|
+
return path22.join(base, "dev.std.log");
|
|
7499
7573
|
}
|
|
7500
7574
|
if (type === "install-dep-std") {
|
|
7501
|
-
return
|
|
7575
|
+
return path22.join(base, "install-dep.std.log");
|
|
7502
7576
|
}
|
|
7503
7577
|
if (type === "browser") {
|
|
7504
|
-
return
|
|
7578
|
+
return path22.join(base, "browser.log");
|
|
7505
7579
|
}
|
|
7506
7580
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7507
7581
|
}
|
|
@@ -7678,9 +7752,9 @@ function camelToKebab(str) {
|
|
|
7678
7752
|
}
|
|
7679
7753
|
|
|
7680
7754
|
// src/commands/build/upload-static.handler.ts
|
|
7681
|
-
import * as
|
|
7755
|
+
import * as fs27 from "fs";
|
|
7682
7756
|
import * as os2 from "os";
|
|
7683
|
-
import * as
|
|
7757
|
+
import * as path23 from "path";
|
|
7684
7758
|
import { execFileSync } from "child_process";
|
|
7685
7759
|
function readCredentialsFromEnv() {
|
|
7686
7760
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7704,8 +7778,8 @@ async function uploadStatic(options) {
|
|
|
7704
7778
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7705
7779
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7706
7780
|
} = options;
|
|
7707
|
-
const resolvedStaticDir =
|
|
7708
|
-
if (!
|
|
7781
|
+
const resolvedStaticDir = path23.resolve(staticDir);
|
|
7782
|
+
if (!fs27.existsSync(resolvedStaticDir)) {
|
|
7709
7783
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7710
7784
|
return;
|
|
7711
7785
|
}
|
|
@@ -7738,8 +7812,8 @@ async function uploadStatic(options) {
|
|
|
7738
7812
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7739
7813
|
}
|
|
7740
7814
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7741
|
-
const confPath =
|
|
7742
|
-
|
|
7815
|
+
const confPath = path23.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7816
|
+
fs27.writeFileSync(confPath, "");
|
|
7743
7817
|
try {
|
|
7744
7818
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7745
7819
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7753,7 +7827,7 @@ async function uploadStatic(options) {
|
|
|
7753
7827
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7754
7828
|
} finally {
|
|
7755
7829
|
try {
|
|
7756
|
-
|
|
7830
|
+
fs27.unlinkSync(confPath);
|
|
7757
7831
|
} catch {
|
|
7758
7832
|
}
|
|
7759
7833
|
}
|
|
@@ -7773,8 +7847,8 @@ async function uploadStatic(options) {
|
|
|
7773
7847
|
}
|
|
7774
7848
|
}
|
|
7775
7849
|
function resolveTosutilPath(tosutilPath) {
|
|
7776
|
-
if (
|
|
7777
|
-
return
|
|
7850
|
+
if (path23.isAbsolute(tosutilPath)) {
|
|
7851
|
+
return fs27.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7778
7852
|
}
|
|
7779
7853
|
try {
|
|
7780
7854
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -7819,7 +7893,7 @@ async function resolveBucketId(appId) {
|
|
|
7819
7893
|
return bucketId;
|
|
7820
7894
|
}
|
|
7821
7895
|
function isDirEmpty(dirPath) {
|
|
7822
|
-
const entries =
|
|
7896
|
+
const entries = fs27.readdirSync(dirPath);
|
|
7823
7897
|
return entries.length === 0;
|
|
7824
7898
|
}
|
|
7825
7899
|
|
|
@@ -7914,12 +7988,12 @@ var commands = [
|
|
|
7914
7988
|
];
|
|
7915
7989
|
|
|
7916
7990
|
// src/index.ts
|
|
7917
|
-
var envPath =
|
|
7918
|
-
if (
|
|
7991
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
7992
|
+
if (fs28.existsSync(envPath)) {
|
|
7919
7993
|
dotenvConfig({ path: envPath });
|
|
7920
7994
|
}
|
|
7921
|
-
var __dirname =
|
|
7922
|
-
var pkg = JSON.parse(
|
|
7995
|
+
var __dirname = path24.dirname(fileURLToPath5(import.meta.url));
|
|
7996
|
+
var pkg = JSON.parse(fs28.readFileSync(path24.join(__dirname, "../package.json"), "utf-8"));
|
|
7923
7997
|
var cli = new FullstackCLI(pkg.version);
|
|
7924
7998
|
cli.useAll(commands);
|
|
7925
7999
|
cli.run();
|