forked from vsuaste/express_graphql_model_gen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·55 lines (49 loc) · 1.44 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
#!/usr/bin/env node
const program = require("commander");
var fs = require("fs");
const funks = require("./funks");
path = require("path");
const colors = require("colors/safe");
program
.description("Code generator for GraphQL server")
.option(
"-f, --jsonFiles <filesFolder>",
"Folder containing one json file for each model"
)
.option(
"-o, --outputDirectory <directory>",
"Directory where generated code will be written"
)
.option(
"-v, --verbose",
"Show detailed messages about the results of running code generation process"
)
.option("-m, --migrations", "generate migrations", false)
.option("-b, --noBasicCode", "does not generate basic code", false)
.parse(process.argv);
const opts = program.opts();
//check input JSON files
if (!opts.jsonFiles) {
//msg
console.log(
colors.red("! Error: "),
"You must indicate the json files in order to generate the code."
);
process.exit(1);
}
//ops: output/input directories
let jsonFiles = opts.jsonFiles;
let directory = opts.outputDirectory || __dirname;
//msg
console.log("Input directory: ", colors.dim(path.resolve(jsonFiles)));
console.log("Output directory: ", colors.dim(path.resolve(directory)));
//op: verbose, migrations
let verbose = opts.verbose !== undefined ? true : false;
let migrations = opts.migrations;
let basicCode = !opts.noBasicCode;
//run codegen
funks.generateCode(opts.jsonFiles, directory, {
verbose,
migrations,
basicCode,
});