-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateModule.js
More file actions
46 lines (36 loc) · 1.28 KB
/
createModule.js
File metadata and controls
46 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
// ============================================ HOW TO USE ===================================== //
// write the following command to generate a new module: node createModule.js moduleName
// ============================================ HOW TO USE ===================================== //
// Define __dirname manually
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const moduleName = process.argv[2];
if (!moduleName) {
console.log("Please provide a module name!");
process.exit(1);
}
const moduleDir = path.join(__dirname, "src", "app", "modules", moduleName);
const files = [
`${moduleName}.controller.ts`,
`${moduleName}.interface.ts`,
`${moduleName}.model.ts`,
`${moduleName}.routes.ts`,
`${moduleName}.service.ts`,
`${moduleName}.validation.ts`,
];
if (!fs.existsSync(moduleDir)) {
fs.mkdirSync(moduleDir, { recursive: true });
}
files.forEach((file) => {
const filePath = path.join(moduleDir, file);
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, ``);
console.log(`Created: ${filePath}`);
} else {
console.log(`File already exists: ${filePath}`);
}
});
console.log(`Module ${moduleName} created successfully!`);