@lark-apaas/fullstack-cli 1.1.24 → 1.1.26
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 +885 -233
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath as
|
|
2
|
+
import fs25 from "fs";
|
|
3
|
+
import path21 from "path";
|
|
4
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
@@ -1041,6 +1041,8 @@ async function fetchColumnComments(connectionString, options = {}) {
|
|
|
1041
1041
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
1042
1042
|
const url = new URL(connectionString);
|
|
1043
1043
|
const schemaName = url.searchParams.get("schema") ?? "public";
|
|
1044
|
+
const start = Date.now();
|
|
1045
|
+
console.log(`[fetchColumnComments] \u2192 Querying pg_description for schema=${schemaName} (timeout=${timeoutMs}ms)`);
|
|
1044
1046
|
const sql = postgres(connectionString, {
|
|
1045
1047
|
connect_timeout: Math.ceil(timeoutMs / 1e3),
|
|
1046
1048
|
idle_timeout: Math.ceil(timeoutMs / 1e3)
|
|
@@ -1069,6 +1071,7 @@ async function fetchColumnComments(connectionString, options = {}) {
|
|
|
1069
1071
|
const key = `${row.tableName}.${row.columnName}`;
|
|
1070
1072
|
commentMap.set(key, row.comment);
|
|
1071
1073
|
}
|
|
1074
|
+
console.log(`[fetchColumnComments] \u2190 Fetched ${commentMap.size} column comments (${Date.now() - start}ms)`);
|
|
1072
1075
|
return commentMap;
|
|
1073
1076
|
} finally {
|
|
1074
1077
|
await sql.end().catch(() => {
|
|
@@ -1167,6 +1170,79 @@ function addJsonbTypeComments(source, columnComments) {
|
|
|
1167
1170
|
return { text: result.join("\n"), added };
|
|
1168
1171
|
}
|
|
1169
1172
|
|
|
1173
|
+
// src/commands/db/gen-dbschema/transforms/text/synced-table-comments.ts
|
|
1174
|
+
var TABLE_COMMENT = "Synced table: data is auto-synced from external source. Do not rename or delete this table.";
|
|
1175
|
+
var FIELD_COMMENT = "Synced field: auto-synced, do not modify or delete";
|
|
1176
|
+
var TABLE_DEF_REGEX = /^(export const\s+\w+\s*=\s*(?:pgTable|pgView|pgMaterializedView)\(\s*["'`])([^"'`]+)(["'`])/;
|
|
1177
|
+
var FIELD_WITH_NAME_REGEX = /^\s*[\w"']+\s*:\s*\w+\(\s*["'`]([^"'`]+)["'`]/;
|
|
1178
|
+
var FIELD_PROP_NAME_REGEX = /^\s*([\w]+)\s*:/;
|
|
1179
|
+
function addSyncedTableComments(source, syncedTableMap) {
|
|
1180
|
+
if (!syncedTableMap || syncedTableMap.size === 0) {
|
|
1181
|
+
return { text: source, added: 0 };
|
|
1182
|
+
}
|
|
1183
|
+
const lines = source.split("\n");
|
|
1184
|
+
const result = [];
|
|
1185
|
+
let added = 0;
|
|
1186
|
+
let currentSyncedFields = null;
|
|
1187
|
+
let insideTableBody = false;
|
|
1188
|
+
let braceDepth = 0;
|
|
1189
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1190
|
+
const line = lines[i];
|
|
1191
|
+
const tableMatch = line.match(TABLE_DEF_REGEX);
|
|
1192
|
+
if (tableMatch) {
|
|
1193
|
+
const tableName = tableMatch[2];
|
|
1194
|
+
const syncedFields = syncedTableMap.get(tableName);
|
|
1195
|
+
if (syncedFields) {
|
|
1196
|
+
currentSyncedFields = syncedFields;
|
|
1197
|
+
insideTableBody = true;
|
|
1198
|
+
braceDepth = 0;
|
|
1199
|
+
const prevLine = result[result.length - 1]?.trim() ?? "";
|
|
1200
|
+
if (!prevLine.includes("Synced table")) {
|
|
1201
|
+
const indentMatch = line.match(/^\s*/);
|
|
1202
|
+
const indent = indentMatch ? indentMatch[0] : "";
|
|
1203
|
+
result.push(`${indent}// ${TABLE_COMMENT}`);
|
|
1204
|
+
added++;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
if (insideTableBody) {
|
|
1209
|
+
for (const ch of line) {
|
|
1210
|
+
if (ch === "{") braceDepth++;
|
|
1211
|
+
if (ch === "}") braceDepth--;
|
|
1212
|
+
}
|
|
1213
|
+
if (braceDepth <= 0) {
|
|
1214
|
+
insideTableBody = false;
|
|
1215
|
+
currentSyncedFields = null;
|
|
1216
|
+
}
|
|
1217
|
+
if (currentSyncedFields && braceDepth >= 1 && !tableMatch) {
|
|
1218
|
+
const columnName = extractColumnName2(line);
|
|
1219
|
+
if (columnName && currentSyncedFields.has(columnName)) {
|
|
1220
|
+
const prevLine = result[result.length - 1]?.trim() ?? "";
|
|
1221
|
+
if (!prevLine.includes("Synced field")) {
|
|
1222
|
+
const indentMatch = line.match(/^\s*/);
|
|
1223
|
+
const indent = indentMatch ? indentMatch[0] : "";
|
|
1224
|
+
result.push(`${indent}// ${FIELD_COMMENT}`);
|
|
1225
|
+
added++;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
result.push(line);
|
|
1231
|
+
}
|
|
1232
|
+
return { text: result.join("\n"), added };
|
|
1233
|
+
}
|
|
1234
|
+
function extractColumnName2(line) {
|
|
1235
|
+
const withNameMatch = line.match(FIELD_WITH_NAME_REGEX);
|
|
1236
|
+
if (withNameMatch) {
|
|
1237
|
+
return withNameMatch[1];
|
|
1238
|
+
}
|
|
1239
|
+
const propMatch = line.match(FIELD_PROP_NAME_REGEX);
|
|
1240
|
+
if (propMatch) {
|
|
1241
|
+
return propMatch[1];
|
|
1242
|
+
}
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1170
1246
|
// src/commands/db/gen-dbschema/transforms/text/table-aliases.ts
|
|
1171
1247
|
var TABLE_ALIAS_MARKER = "// table aliases";
|
|
1172
1248
|
function generateTableAliases(source) {
|
|
@@ -1215,13 +1291,16 @@ function postprocessSchema(rawSource, options = {}) {
|
|
|
1215
1291
|
source = inlineCustomTypes(source);
|
|
1216
1292
|
const jsonbCommentsResult = addJsonbTypeComments(source, options.columnComments);
|
|
1217
1293
|
source = jsonbCommentsResult.text;
|
|
1294
|
+
const syncedCommentsResult = addSyncedTableComments(source, options.syncedTableMap);
|
|
1295
|
+
source = syncedCommentsResult.text;
|
|
1218
1296
|
source = generateTableAliases(source);
|
|
1219
1297
|
source = formatSource(source);
|
|
1220
1298
|
return {
|
|
1221
1299
|
source,
|
|
1222
1300
|
astStats,
|
|
1223
1301
|
patchedDefects: patchResult.fixed,
|
|
1224
|
-
addedJsonbComments: jsonbCommentsResult.added
|
|
1302
|
+
addedJsonbComments: jsonbCommentsResult.added,
|
|
1303
|
+
addedSyncedComments: syncedCommentsResult.added
|
|
1225
1304
|
};
|
|
1226
1305
|
}
|
|
1227
1306
|
function logStats(result, prefix = "[postprocess]") {
|
|
@@ -1271,6 +1350,9 @@ function logStats(result, prefix = "[postprocess]") {
|
|
|
1271
1350
|
if (result.addedJsonbComments > 0) {
|
|
1272
1351
|
console.info(`${prefix} Added ${result.addedJsonbComments} JSDoc comments for jsonb fields`);
|
|
1273
1352
|
}
|
|
1353
|
+
if (result.addedSyncedComments > 0) {
|
|
1354
|
+
console.info(`${prefix} Added ${result.addedSyncedComments} comments for synced tables/fields`);
|
|
1355
|
+
}
|
|
1274
1356
|
}
|
|
1275
1357
|
|
|
1276
1358
|
// src/commands/db/gen-dbschema/index.ts
|
|
@@ -1281,7 +1363,10 @@ async function postprocessDrizzleSchema(targetPath, options = {}) {
|
|
|
1281
1363
|
return void 0;
|
|
1282
1364
|
}
|
|
1283
1365
|
const rawSource = fs3.readFileSync(resolvedPath, "utf8");
|
|
1284
|
-
const result = postprocessSchema(rawSource, {
|
|
1366
|
+
const result = postprocessSchema(rawSource, {
|
|
1367
|
+
columnComments: options.columnComments,
|
|
1368
|
+
syncedTableMap: options.syncedTableMap
|
|
1369
|
+
});
|
|
1285
1370
|
fs3.writeFileSync(resolvedPath, result.source, "utf8");
|
|
1286
1371
|
logStats(result, "[postprocess-drizzle-schema]");
|
|
1287
1372
|
return {
|
|
@@ -1291,10 +1376,112 @@ async function postprocessDrizzleSchema(targetPath, options = {}) {
|
|
|
1291
1376
|
patchedDefects: result.patchedDefects,
|
|
1292
1377
|
replacedTimestamps: result.astStats.replacedTimestamp,
|
|
1293
1378
|
replacedDefaultNow: result.astStats.replacedDefaultNow,
|
|
1294
|
-
addedJsonbComments: result.addedJsonbComments
|
|
1379
|
+
addedJsonbComments: result.addedJsonbComments,
|
|
1380
|
+
addedSyncedComments: result.addedSyncedComments
|
|
1295
1381
|
};
|
|
1296
1382
|
}
|
|
1297
1383
|
|
|
1384
|
+
// src/utils/http-client.ts
|
|
1385
|
+
import { HttpClient } from "@lark-apaas/http-client";
|
|
1386
|
+
var clientInstance = null;
|
|
1387
|
+
function getHttpClient() {
|
|
1388
|
+
if (!clientInstance) {
|
|
1389
|
+
clientInstance = new HttpClient({
|
|
1390
|
+
timeout: 3e4,
|
|
1391
|
+
platform: {
|
|
1392
|
+
enabled: true
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
|
|
1396
|
+
if (canaryEnv) {
|
|
1397
|
+
clientInstance.interceptors.request.use((req) => {
|
|
1398
|
+
req.headers["x-tt-env"] = canaryEnv;
|
|
1399
|
+
return req;
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
return clientInstance;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/commands/db/gen-dbschema/utils/fetch-synced-tables.ts
|
|
1407
|
+
var DEFAULT_TIMEOUT_MS2 = 1e4;
|
|
1408
|
+
async function fetchSyncedTables(appId, workspace) {
|
|
1409
|
+
try {
|
|
1410
|
+
const client = getHttpClient();
|
|
1411
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1412
|
+
setTimeout(
|
|
1413
|
+
() => reject(new Error(`Timeout after ${DEFAULT_TIMEOUT_MS2}ms`)),
|
|
1414
|
+
DEFAULT_TIMEOUT_MS2
|
|
1415
|
+
);
|
|
1416
|
+
});
|
|
1417
|
+
const start = Date.now();
|
|
1418
|
+
console.log(
|
|
1419
|
+
`[fetchSyncedTables] \u2192 GET listTableView (dbBranch=main) appId=${appId ? "set" : "unset"} workspace=${workspace ? "set" : "unset"}`
|
|
1420
|
+
);
|
|
1421
|
+
const response = await Promise.race([
|
|
1422
|
+
client.get(
|
|
1423
|
+
`/api/v1/dataloom/inner/app/${appId}/workspaces/${workspace}/listTableView`,
|
|
1424
|
+
{ params: { dbBranch: "main" }, headers: { "x-supaas-bizsource": "miaoda" } }
|
|
1425
|
+
),
|
|
1426
|
+
timeoutPromise
|
|
1427
|
+
]);
|
|
1428
|
+
console.log(
|
|
1429
|
+
`[fetchSyncedTables] \u2190 listTableView response: ${response.status} ${response.statusText} (${Date.now() - start}ms) with logId=${response.headers.get("x-tt-logid")}`
|
|
1430
|
+
);
|
|
1431
|
+
if (!response.ok) {
|
|
1432
|
+
throw new Error(
|
|
1433
|
+
`listTableView API failed: ${response.status} ${response.statusText}`
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
let json;
|
|
1437
|
+
try {
|
|
1438
|
+
json = await response.json();
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
console.warn(
|
|
1441
|
+
"[fetchSyncedTables] \u26A0 Failed to parse listTableView response JSON, returning empty map:",
|
|
1442
|
+
error instanceof Error ? error.message : String(error)
|
|
1443
|
+
);
|
|
1444
|
+
return /* @__PURE__ */ new Map();
|
|
1445
|
+
}
|
|
1446
|
+
const tableView = json?.data?.data;
|
|
1447
|
+
if (!tableView) {
|
|
1448
|
+
console.warn(
|
|
1449
|
+
"[fetchSyncedTables] \u26A0 listTableView response missing data.data, returning empty map"
|
|
1450
|
+
);
|
|
1451
|
+
return /* @__PURE__ */ new Map();
|
|
1452
|
+
}
|
|
1453
|
+
const syncedMap = extractSyncedTableMap(tableView);
|
|
1454
|
+
const totalCount = (tableView.table?.data?.length ?? 0) + (tableView.view?.data?.length ?? 0) + (tableView.materializedView?.data?.length ?? 0);
|
|
1455
|
+
console.log(
|
|
1456
|
+
`[fetchSyncedTables] \u2713 Extracted synced tables: ${syncedMap.size}/${totalCount} (elapsed ${Date.now() - start}ms)`
|
|
1457
|
+
);
|
|
1458
|
+
return syncedMap;
|
|
1459
|
+
} catch (error) {
|
|
1460
|
+
console.error(
|
|
1461
|
+
"[fetchSyncedTables] \u274C Error fetching synced tables:",
|
|
1462
|
+
error
|
|
1463
|
+
);
|
|
1464
|
+
return /* @__PURE__ */ new Map();
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
function extractSyncedTableMap(tableView) {
|
|
1468
|
+
const syncedMap = /* @__PURE__ */ new Map();
|
|
1469
|
+
const allTables = [
|
|
1470
|
+
...tableView.table?.data ?? [],
|
|
1471
|
+
...tableView.view?.data ?? [],
|
|
1472
|
+
...tableView.materializedView?.data ?? []
|
|
1473
|
+
];
|
|
1474
|
+
for (const table of allTables) {
|
|
1475
|
+
if (table.bitableSyncTask && table.bitableSyncTask.fieldApiNameList?.length > 0) {
|
|
1476
|
+
syncedMap.set(
|
|
1477
|
+
table.tableName,
|
|
1478
|
+
new Set(table.bitableSyncTask.fieldApiNameList)
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return syncedMap;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1298
1485
|
// src/commands/db/gen-nest-resource/generator.ts
|
|
1299
1486
|
import { pluralize } from "inflection";
|
|
1300
1487
|
|
|
@@ -1973,7 +2160,9 @@ async function run(options = {}) {
|
|
|
1973
2160
|
}
|
|
1974
2161
|
const databaseUrl = process.env.SUDA_DATABASE_URL;
|
|
1975
2162
|
if (!databaseUrl) {
|
|
1976
|
-
console.error(
|
|
2163
|
+
console.error(
|
|
2164
|
+
"[gen-db-schema] Error: SUDA_DATABASE_URL environment variable is required"
|
|
2165
|
+
);
|
|
1977
2166
|
process.exit(1);
|
|
1978
2167
|
}
|
|
1979
2168
|
const outputPath = options.output || process.env.DB_SCHEMA_OUTPUT || "server/database/schema.ts";
|
|
@@ -1988,9 +2177,14 @@ async function run(options = {}) {
|
|
|
1988
2177
|
path2.resolve(__dirname2, "../../../dist/config/drizzle.config.js")
|
|
1989
2178
|
];
|
|
1990
2179
|
const configPath = configPathCandidates.find((p) => fs4.existsSync(p));
|
|
1991
|
-
console.log(
|
|
2180
|
+
console.log(
|
|
2181
|
+
"[gen-db-schema] Using drizzle config from:",
|
|
2182
|
+
configPath ?? "(not found)"
|
|
2183
|
+
);
|
|
1992
2184
|
if (!configPath) {
|
|
1993
|
-
console.error(
|
|
2185
|
+
console.error(
|
|
2186
|
+
"[gen-db-schema] Error: drizzle config not found in CLI package"
|
|
2187
|
+
);
|
|
1994
2188
|
process.exit(1);
|
|
1995
2189
|
}
|
|
1996
2190
|
const resolveDrizzleKitBin = () => {
|
|
@@ -2006,7 +2200,9 @@ async function run(options = {}) {
|
|
|
2006
2200
|
const binField = pkgJson.bin;
|
|
2007
2201
|
const binRelPath = typeof binField === "string" ? binField : binField?.["drizzle-kit"];
|
|
2008
2202
|
if (!binRelPath) {
|
|
2009
|
-
throw new Error(
|
|
2203
|
+
throw new Error(
|
|
2204
|
+
"Unable to resolve drizzle-kit binary from package.json"
|
|
2205
|
+
);
|
|
2010
2206
|
}
|
|
2011
2207
|
return path2.resolve(currentDir, binRelPath);
|
|
2012
2208
|
}
|
|
@@ -2017,15 +2213,66 @@ async function run(options = {}) {
|
|
|
2017
2213
|
throw new Error("Unable to locate drizzle-kit package root");
|
|
2018
2214
|
};
|
|
2019
2215
|
let columnComments;
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2216
|
+
let syncedTableMap;
|
|
2217
|
+
const appId = process.env.app_id;
|
|
2218
|
+
const workspace = process.env.suda_workspace_id;
|
|
2219
|
+
console.log(
|
|
2220
|
+
`[gen-db-schema] Pre-fetch info: columnComments=enabled, syncedTables=${appId && workspace ? "enabled" : "skipped"} (app_id=${appId ? "set" : "unset"}, suda_workspace_id=${workspace ? "set" : "unset"})`
|
|
2221
|
+
);
|
|
2222
|
+
const columnCommentsTask = (async () => {
|
|
2223
|
+
const start = Date.now();
|
|
2224
|
+
console.log("[gen-db-schema] \u2192 Fetching column comments...");
|
|
2225
|
+
const res = await fetchColumnComments(databaseUrl, { timeoutMs: 1e4 });
|
|
2226
|
+
console.log(
|
|
2227
|
+
`[gen-db-schema] \u2190 Fetched column comments: ${res.size} items (${Date.now() - start}ms)`
|
|
2228
|
+
);
|
|
2229
|
+
return res;
|
|
2230
|
+
})();
|
|
2231
|
+
const syncedTablesTask = appId && workspace ? (async () => {
|
|
2232
|
+
const start = Date.now();
|
|
2233
|
+
console.log(
|
|
2234
|
+
"[gen-db-schema] \u2192 Fetching synced tables from listTableView..."
|
|
2235
|
+
);
|
|
2236
|
+
const res = await fetchSyncedTables(appId, workspace);
|
|
2237
|
+
console.log(
|
|
2238
|
+
`[gen-db-schema] \u2190 Fetched synced tables: ${res.size} tables (${Date.now() - start}ms)`
|
|
2239
|
+
);
|
|
2240
|
+
return res;
|
|
2241
|
+
})() : void 0;
|
|
2242
|
+
const fetchTasks = await Promise.allSettled([
|
|
2243
|
+
columnCommentsTask,
|
|
2244
|
+
...syncedTablesTask ? [syncedTablesTask] : []
|
|
2245
|
+
]);
|
|
2246
|
+
if (fetchTasks[0].status === "fulfilled") {
|
|
2247
|
+
columnComments = fetchTasks[0].value;
|
|
2248
|
+
console.log(
|
|
2249
|
+
`[gen-db-schema] \u2713 Column comments ready: ${columnComments.size}`
|
|
2250
|
+
);
|
|
2251
|
+
} else {
|
|
2024
2252
|
console.warn(
|
|
2025
2253
|
"[gen-db-schema] \u26A0 Failed to fetch column comments (skipping):",
|
|
2026
|
-
|
|
2254
|
+
fetchTasks[0].reason instanceof Error ? fetchTasks[0].reason.message : String(fetchTasks[0].reason)
|
|
2027
2255
|
);
|
|
2028
2256
|
}
|
|
2257
|
+
if (appId && workspace) {
|
|
2258
|
+
if (fetchTasks[1]?.status === "fulfilled") {
|
|
2259
|
+
syncedTableMap = fetchTasks[1].value;
|
|
2260
|
+
console.log(
|
|
2261
|
+
`[gen-db-schema] \u2713 Synced tables ready: ${syncedTableMap.size}`
|
|
2262
|
+
);
|
|
2263
|
+
} else if (fetchTasks[1]?.status === "rejected") {
|
|
2264
|
+
console.warn(
|
|
2265
|
+
"[gen-db-schema] \u26A0 Failed to fetch synced tables (skipping):",
|
|
2266
|
+
fetchTasks[1].reason instanceof Error ? fetchTasks[1].reason.message : String(fetchTasks[1].reason)
|
|
2267
|
+
);
|
|
2268
|
+
syncedTableMap = /* @__PURE__ */ new Map();
|
|
2269
|
+
}
|
|
2270
|
+
} else {
|
|
2271
|
+
console.info(
|
|
2272
|
+
"[gen-db-schema] \u2139 Skipping synced table detection (app_id or suda_workspace_id not set)"
|
|
2273
|
+
);
|
|
2274
|
+
syncedTableMap = /* @__PURE__ */ new Map();
|
|
2275
|
+
}
|
|
2029
2276
|
try {
|
|
2030
2277
|
const env = {
|
|
2031
2278
|
...process.env,
|
|
@@ -2036,13 +2283,19 @@ async function run(options = {}) {
|
|
|
2036
2283
|
};
|
|
2037
2284
|
const drizzleKitBin = resolveDrizzleKitBin();
|
|
2038
2285
|
const spawnArgs = [drizzleKitBin, "introspect", "--config", configPath];
|
|
2039
|
-
const result = spawnSync(process.execPath, spawnArgs, {
|
|
2286
|
+
const result = spawnSync(process.execPath, spawnArgs, {
|
|
2287
|
+
stdio: "inherit",
|
|
2288
|
+
env,
|
|
2289
|
+
cwd: process.cwd()
|
|
2290
|
+
});
|
|
2040
2291
|
if (result.error) {
|
|
2041
2292
|
console.error("[gen-db-schema] Execution failed:", result.error);
|
|
2042
2293
|
throw result.error;
|
|
2043
2294
|
}
|
|
2044
2295
|
if ((result.status ?? 0) !== 0) {
|
|
2045
|
-
throw new Error(
|
|
2296
|
+
throw new Error(
|
|
2297
|
+
`drizzle-kit introspect failed with status ${result.status}`
|
|
2298
|
+
);
|
|
2046
2299
|
}
|
|
2047
2300
|
const generatedSchema = path2.join(OUT_DIR, "schema.ts");
|
|
2048
2301
|
if (!fs4.existsSync(generatedSchema)) {
|
|
@@ -2050,10 +2303,14 @@ async function run(options = {}) {
|
|
|
2050
2303
|
throw new Error("drizzle-kit introspect failed to generate schema.ts");
|
|
2051
2304
|
}
|
|
2052
2305
|
const stats = await postprocessDrizzleSchema(generatedSchema, {
|
|
2053
|
-
columnComments
|
|
2306
|
+
columnComments,
|
|
2307
|
+
syncedTableMap
|
|
2054
2308
|
});
|
|
2055
2309
|
if (stats?.unmatchedUnknown?.length) {
|
|
2056
|
-
console.warn(
|
|
2310
|
+
console.warn(
|
|
2311
|
+
"[gen-db-schema] Unmatched custom types detected:",
|
|
2312
|
+
stats.unmatchedUnknown
|
|
2313
|
+
);
|
|
2057
2314
|
}
|
|
2058
2315
|
console.log("[gen-db-schema] \u2713 Postprocessed schema");
|
|
2059
2316
|
fs4.mkdirSync(path2.dirname(SCHEMA_FILE), { recursive: true });
|
|
@@ -2068,14 +2325,22 @@ async function run(options = {}) {
|
|
|
2068
2325
|
schemaFilePath,
|
|
2069
2326
|
moduleOutputDir: path2.resolve(process.cwd(), "server/modules")
|
|
2070
2327
|
});
|
|
2071
|
-
console.log(
|
|
2328
|
+
console.log(
|
|
2329
|
+
"[gen-db-schema] \u2713 Generate NestJS Module Boilerplate Successfully"
|
|
2330
|
+
);
|
|
2072
2331
|
}
|
|
2073
2332
|
} catch (error) {
|
|
2074
|
-
console.warn(
|
|
2333
|
+
console.warn(
|
|
2334
|
+
"[gen-db-schema] Generate NestJS Module Boilerplate failed:",
|
|
2335
|
+
error instanceof Error ? error.message : String(error)
|
|
2336
|
+
);
|
|
2075
2337
|
}
|
|
2076
2338
|
console.log("[gen-db-schema] \u2713 Complete");
|
|
2077
2339
|
} catch (err) {
|
|
2078
|
-
console.error(
|
|
2340
|
+
console.error(
|
|
2341
|
+
"[gen-db-schema] Failed:",
|
|
2342
|
+
err instanceof Error ? err.message : String(err)
|
|
2343
|
+
);
|
|
2079
2344
|
exitCode = 1;
|
|
2080
2345
|
} finally {
|
|
2081
2346
|
if (fs4.existsSync(OUT_DIR)) {
|
|
@@ -2419,10 +2684,398 @@ var syncCommand = {
|
|
|
2419
2684
|
}
|
|
2420
2685
|
};
|
|
2421
2686
|
|
|
2422
|
-
// src/
|
|
2687
|
+
// src/utils/telemetry.ts
|
|
2688
|
+
async function reportEvents(events) {
|
|
2689
|
+
if (events.length === 0) {
|
|
2690
|
+
return true;
|
|
2691
|
+
}
|
|
2692
|
+
try {
|
|
2693
|
+
const client = getHttpClient();
|
|
2694
|
+
const response = await client.post("/api/v1/studio/innerapi/resource_events", { events });
|
|
2695
|
+
if (!response.ok) {
|
|
2696
|
+
console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
const result = await response.json();
|
|
2700
|
+
if (result.status_code !== "0") {
|
|
2701
|
+
console.warn(`[telemetry] API error: ${result.message}`);
|
|
2702
|
+
return false;
|
|
2703
|
+
}
|
|
2704
|
+
return true;
|
|
2705
|
+
} catch (error) {
|
|
2706
|
+
console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
|
|
2707
|
+
return false;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
async function reportInstallEvent(pluginKey, version) {
|
|
2711
|
+
await reportEvents([
|
|
2712
|
+
{
|
|
2713
|
+
resourceType: "plugin",
|
|
2714
|
+
resourceKey: pluginKey,
|
|
2715
|
+
eventType: "install",
|
|
2716
|
+
details: { version }
|
|
2717
|
+
}
|
|
2718
|
+
]);
|
|
2719
|
+
}
|
|
2720
|
+
async function reportCreateInstanceEvent(pluginKey, version) {
|
|
2721
|
+
await reportEvents([
|
|
2722
|
+
{
|
|
2723
|
+
resourceType: "plugin",
|
|
2724
|
+
resourceKey: pluginKey,
|
|
2725
|
+
eventType: "create_instance",
|
|
2726
|
+
details: { version }
|
|
2727
|
+
}
|
|
2728
|
+
]);
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
// src/utils/git.ts
|
|
2732
|
+
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2423
2733
|
import fs7 from "fs";
|
|
2424
2734
|
import path5 from "path";
|
|
2425
|
-
|
|
2735
|
+
function isGitRepository(cwd = process.cwd()) {
|
|
2736
|
+
try {
|
|
2737
|
+
const gitDir = path5.join(cwd, ".git");
|
|
2738
|
+
if (fs7.existsSync(gitDir)) {
|
|
2739
|
+
return true;
|
|
2740
|
+
}
|
|
2741
|
+
const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
|
|
2742
|
+
cwd,
|
|
2743
|
+
stdio: "pipe",
|
|
2744
|
+
encoding: "utf-8"
|
|
2745
|
+
});
|
|
2746
|
+
return result.status === 0;
|
|
2747
|
+
} catch {
|
|
2748
|
+
return false;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
function getChangedFiles(cwd = process.cwd()) {
|
|
2752
|
+
try {
|
|
2753
|
+
const output = execSync("git status --porcelain", {
|
|
2754
|
+
cwd,
|
|
2755
|
+
stdio: "pipe",
|
|
2756
|
+
encoding: "utf-8"
|
|
2757
|
+
});
|
|
2758
|
+
return output.split("\n").filter((line) => line.trim()).map((line) => line.substring(3));
|
|
2759
|
+
} catch (error) {
|
|
2760
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2761
|
+
throw new Error(`Failed to get changed files: ${message}`);
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
2765
|
+
const filteredFiles = [];
|
|
2766
|
+
for (const filePath of filesToStage) {
|
|
2767
|
+
if (fs7.existsSync(path5.join(cwd, filePath))) {
|
|
2768
|
+
filteredFiles.push(filePath);
|
|
2769
|
+
continue;
|
|
2770
|
+
}
|
|
2771
|
+
const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
|
|
2772
|
+
cwd,
|
|
2773
|
+
stdio: "pipe",
|
|
2774
|
+
encoding: "utf-8"
|
|
2775
|
+
});
|
|
2776
|
+
if (tracked.status === 0) {
|
|
2777
|
+
filteredFiles.push(filePath);
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
if (filteredFiles.length === 0) {
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
|
|
2784
|
+
cwd,
|
|
2785
|
+
stdio: "pipe",
|
|
2786
|
+
encoding: "utf-8"
|
|
2787
|
+
});
|
|
2788
|
+
if (result.error || result.status !== 0) {
|
|
2789
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2790
|
+
throw new Error(`git add failed: ${errorMsg}`);
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
function hasStagedChanges(cwd = process.cwd()) {
|
|
2794
|
+
const result = spawnSync2("git", ["diff", "--cached", "--quiet"], {
|
|
2795
|
+
cwd,
|
|
2796
|
+
stdio: "pipe",
|
|
2797
|
+
encoding: "utf-8"
|
|
2798
|
+
});
|
|
2799
|
+
if (result.status === 0) {
|
|
2800
|
+
return false;
|
|
2801
|
+
}
|
|
2802
|
+
if (result.status === 1) {
|
|
2803
|
+
return true;
|
|
2804
|
+
}
|
|
2805
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2806
|
+
throw new Error(`Failed to check staged changes: ${errorMsg}`);
|
|
2807
|
+
}
|
|
2808
|
+
function gitCommit(message, cwd = process.cwd()) {
|
|
2809
|
+
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
2810
|
+
cwd,
|
|
2811
|
+
stdio: "pipe",
|
|
2812
|
+
encoding: "utf-8"
|
|
2813
|
+
});
|
|
2814
|
+
if (result.error || result.status !== 0) {
|
|
2815
|
+
const errorMsg = result.stderr || result.error?.message || "Unknown error";
|
|
2816
|
+
throw new Error(`git commit failed: ${errorMsg}`);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
|
|
2820
|
+
if (!isGitRepository(cwd)) {
|
|
2821
|
+
console.log("[fullstack-cli] \u26A0 Not a git repository, skipping auto-commit");
|
|
2822
|
+
return false;
|
|
2823
|
+
}
|
|
2824
|
+
const changedFiles = getChangedFiles(cwd);
|
|
2825
|
+
if (changedFiles.length === 0) {
|
|
2826
|
+
console.log("[fullstack-cli] No changes to commit");
|
|
2827
|
+
return false;
|
|
2828
|
+
}
|
|
2829
|
+
try {
|
|
2830
|
+
gitAddUpgradeFiles(cwd, filesToStage);
|
|
2831
|
+
if (!hasStagedChanges(cwd)) {
|
|
2832
|
+
console.log("[fullstack-cli] No upgrade changes to commit");
|
|
2833
|
+
return false;
|
|
2834
|
+
}
|
|
2835
|
+
const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
|
|
2836
|
+
|
|
2837
|
+
- Sync template files
|
|
2838
|
+
- Cleanup package.json config
|
|
2839
|
+
- Upgrade @lark-apaas dependencies (if any)
|
|
2840
|
+
|
|
2841
|
+
Auto-committed by fullstack-cli`;
|
|
2842
|
+
gitCommit(message, cwd);
|
|
2843
|
+
console.log(`[fullstack-cli] \u2713 Auto-committed ${changedFiles.length} changed file(s)`);
|
|
2844
|
+
return true;
|
|
2845
|
+
} catch (error) {
|
|
2846
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2847
|
+
throw new Error(`Failed to auto-commit changes: ${message}`);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
// src/utils/package-json.ts
|
|
2852
|
+
import fs8 from "fs";
|
|
2853
|
+
import path6 from "path";
|
|
2854
|
+
function readPackageJson(cwd = process.cwd()) {
|
|
2855
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2856
|
+
if (!fs8.existsSync(pkgPath)) {
|
|
2857
|
+
throw new Error(`package.json not found at ${pkgPath}`);
|
|
2858
|
+
}
|
|
2859
|
+
const content = fs8.readFileSync(pkgPath, "utf-8");
|
|
2860
|
+
return JSON.parse(content);
|
|
2861
|
+
}
|
|
2862
|
+
function writePackageJson(pkg2, cwd = process.cwd()) {
|
|
2863
|
+
const pkgPath = path6.join(cwd, "package.json");
|
|
2864
|
+
const content = JSON.stringify(pkg2, null, 2) + "\n";
|
|
2865
|
+
fs8.writeFileSync(pkgPath, content, "utf-8");
|
|
2866
|
+
}
|
|
2867
|
+
function removeUpgradeScript(pkg2) {
|
|
2868
|
+
if (!pkg2.scripts?.upgrade) {
|
|
2869
|
+
return false;
|
|
2870
|
+
}
|
|
2871
|
+
delete pkg2.scripts.upgrade;
|
|
2872
|
+
return true;
|
|
2873
|
+
}
|
|
2874
|
+
function cleanDevScript(pkg2) {
|
|
2875
|
+
if (!pkg2.scripts?.dev) {
|
|
2876
|
+
return false;
|
|
2877
|
+
}
|
|
2878
|
+
const originalDev = pkg2.scripts.dev;
|
|
2879
|
+
const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
|
|
2880
|
+
if (cleanedDev !== originalDev) {
|
|
2881
|
+
pkg2.scripts.dev = cleanedDev;
|
|
2882
|
+
return true;
|
|
2883
|
+
}
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
function cleanupPackageJson(cwd = process.cwd()) {
|
|
2887
|
+
try {
|
|
2888
|
+
const pkg2 = readPackageJson(cwd);
|
|
2889
|
+
let changed = false;
|
|
2890
|
+
if (removeUpgradeScript(pkg2)) {
|
|
2891
|
+
console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
|
|
2892
|
+
changed = true;
|
|
2893
|
+
}
|
|
2894
|
+
if (cleanDevScript(pkg2)) {
|
|
2895
|
+
console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
|
|
2896
|
+
changed = true;
|
|
2897
|
+
}
|
|
2898
|
+
if (changed) {
|
|
2899
|
+
writePackageJson(pkg2, cwd);
|
|
2900
|
+
}
|
|
2901
|
+
return changed;
|
|
2902
|
+
} catch (error) {
|
|
2903
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2904
|
+
console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
|
|
2905
|
+
return false;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
// src/commands/upgrade/shared/utils.ts
|
|
2910
|
+
import path7 from "path";
|
|
2911
|
+
import fs9 from "fs";
|
|
2912
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2913
|
+
function getCliVersion() {
|
|
2914
|
+
try {
|
|
2915
|
+
const __filename = fileURLToPath4(import.meta.url);
|
|
2916
|
+
const __dirname2 = path7.dirname(__filename);
|
|
2917
|
+
const pkgPath = path7.resolve(__dirname2, "../../../package.json");
|
|
2918
|
+
const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
|
|
2919
|
+
const pkg2 = JSON.parse(pkgContent);
|
|
2920
|
+
return pkg2.version || "unknown";
|
|
2921
|
+
} catch {
|
|
2922
|
+
return "unknown";
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
// src/commands/upgrade/get-upgrade-files.ts
|
|
2927
|
+
function getUpgradeFilesToStage(disableGenOpenapi = true) {
|
|
2928
|
+
const syncConfig2 = genSyncConfig({ disableGenOpenapi });
|
|
2929
|
+
const filesToStage = /* @__PURE__ */ new Set();
|
|
2930
|
+
syncConfig2.sync.forEach((rule) => {
|
|
2931
|
+
if (rule.type === "file" || rule.type === "directory") {
|
|
2932
|
+
filesToStage.add(rule.to);
|
|
2933
|
+
} else if (rule.type === "remove-line" || rule.type === "add-line") {
|
|
2934
|
+
filesToStage.add(rule.to);
|
|
2935
|
+
} else if (rule.type === "add-script") {
|
|
2936
|
+
filesToStage.add("package.json");
|
|
2937
|
+
} else if (rule.type === "delete-file" || rule.type === "delete-directory") {
|
|
2938
|
+
filesToStage.add(rule.to);
|
|
2939
|
+
}
|
|
2940
|
+
});
|
|
2941
|
+
filesToStage.add("package.json");
|
|
2942
|
+
filesToStage.add("package-lock.json");
|
|
2943
|
+
return Array.from(filesToStage);
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
// src/commands/upgrade/run.handler.ts
|
|
2947
|
+
async function run3(options = {}) {
|
|
2948
|
+
const userProjectRoot = process.env.INIT_CWD || process.cwd();
|
|
2949
|
+
console.log("[fullstack-cli] Starting upgrade...");
|
|
2950
|
+
try {
|
|
2951
|
+
console.log("[fullstack-cli] Step 1/3: Syncing template files...");
|
|
2952
|
+
await run2({ disableGenOpenapi: options.disableGenOpenapi ?? true });
|
|
2953
|
+
console.log("[fullstack-cli] Step 2/3: Cleaning up package.json...");
|
|
2954
|
+
const cleaned = cleanupPackageJson(userProjectRoot);
|
|
2955
|
+
if (!cleaned) {
|
|
2956
|
+
console.log("[fullstack-cli] \u25CB No cleanup needed");
|
|
2957
|
+
}
|
|
2958
|
+
const shouldCommit = options.commit ?? true;
|
|
2959
|
+
if (shouldCommit) {
|
|
2960
|
+
console.log("[fullstack-cli] Step 3/3: Committing changes...");
|
|
2961
|
+
const version = getCliVersion();
|
|
2962
|
+
const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
|
|
2963
|
+
autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
|
|
2964
|
+
} else {
|
|
2965
|
+
console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
|
|
2966
|
+
}
|
|
2967
|
+
console.log("[fullstack-cli] Upgrade completed successfully \u2705");
|
|
2968
|
+
} catch (error) {
|
|
2969
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2970
|
+
console.error("[fullstack-cli] Failed to upgrade:", message);
|
|
2971
|
+
process.exit(1);
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
// src/commands/upgrade/deps/run.handler.ts
|
|
2976
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
2977
|
+
function findLarkAapaasPackages(cwd, filterPackages) {
|
|
2978
|
+
const pkg2 = readPackageJson(cwd);
|
|
2979
|
+
const allPackages = /* @__PURE__ */ new Set();
|
|
2980
|
+
if (pkg2.dependencies) {
|
|
2981
|
+
Object.keys(pkg2.dependencies).forEach((name) => {
|
|
2982
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2983
|
+
allPackages.add(name);
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
if (pkg2.devDependencies) {
|
|
2988
|
+
Object.keys(pkg2.devDependencies).forEach((name) => {
|
|
2989
|
+
if (name.startsWith("@lark-apaas/")) {
|
|
2990
|
+
allPackages.add(name);
|
|
2991
|
+
}
|
|
2992
|
+
});
|
|
2993
|
+
}
|
|
2994
|
+
const packages = Array.from(allPackages);
|
|
2995
|
+
if (filterPackages) {
|
|
2996
|
+
const filter = new Set(filterPackages.split(",").map((p) => p.trim()));
|
|
2997
|
+
return packages.filter((p) => filter.has(p));
|
|
2998
|
+
}
|
|
2999
|
+
return packages;
|
|
3000
|
+
}
|
|
3001
|
+
function upgradePackages(packages, version, cwd) {
|
|
3002
|
+
if (version) {
|
|
3003
|
+
console.log(`[fullstack-cli] Upgrading to version ${version}...`);
|
|
3004
|
+
packages.forEach((pkg2) => {
|
|
3005
|
+
const target = `${pkg2}@${version}`;
|
|
3006
|
+
console.log(`[fullstack-cli] Installing ${target}...`);
|
|
3007
|
+
const result = spawnSync3("npm", ["install", target], {
|
|
3008
|
+
cwd,
|
|
3009
|
+
stdio: "inherit"
|
|
3010
|
+
});
|
|
3011
|
+
if (result.error || result.status !== 0) {
|
|
3012
|
+
throw new Error(`Failed to install ${target}`);
|
|
3013
|
+
}
|
|
3014
|
+
});
|
|
3015
|
+
} else {
|
|
3016
|
+
console.log("[fullstack-cli] Upgrading to latest compatible versions...");
|
|
3017
|
+
packages.forEach((pkg2) => {
|
|
3018
|
+
console.log(`[fullstack-cli] Updating ${pkg2}...`);
|
|
3019
|
+
const result = spawnSync3("npm", ["update", pkg2], {
|
|
3020
|
+
cwd,
|
|
3021
|
+
stdio: "inherit"
|
|
3022
|
+
});
|
|
3023
|
+
if (result.error || result.status !== 0) {
|
|
3024
|
+
throw new Error(`Failed to update ${pkg2}`);
|
|
3025
|
+
}
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
async function run4(options = {}) {
|
|
3030
|
+
const cwd = process.env.INIT_CWD || process.cwd();
|
|
3031
|
+
console.log("[fullstack-cli] Starting dependencies upgrade...");
|
|
3032
|
+
try {
|
|
3033
|
+
console.log("[fullstack-cli] Step 1/2: Scanning @lark-apaas dependencies...");
|
|
3034
|
+
const packages = findLarkAapaasPackages(cwd, options.packages);
|
|
3035
|
+
if (packages.length === 0) {
|
|
3036
|
+
console.log("[fullstack-cli] No @lark-apaas packages found");
|
|
3037
|
+
return;
|
|
3038
|
+
}
|
|
3039
|
+
console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
|
|
3040
|
+
packages.forEach((p) => console.log(` - ${p}`));
|
|
3041
|
+
console.log("[fullstack-cli] Step 2/2: Upgrading packages...");
|
|
3042
|
+
upgradePackages(packages, options.version, cwd);
|
|
3043
|
+
console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
|
|
3044
|
+
console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
|
|
3045
|
+
} catch (error) {
|
|
3046
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3047
|
+
console.error("[fullstack-cli] Failed to upgrade dependencies:", message);
|
|
3048
|
+
process.exit(1);
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
// src/commands/upgrade/deps/index.ts
|
|
3053
|
+
var depsCommand = {
|
|
3054
|
+
name: "deps",
|
|
3055
|
+
description: "Upgrade @lark-apaas dependencies",
|
|
3056
|
+
register(parentCommand) {
|
|
3057
|
+
parentCommand.command(this.name).description(this.description).option("--version <version>", "Upgrade to specific version").option("--packages <packages>", "Only upgrade specific packages (comma-separated)").action(async (options) => {
|
|
3058
|
+
await run4(options);
|
|
3059
|
+
});
|
|
3060
|
+
}
|
|
3061
|
+
};
|
|
3062
|
+
|
|
3063
|
+
// src/commands/upgrade/index.ts
|
|
3064
|
+
var upgradeCommand = {
|
|
3065
|
+
name: "upgrade",
|
|
3066
|
+
description: "Upgrade template files and auto-commit changes",
|
|
3067
|
+
register(program) {
|
|
3068
|
+
const upgradeCmd = program.command(this.name).description(this.description).option("--disable-gen-openapi", "Disable generating openapi.ts").option("--no-commit", "Skip auto-commit changes").action(async (options) => {
|
|
3069
|
+
await run3(options);
|
|
3070
|
+
});
|
|
3071
|
+
depsCommand.register(upgradeCmd);
|
|
3072
|
+
}
|
|
3073
|
+
};
|
|
3074
|
+
|
|
3075
|
+
// src/commands/action-plugin/utils.ts
|
|
3076
|
+
import fs10 from "fs";
|
|
3077
|
+
import path8 from "path";
|
|
3078
|
+
import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
|
|
2426
3079
|
function parsePluginName(input) {
|
|
2427
3080
|
const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
|
|
2428
3081
|
if (!match) {
|
|
@@ -2439,35 +3092,35 @@ function getProjectRoot() {
|
|
|
2439
3092
|
return process.cwd();
|
|
2440
3093
|
}
|
|
2441
3094
|
function getPackageJsonPath() {
|
|
2442
|
-
return
|
|
3095
|
+
return path8.join(getProjectRoot(), "package.json");
|
|
2443
3096
|
}
|
|
2444
3097
|
function getPluginPath(pluginName) {
|
|
2445
|
-
return
|
|
3098
|
+
return path8.join(getProjectRoot(), "node_modules", pluginName);
|
|
2446
3099
|
}
|
|
2447
|
-
function
|
|
3100
|
+
function readPackageJson2() {
|
|
2448
3101
|
const pkgPath = getPackageJsonPath();
|
|
2449
|
-
if (!
|
|
3102
|
+
if (!fs10.existsSync(pkgPath)) {
|
|
2450
3103
|
throw new Error("package.json not found in current directory");
|
|
2451
3104
|
}
|
|
2452
3105
|
try {
|
|
2453
|
-
const content =
|
|
3106
|
+
const content = fs10.readFileSync(pkgPath, "utf-8");
|
|
2454
3107
|
return JSON.parse(content);
|
|
2455
3108
|
} catch {
|
|
2456
3109
|
throw new Error("Failed to parse package.json");
|
|
2457
3110
|
}
|
|
2458
3111
|
}
|
|
2459
|
-
function
|
|
3112
|
+
function writePackageJson2(pkg2) {
|
|
2460
3113
|
const pkgPath = getPackageJsonPath();
|
|
2461
|
-
|
|
3114
|
+
fs10.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
2462
3115
|
}
|
|
2463
3116
|
function readActionPlugins() {
|
|
2464
|
-
const pkg2 =
|
|
3117
|
+
const pkg2 = readPackageJson2();
|
|
2465
3118
|
return pkg2.actionPlugins || {};
|
|
2466
3119
|
}
|
|
2467
3120
|
function writeActionPlugins(plugins) {
|
|
2468
|
-
const pkg2 =
|
|
3121
|
+
const pkg2 = readPackageJson2();
|
|
2469
3122
|
pkg2.actionPlugins = plugins;
|
|
2470
|
-
|
|
3123
|
+
writePackageJson2(pkg2);
|
|
2471
3124
|
}
|
|
2472
3125
|
function isPluginInstalled(pluginName) {
|
|
2473
3126
|
const plugins = readActionPlugins();
|
|
@@ -2479,7 +3132,7 @@ function getInstalledPluginVersion(pluginName) {
|
|
|
2479
3132
|
}
|
|
2480
3133
|
function npmInstall(tgzPath) {
|
|
2481
3134
|
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
2482
|
-
const result =
|
|
3135
|
+
const result = spawnSync4("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
2483
3136
|
cwd: getProjectRoot(),
|
|
2484
3137
|
stdio: "inherit"
|
|
2485
3138
|
});
|
|
@@ -2491,12 +3144,12 @@ function npmInstall(tgzPath) {
|
|
|
2491
3144
|
}
|
|
2492
3145
|
}
|
|
2493
3146
|
function getPackageVersion(pluginName) {
|
|
2494
|
-
const pkgJsonPath =
|
|
2495
|
-
if (!
|
|
3147
|
+
const pkgJsonPath = path8.join(getPluginPath(pluginName), "package.json");
|
|
3148
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2496
3149
|
return null;
|
|
2497
3150
|
}
|
|
2498
3151
|
try {
|
|
2499
|
-
const content =
|
|
3152
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2500
3153
|
const pkg2 = JSON.parse(content);
|
|
2501
3154
|
return pkg2.version || null;
|
|
2502
3155
|
} catch {
|
|
@@ -2504,49 +3157,49 @@ function getPackageVersion(pluginName) {
|
|
|
2504
3157
|
}
|
|
2505
3158
|
}
|
|
2506
3159
|
function readPluginPackageJson(pluginPath) {
|
|
2507
|
-
const pkgJsonPath =
|
|
2508
|
-
if (!
|
|
3160
|
+
const pkgJsonPath = path8.join(pluginPath, "package.json");
|
|
3161
|
+
if (!fs10.existsSync(pkgJsonPath)) {
|
|
2509
3162
|
return null;
|
|
2510
3163
|
}
|
|
2511
3164
|
try {
|
|
2512
|
-
const content =
|
|
3165
|
+
const content = fs10.readFileSync(pkgJsonPath, "utf-8");
|
|
2513
3166
|
return JSON.parse(content);
|
|
2514
3167
|
} catch {
|
|
2515
3168
|
return null;
|
|
2516
3169
|
}
|
|
2517
3170
|
}
|
|
2518
3171
|
function extractTgzToNodeModules(tgzPath, pluginName) {
|
|
2519
|
-
const nodeModulesPath =
|
|
2520
|
-
const targetDir =
|
|
2521
|
-
const scopeDir =
|
|
2522
|
-
if (!
|
|
2523
|
-
|
|
3172
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
3173
|
+
const targetDir = path8.join(nodeModulesPath, pluginName);
|
|
3174
|
+
const scopeDir = path8.dirname(targetDir);
|
|
3175
|
+
if (!fs10.existsSync(scopeDir)) {
|
|
3176
|
+
fs10.mkdirSync(scopeDir, { recursive: true });
|
|
2524
3177
|
}
|
|
2525
|
-
if (
|
|
2526
|
-
|
|
3178
|
+
if (fs10.existsSync(targetDir)) {
|
|
3179
|
+
fs10.rmSync(targetDir, { recursive: true });
|
|
2527
3180
|
}
|
|
2528
|
-
const tempDir =
|
|
2529
|
-
if (
|
|
2530
|
-
|
|
3181
|
+
const tempDir = path8.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
|
|
3182
|
+
if (fs10.existsSync(tempDir)) {
|
|
3183
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2531
3184
|
}
|
|
2532
|
-
|
|
3185
|
+
fs10.mkdirSync(tempDir, { recursive: true });
|
|
2533
3186
|
try {
|
|
2534
|
-
|
|
2535
|
-
const extractedDir =
|
|
2536
|
-
if (
|
|
2537
|
-
|
|
3187
|
+
execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
|
|
3188
|
+
const extractedDir = path8.join(tempDir, "package");
|
|
3189
|
+
if (fs10.existsSync(extractedDir)) {
|
|
3190
|
+
fs10.renameSync(extractedDir, targetDir);
|
|
2538
3191
|
} else {
|
|
2539
|
-
const files =
|
|
3192
|
+
const files = fs10.readdirSync(tempDir);
|
|
2540
3193
|
if (files.length === 1) {
|
|
2541
|
-
|
|
3194
|
+
fs10.renameSync(path8.join(tempDir, files[0]), targetDir);
|
|
2542
3195
|
} else {
|
|
2543
3196
|
throw new Error("Unexpected tgz structure");
|
|
2544
3197
|
}
|
|
2545
3198
|
}
|
|
2546
3199
|
return targetDir;
|
|
2547
3200
|
} finally {
|
|
2548
|
-
if (
|
|
2549
|
-
|
|
3201
|
+
if (fs10.existsSync(tempDir)) {
|
|
3202
|
+
fs10.rmSync(tempDir, { recursive: true });
|
|
2550
3203
|
}
|
|
2551
3204
|
}
|
|
2552
3205
|
}
|
|
@@ -2555,10 +3208,10 @@ function checkMissingPeerDeps(peerDeps) {
|
|
|
2555
3208
|
return [];
|
|
2556
3209
|
}
|
|
2557
3210
|
const missing = [];
|
|
2558
|
-
const nodeModulesPath =
|
|
3211
|
+
const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
|
|
2559
3212
|
for (const [depName, _version] of Object.entries(peerDeps)) {
|
|
2560
|
-
const depPath =
|
|
2561
|
-
if (!
|
|
3213
|
+
const depPath = path8.join(nodeModulesPath, depName);
|
|
3214
|
+
if (!fs10.existsSync(depPath)) {
|
|
2562
3215
|
missing.push(depName);
|
|
2563
3216
|
}
|
|
2564
3217
|
}
|
|
@@ -2569,7 +3222,7 @@ function installMissingDeps(deps) {
|
|
|
2569
3222
|
return;
|
|
2570
3223
|
}
|
|
2571
3224
|
console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
|
|
2572
|
-
const result =
|
|
3225
|
+
const result = spawnSync4("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
|
|
2573
3226
|
cwd: getProjectRoot(),
|
|
2574
3227
|
stdio: "inherit"
|
|
2575
3228
|
});
|
|
@@ -2582,40 +3235,16 @@ function installMissingDeps(deps) {
|
|
|
2582
3235
|
}
|
|
2583
3236
|
function removePluginDirectory(pluginName) {
|
|
2584
3237
|
const pluginPath = getPluginPath(pluginName);
|
|
2585
|
-
if (
|
|
2586
|
-
|
|
3238
|
+
if (fs10.existsSync(pluginPath)) {
|
|
3239
|
+
fs10.rmSync(pluginPath, { recursive: true });
|
|
2587
3240
|
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
2588
3241
|
}
|
|
2589
3242
|
}
|
|
2590
3243
|
|
|
2591
3244
|
// src/commands/action-plugin/api-client.ts
|
|
2592
3245
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
2593
|
-
import
|
|
2594
|
-
import
|
|
2595
|
-
|
|
2596
|
-
// src/utils/http-client.ts
|
|
2597
|
-
import { HttpClient } from "@lark-apaas/http-client";
|
|
2598
|
-
var clientInstance = null;
|
|
2599
|
-
function getHttpClient() {
|
|
2600
|
-
if (!clientInstance) {
|
|
2601
|
-
clientInstance = new HttpClient({
|
|
2602
|
-
timeout: 3e4,
|
|
2603
|
-
platform: {
|
|
2604
|
-
enabled: true
|
|
2605
|
-
}
|
|
2606
|
-
});
|
|
2607
|
-
const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
|
|
2608
|
-
if (canaryEnv) {
|
|
2609
|
-
clientInstance.interceptors.request.use((req) => {
|
|
2610
|
-
req.headers["x-tt-env"] = canaryEnv;
|
|
2611
|
-
return req;
|
|
2612
|
-
});
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
return clientInstance;
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
// src/commands/action-plugin/api-client.ts
|
|
3246
|
+
import fs11 from "fs";
|
|
3247
|
+
import path9 from "path";
|
|
2619
3248
|
var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
|
|
2620
3249
|
async function getPluginVersions(keys, latestOnly = true) {
|
|
2621
3250
|
const client = getHttpClient();
|
|
@@ -2679,19 +3308,19 @@ async function downloadFromPublic(downloadURL) {
|
|
|
2679
3308
|
return Buffer.from(arrayBuffer);
|
|
2680
3309
|
}
|
|
2681
3310
|
function getPluginCacheDir() {
|
|
2682
|
-
return
|
|
3311
|
+
return path9.join(process.cwd(), PLUGIN_CACHE_DIR);
|
|
2683
3312
|
}
|
|
2684
3313
|
function ensureCacheDir() {
|
|
2685
3314
|
const cacheDir = getPluginCacheDir();
|
|
2686
|
-
if (!
|
|
2687
|
-
|
|
3315
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
3316
|
+
fs11.mkdirSync(cacheDir, { recursive: true });
|
|
2688
3317
|
}
|
|
2689
3318
|
}
|
|
2690
3319
|
function getTempFilePath(pluginKey, version) {
|
|
2691
3320
|
ensureCacheDir();
|
|
2692
3321
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2693
3322
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2694
|
-
return
|
|
3323
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2695
3324
|
}
|
|
2696
3325
|
var MAX_RETRIES = 2;
|
|
2697
3326
|
async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
|
|
@@ -2728,7 +3357,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
2728
3357
|
);
|
|
2729
3358
|
}
|
|
2730
3359
|
const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
|
|
2731
|
-
|
|
3360
|
+
fs11.writeFileSync(tgzPath, tgzBuffer);
|
|
2732
3361
|
console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
|
|
2733
3362
|
return {
|
|
2734
3363
|
tgzPath,
|
|
@@ -2742,18 +3371,18 @@ function getCachePath(pluginKey, version) {
|
|
|
2742
3371
|
ensureCacheDir();
|
|
2743
3372
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2744
3373
|
const filename = `${safeKey}@${version}.tgz`;
|
|
2745
|
-
return
|
|
3374
|
+
return path9.join(getPluginCacheDir(), filename);
|
|
2746
3375
|
}
|
|
2747
3376
|
function hasCachedPlugin(pluginKey, version) {
|
|
2748
3377
|
const cachePath = getCachePath(pluginKey, version);
|
|
2749
|
-
return
|
|
3378
|
+
return fs11.existsSync(cachePath);
|
|
2750
3379
|
}
|
|
2751
3380
|
function listCachedPlugins() {
|
|
2752
3381
|
const cacheDir = getPluginCacheDir();
|
|
2753
|
-
if (!
|
|
3382
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2754
3383
|
return [];
|
|
2755
3384
|
}
|
|
2756
|
-
const files =
|
|
3385
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2757
3386
|
const result = [];
|
|
2758
3387
|
for (const file of files) {
|
|
2759
3388
|
if (!file.endsWith(".tgz")) continue;
|
|
@@ -2761,8 +3390,8 @@ function listCachedPlugins() {
|
|
|
2761
3390
|
if (!match) continue;
|
|
2762
3391
|
const [, rawName, version] = match;
|
|
2763
3392
|
const name = rawName.replace(/^_/, "@").replace(/_/, "/");
|
|
2764
|
-
const filePath =
|
|
2765
|
-
const stat =
|
|
3393
|
+
const filePath = path9.join(cacheDir, file);
|
|
3394
|
+
const stat = fs11.statSync(filePath);
|
|
2766
3395
|
result.push({
|
|
2767
3396
|
name,
|
|
2768
3397
|
version,
|
|
@@ -2775,14 +3404,14 @@ function listCachedPlugins() {
|
|
|
2775
3404
|
}
|
|
2776
3405
|
function cleanAllCache() {
|
|
2777
3406
|
const cacheDir = getPluginCacheDir();
|
|
2778
|
-
if (!
|
|
3407
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2779
3408
|
return 0;
|
|
2780
3409
|
}
|
|
2781
|
-
const files =
|
|
3410
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2782
3411
|
let count = 0;
|
|
2783
3412
|
for (const file of files) {
|
|
2784
3413
|
if (file.endsWith(".tgz")) {
|
|
2785
|
-
|
|
3414
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2786
3415
|
count++;
|
|
2787
3416
|
}
|
|
2788
3417
|
}
|
|
@@ -2790,21 +3419,21 @@ function cleanAllCache() {
|
|
|
2790
3419
|
}
|
|
2791
3420
|
function cleanPluginCache(pluginKey, version) {
|
|
2792
3421
|
const cacheDir = getPluginCacheDir();
|
|
2793
|
-
if (!
|
|
3422
|
+
if (!fs11.existsSync(cacheDir)) {
|
|
2794
3423
|
return 0;
|
|
2795
3424
|
}
|
|
2796
3425
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
2797
|
-
const files =
|
|
3426
|
+
const files = fs11.readdirSync(cacheDir);
|
|
2798
3427
|
let count = 0;
|
|
2799
3428
|
for (const file of files) {
|
|
2800
3429
|
if (version) {
|
|
2801
3430
|
if (file === `${safeKey}@${version}.tgz`) {
|
|
2802
|
-
|
|
3431
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2803
3432
|
count++;
|
|
2804
3433
|
}
|
|
2805
3434
|
} else {
|
|
2806
3435
|
if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
|
|
2807
|
-
|
|
3436
|
+
fs11.unlinkSync(path9.join(cacheDir, file));
|
|
2808
3437
|
count++;
|
|
2809
3438
|
}
|
|
2810
3439
|
}
|
|
@@ -2898,6 +3527,8 @@ async function installOne(nameWithVersion) {
|
|
|
2898
3527
|
if (actualVersion === requestedVersion) {
|
|
2899
3528
|
console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
|
|
2900
3529
|
syncActionPluginsRecord(name, actualVersion);
|
|
3530
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
3531
|
+
});
|
|
2901
3532
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
2902
3533
|
}
|
|
2903
3534
|
}
|
|
@@ -2908,6 +3539,8 @@ async function installOne(nameWithVersion) {
|
|
|
2908
3539
|
if (actualVersion === targetVersion) {
|
|
2909
3540
|
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${actualVersion})`);
|
|
2910
3541
|
syncActionPluginsRecord(name, actualVersion);
|
|
3542
|
+
reportCreateInstanceEvent(name, actualVersion).catch(() => {
|
|
3543
|
+
});
|
|
2911
3544
|
return { name, version: actualVersion, success: true, skipped: true };
|
|
2912
3545
|
}
|
|
2913
3546
|
console.log(`[action-plugin] Found newer version: ${targetVersion} (installed: ${actualVersion || "none"})`);
|
|
@@ -2938,6 +3571,10 @@ async function installOne(nameWithVersion) {
|
|
|
2938
3571
|
writeActionPlugins(plugins);
|
|
2939
3572
|
const source = fromCache ? "from cache" : "downloaded";
|
|
2940
3573
|
console.log(`[action-plugin] Successfully installed ${name}@${installedVersion} (${source})`);
|
|
3574
|
+
reportInstallEvent(name, installedVersion).catch(() => {
|
|
3575
|
+
});
|
|
3576
|
+
reportCreateInstanceEvent(name, installedVersion).catch(() => {
|
|
3577
|
+
});
|
|
2941
3578
|
return { name, version: installedVersion, success: true };
|
|
2942
3579
|
} catch (error) {
|
|
2943
3580
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -3223,40 +3860,40 @@ var actionPluginCommandGroup = {
|
|
|
3223
3860
|
};
|
|
3224
3861
|
|
|
3225
3862
|
// src/commands/capability/utils.ts
|
|
3226
|
-
import
|
|
3863
|
+
import fs12 from "fs";
|
|
3227
3864
|
import { createRequire as createRequire2 } from "module";
|
|
3228
|
-
import
|
|
3865
|
+
import path10 from "path";
|
|
3229
3866
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
3230
3867
|
function getProjectRoot2() {
|
|
3231
3868
|
return process.cwd();
|
|
3232
3869
|
}
|
|
3233
3870
|
function getCapabilitiesDir() {
|
|
3234
|
-
return
|
|
3871
|
+
return path10.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
3235
3872
|
}
|
|
3236
3873
|
function getCapabilityPath(id) {
|
|
3237
|
-
return
|
|
3874
|
+
return path10.join(getCapabilitiesDir(), `${id}.json`);
|
|
3238
3875
|
}
|
|
3239
3876
|
function getPluginManifestPath(pluginKey) {
|
|
3240
|
-
return
|
|
3877
|
+
return path10.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
3241
3878
|
}
|
|
3242
3879
|
function capabilitiesDirExists() {
|
|
3243
|
-
return
|
|
3880
|
+
return fs12.existsSync(getCapabilitiesDir());
|
|
3244
3881
|
}
|
|
3245
3882
|
function listCapabilityIds() {
|
|
3246
3883
|
const dir = getCapabilitiesDir();
|
|
3247
|
-
if (!
|
|
3884
|
+
if (!fs12.existsSync(dir)) {
|
|
3248
3885
|
return [];
|
|
3249
3886
|
}
|
|
3250
|
-
const files =
|
|
3887
|
+
const files = fs12.readdirSync(dir);
|
|
3251
3888
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
3252
3889
|
}
|
|
3253
3890
|
function readCapability(id) {
|
|
3254
3891
|
const filePath = getCapabilityPath(id);
|
|
3255
|
-
if (!
|
|
3892
|
+
if (!fs12.existsSync(filePath)) {
|
|
3256
3893
|
throw new Error(`Capability not found: ${id}`);
|
|
3257
3894
|
}
|
|
3258
3895
|
try {
|
|
3259
|
-
const content =
|
|
3896
|
+
const content = fs12.readFileSync(filePath, "utf-8");
|
|
3260
3897
|
return JSON.parse(content);
|
|
3261
3898
|
} catch (error) {
|
|
3262
3899
|
if (error instanceof SyntaxError) {
|
|
@@ -3283,11 +3920,11 @@ function readAllCapabilities() {
|
|
|
3283
3920
|
}
|
|
3284
3921
|
function readPluginManifest(pluginKey) {
|
|
3285
3922
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
3286
|
-
if (!
|
|
3923
|
+
if (!fs12.existsSync(manifestPath)) {
|
|
3287
3924
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
3288
3925
|
}
|
|
3289
3926
|
try {
|
|
3290
|
-
const content =
|
|
3927
|
+
const content = fs12.readFileSync(manifestPath, "utf-8");
|
|
3291
3928
|
return JSON.parse(content);
|
|
3292
3929
|
} catch (error) {
|
|
3293
3930
|
if (error instanceof SyntaxError) {
|
|
@@ -3304,7 +3941,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
3304
3941
|
}
|
|
3305
3942
|
async function loadPlugin(pluginKey) {
|
|
3306
3943
|
try {
|
|
3307
|
-
const userRequire = createRequire2(
|
|
3944
|
+
const userRequire = createRequire2(path10.join(getProjectRoot2(), "package.json"));
|
|
3308
3945
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
3309
3946
|
const pluginModule = await import(resolvedPath);
|
|
3310
3947
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -3463,9 +4100,12 @@ var capabilityCommandGroup = {
|
|
|
3463
4100
|
commands: [listCommand2]
|
|
3464
4101
|
};
|
|
3465
4102
|
|
|
4103
|
+
// src/commands/component/add.handler.ts
|
|
4104
|
+
import { execFile } from "child_process";
|
|
4105
|
+
|
|
3466
4106
|
// src/commands/component/registry-preparer.ts
|
|
3467
|
-
import
|
|
3468
|
-
import
|
|
4107
|
+
import fs13 from "fs";
|
|
4108
|
+
import path11 from "path";
|
|
3469
4109
|
import os from "os";
|
|
3470
4110
|
|
|
3471
4111
|
// src/commands/component/service.ts
|
|
@@ -3521,7 +4161,7 @@ async function sendInstallEvent(key) {
|
|
|
3521
4161
|
}
|
|
3522
4162
|
|
|
3523
4163
|
// src/commands/component/registry-preparer.ts
|
|
3524
|
-
var REGISTRY_TEMP_DIR =
|
|
4164
|
+
var REGISTRY_TEMP_DIR = path11.join(os.tmpdir(), "miaoda-registry");
|
|
3525
4165
|
function parseComponentKey(key) {
|
|
3526
4166
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
3527
4167
|
if (!match) {
|
|
@@ -3533,11 +4173,11 @@ function parseComponentKey(key) {
|
|
|
3533
4173
|
}
|
|
3534
4174
|
function getLocalRegistryPath(key) {
|
|
3535
4175
|
const { scope, name } = parseComponentKey(key);
|
|
3536
|
-
return
|
|
4176
|
+
return path11.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
3537
4177
|
}
|
|
3538
4178
|
function ensureDir(dirPath) {
|
|
3539
|
-
if (!
|
|
3540
|
-
|
|
4179
|
+
if (!fs13.existsSync(dirPath)) {
|
|
4180
|
+
fs13.mkdirSync(dirPath, { recursive: true });
|
|
3541
4181
|
}
|
|
3542
4182
|
}
|
|
3543
4183
|
async function prepareRecursive(key, visited) {
|
|
@@ -3570,8 +4210,8 @@ async function prepareRecursive(key, visited) {
|
|
|
3570
4210
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
3571
4211
|
};
|
|
3572
4212
|
const localPath = getLocalRegistryPath(key);
|
|
3573
|
-
ensureDir(
|
|
3574
|
-
|
|
4213
|
+
ensureDir(path11.dirname(localPath));
|
|
4214
|
+
fs13.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
3575
4215
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
3576
4216
|
}
|
|
3577
4217
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -3581,18 +4221,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
3581
4221
|
}
|
|
3582
4222
|
function cleanupTempDir() {
|
|
3583
4223
|
try {
|
|
3584
|
-
if (
|
|
3585
|
-
|
|
4224
|
+
if (fs13.existsSync(REGISTRY_TEMP_DIR)) {
|
|
4225
|
+
fs13.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
3586
4226
|
}
|
|
3587
4227
|
} catch {
|
|
3588
4228
|
}
|
|
3589
4229
|
}
|
|
3590
4230
|
function getDownloadedRegistryItem(itemId) {
|
|
3591
4231
|
const localPath = getLocalRegistryPath(itemId);
|
|
3592
|
-
if (!
|
|
4232
|
+
if (!fs13.existsSync(localPath)) {
|
|
3593
4233
|
return null;
|
|
3594
4234
|
}
|
|
3595
|
-
const content =
|
|
4235
|
+
const content = fs13.readFileSync(localPath, "utf-8");
|
|
3596
4236
|
return JSON.parse(content);
|
|
3597
4237
|
}
|
|
3598
4238
|
|
|
@@ -3692,6 +4332,16 @@ async function executeShadcnAdd(registryItemPath) {
|
|
|
3692
4332
|
}
|
|
3693
4333
|
|
|
3694
4334
|
// src/commands/component/add.handler.ts
|
|
4335
|
+
function runActionPluginInit() {
|
|
4336
|
+
return new Promise((resolve) => {
|
|
4337
|
+
execFile("fullstack-cli", ["action-plugin", "init"], { cwd: process.cwd(), stdio: "ignore" }, (error) => {
|
|
4338
|
+
if (error) {
|
|
4339
|
+
debug("action-plugin init \u5931\u8D25: %s", error.message);
|
|
4340
|
+
}
|
|
4341
|
+
resolve();
|
|
4342
|
+
});
|
|
4343
|
+
});
|
|
4344
|
+
}
|
|
3695
4345
|
function printResult(result) {
|
|
3696
4346
|
console.log(JSON.stringify(result, null, 2));
|
|
3697
4347
|
}
|
|
@@ -3728,6 +4378,7 @@ async function add(key) {
|
|
|
3728
4378
|
errors: [{ message: errorMessage }]
|
|
3729
4379
|
});
|
|
3730
4380
|
} finally {
|
|
4381
|
+
await runActionPluginInit();
|
|
3731
4382
|
cleanupTempDir();
|
|
3732
4383
|
}
|
|
3733
4384
|
}
|
|
@@ -3749,58 +4400,58 @@ var componentCommandGroup = {
|
|
|
3749
4400
|
};
|
|
3750
4401
|
|
|
3751
4402
|
// src/commands/migration/version-manager.ts
|
|
3752
|
-
import
|
|
3753
|
-
import
|
|
4403
|
+
import fs14 from "fs";
|
|
4404
|
+
import path12 from "path";
|
|
3754
4405
|
var PACKAGE_JSON = "package.json";
|
|
3755
4406
|
var VERSION_FIELD = "migrationVersion";
|
|
3756
4407
|
function getPackageJsonPath2() {
|
|
3757
|
-
return
|
|
4408
|
+
return path12.join(process.cwd(), PACKAGE_JSON);
|
|
3758
4409
|
}
|
|
3759
4410
|
function getCurrentVersion() {
|
|
3760
4411
|
const pkgPath = getPackageJsonPath2();
|
|
3761
|
-
if (!
|
|
4412
|
+
if (!fs14.existsSync(pkgPath)) {
|
|
3762
4413
|
throw new Error("package.json not found");
|
|
3763
4414
|
}
|
|
3764
|
-
const pkg2 = JSON.parse(
|
|
4415
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3765
4416
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
3766
4417
|
}
|
|
3767
4418
|
function setCurrentVersion(version) {
|
|
3768
4419
|
const pkgPath = getPackageJsonPath2();
|
|
3769
|
-
const pkg2 = JSON.parse(
|
|
4420
|
+
const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
3770
4421
|
pkg2[VERSION_FIELD] = version;
|
|
3771
|
-
|
|
4422
|
+
fs14.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
3772
4423
|
}
|
|
3773
4424
|
|
|
3774
4425
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3775
|
-
import
|
|
3776
|
-
import
|
|
4426
|
+
import fs16 from "fs";
|
|
4427
|
+
import path14 from "path";
|
|
3777
4428
|
|
|
3778
4429
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
3779
|
-
import
|
|
3780
|
-
import
|
|
4430
|
+
import fs15 from "fs";
|
|
4431
|
+
import path13 from "path";
|
|
3781
4432
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
3782
4433
|
function getProjectRoot3() {
|
|
3783
4434
|
return process.cwd();
|
|
3784
4435
|
}
|
|
3785
4436
|
function getCapabilitiesDir2() {
|
|
3786
|
-
return
|
|
4437
|
+
return path13.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
3787
4438
|
}
|
|
3788
4439
|
function getPluginManifestPath2(pluginKey) {
|
|
3789
|
-
return
|
|
4440
|
+
return path13.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
3790
4441
|
}
|
|
3791
4442
|
|
|
3792
4443
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
3793
4444
|
function detectJsonMigration() {
|
|
3794
4445
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
3795
|
-
const oldFilePath =
|
|
3796
|
-
if (!
|
|
4446
|
+
const oldFilePath = path14.join(capabilitiesDir, "capabilities.json");
|
|
4447
|
+
if (!fs16.existsSync(oldFilePath)) {
|
|
3797
4448
|
return {
|
|
3798
4449
|
needsMigration: false,
|
|
3799
4450
|
reason: "capabilities.json not found"
|
|
3800
4451
|
};
|
|
3801
4452
|
}
|
|
3802
4453
|
try {
|
|
3803
|
-
const content =
|
|
4454
|
+
const content = fs16.readFileSync(oldFilePath, "utf-8");
|
|
3804
4455
|
const parsed = JSON.parse(content);
|
|
3805
4456
|
if (!Array.isArray(parsed)) {
|
|
3806
4457
|
return {
|
|
@@ -3851,8 +4502,8 @@ async function check(options) {
|
|
|
3851
4502
|
}
|
|
3852
4503
|
|
|
3853
4504
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
3854
|
-
import
|
|
3855
|
-
import
|
|
4505
|
+
import fs17 from "fs";
|
|
4506
|
+
import path15 from "path";
|
|
3856
4507
|
|
|
3857
4508
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
3858
4509
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -4082,18 +4733,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
4082
4733
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
4083
4734
|
function loadExistingCapabilities() {
|
|
4084
4735
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4085
|
-
if (!
|
|
4736
|
+
if (!fs17.existsSync(capabilitiesDir)) {
|
|
4086
4737
|
return [];
|
|
4087
4738
|
}
|
|
4088
|
-
const files =
|
|
4739
|
+
const files = fs17.readdirSync(capabilitiesDir);
|
|
4089
4740
|
const capabilities = [];
|
|
4090
4741
|
for (const file of files) {
|
|
4091
4742
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
4092
4743
|
continue;
|
|
4093
4744
|
}
|
|
4094
4745
|
try {
|
|
4095
|
-
const filePath =
|
|
4096
|
-
const content =
|
|
4746
|
+
const filePath = path15.join(capabilitiesDir, file);
|
|
4747
|
+
const content = fs17.readFileSync(filePath, "utf-8");
|
|
4097
4748
|
const capability = JSON.parse(content);
|
|
4098
4749
|
if (capability.id && capability.pluginKey) {
|
|
4099
4750
|
capabilities.push(capability);
|
|
@@ -4151,9 +4802,9 @@ async function migrateJsonFiles(options) {
|
|
|
4151
4802
|
}
|
|
4152
4803
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4153
4804
|
for (const cap of newCapabilities) {
|
|
4154
|
-
const filePath =
|
|
4805
|
+
const filePath = path15.join(capabilitiesDir, `${cap.id}.json`);
|
|
4155
4806
|
const content = JSON.stringify(cap, null, 2);
|
|
4156
|
-
|
|
4807
|
+
fs17.writeFileSync(filePath, content, "utf-8");
|
|
4157
4808
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
4158
4809
|
}
|
|
4159
4810
|
return {
|
|
@@ -4165,11 +4816,11 @@ async function migrateJsonFiles(options) {
|
|
|
4165
4816
|
}
|
|
4166
4817
|
|
|
4167
4818
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
4168
|
-
import
|
|
4819
|
+
import fs18 from "fs";
|
|
4169
4820
|
function isPluginInstalled2(pluginKey) {
|
|
4170
4821
|
const actionPlugins = readActionPlugins();
|
|
4171
4822
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
4172
|
-
return
|
|
4823
|
+
return fs18.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
4173
4824
|
}
|
|
4174
4825
|
function detectPluginsToInstall(capabilities) {
|
|
4175
4826
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -4245,12 +4896,12 @@ async function installPlugins(capabilities, options) {
|
|
|
4245
4896
|
}
|
|
4246
4897
|
|
|
4247
4898
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
4248
|
-
import
|
|
4899
|
+
import path17 from "path";
|
|
4249
4900
|
import { Project as Project3 } from "ts-morph";
|
|
4250
4901
|
|
|
4251
4902
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
4252
|
-
import
|
|
4253
|
-
import
|
|
4903
|
+
import fs19 from "fs";
|
|
4904
|
+
import path16 from "path";
|
|
4254
4905
|
var EXCLUDED_DIRS = [
|
|
4255
4906
|
"node_modules",
|
|
4256
4907
|
"dist",
|
|
@@ -4265,9 +4916,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
4265
4916
|
/\.d\.ts$/
|
|
4266
4917
|
];
|
|
4267
4918
|
function scanDirectory(dir, files = []) {
|
|
4268
|
-
const entries =
|
|
4919
|
+
const entries = fs19.readdirSync(dir, { withFileTypes: true });
|
|
4269
4920
|
for (const entry of entries) {
|
|
4270
|
-
const fullPath =
|
|
4921
|
+
const fullPath = path16.join(dir, entry.name);
|
|
4271
4922
|
if (entry.isDirectory()) {
|
|
4272
4923
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
4273
4924
|
continue;
|
|
@@ -4283,14 +4934,14 @@ function scanDirectory(dir, files = []) {
|
|
|
4283
4934
|
return files;
|
|
4284
4935
|
}
|
|
4285
4936
|
function scanServerFiles() {
|
|
4286
|
-
const serverDir =
|
|
4287
|
-
if (!
|
|
4937
|
+
const serverDir = path16.join(getProjectRoot3(), "server");
|
|
4938
|
+
if (!fs19.existsSync(serverDir)) {
|
|
4288
4939
|
return [];
|
|
4289
4940
|
}
|
|
4290
4941
|
return scanDirectory(serverDir);
|
|
4291
4942
|
}
|
|
4292
4943
|
function hasCapabilityImport(filePath) {
|
|
4293
|
-
const content =
|
|
4944
|
+
const content = fs19.readFileSync(filePath, "utf-8");
|
|
4294
4945
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
4295
4946
|
}
|
|
4296
4947
|
function scanFilesToMigrate() {
|
|
@@ -4667,7 +5318,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4667
5318
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
4668
5319
|
const classInfo = analyzeClass(sourceFile);
|
|
4669
5320
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
4670
|
-
const relativePath =
|
|
5321
|
+
const relativePath = path17.relative(getProjectRoot3(), filePath);
|
|
4671
5322
|
return {
|
|
4672
5323
|
filePath: relativePath,
|
|
4673
5324
|
imports,
|
|
@@ -4678,7 +5329,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
4678
5329
|
};
|
|
4679
5330
|
}
|
|
4680
5331
|
function migrateFile(project, analysis, dryRun) {
|
|
4681
|
-
const absolutePath =
|
|
5332
|
+
const absolutePath = path17.join(getProjectRoot3(), analysis.filePath);
|
|
4682
5333
|
if (!analysis.canAutoMigrate) {
|
|
4683
5334
|
return {
|
|
4684
5335
|
filePath: analysis.filePath,
|
|
@@ -4781,17 +5432,17 @@ function getSuggestion(analysis) {
|
|
|
4781
5432
|
}
|
|
4782
5433
|
|
|
4783
5434
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
4784
|
-
import
|
|
4785
|
-
import
|
|
5435
|
+
import fs20 from "fs";
|
|
5436
|
+
import path18 from "path";
|
|
4786
5437
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
4787
5438
|
const deletedFiles = [];
|
|
4788
5439
|
const errors = [];
|
|
4789
5440
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
4790
|
-
const oldJsonPath =
|
|
4791
|
-
if (
|
|
5441
|
+
const oldJsonPath = path18.join(capabilitiesDir, "capabilities.json");
|
|
5442
|
+
if (fs20.existsSync(oldJsonPath)) {
|
|
4792
5443
|
try {
|
|
4793
5444
|
if (!dryRun) {
|
|
4794
|
-
|
|
5445
|
+
fs20.unlinkSync(oldJsonPath);
|
|
4795
5446
|
}
|
|
4796
5447
|
deletedFiles.push("capabilities.json");
|
|
4797
5448
|
} catch (error) {
|
|
@@ -4799,11 +5450,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4799
5450
|
}
|
|
4800
5451
|
}
|
|
4801
5452
|
for (const cap of capabilities) {
|
|
4802
|
-
const tsFilePath =
|
|
4803
|
-
if (
|
|
5453
|
+
const tsFilePath = path18.join(capabilitiesDir, `${cap.id}.ts`);
|
|
5454
|
+
if (fs20.existsSync(tsFilePath)) {
|
|
4804
5455
|
try {
|
|
4805
5456
|
if (!dryRun) {
|
|
4806
|
-
|
|
5457
|
+
fs20.unlinkSync(tsFilePath);
|
|
4807
5458
|
}
|
|
4808
5459
|
deletedFiles.push(`${cap.id}.ts`);
|
|
4809
5460
|
} catch (error) {
|
|
@@ -4819,8 +5470,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
4819
5470
|
}
|
|
4820
5471
|
|
|
4821
5472
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
4822
|
-
import
|
|
4823
|
-
import
|
|
5473
|
+
import fs21 from "fs";
|
|
5474
|
+
import path19 from "path";
|
|
4824
5475
|
var REPORT_FILE = "capability-migration-report.md";
|
|
4825
5476
|
function printSummary(result) {
|
|
4826
5477
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -4983,15 +5634,15 @@ async function generateReport(result) {
|
|
|
4983
5634
|
}
|
|
4984
5635
|
lines.push("");
|
|
4985
5636
|
const logDir = process.env.LOG_DIR || "logs";
|
|
4986
|
-
if (!
|
|
5637
|
+
if (!fs21.existsSync(logDir)) {
|
|
4987
5638
|
return;
|
|
4988
5639
|
}
|
|
4989
|
-
const reportDir =
|
|
4990
|
-
if (!
|
|
4991
|
-
|
|
5640
|
+
const reportDir = path19.join(logDir, "migration");
|
|
5641
|
+
if (!fs21.existsSync(reportDir)) {
|
|
5642
|
+
fs21.mkdirSync(reportDir, { recursive: true });
|
|
4992
5643
|
}
|
|
4993
|
-
const reportPath =
|
|
4994
|
-
|
|
5644
|
+
const reportPath = path19.join(reportDir, REPORT_FILE);
|
|
5645
|
+
fs21.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
4995
5646
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
4996
5647
|
}
|
|
4997
5648
|
|
|
@@ -5168,7 +5819,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
|
|
|
5168
5819
|
}
|
|
5169
5820
|
|
|
5170
5821
|
// src/commands/migration/versions/v001_capability/run.ts
|
|
5171
|
-
async function
|
|
5822
|
+
async function run5(options) {
|
|
5172
5823
|
try {
|
|
5173
5824
|
const migrationOptions = {
|
|
5174
5825
|
dryRun: options.dryRun ?? false
|
|
@@ -5233,7 +5884,7 @@ var v001CapabilityMigration = {
|
|
|
5233
5884
|
name: "capability",
|
|
5234
5885
|
description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
|
|
5235
5886
|
check,
|
|
5236
|
-
run:
|
|
5887
|
+
run: run5
|
|
5237
5888
|
};
|
|
5238
5889
|
|
|
5239
5890
|
// src/commands/migration/versions/index.ts
|
|
@@ -5523,10 +6174,10 @@ var migrationCommand = {
|
|
|
5523
6174
|
};
|
|
5524
6175
|
|
|
5525
6176
|
// src/commands/read-logs/index.ts
|
|
5526
|
-
import
|
|
6177
|
+
import path20 from "path";
|
|
5527
6178
|
|
|
5528
6179
|
// src/commands/read-logs/std-utils.ts
|
|
5529
|
-
import
|
|
6180
|
+
import fs22 from "fs";
|
|
5530
6181
|
function formatStdPrefixTime(localTime) {
|
|
5531
6182
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
5532
6183
|
if (!match) return localTime;
|
|
@@ -5556,11 +6207,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
5556
6207
|
return `[${time}] ${content}`;
|
|
5557
6208
|
}
|
|
5558
6209
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
5559
|
-
const stat =
|
|
6210
|
+
const stat = fs22.statSync(filePath);
|
|
5560
6211
|
if (stat.size === 0) {
|
|
5561
6212
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
5562
6213
|
}
|
|
5563
|
-
const fd =
|
|
6214
|
+
const fd = fs22.openSync(filePath, "r");
|
|
5564
6215
|
const chunkSize = 64 * 1024;
|
|
5565
6216
|
let position = stat.size;
|
|
5566
6217
|
let remainder = "";
|
|
@@ -5574,7 +6225,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5574
6225
|
const length = Math.min(chunkSize, position);
|
|
5575
6226
|
position -= length;
|
|
5576
6227
|
const buffer = Buffer.alloc(length);
|
|
5577
|
-
|
|
6228
|
+
fs22.readSync(fd, buffer, 0, length, position);
|
|
5578
6229
|
let chunk = buffer.toString("utf8");
|
|
5579
6230
|
if (remainder) {
|
|
5580
6231
|
chunk += remainder;
|
|
@@ -5616,7 +6267,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
5616
6267
|
}
|
|
5617
6268
|
}
|
|
5618
6269
|
} finally {
|
|
5619
|
-
|
|
6270
|
+
fs22.closeSync(fd);
|
|
5620
6271
|
}
|
|
5621
6272
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
5622
6273
|
}
|
|
@@ -5637,21 +6288,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
5637
6288
|
}
|
|
5638
6289
|
|
|
5639
6290
|
// src/commands/read-logs/tail.ts
|
|
5640
|
-
import
|
|
6291
|
+
import fs23 from "fs";
|
|
5641
6292
|
function fileExists(filePath) {
|
|
5642
6293
|
try {
|
|
5643
|
-
|
|
6294
|
+
fs23.accessSync(filePath, fs23.constants.F_OK | fs23.constants.R_OK);
|
|
5644
6295
|
return true;
|
|
5645
6296
|
} catch {
|
|
5646
6297
|
return false;
|
|
5647
6298
|
}
|
|
5648
6299
|
}
|
|
5649
6300
|
function readFileTailLines(filePath, maxLines) {
|
|
5650
|
-
const stat =
|
|
6301
|
+
const stat = fs23.statSync(filePath);
|
|
5651
6302
|
if (stat.size === 0) {
|
|
5652
6303
|
return [];
|
|
5653
6304
|
}
|
|
5654
|
-
const fd =
|
|
6305
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5655
6306
|
const chunkSize = 64 * 1024;
|
|
5656
6307
|
const chunks = [];
|
|
5657
6308
|
let position = stat.size;
|
|
@@ -5661,13 +6312,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5661
6312
|
const length = Math.min(chunkSize, position);
|
|
5662
6313
|
position -= length;
|
|
5663
6314
|
const buffer = Buffer.alloc(length);
|
|
5664
|
-
|
|
6315
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5665
6316
|
chunks.unshift(buffer.toString("utf8"));
|
|
5666
6317
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
5667
6318
|
collectedLines += chunkLines;
|
|
5668
6319
|
}
|
|
5669
6320
|
} finally {
|
|
5670
|
-
|
|
6321
|
+
fs23.closeSync(fd);
|
|
5671
6322
|
}
|
|
5672
6323
|
const content = chunks.join("");
|
|
5673
6324
|
const allLines = content.split("\n");
|
|
@@ -5683,11 +6334,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
5683
6334
|
return allLines.slice(allLines.length - maxLines);
|
|
5684
6335
|
}
|
|
5685
6336
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
5686
|
-
const stat =
|
|
6337
|
+
const stat = fs23.statSync(filePath);
|
|
5687
6338
|
if (stat.size === 0) {
|
|
5688
6339
|
return { lines: [], totalLinesCount: 0 };
|
|
5689
6340
|
}
|
|
5690
|
-
const fd =
|
|
6341
|
+
const fd = fs23.openSync(filePath, "r");
|
|
5691
6342
|
const chunkSize = 64 * 1024;
|
|
5692
6343
|
let position = stat.size;
|
|
5693
6344
|
let remainder = "";
|
|
@@ -5699,7 +6350,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5699
6350
|
const length = Math.min(chunkSize, position);
|
|
5700
6351
|
position -= length;
|
|
5701
6352
|
const buffer = Buffer.alloc(length);
|
|
5702
|
-
|
|
6353
|
+
fs23.readSync(fd, buffer, 0, length, position);
|
|
5703
6354
|
let chunk = buffer.toString("utf8");
|
|
5704
6355
|
if (remainder) {
|
|
5705
6356
|
chunk += remainder;
|
|
@@ -5730,7 +6381,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
5730
6381
|
}
|
|
5731
6382
|
}
|
|
5732
6383
|
} finally {
|
|
5733
|
-
|
|
6384
|
+
fs23.closeSync(fd);
|
|
5734
6385
|
}
|
|
5735
6386
|
return { lines: collected.reverse(), totalLinesCount };
|
|
5736
6387
|
}
|
|
@@ -5872,7 +6523,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
5872
6523
|
}
|
|
5873
6524
|
|
|
5874
6525
|
// src/commands/read-logs/json-lines.ts
|
|
5875
|
-
import
|
|
6526
|
+
import fs24 from "fs";
|
|
5876
6527
|
function normalizePid(value) {
|
|
5877
6528
|
if (typeof value === "number") {
|
|
5878
6529
|
return String(value);
|
|
@@ -5923,11 +6574,11 @@ function buildWantedLevelSet(levels) {
|
|
|
5923
6574
|
return set.size > 0 ? set : null;
|
|
5924
6575
|
}
|
|
5925
6576
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
5926
|
-
const stat =
|
|
6577
|
+
const stat = fs24.statSync(filePath);
|
|
5927
6578
|
if (stat.size === 0) {
|
|
5928
6579
|
return { lines: [], totalLinesCount: 0 };
|
|
5929
6580
|
}
|
|
5930
|
-
const fd =
|
|
6581
|
+
const fd = fs24.openSync(filePath, "r");
|
|
5931
6582
|
const chunkSize = 64 * 1024;
|
|
5932
6583
|
let position = stat.size;
|
|
5933
6584
|
let remainder = "";
|
|
@@ -5942,7 +6593,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
5942
6593
|
const length = Math.min(chunkSize, position);
|
|
5943
6594
|
position -= length;
|
|
5944
6595
|
const buffer = Buffer.alloc(length);
|
|
5945
|
-
|
|
6596
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
5946
6597
|
let chunk = buffer.toString("utf8");
|
|
5947
6598
|
if (remainder) {
|
|
5948
6599
|
chunk += remainder;
|
|
@@ -6004,7 +6655,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
6004
6655
|
}
|
|
6005
6656
|
}
|
|
6006
6657
|
} finally {
|
|
6007
|
-
|
|
6658
|
+
fs24.closeSync(fd);
|
|
6008
6659
|
}
|
|
6009
6660
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6010
6661
|
}
|
|
@@ -6047,11 +6698,11 @@ function extractTraceId(obj) {
|
|
|
6047
6698
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
6048
6699
|
const wanted = traceId.trim();
|
|
6049
6700
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
6050
|
-
const stat =
|
|
6701
|
+
const stat = fs24.statSync(filePath);
|
|
6051
6702
|
if (stat.size === 0) {
|
|
6052
6703
|
return { lines: [], totalLinesCount: 0 };
|
|
6053
6704
|
}
|
|
6054
|
-
const fd =
|
|
6705
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6055
6706
|
const chunkSize = 64 * 1024;
|
|
6056
6707
|
let position = stat.size;
|
|
6057
6708
|
let remainder = "";
|
|
@@ -6064,7 +6715,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6064
6715
|
const length = Math.min(chunkSize, position);
|
|
6065
6716
|
position -= length;
|
|
6066
6717
|
const buffer = Buffer.alloc(length);
|
|
6067
|
-
|
|
6718
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6068
6719
|
let chunk = buffer.toString("utf8");
|
|
6069
6720
|
if (remainder) {
|
|
6070
6721
|
chunk += remainder;
|
|
@@ -6117,7 +6768,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
6117
6768
|
}
|
|
6118
6769
|
}
|
|
6119
6770
|
} finally {
|
|
6120
|
-
|
|
6771
|
+
fs24.closeSync(fd);
|
|
6121
6772
|
}
|
|
6122
6773
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6123
6774
|
}
|
|
@@ -6126,11 +6777,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6126
6777
|
if (!wantedLevelSet) {
|
|
6127
6778
|
return { lines: [], totalLinesCount: 0 };
|
|
6128
6779
|
}
|
|
6129
|
-
const stat =
|
|
6780
|
+
const stat = fs24.statSync(filePath);
|
|
6130
6781
|
if (stat.size === 0) {
|
|
6131
6782
|
return { lines: [], totalLinesCount: 0 };
|
|
6132
6783
|
}
|
|
6133
|
-
const fd =
|
|
6784
|
+
const fd = fs24.openSync(filePath, "r");
|
|
6134
6785
|
const chunkSize = 64 * 1024;
|
|
6135
6786
|
let position = stat.size;
|
|
6136
6787
|
let remainder = "";
|
|
@@ -6142,7 +6793,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6142
6793
|
const length = Math.min(chunkSize, position);
|
|
6143
6794
|
position -= length;
|
|
6144
6795
|
const buffer = Buffer.alloc(length);
|
|
6145
|
-
|
|
6796
|
+
fs24.readSync(fd, buffer, 0, length, position);
|
|
6146
6797
|
let chunk = buffer.toString("utf8");
|
|
6147
6798
|
if (remainder) {
|
|
6148
6799
|
chunk += remainder;
|
|
@@ -6189,7 +6840,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
6189
6840
|
}
|
|
6190
6841
|
}
|
|
6191
6842
|
} finally {
|
|
6192
|
-
|
|
6843
|
+
fs24.closeSync(fd);
|
|
6193
6844
|
}
|
|
6194
6845
|
return { lines: collected.reverse(), totalLinesCount };
|
|
6195
6846
|
}
|
|
@@ -6423,34 +7074,34 @@ async function readLogsJsonResult(options) {
|
|
|
6423
7074
|
};
|
|
6424
7075
|
}
|
|
6425
7076
|
function resolveLogFilePath(logDir, type) {
|
|
6426
|
-
const base =
|
|
7077
|
+
const base = path20.isAbsolute(logDir) ? logDir : path20.join(process.cwd(), logDir);
|
|
6427
7078
|
if (type === "server") {
|
|
6428
|
-
return
|
|
7079
|
+
return path20.join(base, "server.log");
|
|
6429
7080
|
}
|
|
6430
7081
|
if (type === "trace") {
|
|
6431
|
-
return
|
|
7082
|
+
return path20.join(base, "trace.log");
|
|
6432
7083
|
}
|
|
6433
7084
|
if (type === "server-std") {
|
|
6434
|
-
return
|
|
7085
|
+
return path20.join(base, "server.std.log");
|
|
6435
7086
|
}
|
|
6436
7087
|
if (type === "client-std") {
|
|
6437
|
-
return
|
|
7088
|
+
return path20.join(base, "client.std.log");
|
|
6438
7089
|
}
|
|
6439
7090
|
if (type === "dev") {
|
|
6440
|
-
return
|
|
7091
|
+
return path20.join(base, "dev.log");
|
|
6441
7092
|
}
|
|
6442
7093
|
if (type === "dev-std") {
|
|
6443
|
-
return
|
|
7094
|
+
return path20.join(base, "dev.std.log");
|
|
6444
7095
|
}
|
|
6445
7096
|
if (type === "install-dep-std") {
|
|
6446
|
-
return
|
|
7097
|
+
return path20.join(base, "install-dep.std.log");
|
|
6447
7098
|
}
|
|
6448
7099
|
if (type === "browser") {
|
|
6449
|
-
return
|
|
7100
|
+
return path20.join(base, "browser.log");
|
|
6450
7101
|
}
|
|
6451
7102
|
throw new Error(`Unsupported log type: ${type}`);
|
|
6452
7103
|
}
|
|
6453
|
-
async function
|
|
7104
|
+
async function run6(options) {
|
|
6454
7105
|
const result = await readLogsJsonResult(options);
|
|
6455
7106
|
process.stdout.write(JSON.stringify(result) + "\n");
|
|
6456
7107
|
}
|
|
@@ -6492,7 +7143,7 @@ var readLogsCommand = {
|
|
|
6492
7143
|
const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
|
|
6493
7144
|
const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
|
|
6494
7145
|
const levels = parseCommaSeparatedList(rawOptions.level);
|
|
6495
|
-
await
|
|
7146
|
+
await run6({ logDir, type, maxLines, offset, traceId, levels });
|
|
6496
7147
|
} catch (error) {
|
|
6497
7148
|
const message = error instanceof Error ? error.message : String(error);
|
|
6498
7149
|
process.stderr.write(message + "\n");
|
|
@@ -6581,6 +7232,7 @@ var buildCommandGroup = {
|
|
|
6581
7232
|
var commands = [
|
|
6582
7233
|
genDbSchemaCommand,
|
|
6583
7234
|
syncCommand,
|
|
7235
|
+
upgradeCommand,
|
|
6584
7236
|
actionPluginCommandGroup,
|
|
6585
7237
|
capabilityCommandGroup,
|
|
6586
7238
|
componentCommandGroup,
|
|
@@ -6590,12 +7242,12 @@ var commands = [
|
|
|
6590
7242
|
];
|
|
6591
7243
|
|
|
6592
7244
|
// src/index.ts
|
|
6593
|
-
var envPath =
|
|
6594
|
-
if (
|
|
7245
|
+
var envPath = path21.join(process.cwd(), ".env");
|
|
7246
|
+
if (fs25.existsSync(envPath)) {
|
|
6595
7247
|
dotenvConfig({ path: envPath });
|
|
6596
7248
|
}
|
|
6597
|
-
var __dirname =
|
|
6598
|
-
var pkg = JSON.parse(
|
|
7249
|
+
var __dirname = path21.dirname(fileURLToPath5(import.meta.url));
|
|
7250
|
+
var pkg = JSON.parse(fs25.readFileSync(path21.join(__dirname, "../package.json"), "utf-8"));
|
|
6599
7251
|
var cli = new FullstackCLI(pkg.version);
|
|
6600
7252
|
cli.useAll(commands);
|
|
6601
7253
|
cli.run();
|