create-prod-backend 1.1.4 → 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 +1 -1
- package/src/core/createProject.js +10 -1
- package/src/prompts/questions.js +21 -14
- package/src/services/dependency.service.js +10 -6
- package/src/services/file.service.js +2 -2
- package/src/services/package.service.js +2 -2
- package/src/templates/base/app.template.js +3 -6
- package/src/templates/config/env.template.js +7 -3
package/package.json
CHANGED
|
@@ -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
|
}
|
package/src/prompts/questions.js
CHANGED
|
@@ -24,20 +24,27 @@ export default [
|
|
|
24
24
|
message: chalk.bold.yellow("Do you want .env?"),
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
type: "
|
|
28
|
-
name: "
|
|
29
|
-
message: chalk.bold.yellow("
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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 = [
|
|
5
|
+
let deps = ["express","cors","dotenv","cookie-parser"];
|
|
5
6
|
|
|
6
|
-
if
|
|
7
|
-
|
|
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
|
|
@@ -13,8 +13,8 @@ export function initPackage(projectPath) {
|
|
|
13
13
|
|
|
14
14
|
pkg.type = "module";
|
|
15
15
|
pkg.scripts = {
|
|
16
|
-
start: "node index.js",
|
|
17
|
-
dev: "nodemon index.js",
|
|
16
|
+
start: "node src/index.js",
|
|
17
|
+
dev: "nodemon src/index.js",
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
export const appTemplate = (answer) => `
|
|
2
2
|
import express from "express";
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
`;
|