-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate-module.js
31 lines (27 loc) · 1.01 KB
/
create-module.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
const { createFileFromSkeleton, write, getFiles, writeFile, render, checkFileExists } = require('./helper');
const { sampleController } = require('./skeletons/controller');
const { sampleModel } = require('./skeletons/model');
const { sampleRoutes } = require('./skeletons/route');
const prettier = require('./lib/prettier');
const fs = require('fs');
/**
*
* @param {*} ModuleName
*/
const createModule = async (moduleName) => {
moduleName = moduleName.toLowerCase();
// replacements object
const replacements = {
NAME: moduleName.toLowerCase(),
CAPSNAME: moduleName.charAt(0).toUpperCase() + moduleName.slice(1)
}
// Write the new model file
writeFile(render(sampleModel, replacements), `${moduleName}.model.js`);
// Write the new controller file
writeFile(render(sampleController, replacements), `${moduleName}.controller.js`);
// Write the new routes file
writeFile(render(sampleRoutes, replacements), `${moduleName}.routes.js`);
}
module.exports = {
createModule
}