openadminjs 0.2.0 → 0.3.0-rc.1
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/README.md +106 -151
- package/dist/adapt-package-manager.js +4 -1
- package/dist/create-project.d.ts +46 -0
- package/dist/create-project.js +417 -150
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.js +35 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +257 -39
- package/dist/render-schema.d.ts +0 -17
- package/dist/render-schema.js +25 -29
- package/dist/resource-slug.d.ts +1 -0
- package/dist/resource-slug.js +7 -0
- package/dist/runtime-mode.d.ts +16 -0
- package/dist/runtime-mode.js +138 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +133 -0
- package/package.json +14 -11
- package/template/.dockerignore +15 -0
- package/template/.env.production.example +5 -0
- package/template/Dockerfile +12 -0
- package/template/README.md +4 -3
- package/template/apps/admin/app/api/auth/login/route.ts +9 -9
- package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
- package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
- package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
- package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
- package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
- package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
- package/template/apps/admin/app/api-tokens/page.tsx +39 -39
- package/template/apps/admin/app/assistant/page.tsx +11 -0
- package/template/apps/admin/app/dashboard/page.tsx +45 -462
- package/template/apps/admin/app/globals.css +52 -16
- package/template/apps/admin/app/layout.tsx +1 -1
- package/template/apps/admin/app/login/page.tsx +13 -145
- package/template/apps/admin/app/plugins/page.tsx +16 -402
- package/template/apps/admin/app/profile/page.tsx +5 -2
- package/template/apps/admin/app/settings/page.tsx +14 -265
- package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
- package/template/apps/admin/components/app-shell.tsx +25 -373
- package/template/apps/admin/components/auth-guard.tsx +8 -28
- package/template/apps/admin/components/logo.tsx +1 -30
- package/template/apps/admin/components/resource-form.tsx +3 -3
- package/template/apps/admin/components/resource-table.tsx +12 -8
- package/template/apps/admin/lib/api.ts +45 -107
- package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
- package/template/apps/admin/lib/server-api.ts +7 -0
- package/template/apps/admin/lib/tokens.ts +9 -81
- package/template/apps/admin/middleware.ts +9 -50
- package/template/apps/admin/next.config.mjs +4 -0
- package/template/apps/admin/package.json +2 -1
- package/template/apps/admin/public/brand/favicon.svg +4 -1
- package/template/apps/admin/tailwind.config.ts +9 -8
- package/template/apps/api/package.json +10 -6
- package/template/apps/api/src/access/catalog.ts +4 -0
- package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
- package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
- package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
- package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
- package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
- package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
- package/template/apps/api/src/admin/admin.controller.ts +17 -4
- package/template/apps/api/src/admin/admin.module.ts +2 -2
- package/template/apps/api/src/admin/resource-policy.ts +1 -0
- package/template/apps/api/src/admin/resource-query.ts +1 -0
- package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
- package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
- package/template/apps/api/src/auth/auth.controller.ts +4 -2
- package/template/apps/api/src/auth/auth.service.ts +68 -83
- package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
- package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
- package/template/apps/api/src/common/api-exception.filter.ts +1 -0
- package/template/apps/api/src/common/auth.guard.ts +66 -39
- package/template/apps/api/src/common/json-field-codec.ts +12 -13
- package/template/apps/api/src/common/prisma.service.ts +9 -17
- package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
- package/template/apps/api/src/graphql/graphql.module.ts +5 -4
- package/template/apps/api/src/health/health.controller.ts +6 -0
- package/template/apps/api/src/main.ts +11 -2
- package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
- package/template/apps/api/src/resources/commerce.resource.ts +3 -34
- package/template/apps/api/src/resources/operations.resource.ts +1 -0
- package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
- package/template/apps/api/src/store/payment/payment.module.ts +2 -3
- package/template/apps/api/src/store/payment/payment.service.ts +121 -227
- package/template/apps/api/webpack.config.cjs +2 -1
- package/template/apps/web/next.config.mjs +4 -0
- package/template/apps/web/public/brand/favicon.svg +4 -1
- package/template/compose.yaml +56 -0
- package/template/examples/crm-admin/README.md +31 -0
- package/template/examples/crm-admin/package.json +17 -0
- package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/template/examples/crm-admin/src/index.ts +7 -0
- package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/template/examples/crm-admin/tsconfig.json +7 -0
- package/template/package.json +6 -1
- package/template/packages/admin-client/package.json +18 -0
- package/template/packages/admin-client/src/contracts.ts +29 -0
- package/template/packages/admin-client/src/index.ts +2 -0
- package/template/packages/admin-client/src/preferences.ts +57 -0
- package/template/packages/admin-client/tsconfig.json +12 -0
- package/template/packages/auth/package.json +1 -1
- package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
- package/template/packages/brand/src/generate-assets.mjs +17 -186
- package/template/packages/core/package.json +1 -1
- package/template/packages/mail/package.json +1 -1
- package/template/packages/nest/package.json +22 -0
- package/template/packages/nest/src/api-exception.filter.ts +23 -0
- package/template/packages/nest/src/index.ts +3 -0
- package/template/packages/nest/src/resource-policy.ts +64 -0
- package/template/packages/nest/src/resource-query.ts +103 -0
- package/template/packages/nest/tsconfig.json +12 -0
- package/template/packages/notifications/package.json +1 -1
- package/template/packages/payments/package.json +1 -1
- package/template/packages/permissions/package.json +1 -1
- package/template/packages/permissions/src/index.ts +2 -2
- package/template/packages/plugin-sdk/package.json +1 -1
- package/template/packages/plugin-sdk/src/index.ts +2 -2
- package/template/packages/prisma/package.json +21 -0
- package/template/packages/prisma/schema/ai.prisma +36 -0
- package/template/packages/prisma/schema/audit.prisma +13 -0
- package/template/packages/prisma/schema/commerce.prisma +79 -0
- package/template/packages/prisma/schema/content.prisma +27 -0
- package/template/packages/prisma/schema/core.prisma +106 -0
- package/template/packages/prisma/schema/header.prisma +8 -0
- package/template/packages/prisma/schema/jobs.prisma +9 -0
- package/template/packages/prisma/schema/media.prisma +9 -0
- package/template/packages/prisma/schema/modules.json +47 -0
- package/template/packages/prisma/schema/notifications.prisma +9 -0
- package/template/packages/prisma/schema/settings.prisma +8 -0
- package/template/packages/prisma/schema/tokens.prisma +10 -0
- package/template/packages/prisma/src/index.d.ts +12 -0
- package/template/packages/prisma/src/index.mjs +138 -0
- package/template/packages/queue/package.json +1 -1
- package/template/packages/resource/package.json +1 -1
- package/template/packages/resource/src/index.ts +1 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/index.ts +37 -0
- package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
- package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
- package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
- package/template/prisma/schema.prisma +82 -54
- package/template/prisma/seed.ts +14 -38
- package/template/runtime-versions.json +15 -0
- package/template/scripts/db-init.mjs +33 -0
- package/template/scripts/install-crm.mjs +50 -0
- package/template/scripts/migrate-existing.mjs +65 -0
- package/template/scripts/schema.mjs +48 -0
- package/template/tsconfig.base.json +23 -5
- package/LICENSE +0 -21
- package/dist/adapt-package-manager.test.d.ts +0 -1
- package/dist/adapt-package-manager.test.js +0 -76
- package/dist/cli.e2e.test.d.ts +0 -1
- package/dist/cli.e2e.test.js +0 -87
- package/dist/create-project.test.d.ts +0 -1
- package/dist/create-project.test.js +0 -275
- package/dist/database-providers.integration.test.d.ts +0 -1
- package/dist/database-providers.integration.test.js +0 -64
- package/dist/db-commands.test.d.ts +0 -1
- package/dist/db-commands.test.js +0 -27
- package/dist/doctor.test.d.ts +0 -1
- package/dist/doctor.test.js +0 -102
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -11
- package/dist/render-schema.test.d.ts +0 -1
- package/dist/render-schema.test.js +0 -57
- package/dist/resource-slug.test.d.ts +0 -1
- package/dist/resource-slug.test.js +0 -9
- package/dist/secrets.test.d.ts +0 -1
- package/dist/secrets.test.js +0 -36
- package/dist/security.test.d.ts +0 -1
- package/dist/security.test.js +0 -54
- package/dist/validate-name.test.d.ts +0 -1
- package/dist/validate-name.test.js +0 -63
- package/template/apps/admin/.storybook/main.ts +0 -12
- package/template/apps/admin/.storybook/preview.ts +0 -10
- package/template/apps/admin/app/login/page.test.tsx +0 -18
- package/template/apps/admin/components/auth-guard.test.tsx +0 -55
- package/template/apps/admin/components/logo.stories.tsx +0 -24
- package/template/apps/admin/lib/api.test.ts +0 -118
- package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
- package/template/apps/admin/vitest.config.ts +0 -7
- package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
- package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
- package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
- package/template/apps/api/src/app.module.test.ts +0 -12
- package/template/apps/api/src/auth/auth.service.test.ts +0 -78
- package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
- package/template/apps/api/src/common/auth.guard.test.ts +0 -62
- package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
- package/template/apps/api/src/common/json-field-codec.test.ts +0 -76
- package/template/apps/api/src/common/prisma.service.test.ts +0 -19
- package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
- package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
- package/template/apps/api/src/graphql/graphql-apollo-config.test.ts +0 -26
- package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
- package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
- package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
- package/template/apps/api/src/queue/queue.service.test.ts +0 -33
- package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
- package/template/apps/api/vitest.config.ts +0 -21
- package/template/apps/web/lib/seo.test.ts +0 -41
- package/template/apps/web/vitest.config.ts +0 -19
- package/template/packages/auth/src/index.test.ts +0 -10
- package/template/packages/brand/src/index.test.ts +0 -9
- package/template/packages/core/src/index.test.ts +0 -27
- package/template/packages/core/vitest.config.ts +0 -9
- package/template/packages/mail/src/index.test.ts +0 -23
- package/template/packages/notifications/src/index.test.ts +0 -9
- package/template/packages/permissions/src/blueprints.test.ts +0 -62
- package/template/packages/permissions/src/index.test.ts +0 -34
- package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
- package/template/packages/plugin-sdk/vitest.config.ts +0 -5
- package/template/packages/queue/src/index.test.ts +0 -12
- package/template/packages/resource/src/index.test.ts +0 -196
- package/template/packages/storage/src/index.test.ts +0 -10
package/dist/create-project.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { migrateRuntime } from "./runtime-mode.js";
|
|
2
|
+
import { writeManagedBaseline } from "./upgrade.js";
|
|
1
3
|
import { accessSync, constants as fsConstants, existsSync, mkdirSync, mkdtempSync, readdirSync, renameSync, rmSync } from "node:fs";
|
|
2
4
|
import net from "node:net";
|
|
3
5
|
import { dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
4
6
|
import { spawnSync } from "node:child_process";
|
|
5
7
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { cancel, confirm, intro, isCancel, note, outro, select, text } from "@clack/prompts";
|
|
8
|
+
import { cancel, confirm, intro, isCancel, note, outro, password, select, text } from "@clack/prompts";
|
|
7
9
|
import fsExtra from "fs-extra";
|
|
8
10
|
import pc from "picocolors";
|
|
9
11
|
import { adaptProjectForPackageManager } from "./adapt-package-manager.js";
|
|
10
|
-
import { generateSecret } from "./secrets.js";
|
|
12
|
+
import { generateSecret, inspectPassword } from "./secrets.js";
|
|
11
13
|
import { renderSchemaForProvider } from "./render-schema.js";
|
|
12
14
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
15
|
const { copySync, ensureDirSync, readFileSync, writeFileSync } = fsExtra;
|
|
@@ -36,6 +38,8 @@ coverage
|
|
|
36
38
|
.env
|
|
37
39
|
.env.*
|
|
38
40
|
!.env.example
|
|
41
|
+
.openadminjs-runtime-backup/
|
|
42
|
+
prisma/schema.prisma.before-compose
|
|
39
43
|
|
|
40
44
|
# logs
|
|
41
45
|
*.log
|
|
@@ -195,6 +199,32 @@ export function validateSuperadminEmailInput(value, fallback = DEFAULT_SUPERADMI
|
|
|
195
199
|
const finalValue = resolveSuperadminEmail(value, fallback);
|
|
196
200
|
return /^\S+@\S+\.\S+$/.test(finalValue) ? undefined : "Enter a valid email address.";
|
|
197
201
|
}
|
|
202
|
+
export const DEFAULT_REDIS_URL = "redis://localhost:6379";
|
|
203
|
+
export const PACKAGE_MANAGERS = ["pnpm", "npm", "yarn"];
|
|
204
|
+
/** Returns the first package manager that is installed on PATH, or undefined. */
|
|
205
|
+
export function firstAvailablePackageManager(preference = PACKAGE_MANAGERS) {
|
|
206
|
+
return preference.find((pm) => isPackageManagerAvailable(pm));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Validates a Redis URL. An empty value is VALID — it disables background job
|
|
210
|
+
* queues. A non-empty value must be a parseable redis:// (or rediss://) URL so
|
|
211
|
+
* pressing Enter on the shown default is always accepted.
|
|
212
|
+
*/
|
|
213
|
+
export function validateRedisUrlInput(value) {
|
|
214
|
+
const v = value.trim();
|
|
215
|
+
if (v === "")
|
|
216
|
+
return undefined;
|
|
217
|
+
try {
|
|
218
|
+
const url = new URL(v);
|
|
219
|
+
if (url.protocol !== "redis:" && url.protocol !== "rediss:") {
|
|
220
|
+
return "Redis URL must start with redis:// or rediss:// (or be blank to disable queues).";
|
|
221
|
+
}
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return "Enter a valid Redis URL (or leave blank to disable queues).";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
198
228
|
export function databaseUrl(packageName, database) {
|
|
199
229
|
if (database === "sqlite") {
|
|
200
230
|
return "file:./dev.db";
|
|
@@ -235,6 +265,31 @@ function runPackageManagerScript(packageManager, script, cwd) {
|
|
|
235
265
|
throw new Error(`Failed to run "${display}" in ${cwd}.`);
|
|
236
266
|
}
|
|
237
267
|
}
|
|
268
|
+
/** Applies schema to the database after install — non-interactive and provider-aware. */
|
|
269
|
+
function runDatabaseSetup(packageManager, database, cwd) {
|
|
270
|
+
const schemaFlag = ["--schema", "../../prisma/schema.prisma"];
|
|
271
|
+
const prismaArgs = database === "postgresql"
|
|
272
|
+
? ["migrate", "deploy", ...schemaFlag]
|
|
273
|
+
: ["db", "push", ...schemaFlag];
|
|
274
|
+
const label = database === "postgresql" ? "prisma migrate deploy" : "prisma db push";
|
|
275
|
+
if (packageManager === "npm") {
|
|
276
|
+
const result = spawnSync("npm", ["exec", "prisma", ...prismaArgs], { cwd: join(cwd, "apps", "api"), stdio: "inherit" });
|
|
277
|
+
if (result.status !== 0 || result.error) {
|
|
278
|
+
throw new Error(`Failed to run "${label}" in ${cwd}/apps/api.\n` +
|
|
279
|
+
"If Prisma engine binaries could not download, check your network/proxy and retry.\n" +
|
|
280
|
+
`Resume with: cd <project> && npm exec prisma ${prismaArgs.join(" ")} (from apps/api).`);
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const filterArgs = packageManager === "pnpm"
|
|
285
|
+
? ["--filter", "@openadminjs/api", "exec", "prisma", ...prismaArgs]
|
|
286
|
+
: ["workspace", "@openadminjs/api", "exec", "prisma", ...prismaArgs];
|
|
287
|
+
const result = spawnSync(packageManager, filterArgs, { cwd, stdio: "inherit" });
|
|
288
|
+
if (result.status !== 0 || result.error) {
|
|
289
|
+
throw new Error(`Failed to run "${label}" via ${packageManager}.\n` +
|
|
290
|
+
"If Prisma engine binaries could not download, check your network/proxy and retry.");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
238
293
|
function runInstall(packageManager, cwd) {
|
|
239
294
|
const args = packageManager === "yarn" ? [] : ["install"];
|
|
240
295
|
const result = spawnSync(packageManager, args, { cwd, stdio: "inherit" });
|
|
@@ -257,6 +312,7 @@ function writeEnvExample(targetDir, database) {
|
|
|
257
312
|
"# Copy this file to apps/api/.env and fill in real values.",
|
|
258
313
|
"# NEVER commit the real .env — it is ignored by .gitignore.",
|
|
259
314
|
`DATABASE_URL=${dbUrl}`,
|
|
315
|
+
"# REDIS_URL is optional. Leave it blank to disable background job queues.",
|
|
260
316
|
"REDIS_URL=redis://localhost:6379",
|
|
261
317
|
"# Generate strong secrets, e.g. `node -e \"console.log(require('crypto').randomBytes(48).toString('base64url'))\"`",
|
|
262
318
|
"JWT_SECRET=replace-with-a-long-random-secret",
|
|
@@ -275,6 +331,9 @@ function resolveCreateProjectOptions(options) {
|
|
|
275
331
|
if (options.database && !["postgresql", "mysql", "sqlite"].includes(options.database)) {
|
|
276
332
|
throw new Error('database must be "postgresql", "mysql", or "sqlite".');
|
|
277
333
|
}
|
|
334
|
+
// Redis is optional: an empty REDIS_URL disables background job queues, which
|
|
335
|
+
// the generated API handles gracefully at runtime.
|
|
336
|
+
const redisUrl = options.skipRedis ? "" : (options.redisUrl ?? "");
|
|
278
337
|
const missing = [];
|
|
279
338
|
if (!options.database)
|
|
280
339
|
missing.push("database");
|
|
@@ -284,8 +343,6 @@ function resolveCreateProjectOptions(options) {
|
|
|
284
343
|
missing.push("superadminPassword");
|
|
285
344
|
if (!options.databaseUrl)
|
|
286
345
|
missing.push("databaseUrl");
|
|
287
|
-
if (!options.redisUrl)
|
|
288
|
-
missing.push("redisUrl");
|
|
289
346
|
if (!options.jwtSecret)
|
|
290
347
|
missing.push("jwtSecret");
|
|
291
348
|
if (!options.jwtRefreshSecret)
|
|
@@ -305,13 +362,16 @@ function resolveCreateProjectOptions(options) {
|
|
|
305
362
|
superadminEmail: options.superadminEmail,
|
|
306
363
|
superadminPassword: options.superadminPassword,
|
|
307
364
|
databaseUrl: options.databaseUrl,
|
|
308
|
-
redisUrl
|
|
365
|
+
redisUrl,
|
|
366
|
+
skipRedis: options.skipRedis ?? redisUrl.trim() === "",
|
|
309
367
|
jwtSecret: options.jwtSecret,
|
|
310
368
|
jwtRefreshSecret: options.jwtRefreshSecret,
|
|
311
369
|
adminOrigin: options.adminOrigin,
|
|
312
370
|
apiPort: options.apiPort,
|
|
313
371
|
git: options.git ?? false,
|
|
314
372
|
install: options.install ?? false,
|
|
373
|
+
nonInteractive: options.nonInteractive ?? false,
|
|
374
|
+
runtimeMode: options.runtimeMode ?? "source",
|
|
315
375
|
templateDir: options.templateDir ?? defaultTemplateDir()
|
|
316
376
|
};
|
|
317
377
|
}
|
|
@@ -346,10 +406,20 @@ export function createProject(options) {
|
|
|
346
406
|
throw new Error("Failed to initialize git repository.");
|
|
347
407
|
}
|
|
348
408
|
}
|
|
409
|
+
let dbInitialized = false;
|
|
349
410
|
if (resolved.install) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
411
|
+
// The scaffold is fully written at this point. If install / db setup fails
|
|
412
|
+
// we keep the project directory and surface an exact resume command rather
|
|
413
|
+
// than deleting the user's freshly generated files.
|
|
414
|
+
try {
|
|
415
|
+
runInstall(resolved.packageManager, targetDir);
|
|
416
|
+
runDatabaseSetup(resolved.packageManager, resolved.database, targetDir);
|
|
417
|
+
runPackageManagerScript(resolved.packageManager, "db:seed", targetDir);
|
|
418
|
+
dbInitialized = true;
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
throw new SetupIncompleteError(error instanceof Error ? error.message : "Setup failed after the project was created.", { targetDir, appName, packageManager: resolved.packageManager });
|
|
422
|
+
}
|
|
353
423
|
}
|
|
354
424
|
return {
|
|
355
425
|
appName,
|
|
@@ -360,9 +430,30 @@ export function createProject(options) {
|
|
|
360
430
|
superadminEmail: resolved.superadminEmail,
|
|
361
431
|
git: resolved.git,
|
|
362
432
|
install: resolved.install,
|
|
363
|
-
dbInitialized
|
|
433
|
+
dbInitialized,
|
|
434
|
+
redisEnabled: resolved.redisUrl.trim() !== "",
|
|
435
|
+
passwordGenerated: false
|
|
364
436
|
};
|
|
365
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Thrown when the scaffold was generated successfully but a later step
|
|
440
|
+
* (install, migrate, seed) failed. Carries the exact command to resume so the
|
|
441
|
+
* user never has to guess, and signals that the directory was intentionally
|
|
442
|
+
* preserved (never auto-deleted).
|
|
443
|
+
*/
|
|
444
|
+
export class SetupIncompleteError extends Error {
|
|
445
|
+
targetDir;
|
|
446
|
+
resumeCommand;
|
|
447
|
+
constructor(message, meta) {
|
|
448
|
+
const pm = meta.packageManager;
|
|
449
|
+
const install = pm === "yarn" ? "yarn" : `${pm} install`;
|
|
450
|
+
const resume = `cd ${meta.appName} && ${install} && ${pm} run db:migrate && ${pm} run db:seed`;
|
|
451
|
+
super(`${message}\n\nThe project was created at ${meta.targetDir} and left in place.\nResume setup with:\n ${resume}`);
|
|
452
|
+
this.name = "SetupIncompleteError";
|
|
453
|
+
this.targetDir = meta.targetDir;
|
|
454
|
+
this.resumeCommand = resume;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
366
457
|
function generateIntoDir(targetDir, resolved, meta) {
|
|
367
458
|
ensureDirSync(targetDir);
|
|
368
459
|
copySync(resolved.templateDir, targetDir, {
|
|
@@ -399,8 +490,20 @@ function generateIntoDir(targetDir, resolved, meta) {
|
|
|
399
490
|
const schema = readFileSync(schemaPath, "utf8");
|
|
400
491
|
writeFileSync(schemaPath, renderSchemaForProvider(schema, resolved.database));
|
|
401
492
|
}
|
|
493
|
+
// Non-PostgreSQL development profiles do not ship provider-specific migration history.
|
|
494
|
+
// Bootstrap is non-interactive and must never accept data loss automatically.
|
|
495
|
+
const apiPackagePath = join(targetDir, "apps", "api", "package.json");
|
|
496
|
+
if (existsSync(apiPackagePath)) {
|
|
497
|
+
const apiPackage = JSON.parse(readFileSync(apiPackagePath, "utf8"));
|
|
498
|
+
apiPackage.scripts["db:migrate"] = "prisma db push --schema ../../prisma/schema.prisma";
|
|
499
|
+
// Production deploy requires the operator to supply provider-correct reviewed migrations.
|
|
500
|
+
writeFileSync(apiPackagePath, JSON.stringify(apiPackage, null, 2) + "\n");
|
|
501
|
+
}
|
|
402
502
|
}
|
|
403
503
|
adaptProjectForPackageManager(targetDir, resolved.packageManager);
|
|
504
|
+
writeManagedBaseline(targetDir);
|
|
505
|
+
if (resolved.runtimeMode === "registry")
|
|
506
|
+
migrateRuntime(targetDir, resolved.templateDir, { apply: true, initial: true });
|
|
404
507
|
// Git safety: write .gitignore + .env.example (tracked, placeholders only) as
|
|
405
508
|
// part of generation, i.e. before any `git init`.
|
|
406
509
|
writeGitignore(targetDir);
|
|
@@ -410,9 +513,12 @@ function generateIntoDir(targetDir, resolved, meta) {
|
|
|
410
513
|
const apiEnvDir = join(targetDir, "apps", "api");
|
|
411
514
|
if (existsSync(templateApiDir)) {
|
|
412
515
|
mkdirSync(apiEnvDir, { recursive: true });
|
|
516
|
+
const redisLine = resolved.redisUrl.trim() === ""
|
|
517
|
+
? "# REDIS_URL is unset — background job queues are disabled.\n# Set it (e.g. redis://localhost:6379) to enable BullMQ queues.\nREDIS_URL="
|
|
518
|
+
: `REDIS_URL=${resolved.redisUrl}`;
|
|
413
519
|
writeFileSync(join(apiEnvDir, ".env"), [
|
|
414
520
|
`DATABASE_URL=${resolved.databaseUrl}`,
|
|
415
|
-
|
|
521
|
+
redisLine,
|
|
416
522
|
`JWT_SECRET=${resolved.jwtSecret}`,
|
|
417
523
|
`JWT_REFRESH_SECRET=${resolved.jwtRefreshSecret}`,
|
|
418
524
|
`ADMIN_ORIGIN=${resolved.adminOrigin}`,
|
|
@@ -422,11 +528,34 @@ function generateIntoDir(targetDir, resolved, meta) {
|
|
|
422
528
|
].join("\n") + "\n");
|
|
423
529
|
}
|
|
424
530
|
}
|
|
531
|
+
/** Returns the shell form to run a root script with the given package manager. */
|
|
532
|
+
function pmRun(pm, script) {
|
|
533
|
+
if (pm === "yarn")
|
|
534
|
+
return `yarn ${script}`;
|
|
535
|
+
if (pm === "npm")
|
|
536
|
+
return `npm run ${script}`;
|
|
537
|
+
return `pnpm ${script}`;
|
|
538
|
+
}
|
|
425
539
|
export function printNextSteps(result) {
|
|
426
540
|
const pm = result.packageManager;
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
|
|
541
|
+
const install = pm === "yarn" ? "yarn" : `${pm} install`;
|
|
542
|
+
const installStep = result.install
|
|
543
|
+
? ""
|
|
544
|
+
: `\n ${install}\n ${pmRun(pm, "db:migrate")}\n ${pmRun(pm, "db:seed")}`;
|
|
545
|
+
const dbStepNote = result.dbInitialized
|
|
546
|
+
? "\nDatabase initialized: migrations + seed completed automatically."
|
|
547
|
+
: "";
|
|
548
|
+
// `dev` starts ONLY the admin UI and the API (see root "dev" script). The
|
|
549
|
+
// public web app is optional and started separately, so we do not advertise
|
|
550
|
+
// a URL the default command never serves.
|
|
551
|
+
const password = result.passwordGenerated
|
|
552
|
+
? "a generated password (see apps/api/.env)"
|
|
553
|
+
: "<the password you entered>";
|
|
554
|
+
const webNote = `\n\nOptional public web app (not started by "${pmRun(pm, "dev")}"):\n ${pm === "yarn" ? "yarn workspace @openadminjs/web dev" : pm === "npm" ? "npm run dev --workspace=@openadminjs/web" : "pnpm --filter @openadminjs/web dev"} → http://localhost:3001`;
|
|
555
|
+
const redisNote = result.redisEnabled
|
|
556
|
+
? ""
|
|
557
|
+
: "\n\nBackground job queues are disabled (no REDIS_URL). Set REDIS_URL in apps/api/.env to enable them.";
|
|
558
|
+
outro(`${pc.green("Project created.")}\n\nNext steps:\n cd ${result.appName}${installStep}\n ${pmRun(pm, "dev")}${dbStepNote}\n\nAdmin: http://localhost:3000\nAPI: http://localhost:4000\nSwagger: http://localhost:4000/api/docs${webNote}${redisNote}\n\nSuperadmin: ${result.superadminEmail} / ${password}`);
|
|
430
559
|
}
|
|
431
560
|
/** Warns where secrets live and that they must never be committed. Never prints secret values. */
|
|
432
561
|
export function printSecurityNotice(result) {
|
|
@@ -437,158 +566,242 @@ export function printSecurityNotice(result) {
|
|
|
437
566
|
pc.yellow("Do NOT commit apps/api/.env or share it. Rotate secrets before production.")
|
|
438
567
|
].join("\n"), "Security");
|
|
439
568
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
(
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
(await select({
|
|
473
|
-
message: "Database",
|
|
474
|
-
options: [
|
|
475
|
-
{ value: "postgresql", label: "PostgreSQL" },
|
|
476
|
-
{ value: "mysql", label: "MySQL" },
|
|
477
|
-
{ value: "sqlite", label: "SQLite (local file, zero-setup)" }
|
|
478
|
-
],
|
|
479
|
-
initialValue: "postgresql"
|
|
480
|
-
}));
|
|
481
|
-
if (isCancel(database)) {
|
|
482
|
-
cancel("Cancelled");
|
|
483
|
-
return undefined;
|
|
569
|
+
/** Cancellation sentinel used to unwind prompts without throwing. */
|
|
570
|
+
const CANCELLED = Symbol("cancelled");
|
|
571
|
+
/** Generates a strong, human-usable password (used in non-interactive mode). */
|
|
572
|
+
export function generatePassword() {
|
|
573
|
+
return generateSecret(18);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Resolves the package manager, honoring an explicit choice, detecting what is
|
|
577
|
+
* actually installed, and offering a recovery path when the desired manager is
|
|
578
|
+
* missing (issue: pnpm-unavailable should not hard-exit).
|
|
579
|
+
*/
|
|
580
|
+
async function resolvePackageManager(options, interactive) {
|
|
581
|
+
const available = PACKAGE_MANAGERS.filter(isPackageManagerAvailable);
|
|
582
|
+
let desired = options.packageManager;
|
|
583
|
+
if (!desired) {
|
|
584
|
+
if (interactive) {
|
|
585
|
+
const pool = available.length ? available : PACKAGE_MANAGERS;
|
|
586
|
+
const answer = await select({
|
|
587
|
+
message: "Package manager",
|
|
588
|
+
options: pool.map((pm) => ({
|
|
589
|
+
value: pm,
|
|
590
|
+
label: pm === "pnpm" ? "pnpm (recommended)" : pm
|
|
591
|
+
})),
|
|
592
|
+
initialValue: pool.includes("pnpm") ? "pnpm" : pool[0]
|
|
593
|
+
});
|
|
594
|
+
if (isCancel(answer))
|
|
595
|
+
return CANCELLED;
|
|
596
|
+
desired = answer;
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
desired = firstAvailablePackageManager() ?? "npm";
|
|
600
|
+
}
|
|
484
601
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
602
|
+
if (isPackageManagerAvailable(desired))
|
|
603
|
+
return desired;
|
|
604
|
+
const fallback = firstAvailablePackageManager();
|
|
605
|
+
const corepackHint = desired === "pnpm" ? " Enable it with `corepack enable && corepack prepare pnpm@latest --activate`." : "";
|
|
606
|
+
if (!interactive) {
|
|
607
|
+
if (options.packageManager) {
|
|
608
|
+
throw new Error(`${desired} was requested but is not installed.${corepackHint}` +
|
|
609
|
+
(fallback ? ` Or re-run with --package-manager ${fallback}.` : ""));
|
|
610
|
+
}
|
|
611
|
+
if (!fallback) {
|
|
612
|
+
throw new Error("No supported package manager (pnpm, npm, or yarn) was found on PATH.");
|
|
613
|
+
}
|
|
614
|
+
return fallback;
|
|
495
615
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if (isCancel(superadminPassword)) {
|
|
506
|
-
cancel("Cancelled");
|
|
507
|
-
return undefined;
|
|
616
|
+
if (available.length) {
|
|
617
|
+
const answer = await select({
|
|
618
|
+
message: `${desired} is not installed. Choose an available package manager`,
|
|
619
|
+
options: available.map((pm) => ({ value: pm, label: pm })),
|
|
620
|
+
initialValue: available[0]
|
|
621
|
+
});
|
|
622
|
+
if (isCancel(answer))
|
|
623
|
+
return CANCELLED;
|
|
624
|
+
return answer;
|
|
508
625
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
626
|
+
throw new Error(`${desired} is not installed and no supported package manager was found on PATH.${corepackHint}`);
|
|
627
|
+
}
|
|
628
|
+
/** Prints a plain (non-clack) summary suitable for non-interactive / CI output. */
|
|
629
|
+
function printSummaryPlain(result) {
|
|
630
|
+
const pm = result.packageManager;
|
|
631
|
+
const lines = [
|
|
632
|
+
"",
|
|
633
|
+
`Project created at ${result.targetDir}`,
|
|
634
|
+
`Package manager: ${pm} Database: ${result.database}`,
|
|
635
|
+
result.dbInitialized ? "Database initialized (migrate + seed)." : "Run migrate + seed before starting.",
|
|
636
|
+
result.redisEnabled ? "Redis queues: enabled." : "Redis queues: disabled (no REDIS_URL).",
|
|
637
|
+
"Secrets written to apps/api/.env (git-ignored). Never commit it.",
|
|
638
|
+
result.passwordGenerated
|
|
639
|
+
? "Superadmin password was generated — read it from apps/api/.env (SUPERADMIN_PASSWORD)."
|
|
640
|
+
: `Superadmin: ${result.superadminEmail}`,
|
|
641
|
+
""
|
|
642
|
+
];
|
|
643
|
+
console.log(lines.join("\n"));
|
|
644
|
+
}
|
|
645
|
+
export async function createProjectInteractive(options = {}) {
|
|
646
|
+
// Preflight checks that don't require project files run before anything is written.
|
|
647
|
+
assertSupportedNode();
|
|
648
|
+
// Interactive only when stdin is a TTY and the caller did not opt out. This
|
|
649
|
+
// avoids `uv_tty_init EINVAL` crashes in CI / piped environments.
|
|
650
|
+
const interactive = !options.nonInteractive && Boolean(process.stdin.isTTY);
|
|
651
|
+
if (!interactive && !options.projectName) {
|
|
652
|
+
throw new Error("A project name is required in non-interactive mode.\n" +
|
|
653
|
+
" Example: openadminjs create my-app --yes --database sqlite\n" +
|
|
654
|
+
"(stdin is not a TTY, or --yes / --non-interactive was passed.)");
|
|
655
|
+
}
|
|
656
|
+
if (interactive)
|
|
657
|
+
intro(pc.green("Create OpenAdminJS"));
|
|
658
|
+
// ── project name ──
|
|
659
|
+
let projectName = options.projectName;
|
|
660
|
+
if (!projectName) {
|
|
661
|
+
const answer = await text({ message: "Project name", defaultValue: "my-app", placeholder: "my-app" });
|
|
662
|
+
if (isCancel(answer))
|
|
663
|
+
return cancelledUndefined();
|
|
664
|
+
projectName = String(answer);
|
|
665
|
+
}
|
|
666
|
+
// ── package manager (with availability fallback) ──
|
|
667
|
+
const packageManager = await resolvePackageManager(options, interactive);
|
|
668
|
+
if (packageManager === CANCELLED)
|
|
669
|
+
return cancelledUndefined();
|
|
670
|
+
// ── database ──
|
|
671
|
+
let database = options.database;
|
|
672
|
+
if (!database) {
|
|
673
|
+
if (interactive) {
|
|
674
|
+
const answer = await select({
|
|
675
|
+
message: "Database",
|
|
676
|
+
options: [
|
|
677
|
+
{ value: "postgresql", label: "PostgreSQL" },
|
|
678
|
+
{ value: "mysql", label: "MySQL" },
|
|
679
|
+
{ value: "sqlite", label: "SQLite (local file, zero-setup)" }
|
|
680
|
+
],
|
|
681
|
+
initialValue: "postgresql"
|
|
682
|
+
});
|
|
683
|
+
if (isCancel(answer))
|
|
684
|
+
return cancelledUndefined();
|
|
685
|
+
database = answer;
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
database = "sqlite";
|
|
689
|
+
}
|
|
517
690
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
691
|
+
// ── superadmin email ──
|
|
692
|
+
let email = options.superadminEmail;
|
|
693
|
+
if (!email) {
|
|
694
|
+
if (interactive) {
|
|
695
|
+
const answer = await text({
|
|
696
|
+
message: "Superadmin email",
|
|
697
|
+
defaultValue: DEFAULT_SUPERADMIN_EMAIL,
|
|
698
|
+
placeholder: DEFAULT_SUPERADMIN_EMAIL,
|
|
699
|
+
validate: (value) => validateSuperadminEmailInput(value)
|
|
700
|
+
});
|
|
701
|
+
if (isCancel(answer))
|
|
702
|
+
return cancelledUndefined();
|
|
703
|
+
email = String(answer);
|
|
530
704
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const next = await text({
|
|
534
|
-
message: "Database URL",
|
|
535
|
-
defaultValue: checkedDatabaseUrl
|
|
536
|
-
});
|
|
537
|
-
if (isCancel(next)) {
|
|
538
|
-
cancel("Cancelled");
|
|
539
|
-
return undefined;
|
|
705
|
+
else {
|
|
706
|
+
email = DEFAULT_SUPERADMIN_EMAIL;
|
|
540
707
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
708
|
+
}
|
|
709
|
+
const resolvedEmail = resolveSuperadminEmail(String(email));
|
|
710
|
+
// ── superadmin password (masked in interactive mode; generated otherwise) ──
|
|
711
|
+
let passwordGenerated = false;
|
|
712
|
+
let superadminPassword = options.superadminPassword;
|
|
713
|
+
if (!superadminPassword) {
|
|
714
|
+
if (interactive) {
|
|
715
|
+
const answer = await password({
|
|
716
|
+
message: "Superadmin password (input hidden, min 8 chars)",
|
|
549
717
|
validate(value) {
|
|
550
|
-
|
|
718
|
+
const { weak, reason } = inspectPassword(value);
|
|
719
|
+
return weak ? capitalize(reason ?? "Password is too weak.") : undefined;
|
|
551
720
|
}
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
721
|
+
});
|
|
722
|
+
if (isCancel(answer))
|
|
723
|
+
return cancelledUndefined();
|
|
724
|
+
superadminPassword = String(answer);
|
|
556
725
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const redisError = await validateRedisConnectivity(checkedRedisUrl);
|
|
561
|
-
if (!redisError)
|
|
562
|
-
break;
|
|
563
|
-
const retry = await confirm({
|
|
564
|
-
message: `${redisError} Retry entering REDIS_URL?`,
|
|
565
|
-
initialValue: true
|
|
566
|
-
});
|
|
567
|
-
if (isCancel(retry)) {
|
|
568
|
-
cancel("Cancelled");
|
|
569
|
-
return undefined;
|
|
726
|
+
else {
|
|
727
|
+
superadminPassword = generatePassword();
|
|
728
|
+
passwordGenerated = true;
|
|
570
729
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
730
|
+
}
|
|
731
|
+
// ── database URL (Enter accepts the shown default) ──
|
|
732
|
+
const defaultDbUrl = databaseUrl(toPackageName(String(projectName)), database);
|
|
733
|
+
let checkedDatabaseUrl = (options.databaseUrl ?? "").trim();
|
|
734
|
+
if (!checkedDatabaseUrl) {
|
|
735
|
+
if (interactive) {
|
|
736
|
+
const answer = await text({
|
|
737
|
+
message: "Database URL",
|
|
738
|
+
defaultValue: defaultDbUrl,
|
|
739
|
+
placeholder: defaultDbUrl,
|
|
740
|
+
validate: (value) => validateDatabaseUrlInput(database, value, defaultDbUrl)
|
|
741
|
+
});
|
|
742
|
+
if (isCancel(answer))
|
|
743
|
+
return cancelledUndefined();
|
|
744
|
+
checkedDatabaseUrl = String(answer).trim() || defaultDbUrl;
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
checkedDatabaseUrl = defaultDbUrl;
|
|
580
748
|
}
|
|
581
|
-
|
|
749
|
+
}
|
|
750
|
+
// Connectivity is checked only interactively and never blocks: the user can
|
|
751
|
+
// decline to retry and continue (e.g. DB not started yet).
|
|
752
|
+
if (interactive) {
|
|
753
|
+
const outcome = await confirmConnectivityLoop(() => validateDbConnectivity(database, checkedDatabaseUrl), "DATABASE_URL", () => text({ message: "Database URL", defaultValue: checkedDatabaseUrl, placeholder: checkedDatabaseUrl }), (next) => {
|
|
754
|
+
checkedDatabaseUrl = next.trim() || checkedDatabaseUrl;
|
|
755
|
+
});
|
|
756
|
+
if (outcome === CANCELLED)
|
|
757
|
+
return cancelledUndefined();
|
|
758
|
+
}
|
|
759
|
+
// ── Redis (optional; blank disables background job queues) ──
|
|
760
|
+
let checkedRedisUrl;
|
|
761
|
+
if (options.skipRedis) {
|
|
762
|
+
checkedRedisUrl = "";
|
|
763
|
+
}
|
|
764
|
+
else if (options.redisUrl !== undefined) {
|
|
765
|
+
checkedRedisUrl = options.redisUrl.trim();
|
|
766
|
+
}
|
|
767
|
+
else if (interactive) {
|
|
768
|
+
const def = database === "sqlite" ? "" : DEFAULT_REDIS_URL;
|
|
769
|
+
const answer = await text({
|
|
770
|
+
message: "Redis URL (blank to disable background job queues)",
|
|
771
|
+
defaultValue: def,
|
|
772
|
+
placeholder: def || "blank = queues disabled",
|
|
773
|
+
validate: (value) => validateRedisUrlInput(value)
|
|
774
|
+
});
|
|
775
|
+
if (isCancel(answer))
|
|
776
|
+
return cancelledUndefined();
|
|
777
|
+
checkedRedisUrl = String(answer).trim();
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
checkedRedisUrl = "";
|
|
781
|
+
}
|
|
782
|
+
if (interactive && checkedRedisUrl) {
|
|
783
|
+
const outcome = await confirmConnectivityLoop(() => validateRedisConnectivity(checkedRedisUrl), "REDIS_URL", () => text({ message: "Redis URL (blank to disable)", defaultValue: checkedRedisUrl }), (next) => {
|
|
784
|
+
checkedRedisUrl = next.trim();
|
|
785
|
+
});
|
|
786
|
+
if (outcome === CANCELLED)
|
|
787
|
+
return cancelledUndefined();
|
|
582
788
|
}
|
|
583
789
|
// JWT secrets are generated with a CSPRNG — never prompted with predictable defaults.
|
|
584
790
|
const jwtSecret = options.jwtSecret ?? generateSecret();
|
|
585
791
|
const jwtRefreshSecret = options.jwtRefreshSecret ?? generateSecret();
|
|
586
792
|
const adminOrigin = options.adminOrigin ?? "http://localhost:3000";
|
|
587
793
|
const apiPort = options.apiPort ?? "4000";
|
|
588
|
-
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
|
|
794
|
+
let git = options.git;
|
|
795
|
+
if (git === undefined) {
|
|
796
|
+
if (interactive) {
|
|
797
|
+
const answer = await confirm({ message: "Initialize git?", initialValue: true });
|
|
798
|
+
if (isCancel(answer))
|
|
799
|
+
return cancelledUndefined();
|
|
800
|
+
git = answer;
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
git = true;
|
|
804
|
+
}
|
|
592
805
|
}
|
|
593
806
|
const install = options.install ?? true;
|
|
594
807
|
const result = createProject({
|
|
@@ -606,9 +819,63 @@ export async function createProjectInteractive(options = {}) {
|
|
|
606
819
|
apiPort: String(apiPort),
|
|
607
820
|
git,
|
|
608
821
|
install,
|
|
822
|
+
nonInteractive: !interactive,
|
|
823
|
+
runtimeMode: options.runtimeMode,
|
|
609
824
|
templateDir: options.templateDir
|
|
610
825
|
});
|
|
611
|
-
|
|
612
|
-
|
|
826
|
+
result.passwordGenerated = passwordGenerated;
|
|
827
|
+
if (interactive) {
|
|
828
|
+
printSecurityNotice(result);
|
|
829
|
+
printNextSteps(result);
|
|
830
|
+
}
|
|
831
|
+
else {
|
|
832
|
+
printSummaryPlain(result);
|
|
833
|
+
}
|
|
613
834
|
return result;
|
|
614
835
|
}
|
|
836
|
+
function cancelledUndefined() {
|
|
837
|
+
cancel("Cancelled");
|
|
838
|
+
return undefined;
|
|
839
|
+
}
|
|
840
|
+
function capitalize(s) {
|
|
841
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Validates a DATABASE_URL against the FINAL resolved value so pressing Enter to
|
|
845
|
+
* accept the shown default is always valid.
|
|
846
|
+
*/
|
|
847
|
+
export function validateDatabaseUrlInput(database, value, fallback) {
|
|
848
|
+
const v = value.trim() || fallback;
|
|
849
|
+
if (database === "sqlite") {
|
|
850
|
+
return /^file:/.test(v) ? undefined : 'SQLite DATABASE_URL must start with "file:".';
|
|
851
|
+
}
|
|
852
|
+
try {
|
|
853
|
+
// eslint-disable-next-line no-new
|
|
854
|
+
new URL(v);
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
catch {
|
|
858
|
+
return "Enter a valid database URL.";
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Runs a non-blocking connectivity check with an interactive retry loop. Returns
|
|
863
|
+
* CANCELLED if the user cancels; otherwise resolves once the check passes or the
|
|
864
|
+
* user declines to retry.
|
|
865
|
+
*/
|
|
866
|
+
async function confirmConnectivityLoop(check, label, reprompt, apply) {
|
|
867
|
+
for (;;) {
|
|
868
|
+
const error = await check();
|
|
869
|
+
if (!error)
|
|
870
|
+
return;
|
|
871
|
+
const retry = await confirm({ message: `${error} Retry entering ${label}?`, initialValue: true });
|
|
872
|
+
if (isCancel(retry))
|
|
873
|
+
return CANCELLED;
|
|
874
|
+
if (!retry)
|
|
875
|
+
return;
|
|
876
|
+
const next = await reprompt();
|
|
877
|
+
if (isCancel(next))
|
|
878
|
+
return CANCELLED;
|
|
879
|
+
apply(String(next));
|
|
880
|
+
}
|
|
881
|
+
}
|