create-prod-backend 1.1.5 → 1.3.5

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
@@ -80,16 +80,23 @@ npx create-prod-backend
80
80
 
81
81
  ## Supported Dependencies
82
82
 
83
+ # Must have
83
84
  * express
84
- * nodemon
85
85
  * cors
86
- * bcryptjs
87
86
  * dotenv
88
- * jsonwebtoken
89
87
  * cookie-parser
88
+
89
+ # Dev Dependency
90
+ * nodemon
91
+
92
+ # Optinal
93
+ * bcryptjs
94
+ * zod
95
+ * argon2
96
+ * jsonwebtoken
90
97
  * cloudinary
91
98
  * multer
92
- * mongoose (optional)
99
+ * mongoose
93
100
 
94
101
  ---
95
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prod-backend",
3
- "version": "1.1.5",
3
+ "version": "1.3.5",
4
4
  "description": "A cli tool to generate a production-ready backend boilerplate with Express.js, MongoDB, and essential features.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -13,7 +13,16 @@ export async function createProject(answer) {
13
13
  createFiles(projectPath, answer);
14
14
 
15
15
  if (answer.npmi) {
16
- console.log(chalk.blue("Installing dependencies..."));
16
+ console.log(chalk.blue("Installing dependencies...\n"));
17
17
  installDeps(projectPath, answer);
18
18
  }
19
+ else {
20
+ console.log(chalk.yellow("Skipping dependency installation."));
21
+ answer.auth && console.log(chalk.yellow("Don't forget to install authentication dependencies: jsonwebtoken, bcrypt"));
22
+ answer.validation && console.log(chalk.yellow("Don't forget to install validation dependency: zod"));
23
+ answer.fileUpload && console.log(chalk.yellow("Don't forget to install file upload dependencies: multer, cloudinary"));
24
+ answer.devTools && console.log(chalk.yellow("Don't forget to install dev tool dependency: nodemon"));
25
+ answer.useMongo && console.log(chalk.yellow("Don't forget to install MongoDB dependency: mongoose"));
26
+ }
27
+
19
28
  }
@@ -24,20 +24,28 @@ export default [
24
24
  message: chalk.bold.yellow("Do you want .env?"),
25
25
  },
26
26
  {
27
- type: "checkbox",
28
- name: "dependencies",
29
- message: chalk.bold.yellow("Select dependencies to install:"),
30
- choices: [
31
- "express",
32
- "nodemon",
33
- "cors",
34
- "bcryptjs",
35
- "dotenv",
36
- "jsonwebtoken",
37
- "cookie-parser",
38
- "cloudinary",
39
- "multer",
40
- ],
27
+ type: "select",
28
+ name: "auth",
29
+ message: chalk.bold.yellow("Add Authentication : "),
30
+ choices: ["No Authentication", "JWT + bcryptjs", "JWT + argon2"],
31
+ },
32
+
33
+ {
34
+ type: "confirm",
35
+ name: "validation",
36
+ message: chalk.bold.yellow("Add Validation (Zod)?"),
37
+ },
38
+
39
+ {
40
+ type: "confirm",
41
+ name: "fileUpload",
42
+ message: chalk.bold.yellow("Add File Upload (Multer + Cloudinary)?"),
43
+ },
44
+
45
+ {
46
+ type: "confirm",
47
+ name: "devTools",
48
+ message: chalk.bold.yellow("Add Dev Tools (Nodemon)?"),
41
49
  },
42
50
  {
43
51
  type: "confirm",
@@ -1,13 +1,18 @@
1
+ import chalk from "chalk";
1
2
  import { execSync } from "child_process";
2
3
 
3
4
  export function installDeps(projectPath, answer) {
4
- let deps = [...answer.dependencies];
5
+ let deps = ["express","cors","dotenv","cookie-parser"];
5
6
 
6
- if (answer.useMongo) {
7
- deps.push("mongoose");
8
- }
7
+ if(answer.auth === "JWT + bcryptjs") deps.push("jsonwebtoken", "bcryptjs");
8
+ if(answer.auth === "JWT + argon2") deps.push("jsonwebtoken", "argon2");
9
+ if(answer.validation) deps.push("zod");
10
+ if(answer.fileUpload) deps.push("multer", "cloudinary");
11
+ if(answer.devTools) deps.push("nodemon");
12
+
13
+ if (answer.useMongo) deps.push("mongoose");
9
14
 
10
- deps = deps.map(dep => dep.replace(/['"]/g, "").trim());
15
+ // deps = deps.map(dep => dep.replace(/['"]/g, "").trim());
11
16
 
12
17
  const dev = [];
13
18
  const normal = [];
@@ -17,7 +22,7 @@ export function installDeps(projectPath, answer) {
17
22
  else normal.push(dep);
18
23
  });
19
24
 
20
- console.log("Installing:", normal, dev); // debug
25
+ console.log(chalk.cyanBright("Installing:"), normal, dev); // debug
21
26
 
22
27
  if (normal.length) {
23
28
  execSync(`npm i ${normal.join(" ")}`, {
@@ -41,12 +41,12 @@ export function createFiles(projectPath, answer) {
41
41
 
42
42
  // .env
43
43
  if (answer.ENV) {
44
- fs.writeFileSync(path.join(projectPath, ".env"), envTemplate());
44
+ fs.writeFileSync(path.join(projectPath, ".env"), envTemplate(answer));
45
45
  }
46
46
 
47
47
  fs.writeFileSync(
48
48
  path.join(projectPath, "README.md"),
49
- `# ${answer.projectName}\n\nGenerated with create-prod-backend CLI.`
49
+ `# ${answer.projectName}\n\nGenerated with create-prod-backend CLI. Customize your README to provide instructions and information about your project. \n\n## Setup\n\n1. Install dependencies: \`npm install\`\n2. Start the server: \`npm start\` \n\n## Environment Variables\n\n- \`PORT\`: Port number for the server (default: 3000)\n- \`MONGO_URI\`: MongoDB connection string (if using MongoDB)\n- \`JWT_SECRET\`: Secret key for JWT authentication (if using auth)\n- \`CLOUDINARY_CLOUD_NAME\`, \`CLOUDINARY_API_KEY\`, \`CLOUDINARY_API_SECRET\`: Cloudinary credentials (if using file upload) \n\n## Features\n\n- Express server setup\n- CORS enabled\n- Environment variable support with dotenv\n${answer.auth ? "- JWT authentication with jsonwebtoken and bcrypt\n" : ""}${answer.validation ? "- Request validation with Zod\n" : ""}${answer.fileUpload ? "- File upload handling with Multer and Cloudinary\n" : ""}${answer.devTools ? "- Development tools with Nodemon\n" : ""}${answer.useMongo ? "- MongoDB integration with Mongoose\n" : ""}\n\n## License\n\nThis project is licensed under the ISC License. \n\n---\n\n*Generated by [create-prod-backend](https://www.npmjs.com/package/create-prod-backend)*`
50
50
  );
51
51
 
52
52
  // gitignore
@@ -1,22 +1,19 @@
1
1
  export const appTemplate = (answer) => `
2
2
  import express from "express";
3
- ${answer.dependencies.includes("cors") ? `import cors from "cors";` : ""}
4
- ${answer.dependencies.includes("cookie-parser") ? `import cookieParser from "cookie-parser";` : ""}
3
+ import cors from "cors";
4
+ import cookieParser from "cookie-parser";
5
5
 
6
6
  const app = express();
7
7
 
8
8
  app.use(express.json());
9
9
  app.use(express.urlencoded({ extended: true }));
10
10
  app.use(express.static("public"));
11
-
12
- ${answer.dependencies.includes("cors") ? `
13
11
  app.use(cors({
14
12
  origin: process.env.CORS_ORIGIN || "*",
15
13
  credentials: true
16
14
  }));
17
- ` : ""}
18
15
 
19
- ${answer.dependencies.includes("cookie-parser") ? `app.use(cookieParser());` : ""}
16
+ app.use(cookieParser());
20
17
 
21
18
  // routes here
22
19
 
@@ -1,12 +1,16 @@
1
- export const envTemplate = () => `
1
+ export const envTemplate = (answer) => `
2
2
  PORT=3000
3
3
  MONGO_URI=your_mongodb_uri
4
4
 
5
- ACCESS_TOKEN_SECRET=your_access_token
5
+ ${answer.auth ? `ACCESS_TOKEN_SECRET=your_access_token
6
6
  ACCESS_TOKEN_EXPIRY=2d
7
7
 
8
8
  REFRESH_TOKEN_SECRET=your_refresh_token
9
- REFRESH_TOKEN_EXPIRY=20d
9
+ REFRESH_TOKEN_EXPIRY=20d` : ""}
10
+
11
+ ${answer.fileUpload ? `CLOUDINARY_CLOUD_NAME=your_cloud_name
12
+ CLOUDINARY_API_KEY=your_api_key
13
+ CLOUDINARY_API_SECRET=your_api_secret` : ""}
10
14
 
11
15
  CORS_ORIGIN=*
12
16
  `;