nestjs-prisma-cli 1.0.3 → 1.0.4
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
CHANGED
|
@@ -8,8 +8,6 @@ A CLI tool to quickly scaffold a **NestJS + Prisma** project with pre-configured
|
|
|
8
8
|
|
|
9
9
|
## 📦 NestJS Prisma Generator CLI
|
|
10
10
|
|
|
11
|
-
**`create-nestjs-prisma`**
|
|
12
|
-
|
|
13
11
|
A CLI tool to quickly scaffold a **NestJS + Prisma** project with built-in support for:
|
|
14
12
|
|
|
15
13
|
- 🔧 Prisma ORM with migrations and seeding
|
|
@@ -49,8 +47,6 @@ nestgen --version
|
|
|
49
47
|
|
|
50
48
|
nestgen
|
|
51
49
|
|
|
52
|
-
```
|
|
53
|
-
|
|
54
50
|
Step 1 : ? Enter your project name: my-app
|
|
55
51
|
|
|
56
52
|
Step 2 : ? Select your database: (Use arrow keys)
|
|
@@ -66,3 +62,5 @@ Step 3 : 🎉 Project ready! Next steps:
|
|
|
66
62
|
npm run start:dev
|
|
67
63
|
npm run prisma:migrate
|
|
68
64
|
npm run seed
|
|
65
|
+
|
|
66
|
+
```
|
package/bin/index.cjs
CHANGED
|
@@ -6,9 +6,7 @@ const path = require("path");
|
|
|
6
6
|
const { execa } = require("execa");
|
|
7
7
|
const { readFileSync } = require("fs");
|
|
8
8
|
|
|
9
|
-
const packageJson = JSON.parse(
|
|
10
|
-
readFileSync(path.join(__dirname, "../package.json"), "utf-8")
|
|
11
|
-
);
|
|
9
|
+
const packageJson = JSON.parse(readFileSync(path.join(__dirname, "../package.json"), "utf-8"));
|
|
12
10
|
|
|
13
11
|
if (process.argv.includes("-v") || process.argv.includes("--version")) {
|
|
14
12
|
console.log(`nestgen ${packageJson.version}`);
|
|
@@ -54,27 +52,69 @@ async function main() {
|
|
|
54
52
|
type: "list",
|
|
55
53
|
name: "database",
|
|
56
54
|
message: "Select your database:",
|
|
57
|
-
choices: ["
|
|
55
|
+
choices: ["MySQL", "PostgreSQL", "SQLite", "MongoDB", "CockroachDB", "SQLServer"]
|
|
58
56
|
}
|
|
59
57
|
]);
|
|
60
58
|
|
|
61
59
|
console.log(chalk.green(`📦 Creating NestJS project "${projectName}"...`));
|
|
62
|
-
|
|
63
60
|
await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], { stdio: "inherit" });
|
|
64
61
|
|
|
65
62
|
const pkgManager = detectPackageManager();
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const coreDeps = [
|
|
64
|
+
"argon2",
|
|
65
|
+
"@nestjs/config",
|
|
66
|
+
"@nestjs/swagger",
|
|
67
|
+
"class-validator",
|
|
68
|
+
"class-transformer",
|
|
69
|
+
"winston",
|
|
70
|
+
"winston-daily-rotate-file",
|
|
71
|
+
"@nestjs/jwt",
|
|
72
|
+
"passport-jwt",
|
|
73
|
+
"@nestjs/passport",
|
|
74
|
+
"@aws-sdk/client-s3",
|
|
75
|
+
"@aws-sdk/s3-request-presigner",
|
|
76
|
+
"moment"
|
|
77
|
+
];
|
|
78
|
+
await execa(pkgManager, ["install", ...coreDeps], { cwd: projectPath, stdio: "inherit" });
|
|
79
|
+
console.log(chalk.green("✅ Core dependencies installed!"));
|
|
80
|
+
|
|
81
|
+
await execa(pkgManager, ["install", "@prisma/client"], { cwd: projectPath, stdio: "inherit" });
|
|
82
|
+
await execa(pkgManager, ["install", "-D", "prisma"], { cwd: projectPath, stdio: "inherit" });
|
|
83
|
+
console.log(chalk.green("✅ Prisma and @prisma/client installed!"));
|
|
84
|
+
|
|
85
|
+
const templatePath = path.resolve(__dirname, "./template");
|
|
86
|
+
const projectPrismaPath = path.join(projectPath, "prisma/schema.prisma");
|
|
87
|
+
|
|
88
|
+
const providerMap = {
|
|
89
|
+
postgresql: "postgresql",
|
|
90
|
+
mysql: "mysql",
|
|
91
|
+
sqlite: "sqlite",
|
|
92
|
+
mongodb: "mongodb",
|
|
93
|
+
cockroachdb: "postgresql",
|
|
94
|
+
sqlserver: "sqlserver"
|
|
95
|
+
};
|
|
96
|
+
const selectedProvider = providerMap[database.toLowerCase()] || "mysql";
|
|
68
97
|
|
|
69
|
-
|
|
98
|
+
let prismaContent = "";
|
|
99
|
+
if (fs.existsSync(templatePath)) {
|
|
100
|
+
await fs.copy(templatePath, projectPath, { overwrite: true });
|
|
101
|
+
const templatePrismaPath = path.join(templatePath, "prisma/schema.prisma");
|
|
102
|
+
if (fs.existsSync(templatePrismaPath)) {
|
|
103
|
+
prismaContent = await fs.readFile(templatePrismaPath, "utf-8");
|
|
104
|
+
prismaContent = prismaContent.replace(
|
|
105
|
+
/datasource\s+db\s*{[^}]*provider\s*=\s*".*"/,
|
|
106
|
+
`datasource db {\n provider = "${selectedProvider}"`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
70
110
|
|
|
71
|
-
|
|
72
|
-
|
|
111
|
+
if (!prismaContent) {
|
|
112
|
+
prismaContent = `generator client {
|
|
73
113
|
provider = "prisma-client-js"
|
|
74
114
|
}
|
|
75
115
|
|
|
76
116
|
datasource db {
|
|
77
|
-
provider = "${
|
|
117
|
+
provider = "${selectedProvider}"
|
|
78
118
|
url = env("DATABASE_URL")
|
|
79
119
|
}
|
|
80
120
|
|
|
@@ -87,16 +127,15 @@ model User {
|
|
|
87
127
|
isActive Boolean @default(true)
|
|
88
128
|
createdAt DateTime @default(now())
|
|
89
129
|
updatedAt DateTime @updatedAt
|
|
90
|
-
|
|
91
130
|
@@map("tbl_user")
|
|
92
131
|
}
|
|
93
132
|
`;
|
|
133
|
+
}
|
|
94
134
|
|
|
95
|
-
await fs.outputFile(
|
|
96
|
-
console.log(chalk.green("✅ Prisma schema created!"));
|
|
135
|
+
await fs.outputFile(projectPrismaPath, prismaContent);
|
|
97
136
|
|
|
98
137
|
const defaultUrlMap = {
|
|
99
|
-
postgresql: `postgresql://
|
|
138
|
+
postgresql: `postgresql://postgres:password@localhost:5432/${dbSafeName}?schema=public`,
|
|
100
139
|
mysql: `mysql://root:password@localhost:3306/${dbSafeName}?schema=public`,
|
|
101
140
|
sqlite: `file:./dev.db`,
|
|
102
141
|
mongodb: `mongodb://localhost:27017/${dbSafeName}`,
|
|
@@ -104,7 +143,7 @@ model User {
|
|
|
104
143
|
sqlserver: `sqlserver://localhost:1433;database=${dbSafeName};user=sa;password=your_password;encrypt=false`
|
|
105
144
|
};
|
|
106
145
|
|
|
107
|
-
const envContent = `DATABASE_URL="${defaultUrlMap[
|
|
146
|
+
const envContent = `DATABASE_URL="${defaultUrlMap[database.toLowerCase()]}"
|
|
108
147
|
|
|
109
148
|
JWT_ACCESS_SECRET="JWT_ACCESS_SECRET"
|
|
110
149
|
JWT_REFRESH_SECRET="JWT_REFRESH_SECRET"
|
|
@@ -120,22 +159,28 @@ NODE_ENV=dev
|
|
|
120
159
|
PROJECT_NAME=${dbSafeName}
|
|
121
160
|
PORT=3000
|
|
122
161
|
`;
|
|
162
|
+
|
|
123
163
|
await fs.outputFile(path.join(projectPath, ".env"), envContent);
|
|
124
|
-
console.log(chalk.
|
|
164
|
+
console.log(chalk.yellow("🎉 Project ready! Next steps:"));
|
|
165
|
+
console.log(chalk.cyan(`cd ${projectName}`));
|
|
125
166
|
|
|
126
|
-
|
|
127
|
-
console.log(chalk.green("✅ Prisma client generated!"));
|
|
167
|
+
console.log(chalk.green("✅ .env created! Please update DATABASE_URL if necessary before running seed."));
|
|
128
168
|
|
|
129
|
-
|
|
130
|
-
if (fs.existsSync(templatePath)) {
|
|
131
|
-
await fs.copy(templatePath, projectPath, { overwrite: true });
|
|
132
|
-
console.log(chalk.green("✅ Template files copied!"));
|
|
133
|
-
}
|
|
169
|
+
console.log(chalk.green("📦 Prisma installed!"));
|
|
134
170
|
|
|
135
|
-
console.log(chalk.yellow("
|
|
136
|
-
console.log(chalk.cyan(`
|
|
171
|
+
console.log(chalk.yellow("🔧 Next steps (run manually):"));
|
|
172
|
+
console.log(chalk.cyan(`1. Generate Prisma Client:`));
|
|
173
|
+
console.log(chalk.cyan(` npx prisma generate`));
|
|
174
|
+
|
|
175
|
+
console.log(chalk.cyan(`2. Apply Prisma Migrations:`));
|
|
176
|
+
console.log(chalk.cyan(` npx prisma migrate dev --name init`));
|
|
177
|
+
|
|
178
|
+
console.log(chalk.cyan(`3. Run Seed Script:`));
|
|
179
|
+
console.log(chalk.cyan(` npx ts-node prisma/seed.ts`));
|
|
180
|
+
|
|
181
|
+
console.log(chalk.yellow("⚠️ Make sure your .env DATABASE_URL is correct before running the above commands!"));
|
|
182
|
+
|
|
137
183
|
console.log(chalk.cyan(`${pkgManager} run start:dev`));
|
|
138
|
-
console.log(chalk.cyan("Check .env"));
|
|
139
184
|
}
|
|
140
185
|
|
|
141
186
|
main().catch(err => {
|
|
@@ -2,7 +2,7 @@ import { IsString, IsOptional, IsEmail } from 'class-validator';
|
|
|
2
2
|
import { ApiProperty } from '@nestjs/swagger';
|
|
3
3
|
|
|
4
4
|
export class CreateUserDto {
|
|
5
|
-
@ApiProperty({ example: '
|
|
5
|
+
@ApiProperty({ example: 'USER_20250815001' })
|
|
6
6
|
@IsString()
|
|
7
7
|
userId: string;
|
|
8
8
|
|