@lark-apaas/fullstack-cli 1.1.22-alpha.17 → 1.1.22-alpha.18
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 +86 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1433,12 +1433,17 @@ async function fetchSyncedTables(appId, workspace) {
|
|
|
1433
1433
|
`listTableView API failed: ${response.status} ${response.statusText}`
|
|
1434
1434
|
);
|
|
1435
1435
|
}
|
|
1436
|
-
|
|
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
|
+
}
|
|
1437
1446
|
const tableView = json?.data?.data;
|
|
1438
|
-
console.log(
|
|
1439
|
-
"[fetchSyncedTables] listTableView raw response:",
|
|
1440
|
-
JSON.stringify(json, null, 2)
|
|
1441
|
-
);
|
|
1442
1447
|
if (!tableView) {
|
|
1443
1448
|
console.warn(
|
|
1444
1449
|
"[fetchSyncedTables] \u26A0 listTableView response missing data.data, returning empty map"
|
|
@@ -1456,7 +1461,7 @@ async function fetchSyncedTables(appId, workspace) {
|
|
|
1456
1461
|
"[fetchSyncedTables] \u274C Error fetching synced tables:",
|
|
1457
1462
|
error
|
|
1458
1463
|
);
|
|
1459
|
-
return
|
|
1464
|
+
return /* @__PURE__ */ new Map();
|
|
1460
1465
|
}
|
|
1461
1466
|
}
|
|
1462
1467
|
function extractSyncedTableMap(tableView) {
|
|
@@ -2155,7 +2160,9 @@ async function run(options = {}) {
|
|
|
2155
2160
|
}
|
|
2156
2161
|
const databaseUrl = process.env.SUDA_DATABASE_URL;
|
|
2157
2162
|
if (!databaseUrl) {
|
|
2158
|
-
console.error(
|
|
2163
|
+
console.error(
|
|
2164
|
+
"[gen-db-schema] Error: SUDA_DATABASE_URL environment variable is required"
|
|
2165
|
+
);
|
|
2159
2166
|
process.exit(1);
|
|
2160
2167
|
}
|
|
2161
2168
|
const outputPath = options.output || process.env.DB_SCHEMA_OUTPUT || "server/database/schema.ts";
|
|
@@ -2170,9 +2177,14 @@ async function run(options = {}) {
|
|
|
2170
2177
|
path2.resolve(__dirname2, "../../../dist/config/drizzle.config.js")
|
|
2171
2178
|
];
|
|
2172
2179
|
const configPath = configPathCandidates.find((p) => fs4.existsSync(p));
|
|
2173
|
-
console.log(
|
|
2180
|
+
console.log(
|
|
2181
|
+
"[gen-db-schema] Using drizzle config from:",
|
|
2182
|
+
configPath ?? "(not found)"
|
|
2183
|
+
);
|
|
2174
2184
|
if (!configPath) {
|
|
2175
|
-
console.error(
|
|
2185
|
+
console.error(
|
|
2186
|
+
"[gen-db-schema] Error: drizzle config not found in CLI package"
|
|
2187
|
+
);
|
|
2176
2188
|
process.exit(1);
|
|
2177
2189
|
}
|
|
2178
2190
|
const resolveDrizzleKitBin = () => {
|
|
@@ -2188,7 +2200,9 @@ async function run(options = {}) {
|
|
|
2188
2200
|
const binField = pkgJson.bin;
|
|
2189
2201
|
const binRelPath = typeof binField === "string" ? binField : binField?.["drizzle-kit"];
|
|
2190
2202
|
if (!binRelPath) {
|
|
2191
|
-
throw new Error(
|
|
2203
|
+
throw new Error(
|
|
2204
|
+
"Unable to resolve drizzle-kit binary from package.json"
|
|
2205
|
+
);
|
|
2192
2206
|
}
|
|
2193
2207
|
return path2.resolve(currentDir, binRelPath);
|
|
2194
2208
|
}
|
|
@@ -2209,14 +2223,20 @@ async function run(options = {}) {
|
|
|
2209
2223
|
const start = Date.now();
|
|
2210
2224
|
console.log("[gen-db-schema] \u2192 Fetching column comments...");
|
|
2211
2225
|
const res = await fetchColumnComments(databaseUrl, { timeoutMs: 1e4 });
|
|
2212
|
-
console.log(
|
|
2226
|
+
console.log(
|
|
2227
|
+
`[gen-db-schema] \u2190 Fetched column comments: ${res.size} items (${Date.now() - start}ms)`
|
|
2228
|
+
);
|
|
2213
2229
|
return res;
|
|
2214
2230
|
})();
|
|
2215
2231
|
const syncedTablesTask = appId && workspace ? (async () => {
|
|
2216
2232
|
const start = Date.now();
|
|
2217
|
-
console.log(
|
|
2233
|
+
console.log(
|
|
2234
|
+
"[gen-db-schema] \u2192 Fetching synced tables from listTableView..."
|
|
2235
|
+
);
|
|
2218
2236
|
const res = await fetchSyncedTables(appId, workspace);
|
|
2219
|
-
console.log(
|
|
2237
|
+
console.log(
|
|
2238
|
+
`[gen-db-schema] \u2190 Fetched synced tables: ${res.size} tables (${Date.now() - start}ms)`
|
|
2239
|
+
);
|
|
2220
2240
|
return res;
|
|
2221
2241
|
})() : void 0;
|
|
2222
2242
|
const fetchTasks = await Promise.allSettled([
|
|
@@ -2225,7 +2245,9 @@ async function run(options = {}) {
|
|
|
2225
2245
|
]);
|
|
2226
2246
|
if (fetchTasks[0].status === "fulfilled") {
|
|
2227
2247
|
columnComments = fetchTasks[0].value;
|
|
2228
|
-
console.log(
|
|
2248
|
+
console.log(
|
|
2249
|
+
`[gen-db-schema] \u2713 Column comments ready: ${columnComments.size}`
|
|
2250
|
+
);
|
|
2229
2251
|
} else {
|
|
2230
2252
|
console.warn(
|
|
2231
2253
|
"[gen-db-schema] \u26A0 Failed to fetch column comments (skipping):",
|
|
@@ -2235,15 +2257,21 @@ async function run(options = {}) {
|
|
|
2235
2257
|
if (appId && workspace) {
|
|
2236
2258
|
if (fetchTasks[1]?.status === "fulfilled") {
|
|
2237
2259
|
syncedTableMap = fetchTasks[1].value;
|
|
2238
|
-
console.log(
|
|
2260
|
+
console.log(
|
|
2261
|
+
`[gen-db-schema] \u2713 Synced tables ready: ${syncedTableMap.size}`
|
|
2262
|
+
);
|
|
2239
2263
|
} else if (fetchTasks[1]?.status === "rejected") {
|
|
2240
2264
|
console.warn(
|
|
2241
2265
|
"[gen-db-schema] \u26A0 Failed to fetch synced tables (skipping):",
|
|
2242
2266
|
fetchTasks[1].reason instanceof Error ? fetchTasks[1].reason.message : String(fetchTasks[1].reason)
|
|
2243
2267
|
);
|
|
2268
|
+
syncedTableMap = /* @__PURE__ */ new Map();
|
|
2244
2269
|
}
|
|
2245
2270
|
} else {
|
|
2246
|
-
console.info(
|
|
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();
|
|
2247
2275
|
}
|
|
2248
2276
|
try {
|
|
2249
2277
|
const env = {
|
|
@@ -2255,13 +2283,19 @@ async function run(options = {}) {
|
|
|
2255
2283
|
};
|
|
2256
2284
|
const drizzleKitBin = resolveDrizzleKitBin();
|
|
2257
2285
|
const spawnArgs = [drizzleKitBin, "introspect", "--config", configPath];
|
|
2258
|
-
const result = spawnSync(process.execPath, spawnArgs, {
|
|
2286
|
+
const result = spawnSync(process.execPath, spawnArgs, {
|
|
2287
|
+
stdio: "inherit",
|
|
2288
|
+
env,
|
|
2289
|
+
cwd: process.cwd()
|
|
2290
|
+
});
|
|
2259
2291
|
if (result.error) {
|
|
2260
2292
|
console.error("[gen-db-schema] Execution failed:", result.error);
|
|
2261
2293
|
throw result.error;
|
|
2262
2294
|
}
|
|
2263
2295
|
if ((result.status ?? 0) !== 0) {
|
|
2264
|
-
throw new Error(
|
|
2296
|
+
throw new Error(
|
|
2297
|
+
`drizzle-kit introspect failed with status ${result.status}`
|
|
2298
|
+
);
|
|
2265
2299
|
}
|
|
2266
2300
|
const generatedSchema = path2.join(OUT_DIR, "schema.ts");
|
|
2267
2301
|
if (!fs4.existsSync(generatedSchema)) {
|
|
@@ -2273,7 +2307,10 @@ async function run(options = {}) {
|
|
|
2273
2307
|
syncedTableMap
|
|
2274
2308
|
});
|
|
2275
2309
|
if (stats?.unmatchedUnknown?.length) {
|
|
2276
|
-
console.warn(
|
|
2310
|
+
console.warn(
|
|
2311
|
+
"[gen-db-schema] Unmatched custom types detected:",
|
|
2312
|
+
stats.unmatchedUnknown
|
|
2313
|
+
);
|
|
2277
2314
|
}
|
|
2278
2315
|
console.log("[gen-db-schema] \u2713 Postprocessed schema");
|
|
2279
2316
|
fs4.mkdirSync(path2.dirname(SCHEMA_FILE), { recursive: true });
|
|
@@ -2288,14 +2325,22 @@ async function run(options = {}) {
|
|
|
2288
2325
|
schemaFilePath,
|
|
2289
2326
|
moduleOutputDir: path2.resolve(process.cwd(), "server/modules")
|
|
2290
2327
|
});
|
|
2291
|
-
console.log(
|
|
2328
|
+
console.log(
|
|
2329
|
+
"[gen-db-schema] \u2713 Generate NestJS Module Boilerplate Successfully"
|
|
2330
|
+
);
|
|
2292
2331
|
}
|
|
2293
2332
|
} catch (error) {
|
|
2294
|
-
console.warn(
|
|
2333
|
+
console.warn(
|
|
2334
|
+
"[gen-db-schema] Generate NestJS Module Boilerplate failed:",
|
|
2335
|
+
error instanceof Error ? error.message : String(error)
|
|
2336
|
+
);
|
|
2295
2337
|
}
|
|
2296
2338
|
console.log("[gen-db-schema] \u2713 Complete");
|
|
2297
2339
|
} catch (err) {
|
|
2298
|
-
console.error(
|
|
2340
|
+
console.error(
|
|
2341
|
+
"[gen-db-schema] Failed:",
|
|
2342
|
+
err instanceof Error ? err.message : String(err)
|
|
2343
|
+
);
|
|
2299
2344
|
exitCode = 1;
|
|
2300
2345
|
} finally {
|
|
2301
2346
|
if (fs4.existsSync(OUT_DIR)) {
|
|
@@ -2745,6 +2790,21 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
|
|
|
2745
2790
|
throw new Error(`git add failed: ${errorMsg}`);
|
|
2746
2791
|
}
|
|
2747
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
|
+
}
|
|
2748
2808
|
function gitCommit(message, cwd = process.cwd()) {
|
|
2749
2809
|
const result = spawnSync2("git", ["commit", "-m", message], {
|
|
2750
2810
|
cwd,
|
|
@@ -2768,6 +2828,10 @@ function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
|
|
|
2768
2828
|
}
|
|
2769
2829
|
try {
|
|
2770
2830
|
gitAddUpgradeFiles(cwd, filesToStage);
|
|
2831
|
+
if (!hasStagedChanges(cwd)) {
|
|
2832
|
+
console.log("[fullstack-cli] No upgrade changes to commit");
|
|
2833
|
+
return false;
|
|
2834
|
+
}
|
|
2771
2835
|
const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
|
|
2772
2836
|
|
|
2773
2837
|
- Sync template files
|