@lark-apaas/fullstack-cli 1.1.40-alpha.2 → 1.1.40-alpha.4
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 +342 -255
- 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) {
|
|
@@ -3113,11 +3115,14 @@ function getGrayscaleConfig(configJson) {
|
|
|
3113
3115
|
return null;
|
|
3114
3116
|
}
|
|
3115
3117
|
try {
|
|
3116
|
-
const
|
|
3118
|
+
const parsed = JSON.parse(raw);
|
|
3119
|
+
const config = parsed.config || parsed;
|
|
3120
|
+
const tenantId = parsed.tenant_id != null ? String(parsed.tenant_id) : void 0;
|
|
3121
|
+
const xTtEnv = parsed.x_tt_env || void 0;
|
|
3117
3122
|
if (!config.enabled) {
|
|
3118
3123
|
return null;
|
|
3119
3124
|
}
|
|
3120
|
-
return config;
|
|
3125
|
+
return { config, tenantId, xTtEnv };
|
|
3121
3126
|
} catch {
|
|
3122
3127
|
console.warn("[grayscale] Failed to parse grayscale config");
|
|
3123
3128
|
return null;
|
|
@@ -3130,7 +3135,8 @@ import path8 from "path";
|
|
|
3130
3135
|
function readFromEnvVars() {
|
|
3131
3136
|
const appId = process.env.app_id || process.env.APP_ID;
|
|
3132
3137
|
const tenantId = process.env.tenant_id || process.env.TENANT_ID;
|
|
3133
|
-
|
|
3138
|
+
const xTtEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV || process.env.x_tt_env;
|
|
3139
|
+
return { appId, tenantId, xTtEnv };
|
|
3134
3140
|
}
|
|
3135
3141
|
function parseEnvFile(filePath) {
|
|
3136
3142
|
const result = {};
|
|
@@ -3159,7 +3165,8 @@ function readFromForceEnvFile(cwd) {
|
|
|
3159
3165
|
const vars = parseEnvFile(envPath2);
|
|
3160
3166
|
return {
|
|
3161
3167
|
appId: vars.app_id || vars.APP_ID,
|
|
3162
|
-
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
|
|
3163
3170
|
};
|
|
3164
3171
|
}
|
|
3165
3172
|
function readFromClientBasePath() {
|
|
@@ -3182,7 +3189,8 @@ function readFromDotEnv(cwd) {
|
|
|
3182
3189
|
const vars = parseEnvFile(envPath2);
|
|
3183
3190
|
return {
|
|
3184
3191
|
appId: vars.app_id || vars.APP_ID,
|
|
3185
|
-
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
|
|
3186
3194
|
};
|
|
3187
3195
|
}
|
|
3188
3196
|
function readFromPackageJson(cwd) {
|
|
@@ -3216,8 +3224,8 @@ function readProjectIdentity(cwd) {
|
|
|
3216
3224
|
if (!merged.tenantId && identity.tenantId) {
|
|
3217
3225
|
merged.tenantId = identity.tenantId;
|
|
3218
3226
|
}
|
|
3219
|
-
if (merged.
|
|
3220
|
-
|
|
3227
|
+
if (!merged.xTtEnv && identity.xTtEnv) {
|
|
3228
|
+
merged.xTtEnv = identity.xTtEnv;
|
|
3221
3229
|
}
|
|
3222
3230
|
}
|
|
3223
3231
|
return merged;
|
|
@@ -3231,77 +3239,98 @@ function isInPercentage(tenantId, percentage) {
|
|
|
3231
3239
|
if (isNaN(id)) return false;
|
|
3232
3240
|
return id % 100 < percentage;
|
|
3233
3241
|
}
|
|
3234
|
-
function
|
|
3235
|
-
|
|
3236
|
-
if (
|
|
3237
|
-
|
|
3238
|
-
|
|
3242
|
+
function matchRule(rule, identity) {
|
|
3243
|
+
let hasAnyCondition = false;
|
|
3244
|
+
if (rule.tenant_ids && rule.tenant_ids.length > 0) {
|
|
3245
|
+
hasAnyCondition = true;
|
|
3246
|
+
if (!identity.tenantId || !rule.tenant_ids.includes(identity.tenantId)) {
|
|
3247
|
+
return false;
|
|
3239
3248
|
}
|
|
3240
3249
|
}
|
|
3241
|
-
if (
|
|
3242
|
-
|
|
3243
|
-
|
|
3250
|
+
if (rule.app_ids && rule.app_ids.length > 0) {
|
|
3251
|
+
hasAnyCondition = true;
|
|
3252
|
+
if (!identity.appId || !rule.app_ids.includes(identity.appId)) {
|
|
3253
|
+
return false;
|
|
3244
3254
|
}
|
|
3245
3255
|
}
|
|
3246
|
-
if (
|
|
3247
|
-
|
|
3248
|
-
|
|
3256
|
+
if (rule.percentage != null && rule.percentage > 0) {
|
|
3257
|
+
hasAnyCondition = true;
|
|
3258
|
+
if (rule.percentage < 100) {
|
|
3259
|
+
if (!identity.tenantId || !isInPercentage(identity.tenantId, rule.percentage)) {
|
|
3260
|
+
return false;
|
|
3261
|
+
}
|
|
3249
3262
|
}
|
|
3250
3263
|
}
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
const enabledRules = config.rules.filter((rule) => rule.enabled).sort((a, b) => b.priority - a.priority);
|
|
3256
|
-
for (const rule of enabledRules) {
|
|
3257
|
-
if (matchConditions(rule, identity)) {
|
|
3258
|
-
return rule;
|
|
3264
|
+
if (rule.x_tt_env) {
|
|
3265
|
+
hasAnyCondition = true;
|
|
3266
|
+
if (identity.xTtEnv !== rule.x_tt_env) {
|
|
3267
|
+
return false;
|
|
3259
3268
|
}
|
|
3260
3269
|
}
|
|
3261
|
-
return
|
|
3270
|
+
return hasAnyCondition;
|
|
3271
|
+
}
|
|
3272
|
+
function matchChannel(channel, identity) {
|
|
3273
|
+
if (!channel.rules || channel.rules.length === 0) return false;
|
|
3274
|
+
return channel.rules.some((rule) => matchRule(rule, identity));
|
|
3275
|
+
}
|
|
3276
|
+
function isBlocked(config, identity) {
|
|
3277
|
+
if (identity.tenantId && config.blocked_tenant_ids?.includes(identity.tenantId)) {
|
|
3278
|
+
return true;
|
|
3279
|
+
}
|
|
3280
|
+
if (identity.appId && config.blocked_app_ids?.includes(identity.appId)) {
|
|
3281
|
+
return true;
|
|
3282
|
+
}
|
|
3283
|
+
return false;
|
|
3262
3284
|
}
|
|
3263
3285
|
function resolveTargetVersions(config, identity) {
|
|
3264
|
-
const
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3286
|
+
const stableVersions = config.stable?.versions || {};
|
|
3287
|
+
let matchedChannel;
|
|
3288
|
+
if (isBlocked(config, identity)) {
|
|
3289
|
+
console.log("[grayscale] Tenant/app is in blocklist, use stable");
|
|
3290
|
+
} else {
|
|
3291
|
+
matchedChannel = (config.channels || []).find((ch) => matchChannel(ch, identity));
|
|
3270
3292
|
}
|
|
3271
|
-
const
|
|
3272
|
-
for (const [
|
|
3293
|
+
const merged = /* @__PURE__ */ new Map();
|
|
3294
|
+
for (const [pkg2, version] of Object.entries(stableVersions)) {
|
|
3273
3295
|
if (config.blocked_versions?.includes(version)) {
|
|
3274
|
-
console.warn(`[grayscale]
|
|
3296
|
+
console.warn(`[grayscale] stable version ${version} of ${pkg2} is blocked, skipping`);
|
|
3275
3297
|
continue;
|
|
3276
3298
|
}
|
|
3277
|
-
|
|
3299
|
+
merged.set(pkg2, version);
|
|
3278
3300
|
}
|
|
3279
|
-
if (
|
|
3280
|
-
|
|
3281
|
-
|
|
3301
|
+
if (matchedChannel) {
|
|
3302
|
+
console.log(`[grayscale] Matched channel: ${matchedChannel.name}`);
|
|
3303
|
+
for (const [pkg2, version] of Object.entries(matchedChannel.versions || {})) {
|
|
3304
|
+
if (config.blocked_versions?.includes(version)) {
|
|
3305
|
+
console.warn(`[grayscale] channel version ${version} of ${pkg2} is blocked, skipping`);
|
|
3306
|
+
continue;
|
|
3307
|
+
}
|
|
3308
|
+
merged.set(pkg2, version);
|
|
3282
3309
|
}
|
|
3310
|
+
} else if (!isBlocked(config, identity)) {
|
|
3311
|
+
console.log("[grayscale] No channel matched, use stable");
|
|
3283
3312
|
}
|
|
3284
|
-
|
|
3285
|
-
console.log(`[grayscale] Matched rule: "${matchedRule.name}" (id: ${matchedRule.id}), channel: ${channelName}`);
|
|
3286
|
-
} else {
|
|
3287
|
-
console.log(`[grayscale] No rule matched, using default channel: ${channelName}`);
|
|
3288
|
-
}
|
|
3289
|
-
return versions;
|
|
3313
|
+
return merged.size > 0 ? merged : null;
|
|
3290
3314
|
}
|
|
3291
3315
|
|
|
3292
3316
|
// src/utils/grayscale/index.ts
|
|
3293
3317
|
function resolveGrayscaleVersions(cwd, configJson) {
|
|
3294
|
-
const
|
|
3295
|
-
if (!
|
|
3318
|
+
const result = getGrayscaleConfig(configJson);
|
|
3319
|
+
if (!result) {
|
|
3296
3320
|
console.log("[grayscale] Config not available, skipping grayscale");
|
|
3297
3321
|
return null;
|
|
3298
3322
|
}
|
|
3323
|
+
const { config, tenantId: payloadTenantId, xTtEnv: payloadXTtEnv } = result;
|
|
3299
3324
|
const identity = readProjectIdentity(cwd);
|
|
3300
|
-
if (
|
|
3301
|
-
|
|
3302
|
-
return null;
|
|
3325
|
+
if (payloadTenantId) {
|
|
3326
|
+
identity.tenantId = payloadTenantId;
|
|
3303
3327
|
}
|
|
3304
|
-
|
|
3328
|
+
if (payloadXTtEnv) {
|
|
3329
|
+
identity.xTtEnv = payloadXTtEnv;
|
|
3330
|
+
}
|
|
3331
|
+
console.log(
|
|
3332
|
+
`[grayscale] Project identity: appId=${identity.appId || "N/A"}, tenantId=${identity.tenantId || "N/A"}, xTtEnv=${identity.xTtEnv || "N/A"}`
|
|
3333
|
+
);
|
|
3305
3334
|
const versions = resolveTargetVersions(config, identity);
|
|
3306
3335
|
if (!versions || versions.size === 0) {
|
|
3307
3336
|
console.log("[grayscale] No target versions resolved");
|
|
@@ -3315,6 +3344,33 @@ function resolveGrayscaleVersions(cwd, configJson) {
|
|
|
3315
3344
|
}
|
|
3316
3345
|
|
|
3317
3346
|
// src/commands/upgrade/deps/run.handler.ts
|
|
3347
|
+
function parseSemver(version) {
|
|
3348
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
3349
|
+
if (!match) return null;
|
|
3350
|
+
return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)];
|
|
3351
|
+
}
|
|
3352
|
+
function compareSemver(a, b) {
|
|
3353
|
+
const va = parseSemver(a);
|
|
3354
|
+
const vb = parseSemver(b);
|
|
3355
|
+
if (!va || !vb) return 0;
|
|
3356
|
+
for (let i = 0; i < 3; i++) {
|
|
3357
|
+
if (va[i] < vb[i]) return -1;
|
|
3358
|
+
if (va[i] > vb[i]) return 1;
|
|
3359
|
+
}
|
|
3360
|
+
return 0;
|
|
3361
|
+
}
|
|
3362
|
+
function satisfiesCaret(installed, range) {
|
|
3363
|
+
const baseVersion = range.slice(1);
|
|
3364
|
+
const base = parseSemver(baseVersion);
|
|
3365
|
+
const inst = parseSemver(installed);
|
|
3366
|
+
if (!base || !inst) return false;
|
|
3367
|
+
if (compareSemver(installed, baseVersion) < 0) return false;
|
|
3368
|
+
if (inst[0] > base[0]) return false;
|
|
3369
|
+
return true;
|
|
3370
|
+
}
|
|
3371
|
+
function isRangeVersion(version) {
|
|
3372
|
+
return version.startsWith("^");
|
|
3373
|
+
}
|
|
3318
3374
|
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
3319
3375
|
const pkg2 = readPackageJson(cwd);
|
|
3320
3376
|
const allPackages = /* @__PURE__ */ new Set();
|
|
@@ -3367,12 +3423,37 @@ function upgradePackages(packages, version, cwd) {
|
|
|
3367
3423
|
});
|
|
3368
3424
|
}
|
|
3369
3425
|
}
|
|
3370
|
-
function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun) {
|
|
3426
|
+
function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode) {
|
|
3371
3427
|
const upgradePlan = [];
|
|
3372
3428
|
for (const pkg2 of packages) {
|
|
3373
3429
|
const version = grayscaleVersions.get(pkg2);
|
|
3374
3430
|
if (version) {
|
|
3375
|
-
|
|
3431
|
+
let current = "";
|
|
3432
|
+
try {
|
|
3433
|
+
const installedPkgPath = path9.join(cwd, "node_modules", pkg2, "package.json");
|
|
3434
|
+
const installedPkg = JSON.parse(fs11.readFileSync(installedPkgPath, "utf-8"));
|
|
3435
|
+
current = installedPkg.version || "";
|
|
3436
|
+
} catch {
|
|
3437
|
+
}
|
|
3438
|
+
if (mode === "destroy") {
|
|
3439
|
+
if (!isRangeVersion(version) && current === version) {
|
|
3440
|
+
console.log(`[fullstack-cli] ${pkg2}@${version} (already installed, skip)`);
|
|
3441
|
+
continue;
|
|
3442
|
+
}
|
|
3443
|
+
} else {
|
|
3444
|
+
if (isRangeVersion(version)) {
|
|
3445
|
+
if (current && satisfiesCaret(current, version)) {
|
|
3446
|
+
console.log(`[fullstack-cli] ${pkg2}@${current} satisfies ${version} (skip)`);
|
|
3447
|
+
continue;
|
|
3448
|
+
}
|
|
3449
|
+
} else {
|
|
3450
|
+
if (current === version) {
|
|
3451
|
+
console.log(`[fullstack-cli] ${pkg2}@${version} (already installed, skip)`);
|
|
3452
|
+
continue;
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
upgradePlan.push({ pkg: pkg2, version, current });
|
|
3376
3457
|
}
|
|
3377
3458
|
}
|
|
3378
3459
|
if (upgradePlan.length === 0) {
|
|
@@ -3380,23 +3461,21 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun) {
|
|
|
3380
3461
|
return;
|
|
3381
3462
|
}
|
|
3382
3463
|
console.log(`[fullstack-cli] Grayscale upgrade plan (${upgradePlan.length} package(s)):`);
|
|
3383
|
-
upgradePlan.forEach(({ pkg: pkg2, version }) => {
|
|
3384
|
-
console.log(` - ${pkg2} -> ${version}`);
|
|
3464
|
+
upgradePlan.forEach(({ pkg: pkg2, version, current }) => {
|
|
3465
|
+
console.log(` - ${pkg2} ${current} -> ${version}`);
|
|
3385
3466
|
});
|
|
3386
3467
|
if (dryRun) {
|
|
3387
3468
|
console.log("[fullstack-cli] Dry run mode, skipping actual installation");
|
|
3388
3469
|
return;
|
|
3389
3470
|
}
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
throw new Error(`Failed to install ${target}`);
|
|
3399
|
-
}
|
|
3471
|
+
const targets = upgradePlan.map(({ pkg: pkg2, version }) => `${pkg2}@${version}`);
|
|
3472
|
+
console.log(`[fullstack-cli] Installing ${targets.join(" ")}...`);
|
|
3473
|
+
const result = spawnSync3("npm", ["install", ...targets], {
|
|
3474
|
+
cwd,
|
|
3475
|
+
stdio: "inherit"
|
|
3476
|
+
});
|
|
3477
|
+
if (result.error || result.status !== 0) {
|
|
3478
|
+
console.warn(`[fullstack-cli] npm install failed`);
|
|
3400
3479
|
}
|
|
3401
3480
|
}
|
|
3402
3481
|
async function run4(options = {}) {
|
|
@@ -3417,16 +3496,24 @@ async function run4(options = {}) {
|
|
|
3417
3496
|
const grayscaleVersions = resolveGrayscaleVersions(cwd, options.grayscaleConfig);
|
|
3418
3497
|
if (grayscaleVersions) {
|
|
3419
3498
|
console.log("[fullstack-cli] Step 3/3: Applying grayscale versions...");
|
|
3420
|
-
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun);
|
|
3499
|
+
installGrayscaleVersions(packages, grayscaleVersions, cwd, !!options.dryRun, options.mode || "rebuild");
|
|
3421
3500
|
if (!options.dryRun) {
|
|
3422
3501
|
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s) via grayscale`);
|
|
3423
3502
|
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
3424
3503
|
}
|
|
3425
3504
|
return;
|
|
3426
3505
|
}
|
|
3506
|
+
if (options.grayscaleConfig) {
|
|
3507
|
+
console.log("[fullstack-cli] Grayscale config provided but not available, skip upgrade");
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3427
3510
|
console.log("[fullstack-cli] Grayscale not available, falling back to default upgrade");
|
|
3428
3511
|
} catch (error) {
|
|
3429
3512
|
const msg = error instanceof Error ? error.message : String(error);
|
|
3513
|
+
if (options.grayscaleConfig) {
|
|
3514
|
+
console.warn(`[fullstack-cli] Grayscale check failed: ${msg}, skip upgrade`);
|
|
3515
|
+
return;
|
|
3516
|
+
}
|
|
3430
3517
|
console.warn(`[fullstack-cli] Grayscale check failed: ${msg}, falling back to default upgrade`);
|
|
3431
3518
|
}
|
|
3432
3519
|
} else if (options.skipGrayscale) {
|
|
@@ -3455,7 +3542,7 @@ var depsCommand = {
|
|
|
3455
3542
|
name: "deps",
|
|
3456
3543
|
description: "Upgrade @lark-apaas dependencies",
|
|
3457
3544
|
register(parentCommand) {
|
|
3458
|
-
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) => {
|
|
3545
|
+
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) => {
|
|
3459
3546
|
await run4(options);
|
|
3460
3547
|
});
|
|
3461
3548
|
}
|
|
@@ -3474,8 +3561,8 @@ var upgradeCommand = {
|
|
|
3474
3561
|
};
|
|
3475
3562
|
|
|
3476
3563
|
// src/commands/action-plugin/utils.ts
|
|
3477
|
-
import
|
|
3478
|
-
import
|
|
3564
|
+
import fs12 from "fs";
|
|
3565
|
+
import path10 from "path";
|
|
3479
3566
|
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
3480
3567
|
function parsePluginName(input) {
|
|
3481
3568
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
@@ -3493,18 +3580,18 @@ function getProjectRoot() {
|
|
|
3493
3580
|
return process.cwd();
|
|
3494
3581
|
}
|
|
3495
3582
|
function getPackageJsonPath() {
|
|
3496
|
-
return
|
|
3583
|
+
return path10.join(getProjectRoot(), "package.json");
|
|
3497
3584
|
}
|
|
3498
3585
|
function getPluginPath(pluginName) {
|
|
3499
|
-
return
|
|
3586
|
+
return path10.join(getProjectRoot(), "node_modules", pluginName);
|
|
3500
3587
|
}
|
|
3501
3588
|
function readPackageJson2() {
|
|
3502
3589
|
const pkgPath = getPackageJsonPath();
|
|
3503
|
-
if (!
|
|
3590
|
+
if (!fs12.existsSync(pkgPath)) {
|
|
3504
3591
|
throw new Error("package.json not found in current directory");
|
|
3505
3592
|
}
|
|
3506
3593
|
try {
|
|
3507
|
-
const content =
|
|
3594
|
+
const content = fs12.readFileSync(pkgPath, "utf-8");
|
|
3508
3595
|
return JSON.parse(content);
|
|
3509
3596
|
} catch {
|
|
3510
3597
|
throw new Error("Failed to parse package.json");
|
|
@@ -3512,7 +3599,7 @@ function readPackageJson2() {
|
|
|
3512
3599
|
}
|
|
3513
3600
|
function writePackageJson2(pkg2) {
|
|
3514
3601
|
const pkgPath = getPackageJsonPath();
|
|
3515
|
-
|
|
3602
|
+
fs12.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3516
3603
|
}
|
|
3517
3604
|
function readActionPlugins() {
|
|
3518
3605
|
const pkg2 = readPackageJson2();
|
|
@@ -3545,12 +3632,12 @@ function npmInstall(tgzPath) {
|
|
|
3545
3632
|
}
|
|
3546
3633
|
}
|
|
3547
3634
|
function getPackageVersion(pluginName) {
|
|
3548
|
-
const pkgJsonPath =
|
|
3549
|
-
if (!
|
|
3635
|
+
const pkgJsonPath = path10.join(getPluginPath(pluginName), "package.json");
|
|
3636
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3550
3637
|
return null;
|
|
3551
3638
|
}
|
|
3552
3639
|
try {
|
|
3553
|
-
const content =
|
|
3640
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3554
3641
|
const pkg2 = JSON.parse(content);
|
|
3555
3642
|
return pkg2.version || null;
|
|
3556
3643
|
} catch {
|
|
@@ -3558,49 +3645,49 @@ function getPackageVersion(pluginName) {
|
|
|
3558
3645
|
}
|
|
3559
3646
|
}
|
|
3560
3647
|
function readPluginPackageJson(pluginPath) {
|
|
3561
|
-
const pkgJsonPath =
|
|
3562
|
-
if (!
|
|
3648
|
+
const pkgJsonPath = path10.join(pluginPath, "package.json");
|
|
3649
|
+
if (!fs12.existsSync(pkgJsonPath)) {
|
|
3563
3650
|
return null;
|
|
3564
3651
|
}
|
|
3565
3652
|
try {
|
|
3566
|
-
const content =
|
|
3653
|
+
const content = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
3567
3654
|
return JSON.parse(content);
|
|
3568
3655
|
} catch {
|
|
3569
3656
|
return null;
|
|
3570
3657
|
}
|
|
3571
3658
|
}
|
|
3572
3659
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
3573
|
-
const nodeModulesPath =
|
|
3574
|
-
const targetDir =
|
|
3575
|
-
const scopeDir =
|
|
3576
|
-
if (!
|
|
3577
|
-
|
|
3660
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3661
|
+
const targetDir = path10.join(nodeModulesPath, pluginName);
|
|
3662
|
+
const scopeDir = path10.dirname(targetDir);
|
|
3663
|
+
if (!fs12.existsSync(scopeDir)) {
|
|
3664
|
+
fs12.mkdirSync(scopeDir, { recursive: true });
|
|
3578
3665
|
}
|
|
3579
|
-
if (
|
|
3580
|
-
|
|
3666
|
+
if (fs12.existsSync(targetDir)) {
|
|
3667
|
+
fs12.rmSync(targetDir, { recursive: true });
|
|
3581
3668
|
}
|
|
3582
|
-
const tempDir =
|
|
3583
|
-
if (
|
|
3584
|
-
|
|
3669
|
+
const tempDir = path10.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3670
|
+
if (fs12.existsSync(tempDir)) {
|
|
3671
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3585
3672
|
}
|
|
3586
|
-
|
|
3673
|
+
fs12.mkdirSync(tempDir, { recursive: true });
|
|
3587
3674
|
try {
|
|
3588
3675
|
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3589
|
-
const extractedDir =
|
|
3590
|
-
if (
|
|
3591
|
-
|
|
3676
|
+
const extractedDir = path10.join(tempDir, "package");
|
|
3677
|
+
if (fs12.existsSync(extractedDir)) {
|
|
3678
|
+
fs12.renameSync(extractedDir, targetDir);
|
|
3592
3679
|
} else {
|
|
3593
|
-
const files =
|
|
3680
|
+
const files = fs12.readdirSync(tempDir);
|
|
3594
3681
|
if (files.length === 1) {
|
|
3595
|
-
|
|
3682
|
+
fs12.renameSync(path10.join(tempDir, files[0]), targetDir);
|
|
3596
3683
|
} else {
|
|
3597
3684
|
throw new Error("Unexpected tgz structure");
|
|
3598
3685
|
}
|
|
3599
3686
|
}
|
|
3600
3687
|
return targetDir;
|
|
3601
3688
|
} finally {
|
|
3602
|
-
if (
|
|
3603
|
-
|
|
3689
|
+
if (fs12.existsSync(tempDir)) {
|
|
3690
|
+
fs12.rmSync(tempDir, { recursive: true });
|
|
3604
3691
|
}
|
|
3605
3692
|
}
|
|
3606
3693
|
}
|
|
@@ -3609,10 +3696,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
3609
3696
|
return [];
|
|
3610
3697
|
}
|
|
3611
3698
|
const missing = [];
|
|
3612
|
-
const nodeModulesPath =
|
|
3699
|
+
const nodeModulesPath = path10.join(getProjectRoot(), "node_modules");
|
|
3613
3700
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
3614
|
-
const depPath =
|
|
3615
|
-
if (!
|
|
3701
|
+
const depPath = path10.join(nodeModulesPath, depName);
|
|
3702
|
+
if (!fs12.existsSync(depPath)) {
|
|
3616
3703
|
missing.push(depName);
|
|
3617
3704
|
}
|
|
3618
3705
|
}
|
|
@@ -3636,16 +3723,16 @@ function installMissingDeps(deps) {
|
|
|
3636
3723
|
}
|
|
3637
3724
|
function removePluginDirectory(pluginName) {
|
|
3638
3725
|
const pluginPath = getPluginPath(pluginName);
|
|
3639
|
-
if (
|
|
3640
|
-
|
|
3726
|
+
if (fs12.existsSync(pluginPath)) {
|
|
3727
|
+
fs12.rmSync(pluginPath, { recursive: true });
|
|
3641
3728
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
3642
3729
|
}
|
|
3643
3730
|
}
|
|
3644
3731
|
|
|
3645
3732
|
// src/commands/action-plugin/api-client.ts
|
|
3646
3733
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
3647
|
-
import
|
|
3648
|
-
import
|
|
3734
|
+
import fs13 from "fs";
|
|
3735
|
+
import path11 from "path";
|
|
3649
3736
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
3650
3737
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
3651
3738
|
const client = getHttpClient();
|
|
@@ -3709,19 +3796,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
3709
3796
|
return Buffer.from(arrayBuffer);
|
|
3710
3797
|
}
|
|
3711
3798
|
function getPluginCacheDir() {
|
|
3712
|
-
return
|
|
3799
|
+
return path11.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
3713
3800
|
}
|
|
3714
3801
|
function ensureCacheDir() {
|
|
3715
3802
|
const cacheDir = getPluginCacheDir();
|
|
3716
|
-
if (!
|
|
3717
|
-
|
|
3803
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3804
|
+
fs13.mkdirSync(cacheDir, { recursive: true });
|
|
3718
3805
|
}
|
|
3719
3806
|
}
|
|
3720
3807
|
function getTempFilePath(pluginKey, version) {
|
|
3721
3808
|
ensureCacheDir();
|
|
3722
3809
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3723
3810
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3724
|
-
return
|
|
3811
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3725
3812
|
}
|
|
3726
3813
|
var MAX_RETRIES = 2;
|
|
3727
3814
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -3758,7 +3845,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
3758
3845
|
);
|
|
3759
3846
|
}
|
|
3760
3847
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
3761
|
-
|
|
3848
|
+
fs13.writeFileSync(tgzPath, tgzBuffer);
|
|
3762
3849
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
3763
3850
|
return {
|
|
3764
3851
|
tgzPath,
|
|
@@ -3772,18 +3859,18 @@ function getCachePath(pluginKey, version) {
|
|
|
3772
3859
|
ensureCacheDir();
|
|
3773
3860
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3774
3861
|
const filename = `${safeKey}@${version}.tgz`;
|
|
3775
|
-
return
|
|
3862
|
+
return path11.join(getPluginCacheDir(), filename);
|
|
3776
3863
|
}
|
|
3777
3864
|
function hasCachedPlugin(pluginKey, version) {
|
|
3778
3865
|
const cachePath = getCachePath(pluginKey, version);
|
|
3779
|
-
return
|
|
3866
|
+
return fs13.existsSync(cachePath);
|
|
3780
3867
|
}
|
|
3781
3868
|
function listCachedPlugins() {
|
|
3782
3869
|
const cacheDir = getPluginCacheDir();
|
|
3783
|
-
if (!
|
|
3870
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3784
3871
|
return [];
|
|
3785
3872
|
}
|
|
3786
|
-
const files =
|
|
3873
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3787
3874
|
const result = [];
|
|
3788
3875
|
for (const file of files) {
|
|
3789
3876
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -3791,8 +3878,8 @@ function listCachedPlugins() {
|
|
|
3791
3878
|
if (!match) continue;
|
|
3792
3879
|
const [, rawName, version] = match;
|
|
3793
3880
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
3794
|
-
const filePath =
|
|
3795
|
-
const stat =
|
|
3881
|
+
const filePath = path11.join(cacheDir, file);
|
|
3882
|
+
const stat = fs13.statSync(filePath);
|
|
3796
3883
|
result.push({
|
|
3797
3884
|
name,
|
|
3798
3885
|
version,
|
|
@@ -3805,14 +3892,14 @@ function listCachedPlugins() {
|
|
|
3805
3892
|
}
|
|
3806
3893
|
function cleanAllCache() {
|
|
3807
3894
|
const cacheDir = getPluginCacheDir();
|
|
3808
|
-
if (!
|
|
3895
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3809
3896
|
return 0;
|
|
3810
3897
|
}
|
|
3811
|
-
const files =
|
|
3898
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3812
3899
|
let count = 0;
|
|
3813
3900
|
for (const file of files) {
|
|
3814
3901
|
if (file.endsWith(".tgz")) {
|
|
3815
|
-
|
|
3902
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3816
3903
|
count++;
|
|
3817
3904
|
}
|
|
3818
3905
|
}
|
|
@@ -3820,21 +3907,21 @@ function cleanAllCache() {
|
|
|
3820
3907
|
}
|
|
3821
3908
|
function cleanPluginCache(pluginKey, version) {
|
|
3822
3909
|
const cacheDir = getPluginCacheDir();
|
|
3823
|
-
if (!
|
|
3910
|
+
if (!fs13.existsSync(cacheDir)) {
|
|
3824
3911
|
return 0;
|
|
3825
3912
|
}
|
|
3826
3913
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
3827
|
-
const files =
|
|
3914
|
+
const files = fs13.readdirSync(cacheDir);
|
|
3828
3915
|
let count = 0;
|
|
3829
3916
|
for (const file of files) {
|
|
3830
3917
|
if (version) {
|
|
3831
3918
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
3832
|
-
|
|
3919
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3833
3920
|
count++;
|
|
3834
3921
|
}
|
|
3835
3922
|
} else {
|
|
3836
3923
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
3837
|
-
|
|
3924
|
+
fs13.unlinkSync(path11.join(cacheDir, file));
|
|
3838
3925
|
count++;
|
|
3839
3926
|
}
|
|
3840
3927
|
}
|
|
@@ -4261,40 +4348,40 @@ var actionPluginCommandGroup = {
|
|
|
4261
4348
|
};
|
|
4262
4349
|
|
|
4263
4350
|
// src/commands/capability/utils.ts
|
|
4264
|
-
import
|
|
4351
|
+
import fs14 from "fs";
|
|
4265
4352
|
import { createRequire as createRequire2 } from "module";
|
|
4266
|
-
import
|
|
4353
|
+
import path12 from "path";
|
|
4267
4354
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4268
4355
|
function getProjectRoot2() {
|
|
4269
4356
|
return process.cwd();
|
|
4270
4357
|
}
|
|
4271
4358
|
function getCapabilitiesDir() {
|
|
4272
|
-
return
|
|
4359
|
+
return path12.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
4273
4360
|
}
|
|
4274
4361
|
function getCapabilityPath(id) {
|
|
4275
|
-
return
|
|
4362
|
+
return path12.join(getCapabilitiesDir(), `${id}.json`);
|
|
4276
4363
|
}
|
|
4277
4364
|
function getPluginManifestPath(pluginKey) {
|
|
4278
|
-
return
|
|
4365
|
+
return path12.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
4279
4366
|
}
|
|
4280
4367
|
function capabilitiesDirExists() {
|
|
4281
|
-
return
|
|
4368
|
+
return fs14.existsSync(getCapabilitiesDir());
|
|
4282
4369
|
}
|
|
4283
4370
|
function listCapabilityIds() {
|
|
4284
4371
|
const dir = getCapabilitiesDir();
|
|
4285
|
-
if (!
|
|
4372
|
+
if (!fs14.existsSync(dir)) {
|
|
4286
4373
|
return [];
|
|
4287
4374
|
}
|
|
4288
|
-
const files =
|
|
4375
|
+
const files = fs14.readdirSync(dir);
|
|
4289
4376
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
4290
4377
|
}
|
|
4291
4378
|
function readCapability(id) {
|
|
4292
4379
|
const filePath = getCapabilityPath(id);
|
|
4293
|
-
if (!
|
|
4380
|
+
if (!fs14.existsSync(filePath)) {
|
|
4294
4381
|
throw new Error(`Capability not found: ${id}`);
|
|
4295
4382
|
}
|
|
4296
4383
|
try {
|
|
4297
|
-
const content =
|
|
4384
|
+
const content = fs14.readFileSync(filePath, "utf-8");
|
|
4298
4385
|
return JSON.parse(content);
|
|
4299
4386
|
} catch (error) {
|
|
4300
4387
|
if (error instanceof SyntaxError) {
|
|
@@ -4321,11 +4408,11 @@ function readAllCapabilities() {
|
|
|
4321
4408
|
}
|
|
4322
4409
|
function readPluginManifest(pluginKey) {
|
|
4323
4410
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
4324
|
-
if (!
|
|
4411
|
+
if (!fs14.existsSync(manifestPath)) {
|
|
4325
4412
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
4326
4413
|
}
|
|
4327
4414
|
try {
|
|
4328
|
-
const content =
|
|
4415
|
+
const content = fs14.readFileSync(manifestPath, "utf-8");
|
|
4329
4416
|
return JSON.parse(content);
|
|
4330
4417
|
} catch (error) {
|
|
4331
4418
|
if (error instanceof SyntaxError) {
|
|
@@ -4342,7 +4429,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
4342
4429
|
}
|
|
4343
4430
|
async function loadPlugin(pluginKey) {
|
|
4344
4431
|
try {
|
|
4345
|
-
const userRequire = createRequire2(
|
|
4432
|
+
const userRequire = createRequire2(path12.join(getProjectRoot2(), "package.json"));
|
|
4346
4433
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
4347
4434
|
const pluginModule = await import(resolvedPath);
|
|
4348
4435
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -4505,8 +4592,8 @@ var capabilityCommandGroup = {
|
|
|
4505
4592
|
import { execFile } from "child_process";
|
|
4506
4593
|
|
|
4507
4594
|
// src/commands/component/registry-preparer.ts
|
|
4508
|
-
import
|
|
4509
|
-
import
|
|
4595
|
+
import fs15 from "fs";
|
|
4596
|
+
import path13 from "path";
|
|
4510
4597
|
import os from "os";
|
|
4511
4598
|
|
|
4512
4599
|
// src/commands/component/service.ts
|
|
@@ -4562,7 +4649,7 @@ async function sendInstallEvent(key) {
|
|
|
4562
4649
|
}
|
|
4563
4650
|
|
|
4564
4651
|
// src/commands/component/registry-preparer.ts
|
|
4565
|
-
var REGISTRY_TEMP_DIR =
|
|
4652
|
+
var REGISTRY_TEMP_DIR = path13.join(os.tmpdir(), "miaoda-registry");
|
|
4566
4653
|
function parseComponentKey(key) {
|
|
4567
4654
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
4568
4655
|
if (!match) {
|
|
@@ -4574,11 +4661,11 @@ function parseComponentKey(key) {
|
|
|
4574
4661
|
}
|
|
4575
4662
|
function getLocalRegistryPath(key) {
|
|
4576
4663
|
const { scope, name } = parseComponentKey(key);
|
|
4577
|
-
return
|
|
4664
|
+
return path13.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
4578
4665
|
}
|
|
4579
4666
|
function ensureDir(dirPath) {
|
|
4580
|
-
if (!
|
|
4581
|
-
|
|
4667
|
+
if (!fs15.existsSync(dirPath)) {
|
|
4668
|
+
fs15.mkdirSync(dirPath, { recursive: true });
|
|
4582
4669
|
}
|
|
4583
4670
|
}
|
|
4584
4671
|
async function prepareRecursive(key, visited) {
|
|
@@ -4611,8 +4698,8 @@ async function prepareRecursive(key, visited) {
|
|
|
4611
4698
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
4612
4699
|
};
|
|
4613
4700
|
const localPath = getLocalRegistryPath(key);
|
|
4614
|
-
ensureDir(
|
|
4615
|
-
|
|
4701
|
+
ensureDir(path13.dirname(localPath));
|
|
4702
|
+
fs15.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
4616
4703
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
4617
4704
|
}
|
|
4618
4705
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -4622,18 +4709,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
4622
4709
|
}
|
|
4623
4710
|
function cleanupTempDir() {
|
|
4624
4711
|
try {
|
|
4625
|
-
if (
|
|
4626
|
-
|
|
4712
|
+
if (fs15.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4713
|
+
fs15.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
4627
4714
|
}
|
|
4628
4715
|
} catch {
|
|
4629
4716
|
}
|
|
4630
4717
|
}
|
|
4631
4718
|
function getDownloadedRegistryItem(itemId) {
|
|
4632
4719
|
const localPath = getLocalRegistryPath(itemId);
|
|
4633
|
-
if (!
|
|
4720
|
+
if (!fs15.existsSync(localPath)) {
|
|
4634
4721
|
return null;
|
|
4635
4722
|
}
|
|
4636
|
-
const content =
|
|
4723
|
+
const content = fs15.readFileSync(localPath, "utf-8");
|
|
4637
4724
|
return JSON.parse(content);
|
|
4638
4725
|
}
|
|
4639
4726
|
|
|
@@ -4801,58 +4888,58 @@ var componentCommandGroup = {
|
|
|
4801
4888
|
};
|
|
4802
4889
|
|
|
4803
4890
|
// src/commands/migration/version-manager.ts
|
|
4804
|
-
import
|
|
4805
|
-
import
|
|
4891
|
+
import fs16 from "fs";
|
|
4892
|
+
import path14 from "path";
|
|
4806
4893
|
var PACKAGE_JSON = "package.json";
|
|
4807
4894
|
var VERSION_FIELD = "migrationVersion";
|
|
4808
4895
|
function getPackageJsonPath2() {
|
|
4809
|
-
return
|
|
4896
|
+
return path14.join(process.cwd(), PACKAGE_JSON);
|
|
4810
4897
|
}
|
|
4811
4898
|
function getCurrentVersion() {
|
|
4812
4899
|
const pkgPath = getPackageJsonPath2();
|
|
4813
|
-
if (!
|
|
4900
|
+
if (!fs16.existsSync(pkgPath)) {
|
|
4814
4901
|
throw new Error("package.json not found");
|
|
4815
4902
|
}
|
|
4816
|
-
const pkg2 = JSON.parse(
|
|
4903
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4817
4904
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
4818
4905
|
}
|
|
4819
4906
|
function setCurrentVersion(version) {
|
|
4820
4907
|
const pkgPath = getPackageJsonPath2();
|
|
4821
|
-
const pkg2 = JSON.parse(
|
|
4908
|
+
const pkg2 = JSON.parse(fs16.readFileSync(pkgPath, "utf-8"));
|
|
4822
4909
|
pkg2[VERSION_FIELD] = version;
|
|
4823
|
-
|
|
4910
|
+
fs16.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4824
4911
|
}
|
|
4825
4912
|
|
|
4826
4913
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4827
|
-
import
|
|
4828
|
-
import
|
|
4914
|
+
import fs18 from "fs";
|
|
4915
|
+
import path16 from "path";
|
|
4829
4916
|
|
|
4830
4917
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
4831
|
-
import
|
|
4832
|
-
import
|
|
4918
|
+
import fs17 from "fs";
|
|
4919
|
+
import path15 from "path";
|
|
4833
4920
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
4834
4921
|
function getProjectRoot3() {
|
|
4835
4922
|
return process.cwd();
|
|
4836
4923
|
}
|
|
4837
4924
|
function getCapabilitiesDir2() {
|
|
4838
|
-
return
|
|
4925
|
+
return path15.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
4839
4926
|
}
|
|
4840
4927
|
function getPluginManifestPath2(pluginKey) {
|
|
4841
|
-
return
|
|
4928
|
+
return path15.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
4842
4929
|
}
|
|
4843
4930
|
|
|
4844
4931
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
4845
4932
|
function detectJsonMigration() {
|
|
4846
4933
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4847
|
-
const oldFilePath =
|
|
4848
|
-
if (!
|
|
4934
|
+
const oldFilePath = path16.join(capabilitiesDir, "capabilities.json");
|
|
4935
|
+
if (!fs18.existsSync(oldFilePath)) {
|
|
4849
4936
|
return {
|
|
4850
4937
|
needsMigration: false,
|
|
4851
4938
|
reason: "capabilities.json not found"
|
|
4852
4939
|
};
|
|
4853
4940
|
}
|
|
4854
4941
|
try {
|
|
4855
|
-
const content =
|
|
4942
|
+
const content = fs18.readFileSync(oldFilePath, "utf-8");
|
|
4856
4943
|
const parsed = JSON.parse(content);
|
|
4857
4944
|
if (!Array.isArray(parsed)) {
|
|
4858
4945
|
return {
|
|
@@ -4903,8 +4990,8 @@ async function check(options) {
|
|
|
4903
4990
|
}
|
|
4904
4991
|
|
|
4905
4992
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4906
|
-
import
|
|
4907
|
-
import
|
|
4993
|
+
import fs19 from "fs";
|
|
4994
|
+
import path17 from "path";
|
|
4908
4995
|
|
|
4909
4996
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
4910
4997
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5134,18 +5221,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5134
5221
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5135
5222
|
function loadExistingCapabilities() {
|
|
5136
5223
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5137
|
-
if (!
|
|
5224
|
+
if (!fs19.existsSync(capabilitiesDir)) {
|
|
5138
5225
|
return [];
|
|
5139
5226
|
}
|
|
5140
|
-
const files =
|
|
5227
|
+
const files = fs19.readdirSync(capabilitiesDir);
|
|
5141
5228
|
const capabilities = [];
|
|
5142
5229
|
for (const file of files) {
|
|
5143
5230
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5144
5231
|
continue;
|
|
5145
5232
|
}
|
|
5146
5233
|
try {
|
|
5147
|
-
const filePath =
|
|
5148
|
-
const content =
|
|
5234
|
+
const filePath = path17.join(capabilitiesDir, file);
|
|
5235
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
5149
5236
|
const capability = JSON.parse(content);
|
|
5150
5237
|
if (capability.id && capability.pluginKey) {
|
|
5151
5238
|
capabilities.push(capability);
|
|
@@ -5203,9 +5290,9 @@ async function migrateJsonFiles(options) {
|
|
|
5203
5290
|
}
|
|
5204
5291
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5205
5292
|
for (const cap of newCapabilities) {
|
|
5206
|
-
const filePath =
|
|
5293
|
+
const filePath = path17.join(capabilitiesDir, `${cap.id}.json`);
|
|
5207
5294
|
const content = JSON.stringify(cap, null, 2);
|
|
5208
|
-
|
|
5295
|
+
fs19.writeFileSync(filePath, content, "utf-8");
|
|
5209
5296
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5210
5297
|
}
|
|
5211
5298
|
return {
|
|
@@ -5217,11 +5304,11 @@ async function migrateJsonFiles(options) {
|
|
|
5217
5304
|
}
|
|
5218
5305
|
|
|
5219
5306
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5220
|
-
import
|
|
5307
|
+
import fs20 from "fs";
|
|
5221
5308
|
function isPluginInstalled2(pluginKey) {
|
|
5222
5309
|
const actionPlugins = readActionPlugins();
|
|
5223
5310
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5224
|
-
return
|
|
5311
|
+
return fs20.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5225
5312
|
}
|
|
5226
5313
|
function detectPluginsToInstall(capabilities) {
|
|
5227
5314
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5297,12 +5384,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5297
5384
|
}
|
|
5298
5385
|
|
|
5299
5386
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5300
|
-
import
|
|
5387
|
+
import path19 from "path";
|
|
5301
5388
|
import { Project as Project3 } from "ts-morph";
|
|
5302
5389
|
|
|
5303
5390
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5304
|
-
import
|
|
5305
|
-
import
|
|
5391
|
+
import fs21 from "fs";
|
|
5392
|
+
import path18 from "path";
|
|
5306
5393
|
var EXCLUDED_DIRS = [
|
|
5307
5394
|
"node_modules",
|
|
5308
5395
|
"dist",
|
|
@@ -5317,9 +5404,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5317
5404
|
/\.d\.ts$/
|
|
5318
5405
|
];
|
|
5319
5406
|
function scanDirectory(dir, files = []) {
|
|
5320
|
-
const entries =
|
|
5407
|
+
const entries = fs21.readdirSync(dir, { withFileTypes: true });
|
|
5321
5408
|
for (const entry of entries) {
|
|
5322
|
-
const fullPath =
|
|
5409
|
+
const fullPath = path18.join(dir, entry.name);
|
|
5323
5410
|
if (entry.isDirectory()) {
|
|
5324
5411
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5325
5412
|
continue;
|
|
@@ -5335,14 +5422,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5335
5422
|
return files;
|
|
5336
5423
|
}
|
|
5337
5424
|
function scanServerFiles() {
|
|
5338
|
-
const serverDir =
|
|
5339
|
-
if (!
|
|
5425
|
+
const serverDir = path18.join(getProjectRoot3(), "server");
|
|
5426
|
+
if (!fs21.existsSync(serverDir)) {
|
|
5340
5427
|
return [];
|
|
5341
5428
|
}
|
|
5342
5429
|
return scanDirectory(serverDir);
|
|
5343
5430
|
}
|
|
5344
5431
|
function hasCapabilityImport(filePath) {
|
|
5345
|
-
const content =
|
|
5432
|
+
const content = fs21.readFileSync(filePath, "utf-8");
|
|
5346
5433
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5347
5434
|
}
|
|
5348
5435
|
function scanFilesToMigrate() {
|
|
@@ -5719,7 +5806,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5719
5806
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
5720
5807
|
const classInfo = analyzeClass(sourceFile);
|
|
5721
5808
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
5722
|
-
const relativePath =
|
|
5809
|
+
const relativePath = path19.relative(getProjectRoot3(), filePath);
|
|
5723
5810
|
return {
|
|
5724
5811
|
filePath: relativePath,
|
|
5725
5812
|
imports,
|
|
@@ -5730,7 +5817,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
5730
5817
|
};
|
|
5731
5818
|
}
|
|
5732
5819
|
function migrateFile(project, analysis, dryRun) {
|
|
5733
|
-
const absolutePath =
|
|
5820
|
+
const absolutePath = path19.join(getProjectRoot3(), analysis.filePath);
|
|
5734
5821
|
if (!analysis.canAutoMigrate) {
|
|
5735
5822
|
return {
|
|
5736
5823
|
filePath: analysis.filePath,
|
|
@@ -5833,17 +5920,17 @@ function getSuggestion(analysis) {
|
|
|
5833
5920
|
}
|
|
5834
5921
|
|
|
5835
5922
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
5836
|
-
import
|
|
5837
|
-
import
|
|
5923
|
+
import fs22 from "fs";
|
|
5924
|
+
import path20 from "path";
|
|
5838
5925
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
5839
5926
|
const deletedFiles = [];
|
|
5840
5927
|
const errors = [];
|
|
5841
5928
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5842
|
-
const oldJsonPath =
|
|
5843
|
-
if (
|
|
5929
|
+
const oldJsonPath = path20.join(capabilitiesDir, "capabilities.json");
|
|
5930
|
+
if (fs22.existsSync(oldJsonPath)) {
|
|
5844
5931
|
try {
|
|
5845
5932
|
if (!dryRun) {
|
|
5846
|
-
|
|
5933
|
+
fs22.unlinkSync(oldJsonPath);
|
|
5847
5934
|
}
|
|
5848
5935
|
deletedFiles.push("capabilities.json");
|
|
5849
5936
|
} catch (error) {
|
|
@@ -5851,11 +5938,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5851
5938
|
}
|
|
5852
5939
|
}
|
|
5853
5940
|
for (const cap of capabilities) {
|
|
5854
|
-
const tsFilePath =
|
|
5855
|
-
if (
|
|
5941
|
+
const tsFilePath = path20.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5942
|
+
if (fs22.existsSync(tsFilePath)) {
|
|
5856
5943
|
try {
|
|
5857
5944
|
if (!dryRun) {
|
|
5858
|
-
|
|
5945
|
+
fs22.unlinkSync(tsFilePath);
|
|
5859
5946
|
}
|
|
5860
5947
|
deletedFiles.push(`${cap.id}.ts`);
|
|
5861
5948
|
} catch (error) {
|
|
@@ -5871,8 +5958,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
5871
5958
|
}
|
|
5872
5959
|
|
|
5873
5960
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
5874
|
-
import
|
|
5875
|
-
import
|
|
5961
|
+
import fs23 from "fs";
|
|
5962
|
+
import path21 from "path";
|
|
5876
5963
|
var REPORT_FILE = "capability-migration-report.md";
|
|
5877
5964
|
function printSummary(result) {
|
|
5878
5965
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6035,15 +6122,15 @@ async function generateReport(result) {
|
|
|
6035
6122
|
}
|
|
6036
6123
|
lines.push("");
|
|
6037
6124
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6038
|
-
if (!
|
|
6125
|
+
if (!fs23.existsSync(logDir)) {
|
|
6039
6126
|
return;
|
|
6040
6127
|
}
|
|
6041
|
-
const reportDir =
|
|
6042
|
-
if (!
|
|
6043
|
-
|
|
6128
|
+
const reportDir = path21.join(logDir, "migration");
|
|
6129
|
+
if (!fs23.existsSync(reportDir)) {
|
|
6130
|
+
fs23.mkdirSync(reportDir, { recursive: true });
|
|
6044
6131
|
}
|
|
6045
|
-
const reportPath =
|
|
6046
|
-
|
|
6132
|
+
const reportPath = path21.join(reportDir, REPORT_FILE);
|
|
6133
|
+
fs23.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6047
6134
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6048
6135
|
}
|
|
6049
6136
|
|
|
@@ -6575,10 +6662,10 @@ var migrationCommand = {
|
|
|
6575
6662
|
};
|
|
6576
6663
|
|
|
6577
6664
|
// src/commands/read-logs/index.ts
|
|
6578
|
-
import
|
|
6665
|
+
import path22 from "path";
|
|
6579
6666
|
|
|
6580
6667
|
// src/commands/read-logs/std-utils.ts
|
|
6581
|
-
import
|
|
6668
|
+
import fs24 from "fs";
|
|
6582
6669
|
function formatStdPrefixTime(localTime) {
|
|
6583
6670
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
6584
6671
|
if (!match) return localTime;
|
|
@@ -6608,11 +6695,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
6608
6695
|
return `[${time}] ${content}`;
|
|
6609
6696
|
}
|
|
6610
6697
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
6611
|
-
const stat =
|
|
6698
|
+
const stat = fs24.statSync(filePath);
|
|
6612
6699
|
if (stat.size === 0) {
|
|
6613
6700
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
6614
6701
|
}
|
|
6615
|
-
const fd =
|
|
6702
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6616
6703
|
const chunkSize = 64 * 1024;
|
|
6617
6704
|
let position = stat.size;
|
|
6618
6705
|
let remainder = "";
|
|
@@ -6626,7 +6713,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6626
6713
|
const length = Math.min(chunkSize, position);
|
|
6627
6714
|
position -= length;
|
|
6628
6715
|
const buffer = Buffer.alloc(length);
|
|
6629
|
-
|
|
6716
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6630
6717
|
let chunk = buffer.toString("utf8");
|
|
6631
6718
|
if (remainder) {
|
|
6632
6719
|
chunk += remainder;
|
|
@@ -6668,7 +6755,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
6668
6755
|
}
|
|
6669
6756
|
}
|
|
6670
6757
|
} finally {
|
|
6671
|
-
|
|
6758
|
+
fs24.closeSync(fd);
|
|
6672
6759
|
}
|
|
6673
6760
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
6674
6761
|
}
|
|
@@ -6689,21 +6776,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
6689
6776
|
}
|
|
6690
6777
|
|
|
6691
6778
|
// src/commands/read-logs/tail.ts
|
|
6692
|
-
import
|
|
6779
|
+
import fs25 from "fs";
|
|
6693
6780
|
function fileExists(filePath) {
|
|
6694
6781
|
try {
|
|
6695
|
-
|
|
6782
|
+
fs25.accessSync(filePath, fs25.constants.F_OK | fs25.constants.R_OK);
|
|
6696
6783
|
return true;
|
|
6697
6784
|
} catch {
|
|
6698
6785
|
return false;
|
|
6699
6786
|
}
|
|
6700
6787
|
}
|
|
6701
6788
|
function readFileTailLines(filePath, maxLines) {
|
|
6702
|
-
const stat =
|
|
6789
|
+
const stat = fs25.statSync(filePath);
|
|
6703
6790
|
if (stat.size === 0) {
|
|
6704
6791
|
return [];
|
|
6705
6792
|
}
|
|
6706
|
-
const fd =
|
|
6793
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6707
6794
|
const chunkSize = 64 * 1024;
|
|
6708
6795
|
const chunks = [];
|
|
6709
6796
|
let position = stat.size;
|
|
@@ -6713,13 +6800,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6713
6800
|
const length = Math.min(chunkSize, position);
|
|
6714
6801
|
position -= length;
|
|
6715
6802
|
const buffer = Buffer.alloc(length);
|
|
6716
|
-
|
|
6803
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6717
6804
|
chunks.unshift(buffer.toString("utf8"));
|
|
6718
6805
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
6719
6806
|
collectedLines += chunkLines;
|
|
6720
6807
|
}
|
|
6721
6808
|
} finally {
|
|
6722
|
-
|
|
6809
|
+
fs25.closeSync(fd);
|
|
6723
6810
|
}
|
|
6724
6811
|
const content = chunks.join("");
|
|
6725
6812
|
const allLines = content.split("\n");
|
|
@@ -6735,11 +6822,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
6735
6822
|
return allLines.slice(allLines.length - maxLines);
|
|
6736
6823
|
}
|
|
6737
6824
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
6738
|
-
const stat =
|
|
6825
|
+
const stat = fs25.statSync(filePath);
|
|
6739
6826
|
if (stat.size === 0) {
|
|
6740
6827
|
return { lines: [], totalLinesCount: 0 };
|
|
6741
6828
|
}
|
|
6742
|
-
const fd =
|
|
6829
|
+
const fd = fs25.openSync(filePath, "r");
|
|
6743
6830
|
const chunkSize = 64 * 1024;
|
|
6744
6831
|
let position = stat.size;
|
|
6745
6832
|
let remainder = "";
|
|
@@ -6751,7 +6838,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6751
6838
|
const length = Math.min(chunkSize, position);
|
|
6752
6839
|
position -= length;
|
|
6753
6840
|
const buffer = Buffer.alloc(length);
|
|
6754
|
-
|
|
6841
|
+
fs25.readSync(fd, buffer, 0, length, position);
|
|
6755
6842
|
let chunk = buffer.toString("utf8");
|
|
6756
6843
|
if (remainder) {
|
|
6757
6844
|
chunk += remainder;
|
|
@@ -6782,7 +6869,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
6782
6869
|
}
|
|
6783
6870
|
}
|
|
6784
6871
|
} finally {
|
|
6785
|
-
|
|
6872
|
+
fs25.closeSync(fd);
|
|
6786
6873
|
}
|
|
6787
6874
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6788
6875
|
}
|
|
@@ -6924,7 +7011,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
6924
7011
|
}
|
|
6925
7012
|
|
|
6926
7013
|
// src/commands/read-logs/json-lines.ts
|
|
6927
|
-
import
|
|
7014
|
+
import fs26 from "fs";
|
|
6928
7015
|
function normalizePid(value) {
|
|
6929
7016
|
if (typeof value === "number") {
|
|
6930
7017
|
return String(value);
|
|
@@ -6975,11 +7062,11 @@ function buildWantedLevelSet(levels) {
|
|
|
6975
7062
|
return set.size > 0 ? set : null;
|
|
6976
7063
|
}
|
|
6977
7064
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
6978
|
-
const stat =
|
|
7065
|
+
const stat = fs26.statSync(filePath);
|
|
6979
7066
|
if (stat.size === 0) {
|
|
6980
7067
|
return { lines: [], totalLinesCount: 0 };
|
|
6981
7068
|
}
|
|
6982
|
-
const fd =
|
|
7069
|
+
const fd = fs26.openSync(filePath, "r");
|
|
6983
7070
|
const chunkSize = 64 * 1024;
|
|
6984
7071
|
let position = stat.size;
|
|
6985
7072
|
let remainder = "";
|
|
@@ -6994,7 +7081,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6994
7081
|
const length = Math.min(chunkSize, position);
|
|
6995
7082
|
position -= length;
|
|
6996
7083
|
const buffer = Buffer.alloc(length);
|
|
6997
|
-
|
|
7084
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
6998
7085
|
let chunk = buffer.toString("utf8");
|
|
6999
7086
|
if (remainder) {
|
|
7000
7087
|
chunk += remainder;
|
|
@@ -7056,7 +7143,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7056
7143
|
}
|
|
7057
7144
|
}
|
|
7058
7145
|
} finally {
|
|
7059
|
-
|
|
7146
|
+
fs26.closeSync(fd);
|
|
7060
7147
|
}
|
|
7061
7148
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7062
7149
|
}
|
|
@@ -7099,11 +7186,11 @@ function extractTraceId(obj) {
|
|
|
7099
7186
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7100
7187
|
const wanted = traceId.trim();
|
|
7101
7188
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7102
|
-
const stat =
|
|
7189
|
+
const stat = fs26.statSync(filePath);
|
|
7103
7190
|
if (stat.size === 0) {
|
|
7104
7191
|
return { lines: [], totalLinesCount: 0 };
|
|
7105
7192
|
}
|
|
7106
|
-
const fd =
|
|
7193
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7107
7194
|
const chunkSize = 64 * 1024;
|
|
7108
7195
|
let position = stat.size;
|
|
7109
7196
|
let remainder = "";
|
|
@@ -7116,7 +7203,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7116
7203
|
const length = Math.min(chunkSize, position);
|
|
7117
7204
|
position -= length;
|
|
7118
7205
|
const buffer = Buffer.alloc(length);
|
|
7119
|
-
|
|
7206
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7120
7207
|
let chunk = buffer.toString("utf8");
|
|
7121
7208
|
if (remainder) {
|
|
7122
7209
|
chunk += remainder;
|
|
@@ -7169,7 +7256,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7169
7256
|
}
|
|
7170
7257
|
}
|
|
7171
7258
|
} finally {
|
|
7172
|
-
|
|
7259
|
+
fs26.closeSync(fd);
|
|
7173
7260
|
}
|
|
7174
7261
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7175
7262
|
}
|
|
@@ -7178,11 +7265,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7178
7265
|
if (!wantedLevelSet) {
|
|
7179
7266
|
return { lines: [], totalLinesCount: 0 };
|
|
7180
7267
|
}
|
|
7181
|
-
const stat =
|
|
7268
|
+
const stat = fs26.statSync(filePath);
|
|
7182
7269
|
if (stat.size === 0) {
|
|
7183
7270
|
return { lines: [], totalLinesCount: 0 };
|
|
7184
7271
|
}
|
|
7185
|
-
const fd =
|
|
7272
|
+
const fd = fs26.openSync(filePath, "r");
|
|
7186
7273
|
const chunkSize = 64 * 1024;
|
|
7187
7274
|
let position = stat.size;
|
|
7188
7275
|
let remainder = "";
|
|
@@ -7194,7 +7281,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7194
7281
|
const length = Math.min(chunkSize, position);
|
|
7195
7282
|
position -= length;
|
|
7196
7283
|
const buffer = Buffer.alloc(length);
|
|
7197
|
-
|
|
7284
|
+
fs26.readSync(fd, buffer, 0, length, position);
|
|
7198
7285
|
let chunk = buffer.toString("utf8");
|
|
7199
7286
|
if (remainder) {
|
|
7200
7287
|
chunk += remainder;
|
|
@@ -7241,7 +7328,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7241
7328
|
}
|
|
7242
7329
|
}
|
|
7243
7330
|
} finally {
|
|
7244
|
-
|
|
7331
|
+
fs26.closeSync(fd);
|
|
7245
7332
|
}
|
|
7246
7333
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7247
7334
|
}
|
|
@@ -7475,30 +7562,30 @@ async function readLogsJsonResult(options) {
|
|
|
7475
7562
|
};
|
|
7476
7563
|
}
|
|
7477
7564
|
function resolveLogFilePath(logDir, type) {
|
|
7478
|
-
const base =
|
|
7565
|
+
const base = path22.isAbsolute(logDir) ? logDir : path22.join(process.cwd(), logDir);
|
|
7479
7566
|
if (type === "server") {
|
|
7480
|
-
return
|
|
7567
|
+
return path22.join(base, "server.log");
|
|
7481
7568
|
}
|
|
7482
7569
|
if (type === "trace") {
|
|
7483
|
-
return
|
|
7570
|
+
return path22.join(base, "trace.log");
|
|
7484
7571
|
}
|
|
7485
7572
|
if (type === "server-std") {
|
|
7486
|
-
return
|
|
7573
|
+
return path22.join(base, "server.std.log");
|
|
7487
7574
|
}
|
|
7488
7575
|
if (type === "client-std") {
|
|
7489
|
-
return
|
|
7576
|
+
return path22.join(base, "client.std.log");
|
|
7490
7577
|
}
|
|
7491
7578
|
if (type === "dev") {
|
|
7492
|
-
return
|
|
7579
|
+
return path22.join(base, "dev.log");
|
|
7493
7580
|
}
|
|
7494
7581
|
if (type === "dev-std") {
|
|
7495
|
-
return
|
|
7582
|
+
return path22.join(base, "dev.std.log");
|
|
7496
7583
|
}
|
|
7497
7584
|
if (type === "install-dep-std") {
|
|
7498
|
-
return
|
|
7585
|
+
return path22.join(base, "install-dep.std.log");
|
|
7499
7586
|
}
|
|
7500
7587
|
if (type === "browser") {
|
|
7501
|
-
return
|
|
7588
|
+
return path22.join(base, "browser.log");
|
|
7502
7589
|
}
|
|
7503
7590
|
throw new Error(`Unsupported log type: ${type}`);
|
|
7504
7591
|
}
|
|
@@ -7675,9 +7762,9 @@ function camelToKebab(str) {
|
|
|
7675
7762
|
}
|
|
7676
7763
|
|
|
7677
7764
|
// src/commands/build/upload-static.handler.ts
|
|
7678
|
-
import * as
|
|
7765
|
+
import * as fs27 from "fs";
|
|
7679
7766
|
import * as os2 from "os";
|
|
7680
|
-
import * as
|
|
7767
|
+
import * as path23 from "path";
|
|
7681
7768
|
import { execFileSync } from "child_process";
|
|
7682
7769
|
function readCredentialsFromEnv() {
|
|
7683
7770
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -7701,8 +7788,8 @@ async function uploadStatic(options) {
|
|
|
7701
7788
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
7702
7789
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
7703
7790
|
} = options;
|
|
7704
|
-
const resolvedStaticDir =
|
|
7705
|
-
if (!
|
|
7791
|
+
const resolvedStaticDir = path23.resolve(staticDir);
|
|
7792
|
+
if (!fs27.existsSync(resolvedStaticDir)) {
|
|
7706
7793
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
7707
7794
|
return;
|
|
7708
7795
|
}
|
|
@@ -7735,8 +7822,8 @@ async function uploadStatic(options) {
|
|
|
7735
7822
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7736
7823
|
}
|
|
7737
7824
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7738
|
-
const confPath =
|
|
7739
|
-
|
|
7825
|
+
const confPath = path23.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7826
|
+
fs27.writeFileSync(confPath, "");
|
|
7740
7827
|
try {
|
|
7741
7828
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7742
7829
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -7750,7 +7837,7 @@ async function uploadStatic(options) {
|
|
|
7750
7837
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7751
7838
|
} finally {
|
|
7752
7839
|
try {
|
|
7753
|
-
|
|
7840
|
+
fs27.unlinkSync(confPath);
|
|
7754
7841
|
} catch {
|
|
7755
7842
|
}
|
|
7756
7843
|
}
|
|
@@ -7770,8 +7857,8 @@ async function uploadStatic(options) {
|
|
|
7770
7857
|
}
|
|
7771
7858
|
}
|
|
7772
7859
|
function resolveTosutilPath(tosutilPath) {
|
|
7773
|
-
if (
|
|
7774
|
-
return
|
|
7860
|
+
if (path23.isAbsolute(tosutilPath)) {
|
|
7861
|
+
return fs27.existsSync(tosutilPath) ? tosutilPath : null;
|
|
7775
7862
|
}
|
|
7776
7863
|
try {
|
|
7777
7864
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -7816,7 +7903,7 @@ async function resolveBucketId(appId) {
|
|
|
7816
7903
|
return bucketId;
|
|
7817
7904
|
}
|
|
7818
7905
|
function isDirEmpty(dirPath) {
|
|
7819
|
-
const entries =
|
|
7906
|
+
const entries = fs27.readdirSync(dirPath);
|
|
7820
7907
|
return entries.length === 0;
|
|
7821
7908
|
}
|
|
7822
7909
|
|
|
@@ -7911,12 +7998,12 @@ var commands = [
|
|
|
7911
7998
|
];
|
|
7912
7999
|
|
|
7913
8000
|
// src/index.ts
|
|
7914
|
-
var envPath =
|
|
7915
|
-
if (
|
|
8001
|
+
var envPath = path24.join(process.cwd(), ".env");
|
|
8002
|
+
if (fs28.existsSync(envPath)) {
|
|
7916
8003
|
dotenvConfig({ path: envPath });
|
|
7917
8004
|
}
|
|
7918
|
-
var __dirname =
|
|
7919
|
-
var pkg = JSON.parse(
|
|
8005
|
+
var __dirname = path24.dirname(fileURLToPath5(import.meta.url));
|
|
8006
|
+
var pkg = JSON.parse(fs28.readFileSync(path24.join(__dirname, "../package.json"), "utf-8"));
|
|
7920
8007
|
var cli = new FullstackCLI(pkg.version);
|
|
7921
8008
|
cli.useAll(commands);
|
|
7922
8009
|
cli.run();
|