1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | var commander = require("commander");
|
5 | var diff_1 = require("./commands/diff");
|
6 | var validate_1 = require("./commands/validate");
|
7 | var similar_1 = require("./commands/similar");
|
8 | var serve_1 = require("./commands/serve");
|
9 | var coverage_1 = require("./commands/coverage");
|
10 | var ui_1 = require("./commands/ui");
|
11 | var introspect_1 = require("./commands/introspect");
|
12 | var options_1 = require("./utils/options");
|
13 | function collect(val, memo) {
|
14 | memo.push(val);
|
15 | return memo;
|
16 | }
|
17 | commander.option('-r, --require [require]', 'Require modules', collect, []);
|
18 | commander.option('-t, --token <s>', 'Access Token');
|
19 | var defaultPort = 4000;
|
20 | commander
|
21 | .command('ui')
|
22 | .description('Serves a GUI')
|
23 | .option('-p, --port <n>', 'Run on a specific port', defaultPort)
|
24 | .action(function (cmd) {
|
25 | return ui_1.ui({
|
26 | port: cmd.port,
|
27 | });
|
28 | });
|
29 | commander
|
30 | .command('diff <old> <new>')
|
31 | .description('Diff two schemas')
|
32 | .action(function (oldSchema, newSchema, cmd) {
|
33 | return diff_1.diff(oldSchema, newSchema, options_1.normalizeOptions(cmd));
|
34 | });
|
35 | commander
|
36 | .command('validate <documents> <schema>')
|
37 | .option('-d, --deprecated', 'Fail on deprecated usage', false)
|
38 | .description('Validate documents against a schema')
|
39 | .action(function (documents, schema, cmd) {
|
40 | return validate_1.validate(documents, schema, options_1.normalizeOptions(cmd));
|
41 | });
|
42 | commander
|
43 | .command('similar <schema>')
|
44 | .option('-n, --type <s>', 'Name of a type')
|
45 | .option('-t, --threshold <n>', 'Threshold of similarity ratio', parseFloat)
|
46 | .option('-w, --write <s>', 'Write a file with stats')
|
47 | .description('Find similar types in a schema')
|
48 | .action(function (schema, cmd) {
|
49 | return similar_1.similar(schema, cmd.type, cmd.threshold, options_1.normalizeOptions(cmd));
|
50 | });
|
51 | commander
|
52 | .command('serve <schema>')
|
53 | .description('Serves a GraphQL API with Playground')
|
54 | .action(function (schema, cmd) {
|
55 | return serve_1.serve(schema, options_1.normalizeOptions(cmd));
|
56 | });
|
57 | commander
|
58 | .command('coverage <documents> <schema>')
|
59 | .option('-s, --silent', 'Do not render any stats in the terminal')
|
60 | .option('-w, --write <s>', 'Write a file with coverage stats')
|
61 | .description('Schema coverage based on documents')
|
62 | .action(function (documents, schema, cmd) {
|
63 | return coverage_1.coverage(documents, schema, options_1.normalizeOptions(cmd));
|
64 | });
|
65 | commander
|
66 | .command('introspect <schema>')
|
67 | .option('-w, --write <s>', 'Write to a file')
|
68 | .description('Introspect a schema')
|
69 | .action(function (schema, cmd) {
|
70 | return introspect_1.introspect(schema, options_1.normalizeOptions(cmd));
|
71 | });
|
72 | commander.command('*').action(function () { return commander.help(); });
|
73 | commander.parse(process.argv);
|
74 | if (process.argv.length === 2) {
|
75 | ui_1.ui({
|
76 | port: defaultPort,
|
77 | }).catch(function (e) {
|
78 | console.log(e);
|
79 | process.exit(1);
|
80 | });
|
81 | }
|
82 |
|
\ | No newline at end of file |