1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const inquirer = require("inquirer");
|
4 | const questions_1 = require("./questions");
|
5 | const targets_1 = require("./targets");
|
6 | const types_1 = require("./types");
|
7 | const helpers_1 = require("./helpers");
|
8 | function log(...msgs) {
|
9 |
|
10 | console.log(...msgs);
|
11 | }
|
12 | async function init() {
|
13 | log(`
|
14 | Welcome to ${helpers_1.bold('GraphQL Code Generator')}!
|
15 | Answer few questions and we will setup everything for you.
|
16 | `);
|
17 | const possibleTargets = await targets_1.guessTargets();
|
18 | const answers = await inquirer.prompt(questions_1.getQuestions(possibleTargets));
|
19 |
|
20 | const config = {
|
21 | overwrite: true,
|
22 | schema: answers.schema,
|
23 | documents: answers.targets.includes(types_1.Tags.browser) ? answers.documents : null,
|
24 | generates: {
|
25 | [answers.output]: {
|
26 | plugins: answers.plugins.map(p => p.value)
|
27 | }
|
28 | }
|
29 | };
|
30 |
|
31 | if (answers.introspection) {
|
32 | addIntrospection(config);
|
33 | }
|
34 |
|
35 | const { relativePath } = helpers_1.writeConfig(answers, config);
|
36 |
|
37 | helpers_1.writePackage(answers, relativePath);
|
38 |
|
39 | log(`
|
40 | Config file generated at ${helpers_1.bold(relativePath)}
|
41 |
|
42 | ${helpers_1.bold('$ npm install')}
|
43 |
|
44 | To install the plugins.
|
45 |
|
46 | ${helpers_1.bold(`$ npm run ${answers.script}`)}
|
47 |
|
48 | To run GraphQL Code Generator.
|
49 | `);
|
50 | }
|
51 | exports.init = init;
|
52 |
|
53 | function addIntrospection(config) {
|
54 | config.generates['./graphql.schema.json'] = {
|
55 | plugins: ['introspection']
|
56 | };
|
57 | }
|
58 |
|
\ | No newline at end of file |