openadminjs 0.1.24 → 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.
Files changed (52) hide show
  1. package/README.md +97 -16
  2. package/dist/adapt-package-manager.d.ts +3 -0
  3. package/dist/adapt-package-manager.js +115 -0
  4. package/dist/adapt-package-manager.test.d.ts +1 -0
  5. package/dist/adapt-package-manager.test.js +76 -0
  6. package/dist/cli.e2e.test.d.ts +1 -0
  7. package/dist/cli.e2e.test.js +87 -0
  8. package/dist/create-project.d.ts +31 -2
  9. package/dist/create-project.js +296 -102
  10. package/dist/create-project.test.js +180 -4
  11. package/dist/database-providers.integration.test.d.ts +1 -0
  12. package/dist/database-providers.integration.test.js +64 -0
  13. package/dist/db-commands.d.ts +20 -0
  14. package/dist/db-commands.js +75 -0
  15. package/dist/db-commands.test.d.ts +1 -0
  16. package/dist/db-commands.test.js +27 -0
  17. package/dist/detect-package-manager.d.ts +8 -0
  18. package/dist/detect-package-manager.js +37 -0
  19. package/dist/doctor.d.ts +13 -0
  20. package/dist/doctor.js +203 -0
  21. package/dist/doctor.test.d.ts +1 -0
  22. package/dist/doctor.test.js +102 -0
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.js +233 -141
  25. package/dist/index.test.js +7 -3
  26. package/dist/render-schema.d.ts +20 -0
  27. package/dist/render-schema.js +37 -0
  28. package/dist/render-schema.test.d.ts +1 -0
  29. package/dist/render-schema.test.js +57 -0
  30. package/dist/secrets.d.ts +24 -0
  31. package/dist/secrets.js +93 -0
  32. package/dist/secrets.test.d.ts +1 -0
  33. package/dist/secrets.test.js +36 -0
  34. package/dist/security.d.ts +13 -0
  35. package/dist/security.js +168 -0
  36. package/dist/security.test.d.ts +1 -0
  37. package/dist/security.test.js +54 -0
  38. package/dist/validate-name.d.ts +33 -0
  39. package/dist/validate-name.js +206 -0
  40. package/dist/validate-name.test.d.ts +1 -0
  41. package/dist/validate-name.test.js +63 -0
  42. package/package.json +26 -1
  43. package/template/README.md +22 -3
  44. package/template/apps/api/package.json +3 -0
  45. package/template/apps/api/src/common/json-field-codec.test.ts +76 -0
  46. package/template/apps/api/src/common/json-field-codec.ts +139 -0
  47. package/template/apps/api/src/common/prisma.service.test.ts +19 -0
  48. package/template/apps/api/src/common/prisma.service.ts +13 -0
  49. package/template/apps/api/src/graphql/graphql-apollo-config.test.ts +26 -0
  50. package/template/apps/api/src/graphql/graphql.module.ts +13 -1
  51. package/template/package.json +2 -0
  52. package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
package/README.md CHANGED
@@ -1,33 +1,55 @@
1
- # OpenAdminJS
1
+ # OpenAdminJS CLI
2
2
 
3
- OpenAdminJS is an open-source, resource-driven admin platform for the Node.js ecosystem, built with Nest.js, Prisma, PostgreSQL, Next.js, TailwindCSS and shadcn/ui.
3
+ **`openadminjs` is a CLI scaffold generator**, not a runtime library you import into React/Next/Nest apps. It creates a full pnpm monorepo (NestJS API, Next.js admin/web, shared packages).
4
4
 
5
- ![OpenAdminJS logo](https://js-senpai.github.io/open-admin-js/assets/brand/openadminjs-logo-new.png)
5
+ Full documentation: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
6
6
 
7
- ## Quick start (for package users)
7
+ ## Requirements
8
8
 
9
- Full documentation: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
9
+ - **Node.js 20+**
10
+ - **pnpm 9+** (the only supported package manager)
11
+ - **PostgreSQL 14+**, **MySQL 8+**, or **SQLite 3** (local file)
10
12
 
11
- ### 1. Create a new project
13
+ The CLI verifies Node.js and pnpm before writing any files.
14
+
15
+ ## Quick start
12
16
 
13
17
  ```bash
14
18
  npx openadminjs create my-app
15
19
  cd my-app
20
+ pnpm install # skipped if you chose install during create
21
+ pnpm db:migrate # skipped if install ran during create
22
+ pnpm db:seed # skipped if install ran during create
23
+ pnpm dev
16
24
  ```
17
25
 
18
- `npx` runs the single `openadminjs` package and scaffolds the project with dependencies installed automatically.
19
- During scaffolding, you can choose the database driver from a list (PostgreSQL, MySQL, or SQLite), and the CLI fills `DATABASE_URL` for you.
26
+ The scaffold generates a **pnpm** monorepo backed by **PostgreSQL**, **MySQL**, or
27
+ **SQLite**; the CLI fills `DATABASE_URL` for you. For MySQL/SQLite the Prisma schema
28
+ is adapted and the initial migration is created on first `db:migrate`. On SQLite the
29
+ API JSON-encodes `Json` columns into `String` fields at runtime. npm and yarn are
30
+ **not** offered.
20
31
 
21
- ### 2. Configure environment
32
+ ### Configure environment
22
33
 
23
- The scaffold wizard asks for database access and key env values (`DATABASE_URL`, `REDIS_URL`, JWT secrets) and writes ready-to-use values into `apps/api/.env` (including `SUPERADMIN_EMAIL` / `SUPERADMIN_PASSWORD` for non-interactive seed).
24
- `ADMIN_ORIGIN` and `API_PORT` are prefilled with defaults (`http://localhost:3000` and `4000`) and can be changed manually if needed.
25
- New projects do **not** include a root `.env.example` or root `.env`—use `apps/api/.env` as the source of truth (you can add your own `.env.example` for your team if you want).
34
+ The scaffold wizard asks for database access and writes ready-to-use values into
35
+ `apps/api/.env` (including `SUPERADMIN_EMAIL` / `SUPERADMIN_PASSWORD` for
36
+ non-interactive seed). **JWT secrets are generated with `crypto.randomBytes`** —
37
+ never predictable defaults. `ADMIN_ORIGIN` and `API_PORT` default to
38
+ `http://localhost:3000` and `4000`.
39
+
40
+ Every new project includes a root **`.gitignore`** (written before `git init`) that
41
+ excludes all `.env` files, plus a tracked **`.env.example`** with placeholders. Real
42
+ secrets live only in `apps/api/.env` and are never printed by the CLI.
26
43
 
27
44
  Typical `apps/api/.env` keys (after create, edit as needed):
28
45
 
46
+ | Provider | `DATABASE_URL` example |
47
+ | --- | --- |
48
+ | PostgreSQL | `postgresql://USER:PASSWORD@localhost:5432/openadminjs?schema=public` |
49
+ | MySQL | `mysql://USER:PASSWORD@localhost:3306/openadminjs` |
50
+ | SQLite | `file:./dev.db` |
51
+
29
52
  ```env
30
- DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/openadminjs?schema=public
31
53
  REDIS_URL=redis://localhost:6379
32
54
  JWT_SECRET=replace-with-a-long-random-string-at-least-32-chars
33
55
  JWT_REFRESH_SECRET=another-long-random-string
@@ -43,7 +65,7 @@ Optional (elsewhere / advanced):
43
65
  OPENADMIN_PLUGIN_PNPM_INSTALL=0
44
66
  ```
45
67
 
46
- ### 3. Run project
68
+ ### Run project
47
69
 
48
70
  ```bash
49
71
  pnpm dev
@@ -58,20 +80,79 @@ Typical URLs:
58
80
  | API Swagger | http://localhost:4000/api/docs |
59
81
  | Web (demo) | http://localhost:3001 |
60
82
 
61
- ### 4. Sign in
83
+ ### Sign in
62
84
 
63
85
  After project creation, migrations and seed are run automatically. Use the superadmin credentials you entered in the scaffold wizard:
64
86
 
65
87
  - **Email:** your `Superadmin email`
66
88
  - **Password:** your `Superadmin password`
67
89
 
90
+ ## Programmatic API
91
+
92
+ ```ts
93
+ import { createProject, databaseUrl } from "openadminjs";
94
+ import { randomBytes } from "node:crypto";
95
+
96
+ // PostgreSQL (ships baseline migration)
97
+ createProject({
98
+ projectName: "my-app",
99
+ packageManager: "pnpm",
100
+ database: "postgresql",
101
+ databaseUrl: databaseUrl("my-app", "postgresql"),
102
+ // ...
103
+ });
104
+
105
+ // MySQL (run db:migrate after install to create the initial migration)
106
+ createProject({
107
+ projectName: "my-app",
108
+ packageManager: "pnpm",
109
+ database: "mysql",
110
+ databaseUrl: databaseUrl("my-app", "mysql"),
111
+ superadminEmail: "admin@localhost.dev",
112
+ superadminPassword: "a-strong-password",
113
+ redisUrl: "redis://localhost:6379",
114
+ jwtSecret: randomBytes(48).toString("base64url"),
115
+ jwtRefreshSecret: randomBytes(48).toString("base64url"),
116
+ adminOrigin: "http://localhost:3000",
117
+ apiPort: "4000"
118
+ });
119
+
120
+ // SQLite (local file — API JSON-encodes Json columns at runtime)
121
+ createProject({
122
+ projectName: "my-app",
123
+ packageManager: "pnpm",
124
+ database: "sqlite",
125
+ databaseUrl: "file:./dev.db",
126
+ superadminEmail: "admin@localhost.dev",
127
+ superadminPassword: "a-strong-password",
128
+ redisUrl: "redis://localhost:6379",
129
+ jwtSecret: randomBytes(48).toString("base64url"),
130
+ jwtRefreshSecret: randomBytes(48).toString("base64url"),
131
+ adminOrigin: "http://localhost:3000",
132
+ apiPort: "4000"
133
+ });
134
+ ```
135
+
136
+ ## Health & security checks
137
+
138
+ ```bash
139
+ openadminjs doctor # verify the project is ready to run
140
+ openadminjs doctor --json
141
+ openadminjs security check
142
+ openadminjs security check --json
143
+ ```
144
+
145
+ `templateDir` defaults to the bundled template. The interactive wizard offers
146
+ **pnpm** + **PostgreSQL / MySQL / SQLite**; the programmatic API accepts the
147
+ `packageManager`/`database` options for advanced use.
148
+
68
149
  ## MVP scope
69
150
 
70
151
  - Resource-driven admin metadata with safe defaults.
71
152
  - Auth, RBAC contracts, generic CRUD API, audit log and file/settings modules.
72
153
  - Next.js admin shell with login, dashboard, resource screens and operational pages.
73
154
  - Generated app `apps/web` for public frontend pages and SEO.
74
- - CLI: `dev`, `build`, `db migrate`, `db seed`, `generate resource`, `doctor`, `security check`.
155
+ - CLI: `create`, `dev`, `build`, `db migrate|seed|studio|reset`, `generate resource|field|plugin`, `doctor`, `security check`.
75
156
 
76
157
  ## Plugin Platform
77
158
 
@@ -0,0 +1,3 @@
1
+ export type PackageManager = "pnpm" | "npm" | "yarn";
2
+ /** Rewrites a scaffolded monorepo for npm or yarn (template ships pnpm-first). */
3
+ export declare function adaptProjectForPackageManager(targetDir: string, packageManager: PackageManager): void;
@@ -0,0 +1,115 @@
1
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ const WORKSPACE_GLOBS = ["apps/*", "packages/*"];
4
+ const ROOT_SCRIPTS = {
5
+ pnpm: {
6
+ dev: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin dev",
7
+ build: "pnpm -r build",
8
+ start: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin start",
9
+ lint: "pnpm -r lint",
10
+ typecheck: "pnpm -r typecheck",
11
+ test: "pnpm -r test",
12
+ "db:migrate": "pnpm --filter @openadminjs/api db:migrate",
13
+ "db:migrate:deploy": "pnpm --filter @openadminjs/api db:migrate:deploy",
14
+ "db:seed": "pnpm --filter @openadminjs/api db:seed",
15
+ "db:studio": "pnpm --filter @openadminjs/api db:studio",
16
+ "db:reset": "pnpm --filter @openadminjs/api db:reset",
17
+ generate: "pnpm --filter @openadminjs/api generate"
18
+ },
19
+ npm: {
20
+ dev: "npm run dev --workspace=@openadminjs/api --workspace=@openadminjs/admin --if-present",
21
+ build: "npm run build --workspaces --if-present",
22
+ start: "npm run start --workspace=@openadminjs/api --workspace=@openadminjs/admin --if-present",
23
+ lint: "npm run lint --workspaces --if-present",
24
+ typecheck: "npm run typecheck --workspaces --if-present",
25
+ test: "npm run test --workspaces --if-present",
26
+ "db:migrate": "npm run db:migrate --workspace=@openadminjs/api",
27
+ "db:migrate:deploy": "npm run db:migrate:deploy --workspace=@openadminjs/api",
28
+ "db:seed": "npm run db:seed --workspace=@openadminjs/api",
29
+ "db:studio": "npm run db:studio --workspace=@openadminjs/api",
30
+ "db:reset": "npm run db:reset --workspace=@openadminjs/api",
31
+ generate: "npm run generate --workspace=@openadminjs/api"
32
+ },
33
+ yarn: {
34
+ dev: "yarn workspace @openadminjs/api dev & yarn workspace @openadminjs/admin dev",
35
+ build: "yarn workspaces run build",
36
+ start: "yarn workspace @openadminjs/api start & yarn workspace @openadminjs/admin start",
37
+ lint: "yarn workspaces run lint",
38
+ typecheck: "yarn workspaces run typecheck",
39
+ test: "yarn workspaces run test",
40
+ "db:migrate": "yarn workspace @openadminjs/api db:migrate",
41
+ "db:migrate:deploy": "yarn workspace @openadminjs/api db:migrate:deploy",
42
+ "db:seed": "yarn workspace @openadminjs/api db:seed",
43
+ "db:studio": "yarn workspace @openadminjs/api db:studio",
44
+ "db:reset": "yarn workspace @openadminjs/api db:reset",
45
+ generate: "yarn workspace @openadminjs/api generate"
46
+ }
47
+ };
48
+ function findPackageJsonFiles(dir) {
49
+ const files = [];
50
+ const stack = [dir];
51
+ while (stack.length) {
52
+ const current = stack.pop();
53
+ if (!current)
54
+ continue;
55
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
56
+ if (entry.name === "node_modules" || entry.name === ".next" || entry.name === "dist" || entry.name === ".turbo") {
57
+ continue;
58
+ }
59
+ const path = join(current, entry.name);
60
+ if (entry.isDirectory())
61
+ stack.push(path);
62
+ else if (entry.name === "package.json")
63
+ files.push(path);
64
+ }
65
+ }
66
+ return files;
67
+ }
68
+ function replaceWorkspaceProtocol(pkg, replacement) {
69
+ for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
70
+ const deps = pkg[section];
71
+ if (!deps)
72
+ continue;
73
+ for (const [name, version] of Object.entries(deps)) {
74
+ if (version.startsWith("workspace:")) {
75
+ deps[name] = replacement;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ function readPackageJson(path) {
81
+ return JSON.parse(readFileSync(path, "utf8"));
82
+ }
83
+ function writePackageJson(path, pkg) {
84
+ writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
85
+ }
86
+ /** Rewrites a scaffolded monorepo for npm or yarn (template ships pnpm-first). */
87
+ export function adaptProjectForPackageManager(targetDir, packageManager) {
88
+ if (packageManager === "pnpm")
89
+ return;
90
+ const rootPath = join(targetDir, "package.json");
91
+ if (!existsSync(rootPath))
92
+ return;
93
+ const root = readPackageJson(rootPath);
94
+ const pnpmOverrides = typeof root.pnpm === "object" && root.pnpm !== null && "overrides" in root.pnpm
95
+ ? root.pnpm.overrides
96
+ : undefined;
97
+ root.workspaces = WORKSPACE_GLOBS;
98
+ root.scripts = { ...root.scripts, ...ROOT_SCRIPTS[packageManager] };
99
+ delete root.packageManager;
100
+ delete root.pnpm;
101
+ if (packageManager === "npm" && pnpmOverrides) {
102
+ root.overrides = pnpmOverrides;
103
+ }
104
+ writePackageJson(rootPath, root);
105
+ const pnpmWorkspaceFile = join(targetDir, "pnpm-workspace.yaml");
106
+ if (existsSync(pnpmWorkspaceFile)) {
107
+ rmSync(pnpmWorkspaceFile);
108
+ }
109
+ const workspaceReplacement = packageManager === "yarn" ? "*" : "workspace:*";
110
+ for (const file of findPackageJsonFiles(targetDir)) {
111
+ const pkg = readPackageJson(file);
112
+ replaceWorkspaceProtocol(pkg, workspaceReplacement);
113
+ writePackageJson(file, pkg);
114
+ }
115
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { tmpdir } from "node:os";
4
+ import { describe, expect, it } from "vitest";
5
+ import { adaptProjectForPackageManager } from "./adapt-package-manager.js";
6
+ import { createProject } from "./create-project.js";
7
+ const BASE_OPTIONS = {
8
+ database: "postgresql",
9
+ superadminEmail: "admin@localhost.dev",
10
+ superadminPassword: "password1234",
11
+ databaseUrl: "postgresql://localhost:5432/my-app?schema=public",
12
+ redisUrl: "redis://localhost:6379",
13
+ jwtSecret: "test-jwt-secret",
14
+ jwtRefreshSecret: "test-jwt-refresh-secret",
15
+ adminOrigin: "http://localhost:3000",
16
+ apiPort: "4000",
17
+ git: false,
18
+ install: false
19
+ };
20
+ describe("adaptProjectForPackageManager", () => {
21
+ it("keeps pnpm layout unchanged", () => {
22
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-adapt-"));
23
+ try {
24
+ const result = createProject({ ...BASE_OPTIONS, packageManager: "pnpm", projectName: "pnpm-app", cwd });
25
+ expect(existsSync(join(result.targetDir, "pnpm-workspace.yaml"))).toBe(true);
26
+ const root = JSON.parse(readFileSync(join(result.targetDir, "package.json"), "utf8"));
27
+ expect(root.packageManager).toContain("pnpm");
28
+ }
29
+ finally {
30
+ rmSync(cwd, { recursive: true, force: true });
31
+ }
32
+ });
33
+ it("adapts npm projects with workspaces and npm scripts", () => {
34
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-adapt-"));
35
+ try {
36
+ const result = createProject({ ...BASE_OPTIONS, packageManager: "npm", projectName: "npm-app", cwd });
37
+ expect(existsSync(join(result.targetDir, "pnpm-workspace.yaml"))).toBe(false);
38
+ const root = JSON.parse(readFileSync(join(result.targetDir, "package.json"), "utf8"));
39
+ expect(root.workspaces).toEqual(["apps/*", "packages/*"]);
40
+ expect(root.scripts?.["db:migrate"]).toContain("--workspace=@openadminjs/api");
41
+ expect(root.overrides?.["@nestjs/common"]).toBeTruthy();
42
+ expect(root.pnpm).toBeUndefined();
43
+ const apiPkg = JSON.parse(readFileSync(join(result.targetDir, "apps", "api", "package.json"), "utf8"));
44
+ expect(apiPkg.dependencies["@openadminjs/core"]).toBe("workspace:*");
45
+ }
46
+ finally {
47
+ rmSync(cwd, { recursive: true, force: true });
48
+ }
49
+ });
50
+ it("adapts yarn projects and replaces workspace protocol with *", () => {
51
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-adapt-"));
52
+ try {
53
+ const result = createProject({ ...BASE_OPTIONS, packageManager: "yarn", projectName: "yarn-app", cwd });
54
+ expect(existsSync(join(result.targetDir, "pnpm-workspace.yaml"))).toBe(false);
55
+ const root = JSON.parse(readFileSync(join(result.targetDir, "package.json"), "utf8"));
56
+ expect(root.scripts?.dev).toContain("yarn workspace @openadminjs/api dev");
57
+ const apiPkg = JSON.parse(readFileSync(join(result.targetDir, "apps", "api", "package.json"), "utf8"));
58
+ expect(apiPkg.dependencies["@openadminjs/core"]).toBe("*");
59
+ }
60
+ finally {
61
+ rmSync(cwd, { recursive: true, force: true });
62
+ }
63
+ });
64
+ it("is a no-op for pnpm when called directly", () => {
65
+ const dir = mkdtempSync(join(tmpdir(), "openadminjs-adapt-"));
66
+ try {
67
+ writeFileSync(join(dir, "package.json"), `${JSON.stringify({ name: "x", scripts: { dev: "pnpm dev" }, packageManager: "pnpm@9.15.0" }, null, 2)}\n`);
68
+ writeFileSync(join(dir, "pnpm-workspace.yaml"), "packages:\n - apps/*\n");
69
+ adaptProjectForPackageManager(dir, "pnpm");
70
+ expect(existsSync(join(dir, "pnpm-workspace.yaml"))).toBe(true);
71
+ }
72
+ finally {
73
+ rmSync(dir, { recursive: true, force: true });
74
+ }
75
+ });
76
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,87 @@
1
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { spawnSync } from "node:child_process";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { tmpdir } from "node:os";
6
+ import { beforeAll, describe, expect, it } from "vitest";
7
+ const here = dirname(fileURLToPath(import.meta.url));
8
+ const cliRoot = join(here, "..");
9
+ const distEntry = join(cliRoot, "dist", "index.js");
10
+ const pkgVersion = JSON.parse(readFileSync(join(cliRoot, "package.json"), "utf8")).version;
11
+ function run(args, cwd = cliRoot) {
12
+ return spawnSync(process.execPath, [distEntry, ...args], { cwd, encoding: "utf8" });
13
+ }
14
+ beforeAll(() => {
15
+ // Compile the CLI to dist via the TypeScript compiler entry (works in CI and sandbox).
16
+ const tsc = join(cliRoot, "node_modules", "typescript", "bin", "tsc");
17
+ const res = spawnSync(process.execPath, [tsc, "-p", "tsconfig.json"], { cwd: cliRoot, encoding: "utf8" });
18
+ if (res.status !== 0)
19
+ throw new Error(`tsc build failed: ${res.stderr || res.stdout}`);
20
+ if (!existsSync(distEntry))
21
+ throw new Error("dist/index.js not produced");
22
+ }, 60000);
23
+ describe("openadminjs CLI e2e", () => {
24
+ it("--version prints the package version and exits 0", () => {
25
+ const r = run(["--version"]);
26
+ expect(r.status).toBe(0);
27
+ expect(r.stdout).toContain(`openadminjs ${pkgVersion}`);
28
+ });
29
+ it("-v behaves like --version", () => {
30
+ const r = run(["-v"]);
31
+ expect(r.status).toBe(0);
32
+ expect(r.stdout).toContain(`openadminjs ${pkgVersion}`);
33
+ });
34
+ it("--help exits 0 and lists commands", () => {
35
+ const r = run(["--help"]);
36
+ expect(r.status).toBe(0);
37
+ expect(r.stdout).toMatch(/create/);
38
+ expect(r.stdout).toMatch(/generate/);
39
+ expect(r.stdout).toMatch(/doctor/);
40
+ });
41
+ it("unknown command errors and exits non-zero", () => {
42
+ const r = run(["definitely-not-a-command"]);
43
+ expect(r.status).not.toBe(0);
44
+ expect(r.stderr).toMatch(/Unknown command/);
45
+ expect(r.stderr).toMatch(/--help/);
46
+ });
47
+ it("db migrate --dry-run prints the command without running it", () => {
48
+ const r = run(["db", "migrate", "dev", "--dry-run"]);
49
+ expect(r.status).toBe(0);
50
+ expect(r.stdout).toMatch(/db:migrate/);
51
+ });
52
+ it("generate field is routed to its own handler (not the generic generate)", () => {
53
+ const proj = mkdtempSync(join(tmpdir(), "oaj-e2e-"));
54
+ try {
55
+ const resDir = join(proj, "apps", "api", "src", "resources");
56
+ mkdirSync(resDir, { recursive: true });
57
+ writeFileSync(join(resDir, "post.resource.ts"), `import { defineResource } from '@openadminjs/core';\n\nexport default defineResource({\n name: 'posts',\n model: 'Post',\n fields: {\n id: { type: 'id', label: 'ID' },\n },\n permissions: {},\n});\n`);
58
+ const r = run(["generate", "field", "post", "title", "--type", "text", "--required"], proj);
59
+ expect(r.status).toBe(0);
60
+ const updated = readFileSync(join(resDir, "post.resource.ts"), "utf8");
61
+ expect(updated).toContain("title:");
62
+ expect(updated).toContain("required: true");
63
+ }
64
+ finally {
65
+ rmSync(proj, { recursive: true, force: true });
66
+ }
67
+ });
68
+ it("generate resource creates a resource file and rejects unsafe names", () => {
69
+ const proj = mkdtempSync(join(tmpdir(), "oaj-e2e-"));
70
+ try {
71
+ const ok = run(["generate", "resource", "BlogPost"], proj);
72
+ expect(ok.status).toBe(0);
73
+ expect(existsSync(join(proj, "apps", "api", "src", "resources", "blog-post.resource.ts"))).toBe(true);
74
+ const bad = run(["generate", "resource", "../evil"], proj);
75
+ expect(bad.status).not.toBe(0);
76
+ expect(existsSync(join(proj, "..", "evil.resource.ts"))).toBe(false);
77
+ }
78
+ finally {
79
+ rmSync(proj, { recursive: true, force: true });
80
+ }
81
+ });
82
+ it("generate with unknown kind errors", () => {
83
+ const r = run(["generate", "bogus", "x"]);
84
+ expect(r.status).not.toBe(0);
85
+ expect(r.stderr).toMatch(/Unknown generate kind/);
86
+ });
87
+ });
@@ -1,4 +1,7 @@
1
- export type PackageManager = "pnpm" | "npm" | "yarn";
1
+ import { type PackageManager } from "./adapt-package-manager.js";
2
+ /** Minimum supported Node.js major version (kept in sync with package.json engines). */
3
+ export declare const MIN_NODE_MAJOR = 20;
4
+ export type { PackageManager } from "./adapt-package-manager.js";
2
5
  export type DatabaseDriver = "postgresql" | "mysql" | "sqlite";
3
6
  export type CreateProjectOptions = {
4
7
  projectName?: string;
@@ -30,6 +33,32 @@ export type CreateProjectResult = {
30
33
  };
31
34
  export declare function toPackageName(input: string): string;
32
35
  export declare function defaultTemplateDir(): string;
33
- export declare function createProject(options: Required<CreateProjectOptions>): CreateProjectResult;
36
+ /** Returns the current Node.js major version. */
37
+ export declare function currentNodeMajor(): number;
38
+ /** Throws if the running Node.js is older than the supported minimum. */
39
+ export declare function assertSupportedNode(): void;
40
+ /** Returns true when the given package manager is on PATH. */
41
+ export declare function isPackageManagerAvailable(packageManager: PackageManager): boolean;
42
+ /** Throws with an actionable message when pnpm is not installed. */
43
+ export declare function assertPnpmAvailable(): void;
44
+ export declare const DEFAULT_SUPERADMIN_EMAIL = "admin@localhost.dev";
45
+ /** Resolves the final email, applying the default when the user pressed Enter. */
46
+ export declare function resolveSuperadminEmail(value: string, fallback?: string): string;
47
+ /**
48
+ * Validates the superadmin email against the FINAL value (after default
49
+ * resolution), so pressing Enter to accept the default is always valid.
50
+ */
51
+ export declare function validateSuperadminEmailInput(value: string, fallback?: string): string | undefined;
52
+ export declare function databaseUrl(packageName: string, database: DatabaseDriver): string;
53
+ /**
54
+ * Generates the scaffold into a sibling staging directory and atomically renames
55
+ * it into place only after generation succeeds. On failure the staging directory
56
+ * is removed and an existing target directory is never touched.
57
+ */
58
+ export declare function createProject(options: CreateProjectOptions & {
59
+ projectName: string;
60
+ }): CreateProjectResult;
34
61
  export declare function printNextSteps(result: CreateProjectResult): void;
62
+ /** Warns where secrets live and that they must never be committed. Never prints secret values. */
63
+ export declare function printSecurityNotice(result: CreateProjectResult): void;
35
64
  export declare function createProjectInteractive(options?: CreateProjectOptions): Promise<CreateProjectResult | undefined>;