UNPKG

1.77 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const inquirer = require("inquirer");
4const questions_1 = require("./questions");
5const targets_1 = require("./targets");
6const types_1 = require("./types");
7const helpers_1 = require("./helpers");
8function log(...msgs) {
9 // tslint:disable-next-line
10 console.log(...msgs);
11}
12async 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 // define config
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 // introspection
31 if (answers.introspection) {
32 addIntrospection(config);
33 }
34 // config file
35 const { relativePath } = helpers_1.writeConfig(answers, config);
36 // write package.json
37 helpers_1.writePackage(answers, relativePath);
38 // Emit status to the terminal
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}
51exports.init = init;
52// adds an introspection to `generates`
53function addIntrospection(config) {
54 config.generates['./graphql.schema.json'] = {
55 plugins: ['introspection']
56 };
57}
58//# sourceMappingURL=index.js.map
\No newline at end of file