-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathindex.js
87 lines (76 loc) · 2.04 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
const path = require('path');
const { ArgumentParser } = require('argparse');
const { validateSchema } = require('./api/utils');
const makeAPI = require('./api/makeAPI');
const makeApp = require('./app/makeApp');
const makeEmbeddable = require('./embeddable/makeEmbeddable');
const parser = new ArgumentParser({
version: require('./package.json').version,
addHelp: true,
description: 'Sugar Generator',
});
parser.addArgument(
['-t', '--type'],
{
help: 'one of ["api", "component"]',
choices: ["api", "component"],
metavar: "Generator Type",
dest: "type",
defaultValue: "api",
required: false,
}
);
parser.addArgument(
['-f', '--flavor'],
{
help: 'one of ["graphql", "rest"]',
choices: ["rest", "graphql"],
required: false,
metavar: "flavor. do you want just rest or graphql + rest?",
dest: "flavor",
defaultValue: "graphql",
}
);
parser.addArgument(
['-l', '--log'],
{
help: 'logging',
choices: [true, false],
metavar: "logging",
dest: "logging",
defaultValue: true,
}
);
// required
parser.addArgument(
['-s', '--schema'],
{
help: 'path to JSON of mongodb schema',
required: true,
metavar: "Schema",
dest: "schema"
}
);
parser.addArgument(
['-o', '--output'],
{
help: 'where will the generated code go?',
metavar: "output",
dest: "destination",
// defaultValue: __dirname,
}
);
const args = parser.parseArgs();
console.log('ARGS', args)
args.schema = path.join(process.cwd(), args.schema);
args.destination = path.join(process.cwd(), args.destination);
const validSchema = validateSchema(args.schema);
if (validSchema === true) {
makeAPI(Object.assign({}, args, { destination: `${args.destination}/api` }));
makeApp(Object.assign({}, args, { destination: `${args.destination}/app` }));
// makeEmbeddable(Object.assign({}, args, { destination: `${args.destination}/embeddable` }));
console.log('not making embeddable');
} else {
console.error('Error => invalid schema.', validSchema === false ? '' : validSchema);
}