-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (53 loc) · 2.02 KB
/
index.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
// Dependencies
const os = require('os');
const fs = require('fs');
const util = require('./util');
const op = require('./operations');
const templates = require('./templates');
const { input } = util;
let appName = '', appDescription = '', appResources=[];
async function mainFunc(){
let appName = await input('App Name: ');
let appDescription = await input('App Description: ');
let appResources = await input('App Resource, [seperated by space]: ');
appResources = appResources.split(' ');
op.createAppDirectory(appName);
op.createPackageJson(appName, appDescription);
op.createServerjs(appName, appResources);
op.createApiDirectories(appName);
op.createDotEnv(appName)
op.createDotGitIgnore(appName);
op.createControllers(appName, appResources);
op.createRoutes(appName, appResources);
op.createModel(appName, appResources);
op.installDependencies(appName, function(){
console.log(`\n\n${appName} REST API CREATED !`);
console.log(`Next Steps: \n1. Define DATABASE_URI in .env file\n2. Define Schema in api/models/schema.js file.\n`);
console.log('HAPPY CODING');
process.exit(0);
});
}
async function addResource(){
if(!fs.existsSync('package.json')){
console.log('package.json not found\n\nYou should be inside a node.js project to add a new resource\n\n');
process.exit(0);
}
let resourceName = await input('Resource Names, [seperated by space]: ');
let resources = resourceName.split(' ');
let appName = JSON.parse(fs.readFileSync('package.json').toString()).name;
if(!fs.existsSync('api'))
op.createApiDirectories(appName, false);
op.createControllers(appName, resources, false);
op.createRoutes(appName, resources, false);
if(!fs.existsSync('api/models/schema.js'))
op.createModel(appName, resources, false);
else
op.addSchema(resources);
op.editServerJS(resources);
console.log('\n\nNEW RESOURCES ADDED.\nNext Steps: \n1. Define Schema for new resources in api/models/schema.js');
process.exit(0);
}
module.exports = {
mainFunc,
addResource
}