nestjs-prisma-cli 1.0.4 → 1.0.6
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 +7 -4
- package/bin/{index.cjs → index.js} +71 -39
- package/package.json +4 -5
- package/template/Dockerfile +30 -0
- /package/{bin/template → template}/.github/workflows/deploy-to-ecr.yml +0 -0
- /package/{bin/template → template}/prisma/schema.prisma +0 -0
- /package/{bin/template → template}/prisma/seed.ts +0 -0
- /package/{bin/template → template}/src/app.controller.spec.ts +0 -0
- /package/{bin/template → template}/src/app.controller.ts +0 -0
- /package/{bin/template → template}/src/app.module.ts +0 -0
- /package/{bin/template → template}/src/app.service.ts +0 -0
- /package/{bin/template → template}/src/common/classes/base64.ts +0 -0
- /package/{bin/template → template}/src/common/decorator/public.decorator.ts +0 -0
- /package/{bin/template → template}/src/common/dto/index.ts +0 -0
- /package/{bin/template → template}/src/common/dto/paginated-response.dto.ts +0 -0
- /package/{bin/template → template}/src/common/dto/pagination.dto.ts +0 -0
- /package/{bin/template → template}/src/common/enums/db-error-code.enum.ts +0 -0
- /package/{bin/template → template}/src/common/enums/index.ts +0 -0
- /package/{bin/template → template}/src/common/enums/message-code.enum.ts +0 -0
- /package/{bin/template → template}/src/common/http-interceptor/http-error-type.ts +0 -0
- /package/{bin/template → template}/src/common/http-interceptor/http-exception.filter.ts +0 -0
- /package/{bin/template → template}/src/common/http-interceptor/index.ts +0 -0
- /package/{bin/template → template}/src/common/http-interceptor/logging.interceptor.ts +0 -0
- /package/{bin/template → template}/src/common/http-interceptor/response.interceptor.ts +0 -0
- /package/{bin/template → template}/src/common/logger/winston.logger.ts +0 -0
- /package/{bin/template → template}/src/common/s3/s3.module.ts +0 -0
- /package/{bin/template → template}/src/common/s3/s3.service.spec.ts +0 -0
- /package/{bin/template → template}/src/common/s3/s3.service.ts +0 -0
- /package/{bin/template → template}/src/common/utils/pagination.util.ts +0 -0
- /package/{bin/template → template}/src/main.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/auth.controller.spec.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/auth.controller.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/auth.module.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/auth.service.spec.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/auth.service.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/dto/login.dto.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/jwt/jwt.guard.spec.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/jwt/jwt.guard.ts +0 -0
- /package/{bin/template → template}/src/modules/auth/jwt/jwt.strategy.ts +0 -0
- /package/{bin/template → template}/src/modules/user/dto/create-user.dto.ts +0 -0
- /package/{bin/template → template}/src/modules/user/dto/update-user.dto.ts +0 -0
- /package/{bin/template → template}/src/modules/user/user.controller.spec.ts +0 -0
- /package/{bin/template → template}/src/modules/user/user.controller.ts +0 -0
- /package/{bin/template → template}/src/modules/user/user.module.ts +0 -0
- /package/{bin/template → template}/src/modules/user/user.service.spec.ts +0 -0
- /package/{bin/template → template}/src/modules/user/user.service.ts +0 -0
- /package/{bin/template → template}/src/prisma/prisma.module.ts +0 -0
- /package/{bin/template → template}/src/prisma/prisma.service.spec.ts +0 -0
- /package/{bin/template → template}/src/prisma/prisma.service.ts +0 -0
- /package/{bin/template → template}/test/app.e2e-spec.ts +0 -0
- /package/{bin/template → template}/test/jest-e2e.json +0 -0
package/README.md
CHANGED
|
@@ -33,7 +33,8 @@ npm install -g nestjs-prisma-cli
|
|
|
33
33
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
###
|
|
36
|
+
### 2️⃣ Check CLI version
|
|
37
|
+
|
|
37
38
|
```bash
|
|
38
39
|
|
|
39
40
|
nestgen -v
|
|
@@ -43,6 +44,7 @@ nestgen --version
|
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
### 3️⃣ Generate a new project
|
|
47
|
+
|
|
46
48
|
```bash
|
|
47
49
|
|
|
48
50
|
nestgen
|
|
@@ -50,8 +52,8 @@ nestgen
|
|
|
50
52
|
Step 1 : ? Enter your project name: my-app
|
|
51
53
|
|
|
52
54
|
Step 2 : ? Select your database: (Use arrow keys)
|
|
53
|
-
PostgreSQL
|
|
54
55
|
MySQL
|
|
56
|
+
PostgreSQL
|
|
55
57
|
SQLite
|
|
56
58
|
MongoDB
|
|
57
59
|
CockroachDB
|
|
@@ -59,8 +61,9 @@ Step 2 : ? Select your database: (Use arrow keys)
|
|
|
59
61
|
Step 3 : 🎉 Project ready! Next steps:
|
|
60
62
|
cd my-app
|
|
61
63
|
Check .env
|
|
64
|
+
npx prisma generate
|
|
65
|
+
npx prisma migrate dev --name init
|
|
66
|
+
npx ts-node prisma/seed.ts
|
|
62
67
|
npm run start:dev
|
|
63
|
-
npm run prisma:migrate
|
|
64
|
-
npm run seed
|
|
65
68
|
|
|
66
69
|
```
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { execa } from "execa";
|
|
7
|
+
import { readFileSync } from "fs";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
|
|
13
|
+
const packageJson = JSON.parse(
|
|
14
|
+
readFileSync(path.join(__dirname, "../package.json"), "utf-8")
|
|
15
|
+
);
|
|
10
16
|
|
|
11
17
|
if (process.argv.includes("-v") || process.argv.includes("--version")) {
|
|
12
18
|
console.log(`nestgen ${packageJson.version}`);
|
|
@@ -37,8 +43,9 @@ async function main() {
|
|
|
37
43
|
console.log(chalk.blue("🚀 Welcome to NestJS + Prisma Project Generator!"));
|
|
38
44
|
|
|
39
45
|
const { projectName } = await inquirer.prompt([
|
|
40
|
-
{ type: "input", name: "projectName", message: "Enter your project name:" }
|
|
46
|
+
{ type: "input", name: "projectName", message: "Enter your project name:" },
|
|
41
47
|
]);
|
|
48
|
+
|
|
42
49
|
const dbSafeName = projectName.replace(/-/g, "_") + "_db";
|
|
43
50
|
const projectPath = path.join(process.cwd(), projectName);
|
|
44
51
|
|
|
@@ -52,14 +59,17 @@ async function main() {
|
|
|
52
59
|
type: "list",
|
|
53
60
|
name: "database",
|
|
54
61
|
message: "Select your database:",
|
|
55
|
-
choices: ["
|
|
56
|
-
}
|
|
62
|
+
choices: ["PostgreSQL", "MySQL", "SQLite", "MongoDB", "CockroachDB", "SQLServer"],
|
|
63
|
+
},
|
|
57
64
|
]);
|
|
58
65
|
|
|
59
66
|
console.log(chalk.green(`📦 Creating NestJS project "${projectName}"...`));
|
|
60
|
-
await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], {
|
|
67
|
+
await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], {
|
|
68
|
+
stdio: "inherit",
|
|
69
|
+
});
|
|
61
70
|
|
|
62
71
|
const pkgManager = detectPackageManager();
|
|
72
|
+
|
|
63
73
|
const coreDeps = [
|
|
64
74
|
"argon2",
|
|
65
75
|
"@nestjs/config",
|
|
@@ -73,42 +83,68 @@ async function main() {
|
|
|
73
83
|
"@nestjs/passport",
|
|
74
84
|
"@aws-sdk/client-s3",
|
|
75
85
|
"@aws-sdk/s3-request-presigner",
|
|
76
|
-
"moment"
|
|
86
|
+
"moment",
|
|
77
87
|
];
|
|
78
88
|
await execa(pkgManager, ["install", ...coreDeps], { cwd: projectPath, stdio: "inherit" });
|
|
79
|
-
console.log(chalk.green("✅ Core dependencies installed!"));
|
|
80
89
|
|
|
81
90
|
await execa(pkgManager, ["install", "@prisma/client"], { cwd: projectPath, stdio: "inherit" });
|
|
82
91
|
await execa(pkgManager, ["install", "-D", "prisma"], { cwd: projectPath, stdio: "inherit" });
|
|
83
|
-
console.log(chalk.green("✅ Prisma and @prisma/client installed!"));
|
|
84
92
|
|
|
85
|
-
|
|
93
|
+
console.log(chalk.green("✅ Dependencies installed!"));
|
|
94
|
+
|
|
95
|
+
const templatePath = path.resolve(__dirname, "../template");
|
|
86
96
|
const projectPrismaPath = path.join(projectPath, "prisma/schema.prisma");
|
|
87
97
|
|
|
98
|
+
const extraItems = [
|
|
99
|
+
{ src: path.resolve(__dirname, "../.github"), dest: path.join(projectPath, ".github") },
|
|
100
|
+
{ src: path.resolve(__dirname, "../Dockerfile"), dest: path.join(projectPath, "Dockerfile") },
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
async function safeCopy(src, dest, label) {
|
|
104
|
+
try {
|
|
105
|
+
if (await fs.pathExists(src)) {
|
|
106
|
+
await fs.copy(src, dest, { overwrite: true });
|
|
107
|
+
console.log(chalk.green(`✅ ${label} copied!`));
|
|
108
|
+
} else {
|
|
109
|
+
console.log(chalk.yellow(`⚠️ ${label} not found, skipped.`));
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.log(chalk.red(`❌ Failed to copy ${label}:`), err.message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for (const item of extraItems) {
|
|
117
|
+
const label = path.basename(item.dest);
|
|
118
|
+
await safeCopy(item.src, item.dest, label);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (await fs.pathExists(templatePath)) {
|
|
122
|
+
console.log(chalk.blue("📄 Copying template files..."));
|
|
123
|
+
await fs.copy(templatePath, projectPath, { overwrite: true });
|
|
124
|
+
console.log(chalk.green("✅ Template files copied!"));
|
|
125
|
+
} else {
|
|
126
|
+
console.log(chalk.yellow("⚠️ Template folder not found. Skipping copy."));
|
|
127
|
+
}
|
|
128
|
+
|
|
88
129
|
const providerMap = {
|
|
89
130
|
postgresql: "postgresql",
|
|
90
131
|
mysql: "mysql",
|
|
91
132
|
sqlite: "sqlite",
|
|
92
133
|
mongodb: "mongodb",
|
|
93
134
|
cockroachdb: "postgresql",
|
|
94
|
-
sqlserver: "sqlserver"
|
|
135
|
+
sqlserver: "sqlserver",
|
|
95
136
|
};
|
|
96
137
|
const selectedProvider = providerMap[database.toLowerCase()] || "mysql";
|
|
97
138
|
|
|
98
139
|
let prismaContent = "";
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (!prismaContent) {
|
|
140
|
+
const templatePrismaPath = path.join(templatePath, "prisma/schema.prisma");
|
|
141
|
+
if (fs.existsSync(templatePrismaPath)) {
|
|
142
|
+
prismaContent = await fs.readFile(templatePrismaPath, "utf-8");
|
|
143
|
+
prismaContent = prismaContent.replace(
|
|
144
|
+
/datasource\s+db\s*{[^}]*provider\s*=\s*".*"/,
|
|
145
|
+
`datasource db {\n provider = "${selectedProvider}"`
|
|
146
|
+
);
|
|
147
|
+
} else {
|
|
112
148
|
prismaContent = `generator client {
|
|
113
149
|
provider = "prisma-client-js"
|
|
114
150
|
}
|
|
@@ -140,7 +176,7 @@ model User {
|
|
|
140
176
|
sqlite: `file:./dev.db`,
|
|
141
177
|
mongodb: `mongodb://localhost:27017/${dbSafeName}`,
|
|
142
178
|
cockroachdb: `postgresql://root:password@localhost:26257/${dbSafeName}?sslmode=disable`,
|
|
143
|
-
sqlserver: `sqlserver://localhost:1433;database=${dbSafeName};user=sa;password=your_password;encrypt=false
|
|
179
|
+
sqlserver: `sqlserver://localhost:1433;database=${dbSafeName};user=sa;password=your_password;encrypt=false`,
|
|
144
180
|
};
|
|
145
181
|
|
|
146
182
|
const envContent = `DATABASE_URL="${defaultUrlMap[database.toLowerCase()]}"
|
|
@@ -161,29 +197,25 @@ PORT=3000
|
|
|
161
197
|
`;
|
|
162
198
|
|
|
163
199
|
await fs.outputFile(path.join(projectPath, ".env"), envContent);
|
|
164
|
-
console.log(chalk.yellow("🎉 Project ready! Next steps:"));
|
|
165
|
-
console.log(chalk.cyan(`cd ${projectName}`));
|
|
166
|
-
|
|
167
|
-
console.log(chalk.green("✅ .env created! Please update DATABASE_URL if necessary before running seed."));
|
|
168
200
|
|
|
169
|
-
console.log(chalk.
|
|
201
|
+
console.log(chalk.yellow("🎉 Project ready!"));
|
|
202
|
+
console.log(chalk.green("✅ .env created! Please update DATABASE_URL if necessary before running Prisma commands."));
|
|
203
|
+
console.log(chalk.cyan(`cd ${projectName}`));
|
|
170
204
|
|
|
171
205
|
console.log(chalk.yellow("🔧 Next steps (run manually):"));
|
|
172
206
|
console.log(chalk.cyan(`1. Generate Prisma Client:`));
|
|
173
207
|
console.log(chalk.cyan(` npx prisma generate`));
|
|
174
|
-
|
|
175
208
|
console.log(chalk.cyan(`2. Apply Prisma Migrations:`));
|
|
176
209
|
console.log(chalk.cyan(` npx prisma migrate dev --name init`));
|
|
177
|
-
|
|
178
210
|
console.log(chalk.cyan(`3. Run Seed Script:`));
|
|
179
211
|
console.log(chalk.cyan(` npx ts-node prisma/seed.ts`));
|
|
180
212
|
|
|
181
213
|
console.log(chalk.yellow("⚠️ Make sure your .env DATABASE_URL is correct before running the above commands!"));
|
|
182
|
-
|
|
214
|
+
console.log(chalk.cyan(`\nStart the development server:`));
|
|
183
215
|
console.log(chalk.cyan(`${pkgManager} run start:dev`));
|
|
184
216
|
}
|
|
185
217
|
|
|
186
|
-
main().catch(err => {
|
|
218
|
+
main().catch((err) => {
|
|
187
219
|
console.error(chalk.red("❌ Error:"), err);
|
|
188
220
|
process.exit(1);
|
|
189
221
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-prisma-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A CLI to generate NestJS + Prisma project boilerplate with Swagger, Auth, and AWS S3 setup",
|
|
5
|
-
"main": "bin/index.js",
|
|
6
5
|
"type": "module",
|
|
6
|
+
"main": "bin/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"bin/",
|
|
9
9
|
"template/"
|
|
10
10
|
],
|
|
11
11
|
"bin": {
|
|
12
|
-
"nestgen": "./bin/index.
|
|
12
|
+
"nestgen": "./bin/index.js"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"start": "node ./bin/index.js",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"chalk": "^4.1.2",
|
|
29
29
|
"execa": "^9.6.0",
|
|
30
30
|
"fs-extra": "^11.3.1",
|
|
31
|
-
"inquirer": "^
|
|
32
|
-
"path": "^0.12.7"
|
|
31
|
+
"inquirer": "^9.2.7"
|
|
33
32
|
},
|
|
34
33
|
"engines": {
|
|
35
34
|
"node": ">=18"
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|