nestjs-prisma-cli 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,68 @@
1
+ # 🚀 NestJS + Prisma Project Generator
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](#license)
4
+
5
+ A CLI tool to quickly scaffold a **NestJS + Prisma** project with pre-configured **Swagger, Authentication, AWS S3 integration, and Prisma setup**.
6
+
7
+ ---
8
+
9
+ ## 📦 NestJS Prisma Generator CLI
10
+
11
+ **`create-nestjs-prisma`**
12
+
13
+ A CLI tool to quickly scaffold a **NestJS + Prisma** project with built-in support for:
14
+
15
+ - 🔧 Prisma ORM with migrations and seeding
16
+ - 📖 Swagger (OpenAPI) setup
17
+ - 🔑 Authentication boilerplate
18
+ - ☁️ AWS S3 integration
19
+
20
+ Compatible with **Node.js >=18** and **NestJS v10+**.
21
+
22
+ ---
23
+
24
+ ## 📥 Installation
25
+
26
+ ## ⚡ Quick Start Guide
27
+
28
+ Once the CLI is installed, you can use the following commands:
29
+
30
+ ### 1️⃣ Install CLI globally
31
+
32
+ ```bash
33
+
34
+ npm install -g nestjs-prisma-cli
35
+
36
+ ```
37
+
38
+ ### 2️⃣ Check CLI version
39
+ ```bash
40
+
41
+ nestgen -v
42
+ # or
43
+ nestgen --version
44
+
45
+ ```
46
+
47
+ ### 3️⃣ Generate a new project
48
+ ```bash
49
+
50
+ nestgen
51
+
52
+ ```
53
+
54
+ Step 1 : ? Enter your project name: my-app
55
+
56
+ Step 2 : ? Select your database: (Use arrow keys)
57
+ PostgreSQL
58
+ MySQL
59
+ SQLite
60
+ MongoDB
61
+ CockroachDB
62
+ SQLServer
63
+ Step 3 : 🎉 Project ready! Next steps:
64
+ cd my-app
65
+ Check .env
66
+ npm run start:dev
67
+ npm run prisma:migrate
68
+ npm run seed
@@ -1,12 +1,39 @@
1
- import inquirer from "inquirer";
2
- import chalk from "chalk";
3
- import fs from "fs-extra";
4
- import path from "path";
5
- import { execa } from "execa";
6
- import { fileURLToPath } from "url";
1
+ #!/usr/bin/env node
2
+ const inquirer = require("inquirer");
3
+ const chalk = require("chalk");
4
+ const fs = require("fs-extra");
5
+ const path = require("path");
6
+ const { execa } = require("execa");
7
+ const { readFileSync } = require("fs");
8
+
9
+ const packageJson = JSON.parse(
10
+ readFileSync(path.join(__dirname, "../package.json"), "utf-8")
11
+ );
12
+
13
+ if (process.argv.includes("-v") || process.argv.includes("--version")) {
14
+ console.log(`nestgen ${packageJson.version}`);
15
+ process.exit(0);
16
+ }
17
+
18
+ if (process.argv.includes("-h") || process.argv.includes("--help")) {
19
+ console.log(`
20
+ Usage: nestgen [options]
21
+
22
+ Options:
23
+ -v, --version Show version
24
+ -h, --help Show help
25
+ `);
26
+ process.exit(0);
27
+ }
7
28
 
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
29
+ const detectPackageManager = () => {
30
+ try {
31
+ fs.accessSync(path.join(process.cwd(), "yarn.lock"));
32
+ return "yarn";
33
+ } catch {
34
+ return "npm";
35
+ }
36
+ };
10
37
 
11
38
  async function main() {
12
39
  console.log(chalk.blue("🚀 Welcome to NestJS + Prisma Project Generator!"));
@@ -14,7 +41,6 @@ async function main() {
14
41
  const { projectName } = await inquirer.prompt([
15
42
  { type: "input", name: "projectName", message: "Enter your project name:" }
16
43
  ]);
17
-
18
44
  const dbSafeName = projectName.replace(/-/g, "_") + "_db";
19
45
  const projectPath = path.join(process.cwd(), projectName);
20
46
 
@@ -33,66 +59,12 @@ async function main() {
33
59
  ]);
34
60
 
35
61
  console.log(chalk.green(`📦 Creating NestJS project "${projectName}"...`));
62
+
36
63
  await execa("npx", ["@nestjs/cli", "new", projectName, "--skip-install"], { stdio: "inherit" });
37
64
 
38
- console.log(chalk.green("📥 Installing dependencies..."));
39
- await execa("npm", ["install"], { cwd: projectPath, stdio: "inherit" });
40
-
41
- await execa("npm", [
42
- "install",
43
- "--save",
44
- "@aws-sdk/client-s3",
45
- "@aws-sdk/s3-request-presigner",
46
- "@nestjs/config",
47
- "@nestjs/jwt",
48
- "@nestjs/passport",
49
- "@nestjs/swagger",
50
- "argon2",
51
- "class-transformer",
52
- "class-validator",
53
- "moment",
54
- "multer",
55
- "passport",
56
- "passport-jwt",
57
- "prisma",
58
- "@prisma/client",
59
- "reflect-metadata",
60
- "rxjs",
61
- "swagger-ui-express",
62
- "winston",
63
- "winston-daily-rotate-file"
64
- ], { cwd: projectPath, stdio: "inherit" });
65
-
66
- await execa("npm", [
67
- "install",
68
- "--save-dev",
69
- "@eslint/eslintrc",
70
- "@eslint/js",
71
- "@nestjs/cli",
72
- "@nestjs/schematics",
73
- "@nestjs/testing",
74
- "@swc/cli",
75
- "@swc/core",
76
- "@types/express",
77
- "@types/jest",
78
- "@types/multer",
79
- "@types/node",
80
- "@types/supertest",
81
- "eslint",
82
- "eslint-config-prettier",
83
- "eslint-plugin-prettier",
84
- "globals",
85
- "jest",
86
- "prettier",
87
- "source-map-support",
88
- "supertest",
89
- "ts-jest",
90
- "ts-loader",
91
- "ts-node",
92
- "tsconfig-paths",
93
- "typescript",
94
- "typescript-eslint"
95
- ], { cwd: projectPath, stdio: "inherit" });
65
+ const pkgManager = detectPackageManager();
66
+ console.log(chalk.green(`📥 Installing dependencies with ${pkgManager}...`));
67
+ await execa(pkgManager, ["install"], { cwd: projectPath, stdio: "inherit" });
96
68
 
97
69
  console.log(chalk.green("✅ Dependencies installed!"));
98
70
 
@@ -119,7 +91,9 @@ model User {
119
91
  @@map("tbl_user")
120
92
  }
121
93
  `;
94
+
122
95
  await fs.outputFile(path.join(projectPath, "prisma/schema.prisma"), prismaSchema);
96
+ console.log(chalk.green("✅ Prisma schema created!"));
123
97
 
124
98
  const defaultUrlMap = {
125
99
  postgresql: `postgresql://root:password@localhost:5432/${dbSafeName}?schema=public`,
@@ -146,45 +120,22 @@ NODE_ENV=dev
146
120
  PROJECT_NAME=${dbSafeName}
147
121
  PORT=3000
148
122
  `;
149
-
150
123
  await fs.outputFile(path.join(projectPath, ".env"), envContent);
151
- console.log(chalk.green("✅ Prisma schema + .env created!"));
124
+ console.log(chalk.green("✅ .env created!"));
152
125
 
153
126
  await execa("npx", ["prisma", "generate"], { cwd: projectPath, stdio: "inherit" });
154
127
  console.log(chalk.green("✅ Prisma client generated!"));
155
128
 
156
129
  const templatePath = path.join(__dirname, "template");
157
- if (!fs.existsSync(templatePath)) {
158
- console.log(chalk.red("❌ Template folder not found!"));
159
- process.exit(1);
130
+ if (fs.existsSync(templatePath)) {
131
+ await fs.copy(templatePath, projectPath, { overwrite: true });
132
+ console.log(chalk.green("✅ Template files copied!"));
160
133
  }
161
- await fs.copy(templatePath, projectPath, { overwrite: true });
162
- console.log(chalk.green("✅ Template files copied successfully!"));
163
-
164
- const packageJsonPath = path.join(projectPath, "package.json");
165
- const packageJson = await fs.readJSON(packageJsonPath);
166
- packageJson.scripts = {
167
- ...packageJson.scripts,
168
- "prisma:migrate": "prisma migrate dev --name init",
169
- "prisma:generate": "prisma generate",
170
- "prisma:deploy": "prisma migrate deploy",
171
- "prisma:studio": "prisma studio",
172
- "prisma:reset": "prisma migrate reset --force",
173
- "postinstall": "prisma generate",
174
- "migrate:dev": "dotenv -e .env -- prisma migrate dev",
175
- "migrate:staging": "dotenv -e .env -- prisma migrate deploy",
176
- "migrate:prod": "dotenv -e .env -- prisma migrate deploy",
177
- "seed": "ts-node prisma/seed.ts"
178
- };
179
- await fs.writeJSON(packageJsonPath, packageJson, { spaces: 2 });
180
- console.log(chalk.green("✅ package.json scripts updated successfully!"));
181
134
 
182
- console.log(chalk.yellow("🎉 Project is ready! Next steps:"));
135
+ console.log(chalk.yellow("🎉 Project ready! Next steps:"));
183
136
  console.log(chalk.cyan(`cd ${projectName}`));
137
+ console.log(chalk.cyan(`${pkgManager} run start:dev`));
184
138
  console.log(chalk.cyan("Check .env"));
185
- console.log(chalk.cyan("npm run prisma:migrate"));
186
- console.log(chalk.cyan("npm run seed"));
187
- console.log(chalk.cyan("npm run start:dev"));
188
139
  }
189
140
 
190
141
  main().catch(err => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-prisma-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A CLI to generate NestJS + Prisma project boilerplate with Swagger, Auth, and AWS S3 setup",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  "template/"
10
10
  ],
11
11
  "bin": {
12
- "nestgen": "./bin/index.js"
12
+ "nestgen": "./bin/index.cjs"
13
13
  },
14
14
  "scripts": {
15
15
  "start": "node ./bin/index.js",
@@ -29,7 +29,6 @@
29
29
  "execa": "^9.6.0",
30
30
  "fs-extra": "^11.3.1",
31
31
  "inquirer": "^8.2.7",
32
- "nestjs-prisma-generator": "file:nestjs-prisma-generator-1.0.0.tgz",
33
32
  "path": "^0.12.7"
34
33
  },
35
34
  "engines": {