jru-express 1.0.0
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/index.js +93 -0
- package/package.json +23 -0
- package/templates/README.md +11 -0
- package/templates/server.js +7 -0
- package/templates/src/app.js +13 -0
- package/templates/src/config/db.js +0 -0
- package/templates/src/middleware/error.middleware.js +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
const { Command } = require("commander");
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name("jru-express")
|
|
12
|
+
.description("Generate a basic Express.js backend")
|
|
13
|
+
.argument("<project-name>", "Name of the project")
|
|
14
|
+
.action((projectName) => {
|
|
15
|
+
|
|
16
|
+
const projectPath = path.join(process.cwd(), projectName);
|
|
17
|
+
const templatePath = path.join(__dirname, "templates");
|
|
18
|
+
|
|
19
|
+
// Check if project already exists
|
|
20
|
+
if (fs.existsSync(projectPath)) {
|
|
21
|
+
console.error(`Project "${projectName}" already exists.`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log("\nCreating JruExpress project...\n");
|
|
26
|
+
|
|
27
|
+
// Create project directory
|
|
28
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
29
|
+
|
|
30
|
+
// Copy template structure
|
|
31
|
+
fs.cpSync(templatePath, projectPath, {
|
|
32
|
+
recursive: true
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log("✔ Folder structure created");
|
|
36
|
+
|
|
37
|
+
// Move into project directory
|
|
38
|
+
process.chdir(projectPath);
|
|
39
|
+
|
|
40
|
+
// Initialize npm
|
|
41
|
+
console.log("✔ Initializing npm...");
|
|
42
|
+
execSync("npm init -y", { stdio: "inherit" });
|
|
43
|
+
|
|
44
|
+
// Install Express
|
|
45
|
+
console.log("\n✔ Installing Express...");
|
|
46
|
+
execSync("npm install express", { stdio: "inherit" });
|
|
47
|
+
|
|
48
|
+
// Install Nodemon
|
|
49
|
+
console.log("\n✔ Installing Nodemon...");
|
|
50
|
+
execSync("npm install --save-dev nodemon", {
|
|
51
|
+
stdio: "inherit"
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Update package.json scripts
|
|
55
|
+
const packageJsonPath = path.join(projectPath, "package.json");
|
|
56
|
+
|
|
57
|
+
const packageJson = JSON.parse(
|
|
58
|
+
fs.readFileSync(packageJsonPath, "utf8")
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
packageJson.scripts = {
|
|
62
|
+
start: "node server.js",
|
|
63
|
+
dev: "nodemon server.js"
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
fs.writeFileSync(
|
|
67
|
+
packageJsonPath,
|
|
68
|
+
JSON.stringify(packageJson, null, 2)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
console.log("\n✔ Scripts configured");
|
|
72
|
+
|
|
73
|
+
console.log(`
|
|
74
|
+
╔══════════════════════════════════════╗
|
|
75
|
+
║ JruExpress Project Ready ║
|
|
76
|
+
╚══════════════════════════════════════╝
|
|
77
|
+
|
|
78
|
+
Project: ${projectName}
|
|
79
|
+
|
|
80
|
+
Run:
|
|
81
|
+
|
|
82
|
+
cd ${projectName}
|
|
83
|
+
|
|
84
|
+
Development:
|
|
85
|
+
npm run dev
|
|
86
|
+
|
|
87
|
+
Production:
|
|
88
|
+
npm start
|
|
89
|
+
|
|
90
|
+
`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jru-express",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "My basic Express backend generator",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"jru-express": "index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"No tests yet\""
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"express",
|
|
14
|
+
"backend",
|
|
15
|
+
"generator",
|
|
16
|
+
"scaffold"
|
|
17
|
+
],
|
|
18
|
+
"author": "The Great RAR",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"commander": "^14.0.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
File without changes
|
|
File without changes
|