create-prod-backend 1.1.5 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prod-backend",
3
- "version": "1.1.5",
3
+ "version": "1.2.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,27 @@ 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: "confirm",
28
+ name: "auth",
29
+ message: chalk.bold.yellow("Add Authentication (JWT + bcrypt)?"),
30
+ },
31
+
32
+ {
33
+ type: "confirm",
34
+ name: "validation",
35
+ message: chalk.bold.yellow("Add Validation (Zod)?"),
36
+ },
37
+
38
+ {
39
+ type: "confirm",
40
+ name: "fileUpload",
41
+ message: chalk.bold.yellow("Add File Upload (Multer + Cloudinary)?"),
42
+ },
43
+
44
+ {
45
+ type: "confirm",
46
+ name: "devTools",
47
+ message: chalk.bold.yellow("Add Dev Tools (Nodemon)?"),
41
48
  },
42
49
  {
43
50
  type: "confirm",
@@ -1,13 +1,17 @@
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) deps.push("jsonwebtoken", "bcrypt");
8
+ if(answer.validation) deps.push("zod");
9
+ if(answer.fileUpload) deps.push("multer", "cloudinary");
10
+ if(answer.devTools) deps.push("nodemon");
11
+
12
+ if (answer.useMongo) deps.push("mongoose");
9
13
 
10
- deps = deps.map(dep => dep.replace(/['"]/g, "").trim());
14
+ // deps = deps.map(dep => dep.replace(/['"]/g, "").trim());
11
15
 
12
16
  const dev = [];
13
17
  const normal = [];
@@ -17,7 +21,7 @@ export function installDeps(projectPath, answer) {
17
21
  else normal.push(dep);
18
22
  });
19
23
 
20
- console.log("Installing:", normal, dev); // debug
24
+ console.log(chalk.cyanBright("Installing:"), normal, dev); // debug
21
25
 
22
26
  if (normal.length) {
23
27
  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
  `;