-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·63 lines (55 loc) · 1.71 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
#!/usr/bin/env node
'use strict';
if (require.main === module) {
const chalk = require('chalk');
const argv = require('minimist')(process.argv);
const path = require('path');
const fs = require('fs');
const ip = argv._.splice(2);
console.log("");
process.on('exit', ()=>{
console.log("");
});
let config;
if (ip.indexOf("init") === -1) {
if (!fs.existsSync(path.join(process.cwd(), "package.json"))) {
console.log(" | " + chalk.red.bold("This is not the project root. Run this command from the project root") + " |");
process.exit(0);
}
config = require(path.join(process.cwd(), "package"));
}
global.color = argv.c || argv.color;
global.npmconfig = config;
process.on('unhandledRejection', (reason, p) => {
console.log(chalk.red("Unhandled Rejection at: Promise "), p, chalk.red(" reason: "), chalk.red(reason));
});
process.on('unhandledException', (error, m)=> {
console.log(chalk.red("Unhandled Exception at: Error "), m, chalk.red(" reason: "), chalk.red(error));
})
let jgen = require('./lib');
if (ip[0] === "init") {
jgen.setup(ip[1]);
} else if (ip[0] === "fix" || ip[0] === "update") {
jgen.fix();
} else if (ip[0] === "model") {
if (!ip[1]) {
jgen.showModels();
}
if (ip[1].toLowerCase() === "remove") {
let arr = ip.splice(2, process.argv.length);
jgen.removeModels(arr);
} else {
jgen.model(ip[1]);
}
} else if (ip[0] === "tree") {
let arr = ip.splice(1, process.argv.length);
if (arr.length > 0) {
jgen.tree(arr);
} else {
jgen.tree();
}
}
} else {
exports.APIAuthentication = require('./lib/scripts/api-authentication');
exports.Schema = require('./lib/schema');
}