UNPKG

3.03 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4var commander = require("commander");
5var diff_1 = require("./commands/diff");
6var validate_1 = require("./commands/validate");
7var similar_1 = require("./commands/similar");
8var serve_1 = require("./commands/serve");
9var coverage_1 = require("./commands/coverage");
10var ui_1 = require("./commands/ui");
11var introspect_1 = require("./commands/introspect");
12var options_1 = require("./utils/options");
13function collect(val, memo) {
14 memo.push(val);
15 return memo;
16}
17commander.option('-r, --require [require]', 'Require modules', collect, []);
18commander.option('-t, --token <s>', 'Access Token');
19var defaultPort = 4000;
20commander
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});
29commander
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});
35commander
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});
42commander
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});
51commander
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});
57commander
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});
65commander
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});
72commander.command('*').action(function () { return commander.help(); });
73commander.parse(process.argv);
74if (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//# sourceMappingURL=index.js.map
\No newline at end of file