gencow 0.1.299 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/gencow.mjs +0 -6
- package/core/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +16 -9
- package/runtime/config.mjs +218 -2
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10399 -8951
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +2 -1
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
package/lib/db-command.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { resolveLocalRuntimeFeatures } from "./local-runtime-features.mjs";
|
|
2
|
+
import { createLocalDbMigrateCommand } from "./local-database-commands.mjs";
|
|
3
|
+
import { formatRuntimeDiagnostic } from "../runtime/engine/index.mjs";
|
|
1
4
|
import { execSync } from "child_process";
|
|
5
|
+
import { request as httpRequest } from "node:http";
|
|
2
6
|
import {
|
|
3
7
|
cpSync,
|
|
4
8
|
existsSync,
|
|
@@ -28,6 +32,57 @@ import { platformFetch, requireCreds } from "./platform-client.mjs";
|
|
|
28
32
|
import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
|
|
29
33
|
import { readProjectMetadata, resolveProjectSelection } from "./project-context.mjs";
|
|
30
34
|
|
|
35
|
+
// Node's fetch adds browser Fetch Metadata even for a CLI request. Use the
|
|
36
|
+
// native HTTP transport for this loopback-only mutation; the Runtime must keep
|
|
37
|
+
// rejecting browser-originated seed requests.
|
|
38
|
+
function localSeedPost(url) {
|
|
39
|
+
const target = new URL(url);
|
|
40
|
+
if (
|
|
41
|
+
target.protocol !== "http:" || target.hostname !== "127.0.0.1" || target.pathname !== "/_admin/seed" ||
|
|
42
|
+
target.username || target.password || target.search || target.hash
|
|
43
|
+
)
|
|
44
|
+
return Promise.reject(new Error("Invalid local seed endpoint"));
|
|
45
|
+
return new Promise((resolveResponse, reject) => {
|
|
46
|
+
const request = httpRequest(
|
|
47
|
+
{ hostname: "127.0.0.1", port: target.port, path: target.pathname,
|
|
48
|
+
method: "POST", headers: { "content-type": "application/json", "content-length": "0" } },
|
|
49
|
+
(response) => {
|
|
50
|
+
const chunks = [];
|
|
51
|
+
response.on("data", (chunk) => chunks.push(chunk));
|
|
52
|
+
response.on("error", reject);
|
|
53
|
+
response.on("aborted", () => reject(new Error("Local seed response interrupted")));
|
|
54
|
+
response.on("end", () => {
|
|
55
|
+
const status = response.statusCode ?? 0;
|
|
56
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
57
|
+
resolveResponse({ status, ok: status >= 200 && status < 300, json: async () => JSON.parse(text) });
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
request.on("error", reject);
|
|
62
|
+
request.end();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function localMaintenanceDiagnostic(code, nextAction, dataImpact = "none") {
|
|
67
|
+
return formatRuntimeDiagnostic({ code, stage: "request", capability: "database", servingStarted: "unchanged",
|
|
68
|
+
dataImpact, retryable: false, retryPrecondition: "Settle any current local database owner and inspect prior effects before retrying.",
|
|
69
|
+
nextAction, correlationId: crypto.randomUUID() });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function localSeedFailure(data, fallbackCode, dataImpact = "unknown") {
|
|
73
|
+
const safeText = (value, fallback) => typeof value === "string" && value.length <= 400 &&
|
|
74
|
+
!/[\u0000-\u001f\u007f]|(?:https?|postgres(?:ql)?):\/\/|(?:^|\s)\/(?!\/)|\b(?:select|insert|update|delete|truncate|params:)\b/iu.test(value)
|
|
75
|
+
? value : fallback;
|
|
76
|
+
const code = typeof data?.code === "string" && /^[A-Z][A-Z0-9_]{2,100}$/u.test(data.code) ? data.code : fallbackCode;
|
|
77
|
+
const correlationId = typeof data?.correlationId === "string" && /^[A-Za-z0-9_-]{8,128}$/u.test(data.correlationId)
|
|
78
|
+
? data.correlationId : crypto.randomUUID();
|
|
79
|
+
return formatRuntimeDiagnostic({ code, stage: "request", capability: "application", servingStarted: "unchanged",
|
|
80
|
+
dataImpact: ["none", "committed", "unknown"].includes(data?.dataImpact) ? data.dataImpact : dataImpact,
|
|
81
|
+
retryable: data?.retryable === true,
|
|
82
|
+
retryPrecondition: safeText(data?.retryPrecondition, "Inspect the local Runtime and any prior seed effects before retrying."),
|
|
83
|
+
nextAction: safeText(data?.nextAction, "Inspect the app state and seed configuration before rerunning gencow db:seed --local."), correlationId });
|
|
84
|
+
}
|
|
85
|
+
|
|
31
86
|
export function resolveDbCloudTarget(args, gencowJson = null) {
|
|
32
87
|
let explicitAppId = null;
|
|
33
88
|
let hasExplicitApp = false;
|
|
@@ -166,9 +221,10 @@ function renderDbGenerateHelp(logImpl = log) {
|
|
|
166
221
|
logImpl(` ${HINTS_DATA_LOSS_NOTICE}\n`);
|
|
167
222
|
}
|
|
168
223
|
|
|
169
|
-
function renderLocalSeedMissingFile({ infoImpl = info, logImpl = log, warnImpl = warn } = {}) {
|
|
170
|
-
|
|
171
|
-
|
|
224
|
+
function renderLocalSeedMissingFile({ infoImpl = info, logImpl = log, warnImpl = warn, rootDir = "gencow" } = {}) {
|
|
225
|
+
const safeRoot = typeof rootDir === "string" && /^(?!\/)(?!.*\.\.)[A-Za-z0-9_./-]{1,160}$/u.test(rootDir) ? rootDir : "configured backend root";
|
|
226
|
+
warnImpl(`${safeRoot}/seed.ts not found`);
|
|
227
|
+
infoImpl(`\n ${DIM}Create ${safeRoot}/seed.ts:${RESET}\n`);
|
|
172
228
|
logImpl(` ${DIM}import { tasks } from "./schema";${RESET}`);
|
|
173
229
|
logImpl(` ${DIM}export default async function seed(ctx) {${RESET}`);
|
|
174
230
|
logImpl(` ${DIM} await ctx.db.insert(tasks).values([${RESET}`);
|
|
@@ -191,6 +247,7 @@ export function createDbCommands({
|
|
|
191
247
|
sourceRevision,
|
|
192
248
|
buildEnv,
|
|
193
249
|
cleanupOldBackups,
|
|
250
|
+
applyLocalMigrationsImpl,
|
|
194
251
|
createInterfaceImpl,
|
|
195
252
|
cwdImpl = () => process.cwd(),
|
|
196
253
|
drizzleKitCmdImpl,
|
|
@@ -198,6 +255,7 @@ export function createDbCommands({
|
|
|
198
255
|
exitImpl = (code) => process.exit(code),
|
|
199
256
|
existsSyncImpl = existsSync,
|
|
200
257
|
fetchImpl = fetch,
|
|
258
|
+
localSeedPostImpl = fetchImpl === globalThis.fetch ? localSeedPost : fetchImpl,
|
|
201
259
|
isLocalDbTarget,
|
|
202
260
|
isMonorepo,
|
|
203
261
|
loadConfig,
|
|
@@ -229,6 +287,8 @@ export function createDbCommands({
|
|
|
229
287
|
} = {}) {
|
|
230
288
|
const dbMigrationDependencies = {
|
|
231
289
|
buildEnv,
|
|
290
|
+
applyLocalMigrationsImpl,
|
|
291
|
+
spawnSyncImpl,
|
|
232
292
|
cpSyncImpl,
|
|
233
293
|
createInterfaceImpl,
|
|
234
294
|
cwdImpl,
|
|
@@ -275,7 +335,7 @@ export function createDbCommands({
|
|
|
275
335
|
return {
|
|
276
336
|
async dbReset(...args) {
|
|
277
337
|
const config = await loadConfig();
|
|
278
|
-
const cwd = cwdImpl();
|
|
338
|
+
const cwd = resolveProjectSelection({ allowMissingConfig: true, cwd: cwdImpl(), existsSyncImpl, resolvePathImpl, processEnv }).projectDir;
|
|
279
339
|
const isLocal = isLocalDbTarget(args);
|
|
280
340
|
|
|
281
341
|
if (!isLocal) {
|
|
@@ -293,71 +353,43 @@ export function createDbCommands({
|
|
|
293
353
|
|
|
294
354
|
let serverAlive = false;
|
|
295
355
|
try {
|
|
296
|
-
const
|
|
356
|
+
const response = await fetchImpl(`http://127.0.0.1:${port}/health`, {
|
|
297
357
|
signal: AbortSignal.timeout(2000),
|
|
298
358
|
});
|
|
299
|
-
serverAlive =
|
|
359
|
+
serverAlive = response.ok;
|
|
300
360
|
} catch {
|
|
301
361
|
/* ignore */
|
|
302
362
|
}
|
|
303
363
|
|
|
304
364
|
if (serverAlive) {
|
|
305
|
-
|
|
365
|
+
errorImpl(localMaintenanceDiagnostic("RUNTIME_LOCAL_RESET_REQUIRES_STOP", "Stop gencow dev --local, then run gencow db:reset --local."));
|
|
306
366
|
logImpl("");
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (data === null) {
|
|
316
|
-
errorImpl("Server connection failed: the server response could not be read.");
|
|
317
|
-
logImpl("");
|
|
318
|
-
return 1;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (!res.ok) {
|
|
322
|
-
renderMaintenanceFailure(data, res.status, {
|
|
323
|
-
errorImpl,
|
|
324
|
-
infoImpl,
|
|
325
|
-
label: "Reset failed",
|
|
326
|
-
retryCommand: "gencow db:reset",
|
|
327
|
-
impactNote: "verify which tables still contain data before rerunning",
|
|
328
|
-
});
|
|
329
|
-
logImpl("");
|
|
330
|
-
return 1;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
successImpl(`TRUNCATE done: ${data.truncated?.length || 0} tables`);
|
|
334
|
-
if (data.truncated?.length > 0) {
|
|
335
|
-
infoImpl(` ${DIM}${data.truncated.join(", ")}${RESET}`);
|
|
336
|
-
}
|
|
337
|
-
if (data.seeded) {
|
|
338
|
-
successImpl(`Seed completed ✓`);
|
|
339
|
-
} else {
|
|
340
|
-
infoImpl(`${DIM}No seed.ts found — skipping${RESET}`);
|
|
341
|
-
}
|
|
342
|
-
} catch (e) {
|
|
343
|
-
errorImpl(`Server connection failed: ${e.message}`);
|
|
344
|
-
logImpl("");
|
|
367
|
+
return 1;
|
|
368
|
+
} else {
|
|
369
|
+
const env = buildEnv(config, { cwd, processEnv });
|
|
370
|
+
if (
|
|
371
|
+
(await resolveLocalRuntimeFeatures(config, env)).database?.adapter !== "pglite" ||
|
|
372
|
+
/^postgres(?:ql)?:/iu.test(config.db.url)
|
|
373
|
+
) {
|
|
374
|
+
errorImpl(localMaintenanceDiagnostic("RUNTIME_LOCAL_RESET_UNSUPPORTED", "Use the documented PostgreSQL administration procedure; this local reset supports only PGlite."));
|
|
345
375
|
return 1;
|
|
346
376
|
}
|
|
347
|
-
} else {
|
|
348
377
|
const dbPath = resolvePathImpl(cwd, config.db.url);
|
|
349
378
|
if (existsSyncImpl(dbPath)) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
379
|
+
try {
|
|
380
|
+
const backupDir = resolvePathImpl(cwd, ".gencow", "backups");
|
|
381
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-");
|
|
382
|
+
const backupPath = resolvePathImpl(backupDir, ts);
|
|
383
|
+
mkdirSyncImpl(backupPath, { recursive: true });
|
|
384
|
+
cpSyncImpl(dbPath, backupPath, { recursive: true });
|
|
385
|
+
successImpl(`Backup created: .gencow/backups/${ts}`);
|
|
386
|
+
cleanupOldBackups(backupDir, 3);
|
|
387
|
+
rmSyncImpl(dbPath, { recursive: true, force: true });
|
|
388
|
+
successImpl("DB deleted — restart with gencow dev --local to create a new one");
|
|
389
|
+
} catch {
|
|
390
|
+
errorImpl(localMaintenanceDiagnostic("RUNTIME_LOCAL_RESET_FAILED", "Inspect the local database and backup before retrying.", "unknown"));
|
|
391
|
+
return 1;
|
|
392
|
+
}
|
|
361
393
|
} else {
|
|
362
394
|
infoImpl("DB does not exist yet. Run gencow dev --local to get started.");
|
|
363
395
|
}
|
|
@@ -379,35 +411,39 @@ export function createDbCommands({
|
|
|
379
411
|
logImpl(`\n${BOLD}${CYAN}Gencow DB Seed${RESET} ${DIM}(local)${RESET}\n`);
|
|
380
412
|
|
|
381
413
|
try {
|
|
382
|
-
const statusRes = await fetchImpl(`http://
|
|
414
|
+
const statusRes = await fetchImpl(`http://127.0.0.1:${port}/health`, {
|
|
383
415
|
signal: AbortSignal.timeout(2000),
|
|
384
416
|
});
|
|
385
|
-
if (!statusRes.ok)
|
|
417
|
+
if (!statusRes.ok) {
|
|
418
|
+
errorImpl(localSeedFailure(await statusRes.json().catch(() => null), "RUNTIME_LOCAL_SERVER_STATUS_UNAVAILABLE", "none"));
|
|
419
|
+
return 1;
|
|
420
|
+
}
|
|
386
421
|
} catch {
|
|
387
|
-
errorImpl(
|
|
388
|
-
|
|
422
|
+
errorImpl(localSeedFailure({ nextAction: "Run gencow dev --local from this app workspace, then retry gencow db:seed --local.",
|
|
423
|
+
retryPrecondition: "Start the local Runtime and wait for it to become ready.", dataImpact: "none" }, "RUNTIME_LOCAL_SERVER_UNREACHABLE", "none"));
|
|
389
424
|
logImpl("");
|
|
390
425
|
return 1;
|
|
391
426
|
}
|
|
392
427
|
|
|
393
428
|
try {
|
|
394
|
-
const res = await
|
|
429
|
+
const res = await localSeedPostImpl(`http://127.0.0.1:${port}/_admin/seed`, {
|
|
395
430
|
method: "POST",
|
|
396
431
|
headers: { "Content-Type": "application/json" },
|
|
397
432
|
});
|
|
398
433
|
const data = await res.json();
|
|
399
434
|
|
|
400
|
-
if (res.status === 404) {
|
|
401
|
-
|
|
435
|
+
if (res.status === 404 && data?.code === "RUNTIME_LOCAL_SEED_NOT_FOUND") {
|
|
436
|
+
errorImpl(localSeedFailure(data, "RUNTIME_LOCAL_SEED_NOT_FOUND", "none"));
|
|
437
|
+
renderLocalSeedMissingFile({ infoImpl, logImpl, warnImpl, rootDir: config.rootDir });
|
|
402
438
|
return 1;
|
|
403
439
|
} else if (!res.ok) {
|
|
404
|
-
errorImpl(
|
|
440
|
+
errorImpl(localSeedFailure(data, "RUNTIME_LOCAL_SEED_FAILED"));
|
|
405
441
|
return 1;
|
|
406
442
|
} else {
|
|
407
443
|
successImpl("Seed completed ✓");
|
|
408
444
|
}
|
|
409
|
-
} catch
|
|
410
|
-
errorImpl(
|
|
445
|
+
} catch {
|
|
446
|
+
errorImpl(localSeedFailure(null, "RUNTIME_LOCAL_SEED_TRANSPORT_UNAVAILABLE"));
|
|
411
447
|
return 1;
|
|
412
448
|
}
|
|
413
449
|
logImpl("");
|
|
@@ -496,7 +532,15 @@ export function createDbCommands({
|
|
|
496
532
|
|
|
497
533
|
async dbRestore() {
|
|
498
534
|
const config = await loadConfig();
|
|
499
|
-
const cwd = cwdImpl();
|
|
535
|
+
const cwd = resolveProjectSelection({ allowMissingConfig: true, cwd: cwdImpl(), existsSyncImpl, resolvePathImpl, processEnv }).projectDir;
|
|
536
|
+
const env = buildEnv(config, { cwd, processEnv });
|
|
537
|
+
if (
|
|
538
|
+
(await resolveLocalRuntimeFeatures(config, env)).database?.adapter !== "pglite" ||
|
|
539
|
+
/^postgres(?:ql)?:/iu.test(config.db.url)
|
|
540
|
+
) {
|
|
541
|
+
errorImpl(localMaintenanceDiagnostic("RUNTIME_LOCAL_RESTORE_UNSUPPORTED", "Use the documented PostgreSQL administration procedure; this local restore supports only PGlite."));
|
|
542
|
+
return 1;
|
|
543
|
+
}
|
|
500
544
|
const backupDir = resolvePathImpl(cwd, ".gencow", "backups");
|
|
501
545
|
const dbPath = resolvePathImpl(cwd, config.db.url);
|
|
502
546
|
|
|
@@ -529,12 +573,15 @@ export function createDbCommands({
|
|
|
529
573
|
const latest = backups[0];
|
|
530
574
|
const latestPath = resolvePathImpl(backupDir, latest);
|
|
531
575
|
|
|
532
|
-
|
|
533
|
-
rmSyncImpl(dbPath, { recursive: true, force: true });
|
|
576
|
+
try {
|
|
577
|
+
if (existsSyncImpl(dbPath)) rmSyncImpl(dbPath, { recursive: true, force: true });
|
|
578
|
+
cpSyncImpl(latestPath, dbPath, { recursive: true });
|
|
579
|
+
successImpl(`Restored from: .gencow/backups/${latest}`);
|
|
580
|
+
infoImpl("Restart with gencow dev --local.");
|
|
581
|
+
} catch {
|
|
582
|
+
errorImpl(localMaintenanceDiagnostic("RUNTIME_LOCAL_RESTORE_FAILED", "Inspect the local database and backup before retrying.", "unknown"));
|
|
583
|
+
return 1;
|
|
534
584
|
}
|
|
535
|
-
cpSyncImpl(latestPath, dbPath, { recursive: true });
|
|
536
|
-
successImpl(`Restored from: .gencow/backups/${latest}`);
|
|
537
|
-
infoImpl("Restart with gencow dev --local.");
|
|
538
585
|
logImpl("");
|
|
539
586
|
},
|
|
540
587
|
|
|
@@ -595,13 +642,7 @@ export function createDbCommands({
|
|
|
595
642
|
successImpl("Migration files generated in the configured migration directory.");
|
|
596
643
|
},
|
|
597
644
|
|
|
598
|
-
|
|
599
|
-
const config = await loadConfig();
|
|
600
|
-
logImpl(`\n${BOLD}${CYAN}Gencow DB Migrate${RESET}\n`);
|
|
601
|
-
infoImpl("Applying pending migrations...");
|
|
602
|
-
runInServer("pnpm db:migrate", buildEnv(config));
|
|
603
|
-
successImpl("Migrations applied!");
|
|
604
|
-
},
|
|
645
|
+
dbMigrate: createLocalDbMigrateCommand(dbMigrationDependencies),
|
|
605
646
|
|
|
606
647
|
async dbStudio() {
|
|
607
648
|
infoImpl(`Drizzle Studio is ${BOLD}coming soon${RESET}.`);
|
|
@@ -18,6 +18,12 @@ import {
|
|
|
18
18
|
import { BOLD, CYAN, DIM, RED, RESET } from "./output.mjs";
|
|
19
19
|
import { askConfirmation } from "./confirm-gate.mjs";
|
|
20
20
|
import { emitMigrationAdvisories, extractMigrationAdvisories } from "./migration-advisory.mjs";
|
|
21
|
+
import { runtimeDiagnostic } from "../runtime/engine/index.mjs";
|
|
22
|
+
import { localMigrationDiagnostic } from "./local-development-migrations.mjs";
|
|
23
|
+
import { runLocalDatabaseCommand } from "./local-database-commands.mjs";
|
|
24
|
+
import { configuredLocalDatabaseAdapter } from "./local-runtime-features.mjs";
|
|
25
|
+
import { isActionableMigrationDiagnostic } from "./migration-diagnostic.mjs";
|
|
26
|
+
import { resolveProjectSelection } from "./project-context.mjs";
|
|
21
27
|
|
|
22
28
|
function explicitAppRequested(args) {
|
|
23
29
|
return args.includes("--app") || args.includes("-a");
|
|
@@ -80,7 +86,7 @@ export async function promptDbPushConfirm(appId, createInterfaceImpl, plain = fa
|
|
|
80
86
|
return answer.trim().toLowerCase() === "yes";
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
export function handleLocalMigrationCommand({
|
|
89
|
+
export async function handleLocalMigrationCommand({
|
|
84
90
|
deps,
|
|
85
91
|
args,
|
|
86
92
|
command,
|
|
@@ -95,39 +101,36 @@ export function handleLocalMigrationCommand({
|
|
|
95
101
|
emitFailure(buildClientUserFixableDiagnostic("MIGRATION_CHECK_CLOUD_ONLY", correlationId()));
|
|
96
102
|
return true;
|
|
97
103
|
}
|
|
104
|
+
const projectDir = resolveProjectSelection({ allowMissingConfig: true, cwd: deps.cwdImpl(),
|
|
105
|
+
existsSyncImpl: deps.existsSyncImpl, resolvePathImpl: deps.resolvePathImpl, processEnv: deps.processEnv }).projectDir;
|
|
106
|
+
const localDeps = { ...deps, cwdImpl: () => projectDir };
|
|
98
107
|
const { envPath } = resolveBackendEnvFile(config, {
|
|
99
|
-
cwd:
|
|
108
|
+
cwd: projectDir,
|
|
100
109
|
existsSyncImpl: deps.existsSyncImpl,
|
|
101
110
|
resolvePathImpl: deps.resolvePathImpl,
|
|
102
111
|
warnImpl: deps.warnImpl,
|
|
103
112
|
});
|
|
104
|
-
const
|
|
113
|
+
const hasDbUrl = deps.hasLocalDatabaseUrl({
|
|
105
114
|
envPath,
|
|
106
115
|
existsSyncImpl: deps.existsSyncImpl,
|
|
107
116
|
infoImpl: deps.infoImpl,
|
|
108
117
|
processEnv: deps.processEnv,
|
|
109
118
|
readFileSyncImpl: deps.readFileSyncImpl,
|
|
110
119
|
});
|
|
120
|
+
const adapter = configuredLocalDatabaseAdapter(config);
|
|
121
|
+
const hasDb = adapter === "postgres" || (adapter !== "pglite" && hasDbUrl);
|
|
111
122
|
if (!jsonMode) {
|
|
112
123
|
const targetDb = hasDb ? "local PG" : "local fallback: PGlite";
|
|
113
124
|
deps.logImpl(`\n${BOLD}${CYAN}Gencow DB Push${RESET} ${DIM}(${targetDb})${RESET}\n`);
|
|
114
|
-
deps.infoImpl("Pushing schema.ts → database (no migration files)...");
|
|
125
|
+
deps.infoImpl(hasDb ? "Pushing schema.ts → database (no migration files)..." : "Generating and applying local PGlite migrations...");
|
|
115
126
|
}
|
|
116
127
|
try {
|
|
117
|
-
|
|
118
|
-
const childOptions = jsonMode ? { infoImpl: () => {}, stdio: "pipe" } : undefined;
|
|
119
|
-
if (hasDb) {
|
|
120
|
-
deps.runInServer("pnpm db:push --force", env, childOptions);
|
|
121
|
-
} else {
|
|
122
|
-
// Drizzle Kit cannot attach PGlite's packaged pgvector/pg_trgm modules.
|
|
123
|
-
// Generate the same desired-state migration, then apply it through the
|
|
124
|
-
// runtime connection that owns those extensions.
|
|
125
|
-
deps.runInServer("pnpm db:generate", env, childOptions);
|
|
126
|
-
deps.runInServer("bun src/local-pglite-migrate.ts", env, childOptions);
|
|
127
|
-
}
|
|
128
|
+
await runLocalDatabaseCommand({ command, config, deps: localDeps, jsonMode });
|
|
128
129
|
} catch (error) {
|
|
129
130
|
if (!jsonMode) throw error;
|
|
130
|
-
|
|
131
|
+
const diagnostic = localMigrationDiagnostic(error) ?? runtimeDiagnostic(error);
|
|
132
|
+
emitFailure(diagnostic ? { diagnosticVersion: 1, ok: false, command, target: "local", ...diagnostic }
|
|
133
|
+
: isActionableMigrationDiagnostic(error?.diagnostic) ? error.diagnostic : buildLocalExecutionFailureDiagnostic(correlationId()));
|
|
131
134
|
return true;
|
|
132
135
|
}
|
|
133
136
|
if (jsonMode) {
|
package/lib/db-push-command.mjs
CHANGED
|
@@ -262,7 +262,7 @@ export function createDevCloudCommand(deps) {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
try {
|
|
265
|
-
await deps.generateApiTsImpl(config, { cwd: projectDir });
|
|
265
|
+
await deps.generateApiTsImpl(config, { cwd: projectDir, includeStandalone: false });
|
|
266
266
|
} catch {
|
|
267
267
|
/* ignore */
|
|
268
268
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import { execSync, spawn } from "child_process";
|
|
2
|
-
import {
|
|
3
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, unlinkSync } from "fs";
|
|
3
4
|
import { dirname, resolve } from "path";
|
|
4
5
|
|
|
5
6
|
import {
|
|
@@ -11,13 +12,8 @@ import { formatCommandError } from "./cli-command-runner.mjs";
|
|
|
11
12
|
import { runMetadataUpgrade } from "./db-metadata-command.mjs";
|
|
12
13
|
import { runDrizzleGenerateWithFallback } from "./drizzle-generate.mjs";
|
|
13
14
|
import { beginMetadataCapture, inspectMetadataHistory, MigrationMetadataError } from "./metadata-upgrade.mjs";
|
|
14
|
-
import { resolveProjectSelection } from "./project-context.mjs";
|
|
15
|
-
|
|
16
|
-
export function resolveBundledServerEntry(findServerRootValue, resolvePathImpl, existsSyncImpl) {
|
|
17
|
-
const runtimeEntry = resolvePathImpl(findServerRootValue, "..", "runtime", "server.mjs");
|
|
18
|
-
if (existsSyncImpl(runtimeEntry)) return runtimeEntry;
|
|
19
|
-
return resolvePathImpl(findServerRootValue, "index.js");
|
|
20
|
-
}
|
|
15
|
+
import { getCliInvocationSelection, resolveProjectSelection } from "./project-context.mjs";
|
|
16
|
+
import { resolveLocalRuntimeFeatures } from "./local-runtime-features.mjs";
|
|
21
17
|
|
|
22
18
|
export function shouldUseLocalDev({ devArgs, processEnv = process.env }) {
|
|
23
19
|
return processEnv.GENCOW_LOCAL === "1" || devArgs.includes("--local");
|
|
@@ -69,7 +65,6 @@ export function createDevLocalCommands({
|
|
|
69
65
|
buildEnv,
|
|
70
66
|
CYAN = "",
|
|
71
67
|
cleanupOldBackups,
|
|
72
|
-
copyFileSyncImpl = copyFileSync,
|
|
73
68
|
cpSyncImpl = cpSync,
|
|
74
69
|
cwdImpl = () => process.cwd(),
|
|
75
70
|
DIM = "",
|
|
@@ -78,10 +73,8 @@ export function createDevLocalCommands({
|
|
|
78
73
|
execSyncImpl = execSync,
|
|
79
74
|
existsSyncImpl = existsSync,
|
|
80
75
|
exitImpl = (code) => process.exit(code ?? 0),
|
|
81
|
-
findServerRoot,
|
|
82
76
|
generateApiTsImpl,
|
|
83
77
|
GREEN = "",
|
|
84
|
-
isMonorepo,
|
|
85
78
|
loadConfig,
|
|
86
79
|
logImpl,
|
|
87
80
|
infoImpl,
|
|
@@ -94,7 +87,6 @@ export function createDevLocalCommands({
|
|
|
94
87
|
readFileSyncImpl = readFileSync,
|
|
95
88
|
RESET = "",
|
|
96
89
|
resolvePathImpl = resolve,
|
|
97
|
-
rmSyncImpl = rmSync,
|
|
98
90
|
runDevCloudImpl,
|
|
99
91
|
renderDevHelpImpl = (log) => {
|
|
100
92
|
log("Usage: gencow dev [--local] [--verbose] [--app <name>]");
|
|
@@ -102,7 +94,6 @@ export function createDevLocalCommands({
|
|
|
102
94
|
},
|
|
103
95
|
setTimeoutImpl = setTimeout,
|
|
104
96
|
spawnImpl = spawn,
|
|
105
|
-
spawnInServer,
|
|
106
97
|
unlinkSyncImpl = unlinkSync,
|
|
107
98
|
} = {}) {
|
|
108
99
|
function resolveProjectDirFromInvocation(cwd) {
|
|
@@ -127,7 +118,8 @@ export function createDevLocalCommands({
|
|
|
127
118
|
|
|
128
119
|
const cwd = cwdImpl();
|
|
129
120
|
const projectDir = resolveProjectDirFromInvocation(cwd);
|
|
130
|
-
const
|
|
121
|
+
const { assertLocalDashboardConfiguration } = await import("./local-dashboard-plan.mjs");
|
|
122
|
+
const config = await loadConfig({ cwd: projectDir, processEnv, validateLoadedConfig: assertLocalDashboardConfiguration });
|
|
131
123
|
const authDup = detectConflictingAuthSchemaFiles(projectDir, config, { existsSyncImpl, resolvePathImpl });
|
|
132
124
|
if (authDup.conflict) {
|
|
133
125
|
logImpl("");
|
|
@@ -137,20 +129,20 @@ export function createDevLocalCommands({
|
|
|
137
129
|
}
|
|
138
130
|
logImpl(`\n${BOLD}${CYAN}Gencow Dev${RESET} ${DIM}(local)${RESET}\n`);
|
|
139
131
|
infoImpl(`Backend root: ${DIM}${config.rootDir}${RESET}`);
|
|
140
|
-
|
|
132
|
+
const { storage } = await resolveLocalRuntimeFeatures(config, processEnv);
|
|
133
|
+
infoImpl(`Storage: ${DIM}${storage.adapter === "filesystem" ? storage.path : storage.adapter}${RESET}`);
|
|
141
134
|
infoImpl(`DB: ${DIM}${config.db.url}${RESET}`);
|
|
142
135
|
logImpl("");
|
|
143
136
|
|
|
144
137
|
const functionsAbsolute = resolvePathImpl(projectDir, config.rootDir);
|
|
145
138
|
const dbDir = resolvePathImpl(projectDir, config.db.url);
|
|
146
|
-
const storageDir = resolvePathImpl(projectDir, config.storage);
|
|
147
139
|
const migrationsDir = resolvePathImpl(projectDir, config.rootDir, "migrations");
|
|
148
140
|
// Metadata failures must stop before touching a running local server or its data.
|
|
149
141
|
// Keep schema/environment errors on the existing fallback path below.
|
|
150
142
|
let genEnv;
|
|
151
143
|
let genEnvError;
|
|
152
144
|
try {
|
|
153
|
-
genEnv = buildEnv(config, { cwd: projectDir });
|
|
145
|
+
genEnv = buildEnv(config, { cwd: projectDir, localStorage: storage });
|
|
154
146
|
} catch (error) {
|
|
155
147
|
if (error?.code?.startsWith("MIGRATION_METADATA_")) throw error;
|
|
156
148
|
genEnvError = error;
|
|
@@ -173,7 +165,9 @@ export function createDevLocalCommands({
|
|
|
173
165
|
}
|
|
174
166
|
mkdirSyncImpl(functionsAbsolute, { recursive: true });
|
|
175
167
|
mkdirSyncImpl(dbDir, { recursive: true });
|
|
176
|
-
|
|
168
|
+
if (storage.adapter === "filesystem") {
|
|
169
|
+
mkdirSyncImpl(resolvePathImpl(projectDir, storage.path), { recursive: true, mode: 0o700 });
|
|
170
|
+
}
|
|
177
171
|
mkdirSyncImpl(migrationsDir, { recursive: true });
|
|
178
172
|
|
|
179
173
|
const oldDataDir = resolvePathImpl(projectDir, "packages/server/data");
|
|
@@ -241,44 +235,13 @@ export function createDevLocalCommands({
|
|
|
241
235
|
await generateApiTsImpl(config, { cwd: projectDir });
|
|
242
236
|
|
|
243
237
|
logImpl("");
|
|
244
|
-
infoImpl("Starting
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const localServer = resolvePathImpl(projectDir, ".gencow", "server.js");
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
unlinkSyncImpl(localServer);
|
|
255
|
-
} catch {
|
|
256
|
-
/* ignore */
|
|
257
|
-
}
|
|
258
|
-
copyFileSyncImpl(bundledServer, localServer);
|
|
259
|
-
|
|
260
|
-
const cliRoot = resolvePathImpl(serverRoot, "..");
|
|
261
|
-
const dashboardSource = resolvePathImpl(cliRoot, "dashboard");
|
|
262
|
-
const dashboardDest = resolvePathImpl(projectDir, ".gencow", "dashboard");
|
|
263
|
-
if (existsSyncImpl(dashboardSource)) {
|
|
264
|
-
try {
|
|
265
|
-
rmSyncImpl(dashboardDest, { recursive: true, force: true });
|
|
266
|
-
} catch {
|
|
267
|
-
/* ignore */
|
|
268
|
-
}
|
|
269
|
-
cpSyncImpl(dashboardSource, dashboardDest, { recursive: true });
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
proc = spawnImpl("bun", ["--watch", localServer, "--gencow-local-development"], {
|
|
273
|
-
cwd: projectDir,
|
|
274
|
-
stdio: "inherit",
|
|
275
|
-
shell: true,
|
|
276
|
-
env: {
|
|
277
|
-
...buildEnv(config, { cwd: projectDir }),
|
|
278
|
-
GENCOW_DASHBOARD_DIR: dashboardDest,
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
}
|
|
238
|
+
infoImpl("Starting local Runtime with native Bun watch...\n");
|
|
239
|
+
const selection = getCliInvocationSelection();
|
|
240
|
+
const proc = spawnImpl("bun", ["--watch", fileURLToPath(new URL("./runtime-local-worker.mjs", import.meta.url)),
|
|
241
|
+
JSON.stringify({projectDir,configPath:selection?.configPath ?? null,client:selection?.client ?? null,target:selection?.target ?? null})], {
|
|
242
|
+
cwd: projectDir, stdio: "inherit", shell: false,
|
|
243
|
+
env: buildEnv(config, { cwd: projectDir, localStorage: storage }),
|
|
244
|
+
});
|
|
282
245
|
|
|
283
246
|
proc.on("exit", (code) => processRef.exit(code ?? 0));
|
|
284
247
|
processRef.on("SIGINT", () => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createAutomaticLocalDocumentConverter,
|
|
3
|
+
createLocalDocumentParserLoaders,
|
|
4
|
+
} from "../runtime/engine/document-local.mjs";
|
|
5
|
+
|
|
6
|
+
/** Trusted CLI-local supplier. Resolve CLI-owned parsers, never the tenant/workspace package graph. */
|
|
7
|
+
export function createCliDocumentConverter() {
|
|
8
|
+
return createAutomaticLocalDocumentConverter({
|
|
9
|
+
loaders: createLocalDocumentParserLoaders(import.meta.url),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { RuntimeDiagnosticError } from "../runtime/engine/index.mjs";
|
|
5
|
+
import { validateDashboardArtifact } from "./dashboard-artifact.mjs";
|
|
6
|
+
|
|
7
|
+
const ownCliRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
|
|
9
|
+
function failure(code, nextAction) {
|
|
10
|
+
return new RuntimeDiagnosticError({
|
|
11
|
+
code,
|
|
12
|
+
stage: "startup",
|
|
13
|
+
capability: "dashboard",
|
|
14
|
+
servingStarted: false,
|
|
15
|
+
dataImpact: "none",
|
|
16
|
+
retryable: false,
|
|
17
|
+
retryPrecondition:
|
|
18
|
+
"Correct dashboard configuration or restore the intended built artifact before restarting.",
|
|
19
|
+
nextAction,
|
|
20
|
+
correlationId: crypto.randomUUID(),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Local-only option policy runs before generic schema errors can erase its
|
|
25
|
+
* actionable diagnosis, and again on the normalized launch boundary. */
|
|
26
|
+
export function assertLocalDashboardConfiguration(config) {
|
|
27
|
+
const dashboard = config.localFeatures?.dashboard ?? config.experimental?.localFeatures?.dashboard;
|
|
28
|
+
if (dashboard === false || dashboard?.enabled === false) return undefined;
|
|
29
|
+
if ((dashboard?.path !== undefined && dashboard.path !== "/_dashboard") || dashboard?.port !== undefined) {
|
|
30
|
+
throw failure(
|
|
31
|
+
"RUNTIME_LOCAL_DASHBOARD_CONFIG_UNSUPPORTED",
|
|
32
|
+
"Use localFeatures.dashboard with the default /_dashboard mount and application port; remove dashboard.path/dashboard.port overrides, then run gencow dev --local.",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** CLI owns asset discovery; Runtime receives only immutable resolved launch options. */
|
|
38
|
+
export function resolveLocalDashboardPlan({ config, cliRoot = ownCliRoot }) {
|
|
39
|
+
const dashboard = config.localFeatures?.dashboard ?? config.experimental?.localFeatures?.dashboard;
|
|
40
|
+
if (dashboard === false || dashboard?.enabled === false) return undefined;
|
|
41
|
+
assertLocalDashboardConfiguration(config);
|
|
42
|
+
const checkout = resolve(cliRoot, "../..");
|
|
43
|
+
const workspace =
|
|
44
|
+
existsSync(resolve(checkout, "pnpm-workspace.yaml")) &&
|
|
45
|
+
existsSync(resolve(checkout, "apps/system/dashboard/package.json")) &&
|
|
46
|
+
resolve(checkout, "packages/cli") === resolve(cliRoot);
|
|
47
|
+
const directory = workspace
|
|
48
|
+
? resolve(checkout, "apps/system/dashboard/dist")
|
|
49
|
+
: resolve(cliRoot, "dashboard");
|
|
50
|
+
try {
|
|
51
|
+
return Object.freeze({ assetsDirectory: validateDashboardArtifact(directory), path: "/_dashboard" });
|
|
52
|
+
} catch {
|
|
53
|
+
throw failure(
|
|
54
|
+
"RUNTIME_LOCAL_DASHBOARD_ASSETS_MISSING",
|
|
55
|
+
workspace
|
|
56
|
+
? "Run pnpm run build:dashboard in the workspace, then run gencow dev --local."
|
|
57
|
+
: "In this app workspace, reinstall the same intended gencow version/artifact, then run gencow dev --local.",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|