nestjs-prisma-cli 1.0.5 → 1.0.7

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 (51) hide show
  1. package/README.md +45 -23
  2. package/bin/index.js +80 -45
  3. package/package.json +1 -1
  4. package/template/Dockerfile +30 -0
  5. /package/{bin/template → template}/.github/workflows/deploy-to-ecr.yml +0 -0
  6. /package/{bin/template → template}/prisma/schema.prisma +0 -0
  7. /package/{bin/template → template}/prisma/seed.ts +0 -0
  8. /package/{bin/template → template}/src/app.controller.spec.ts +0 -0
  9. /package/{bin/template → template}/src/app.controller.ts +0 -0
  10. /package/{bin/template → template}/src/app.module.ts +0 -0
  11. /package/{bin/template → template}/src/app.service.ts +0 -0
  12. /package/{bin/template → template}/src/common/classes/base64.ts +0 -0
  13. /package/{bin/template → template}/src/common/decorator/public.decorator.ts +0 -0
  14. /package/{bin/template → template}/src/common/dto/index.ts +0 -0
  15. /package/{bin/template → template}/src/common/dto/paginated-response.dto.ts +0 -0
  16. /package/{bin/template → template}/src/common/dto/pagination.dto.ts +0 -0
  17. /package/{bin/template → template}/src/common/enums/db-error-code.enum.ts +0 -0
  18. /package/{bin/template → template}/src/common/enums/index.ts +0 -0
  19. /package/{bin/template → template}/src/common/enums/message-code.enum.ts +0 -0
  20. /package/{bin/template → template}/src/common/http-interceptor/http-error-type.ts +0 -0
  21. /package/{bin/template → template}/src/common/http-interceptor/http-exception.filter.ts +0 -0
  22. /package/{bin/template → template}/src/common/http-interceptor/index.ts +0 -0
  23. /package/{bin/template → template}/src/common/http-interceptor/logging.interceptor.ts +0 -0
  24. /package/{bin/template → template}/src/common/http-interceptor/response.interceptor.ts +0 -0
  25. /package/{bin/template → template}/src/common/logger/winston.logger.ts +0 -0
  26. /package/{bin/template → template}/src/common/s3/s3.module.ts +0 -0
  27. /package/{bin/template → template}/src/common/s3/s3.service.spec.ts +0 -0
  28. /package/{bin/template → template}/src/common/s3/s3.service.ts +0 -0
  29. /package/{bin/template → template}/src/common/utils/pagination.util.ts +0 -0
  30. /package/{bin/template → template}/src/main.ts +0 -0
  31. /package/{bin/template → template}/src/modules/auth/auth.controller.spec.ts +0 -0
  32. /package/{bin/template → template}/src/modules/auth/auth.controller.ts +0 -0
  33. /package/{bin/template → template}/src/modules/auth/auth.module.ts +0 -0
  34. /package/{bin/template → template}/src/modules/auth/auth.service.spec.ts +0 -0
  35. /package/{bin/template → template}/src/modules/auth/auth.service.ts +0 -0
  36. /package/{bin/template → template}/src/modules/auth/dto/login.dto.ts +0 -0
  37. /package/{bin/template → template}/src/modules/auth/jwt/jwt.guard.spec.ts +0 -0
  38. /package/{bin/template → template}/src/modules/auth/jwt/jwt.guard.ts +0 -0
  39. /package/{bin/template → template}/src/modules/auth/jwt/jwt.strategy.ts +0 -0
  40. /package/{bin/template → template}/src/modules/user/dto/create-user.dto.ts +0 -0
  41. /package/{bin/template → template}/src/modules/user/dto/update-user.dto.ts +0 -0
  42. /package/{bin/template → template}/src/modules/user/user.controller.spec.ts +0 -0
  43. /package/{bin/template → template}/src/modules/user/user.controller.ts +0 -0
  44. /package/{bin/template → template}/src/modules/user/user.module.ts +0 -0
  45. /package/{bin/template → template}/src/modules/user/user.service.spec.ts +0 -0
  46. /package/{bin/template → template}/src/modules/user/user.service.ts +0 -0
  47. /package/{bin/template → template}/src/prisma/prisma.module.ts +0 -0
  48. /package/{bin/template → template}/src/prisma/prisma.service.spec.ts +0 -0
  49. /package/{bin/template → template}/src/prisma/prisma.service.ts +0 -0
  50. /package/{bin/template → template}/test/app.e2e-spec.ts +0 -0
  51. /package/{bin/template → template}/test/jest-e2e.json +0 -0
package/README.md CHANGED
@@ -21,49 +21,71 @@ Compatible with **Node.js >=18** and **NestJS v10+**.
21
21
 
22
22
  ## 📥 Installation
23
23
 
24
- ## ⚡ Quick Start Guide
24
+ ### ⚡ Quick Start Guide
25
25
 
26
26
  Once the CLI is installed, you can use the following commands:
27
27
 
28
28
  ### 1️⃣ Install CLI globally
29
29
 
30
30
  ```bash
31
-
32
31
  npm install -g nestjs-prisma-cli
33
-
34
32
  ```
35
33
 
34
+
36
35
  ### 2️⃣ Check CLI version
37
36
 
38
37
  ```bash
39
-
40
38
  nestgen -v
39
+ ```
41
40
  # or
41
+ ```bash
42
42
  nestgen --version
43
-
44
43
  ```
45
44
 
46
- ### 3️⃣ Generate a new project
47
45
 
46
+ ### 3️⃣ Generate a new project
48
47
  ```bash
49
-
50
48
  nestgen
49
+ ```
51
50
 
52
- Step 1 : ? Enter your project name: my-app
53
-
54
- Step 2 : ? Select your database: (Use arrow keys)
55
- MySQL
56
- PostgreSQL
57
- SQLite
58
- MongoDB
59
- CockroachDB
60
- SQLServer
61
- Step 3 : 🎉 Project ready! Next steps:
62
- cd my-app
63
- Check .env
64
- npx prisma generate
65
- npx prisma migrate dev --name init
66
- npx ts-node prisma/seed.ts
67
- npm run start:dev
51
+ ```text
52
+ ? Enter your project name: my-app
53
+ Step 2: ? Select your database: (Use arrow keys)
54
+ MySQL
55
+ PostgreSQL
56
+ SQLite
57
+ MongoDB
58
+ CockroachDB
59
+ SQLServer
60
+ Step 3: 🎉 Project ready! Next steps:
61
+ ```
68
62
 
63
+ ### Navigate into your project
64
+ ```bash
65
+ cd my-app
69
66
  ```
67
+ ### Update .env
68
+ ```bash
69
+ DATABASE_URL="your_database_connection_string"
70
+ ```
71
+ ```bash
72
+ npx prisma generate
73
+ ```
74
+ ### SQL Databases
75
+ ### (PostgreSQL, MySQL, SQLite, CockroachDB, SQLServer)
76
+ ```bash
77
+ npx prisma migrate dev --name init
78
+ ```
79
+ ### NoSQL Database
80
+ ### (MongoDB)
81
+ ```bash
82
+ npx prisma db push
83
+ ```
84
+ ### Then, follow this
85
+ ```bash
86
+ npx ts-node prisma/seed.ts
87
+ ```
88
+ ```bash
89
+ npm run start:dev
90
+ ```
91
+
package/bin/index.js CHANGED
@@ -4,8 +4,8 @@ import chalk from "chalk";
4
4
  import fs from "fs-extra";
5
5
  import path from "path";
6
6
  import { execa } from "execa";
7
- import { readFileSync } from "fs";
8
- import { fileURLToPath } from "url";
7
+ import { readFileSync } from "fs";
8
+ import { fileURLToPath } from "url";
9
9
 
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = path.dirname(__filename);
@@ -39,6 +39,62 @@ const detectPackageManager = () => {
39
39
  }
40
40
  };
41
41
 
42
+ export async function generatePrismaSchema(selectedProvider, templatePrismaPath) {
43
+ if (selectedProvider === "mongodb") {
44
+ return `generator client {
45
+ provider = "prisma-client-js"
46
+ }
47
+
48
+ datasource db {
49
+ provider = "mongodb"
50
+ url = env("DATABASE_URL")
51
+ }
52
+
53
+ model User {
54
+ id String @id @default(auto()) @map("_id") @db.ObjectId
55
+ userId String @unique
56
+ name String?
57
+ email String
58
+ password String
59
+ isActive Boolean @default(true)
60
+ createdAt DateTime @default(now())
61
+ updatedAt DateTime @updatedAt
62
+ @@map("tbl_user")
63
+ }
64
+ `;
65
+ }
66
+
67
+ try {
68
+ let prismaContent = await fs.readFile(templatePrismaPath, "utf-8");
69
+ return prismaContent.replace(
70
+ /datasource\s+db\s*{[^}]*provider\s*=\s*".*"/,
71
+ `datasource db {\n provider = "${selectedProvider}"`
72
+ );
73
+ } catch {
74
+ return `generator client {
75
+ provider = "prisma-client-js"
76
+ }
77
+
78
+ datasource db {
79
+ provider = "${selectedProvider}"
80
+ url = env("DATABASE_URL")
81
+ }
82
+
83
+ model User {
84
+ id Int @id @default(autoincrement())
85
+ userId String @unique
86
+ name String?
87
+ email String
88
+ password String
89
+ isActive Boolean @default(true)
90
+ createdAt DateTime @default(now())
91
+ updatedAt DateTime @updatedAt
92
+ @@map("tbl_user")
93
+ }
94
+ `;
95
+ }
96
+ }
97
+
42
98
  async function main() {
43
99
  console.log(chalk.blue("🚀 Welcome to NestJS + Prisma Project Generator!"));
44
100
 
@@ -64,9 +120,12 @@ async function main() {
64
120
  ]);
65
121
 
66
122
  console.log(chalk.green(`📦 Creating NestJS project "${projectName}"...`));
67
- await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], { stdio: "inherit" });
123
+ await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], {
124
+ stdio: "inherit",
125
+ });
68
126
 
69
127
  const pkgManager = detectPackageManager();
128
+
70
129
  const coreDeps = [
71
130
  "argon2",
72
131
  "@nestjs/config",
@@ -83,14 +142,20 @@ async function main() {
83
142
  "moment",
84
143
  ];
85
144
  await execa(pkgManager, ["install", ...coreDeps], { cwd: projectPath, stdio: "inherit" });
86
- console.log(chalk.green("✅ Core dependencies installed!"));
87
145
 
88
146
  await execa(pkgManager, ["install", "@prisma/client"], { cwd: projectPath, stdio: "inherit" });
89
147
  await execa(pkgManager, ["install", "-D", "prisma"], { cwd: projectPath, stdio: "inherit" });
90
- console.log(chalk.green("✅ Prisma and @prisma/client installed!"));
91
148
 
92
- const templatePath = path.resolve("./template");
149
+ console.log(chalk.green("✅ Dependencies installed!"));
150
+
151
+ const templatePath = path.resolve(__dirname, "../template");
93
152
  const projectPrismaPath = path.join(projectPath, "prisma/schema.prisma");
153
+ const templatePrismaPath = path.join(templatePath, "prisma/schema.prisma");
154
+
155
+ if (await fs.pathExists(templatePath)) {
156
+ await fs.copy(templatePath, projectPath, { overwrite: true });
157
+ console.log(chalk.green("✅ Template files copied!"));
158
+ }
94
159
 
95
160
  const providerMap = {
96
161
  postgresql: "postgresql",
@@ -102,43 +167,7 @@ async function main() {
102
167
  };
103
168
  const selectedProvider = providerMap[database.toLowerCase()] || "mysql";
104
169
 
105
- let prismaContent = "";
106
- if (fs.existsSync(templatePath)) {
107
- await fs.copy(templatePath, projectPath, { overwrite: true });
108
- const templatePrismaPath = path.join(templatePath, "prisma/schema.prisma");
109
- if (fs.existsSync(templatePrismaPath)) {
110
- prismaContent = await fs.readFile(templatePrismaPath, "utf-8");
111
- prismaContent = prismaContent.replace(
112
- /datasource\s+db\s*{[^}]*provider\s*=\s*".*"/,
113
- `datasource db {\n provider = "${selectedProvider}"`
114
- );
115
- }
116
- }
117
-
118
- if (!prismaContent) {
119
- prismaContent = `generator client {
120
- provider = "prisma-client-js"
121
- }
122
-
123
- datasource db {
124
- provider = "${selectedProvider}"
125
- url = env("DATABASE_URL")
126
- }
127
-
128
- model User {
129
- id Int @id @default(autoincrement())
130
- userId String @unique
131
- name String?
132
- email String
133
- password String
134
- isActive Boolean @default(true)
135
- createdAt DateTime @default(now())
136
- updatedAt DateTime @updatedAt
137
- @@map("tbl_user")
138
- }
139
- `;
140
- }
141
-
170
+ const prismaContent = await generatePrismaSchema(selectedProvider, templatePrismaPath);
142
171
  await fs.outputFile(projectPrismaPath, prismaContent);
143
172
 
144
173
  const defaultUrlMap = {
@@ -172,11 +201,17 @@ PORT=3000
172
201
  console.log(chalk.yellow("🎉 Project ready!"));
173
202
  console.log(chalk.green("✅ .env created! Please update DATABASE_URL if necessary before running Prisma commands."));
174
203
  console.log(chalk.cyan(`cd ${projectName}`));
204
+
175
205
  console.log(chalk.yellow("🔧 Next steps (run manually):"));
176
206
  console.log(chalk.cyan(`1. Generate Prisma Client:`));
177
207
  console.log(chalk.cyan(` npx prisma generate`));
178
- console.log(chalk.cyan(`2. Apply Prisma Migrations:`));
179
- console.log(chalk.cyan(` npx prisma migrate dev --name init`));
208
+ if (selectedProvider === "mongodb") {
209
+ console.log(chalk.cyan(`2. Push schema to MongoDB:`));
210
+ console.log(chalk.cyan(` npx prisma db push`));
211
+ } else {
212
+ console.log(chalk.cyan(`2. Apply Prisma Migrations:`));
213
+ console.log(chalk.cyan(` npx prisma migrate dev --name init`));
214
+ }
180
215
  console.log(chalk.cyan(`3. Run Seed Script:`));
181
216
  console.log(chalk.cyan(` npx ts-node prisma/seed.ts`));
182
217
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-prisma-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A CLI to generate NestJS + Prisma project boilerplate with Swagger, Auth, and AWS S3 setup",
5
5
  "type": "module",
6
6
  "main": "bin/index.js",
@@ -0,0 +1,30 @@
1
+ # Use an official Node.js runtime as the base image
2
+ FROM node:22-alpine
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy Prisma schema first (needed for prisma generate)
8
+ COPY prisma ./prisma/
9
+
10
+ # Copy package.json and package-lock.json
11
+ COPY package*.json ./
12
+
13
+ # Install dependencies (this will trigger prisma generate)
14
+ RUN npm install
15
+
16
+ # Manually run prisma generate again (optional but safe)
17
+ RUN npx prisma generate
18
+
19
+ # Copy the rest of the app
20
+ COPY src ./src/
21
+ COPY tsconfig*.json ./
22
+
23
+ # Build the app
24
+ RUN npm run build
25
+
26
+ # Expose the app port
27
+ EXPOSE 8080
28
+
29
+ # Run Prisma migration and start server
30
+ CMD ["sh", "-c", "npx prisma migrate deploy && node dist/src/main.js"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes