create-prod-backend 1.3.5 → 1.4.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 CHANGED
@@ -79,24 +79,18 @@ npx create-prod-backend
79
79
  ---
80
80
 
81
81
  ## Supported Dependencies
82
-
83
- # Must have
84
82
  * express
85
83
  * cors
86
84
  * dotenv
87
85
  * cookie-parser
88
-
89
- # Dev Dependency
90
- * nodemon
91
-
92
- # Optinal
93
- * bcryptjs
94
- * zod
95
- * argon2
96
- * jsonwebtoken
97
- * cloudinary
98
- * multer
99
- * mongoose
86
+ * nodemon (devDependency)
87
+ * bcryptjs (Optional)
88
+ * zod (Optional)
89
+ * argon2 (Optional)
90
+ * jsonwebtoken (Optional)
91
+ * cloudinary (Optional)
92
+ * multer (Optional)
93
+ * mongoose (Optional)
100
94
 
101
95
  ---
102
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prod-backend",
3
- "version": "1.3.5",
3
+ "version": "1.4.6",
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": {
package/src/index.js CHANGED
@@ -1,17 +1,33 @@
1
1
  import inquirer from "inquirer";
2
2
  import questions from "./prompts/questions.js";
3
3
  import { createProject } from "./core/createProject.js";
4
+ import { execSync } from "child_process";
4
5
  import chalk from "chalk";
5
6
 
6
7
  export default async function runCLI() {
7
8
  console.log(chalk.bold.cyan("\n------------------Welcome to the CREATE-PROD-BACKEND CLI------------------\n"));
8
9
 
9
10
  try {
11
+ const backendapp = await inquirer.prompt([
12
+ {
13
+ type: "select",
14
+ name: "usebackend",
15
+ message: chalk.bold.yellow("What do you want to create?"),
16
+ choices: ["Express Backend", "Next.js App"],
17
+ },
18
+ ]);
19
+
20
+ if (backendapp.usebackend === "Next.js App") {
21
+ execSync("npx create-next-app@latest", { stdio: "inherit" });
22
+ return;
23
+ }
24
+
10
25
  const answer = await inquirer.prompt(questions);
11
26
 
12
27
  await createProject(answer);
13
28
 
14
29
  console.log(chalk.green(`\n${chalk.bold(answer.projectName)} project created successfully!\n`));
30
+ console.log(chalk.yellow("You can change Docker file according to your need"));
15
31
  console.log(chalk.yellow("Happy coding! :)"));
16
32
  } catch (error) {
17
33
  console.error(chalk.red(("Error:", error.message)));
@@ -18,6 +18,11 @@ export default [
18
18
  name: "useMongo",
19
19
  message: chalk.bold.yellow("Do you want MongoDB?"),
20
20
  },
21
+ {
22
+ type: "confirm",
23
+ name: "useDocker",
24
+ message: chalk.bold.yellow("Do you want Docker Setup?")
25
+ },
21
26
  {
22
27
  type: "confirm",
23
28
  name: "ENV",
@@ -2,21 +2,24 @@ import fs from "fs";
2
2
  import path from "path";
3
3
 
4
4
  import { indexTemplate } from "../templates/base/index.template.js";
5
+ import { dockerfileTemplate } from "../templates/docker-setup/docker.template.js"
5
6
  import { appTemplate } from "../templates/base/app.template.js";
6
7
  import { mongoTemplate } from "../templates/db/mongo.template.js";
7
8
  import { envTemplate } from "../templates/config/env.template.js";
8
9
  import { utilsTemplates } from "../templates/utils/utils.template.js";
10
+ import { dockercomposeTemplate } from "../templates/docker-setup/dockercompose.template.js"
11
+ import { dockerignoreTemplate } from "../templates/docker-setup/dockerignore.template.js"
9
12
 
10
13
  export function createFiles(projectPath, answer) {
11
14
  // index.js
12
15
  fs.writeFileSync(
13
- path.join(projectPath,"src", "index.js"),
16
+ path.join(projectPath, "src", "index.js"),
14
17
  indexTemplate(answer)
15
18
  );
16
19
 
17
20
  // app.js
18
21
  fs.writeFileSync(
19
- path.join(projectPath,"src", "app.js"),
22
+ path.join(projectPath, "src", "app.js"),
20
23
  appTemplate(answer)
21
24
  );
22
25
 
@@ -44,6 +47,13 @@ export function createFiles(projectPath, answer) {
44
47
  fs.writeFileSync(path.join(projectPath, ".env"), envTemplate(answer));
45
48
  }
46
49
 
50
+ // docker
51
+ if (answer.useDocker) {
52
+ fs.writeFileSync(path.join(projectPath, 'Dockerfile'), dockerfileTemplate());
53
+ fs.writeFileSync(path.join(projectPath, 'docker-compose.yml'), dockercomposeTemplate());
54
+ fs.writeFileSync(path.join(projectPath, '.dockerignore'), dockerignoreTemplate());
55
+ }
56
+
47
57
  fs.writeFileSync(
48
58
  path.join(projectPath, "README.md"),
49
59
  `# ${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)*`
@@ -0,0 +1,19 @@
1
+ export const dockerfileTemplate = () => `
2
+ # Base image
3
+ FROM node:18-alpine
4
+
5
+ # Set working directory
6
+ WORKDIR /app
7
+
8
+ # Copy package files
9
+ COPY package*.json ./
10
+
11
+ # Install dependencies
12
+ RUN npm install
13
+
14
+ # Copy source code
15
+ COPY . .
16
+
17
+ # Start server
18
+ ENTRYPOINT ["node", "src/index.js"]
19
+ `;
@@ -0,0 +1,18 @@
1
+ export const dockercomposeTemplate = () => {
2
+ return `
3
+ version: "3.8"
4
+
5
+ services:
6
+ app:
7
+ build: .
8
+ container_name: node_app
9
+ ports:
10
+ - "5000:5000"
11
+ volumes:
12
+ - .:/app
13
+ - /app/node_modules
14
+ environment:
15
+ - PORT=5000
16
+ command: npm run dev
17
+ `;
18
+ };
@@ -0,0 +1,24 @@
1
+ export const dockerignoreTemplate = () => `
2
+ node_modules/
3
+ npm-debug.log
4
+ yarn-error.log
5
+
6
+ .git
7
+ .gitignore
8
+
9
+ .env
10
+ .env.local
11
+
12
+ Dockerfile
13
+ docker-compose.yml
14
+ .dockerignore
15
+
16
+ coverage
17
+ dist
18
+ build
19
+
20
+ .vscode
21
+ .idea
22
+
23
+ *.log
24
+ `