-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateFiles.js
68 lines (68 loc) · 1.72 KB
/
generateFiles.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
if (process.argv.length < 3) {
console.error(
'Usage: node generate-folder-structure.js <FolderName> <FileName>'
);
process.exit(1);
}
// Get folder and file names from command-line arguments
const folderName = process.argv[2];
const fileName = process.argv[3];
// Define the target directory
const targetDirectory = path.join(
__dirname,
'src',
'app',
'modules',
folderName
);
// Create the target directory
fs.mkdirSync(targetDirectory, { recursive: true });
// Create and write the files in the target directory
const controllerTemplate = `
// Your controller code here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.controller.ts`),
controllerTemplate
);
const serviceTemplate = `
// Your service code here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.service.ts`),
serviceTemplate
);
const routesTemplate = `
// Define your routes here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.routes.ts`),
routesTemplate
);
const interfacesTemplate = `
// Define your interfaces here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.interfaces.ts`),
interfacesTemplate
);
const constantsTemplate = `
// Define your constants here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.constants.ts`),
constantsTemplate
);
const validationTemplate = `
// Define your validations here
`;
fs.writeFileSync(
path.join(targetDirectory, `${fileName}.validation.ts`),
validationTemplate
);
console.log(
`Folder '${folderName}' and files created successfully in 'src/app/modules'.`
);