1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const helpers_1 = require("./helpers");
|
4 | const types_1 = require("./types");
|
5 | const plugins_1 = require("./plugins");
|
6 | function getQuestions(possibleTargets) {
|
7 | return [
|
8 | {
|
9 | type: 'checkbox',
|
10 | name: 'targets',
|
11 | message: `What type of application are you building?`,
|
12 | choices: getApplicationTypeChoices(possibleTargets)
|
13 | },
|
14 | {
|
15 | type: 'input',
|
16 | name: 'schema',
|
17 | message: 'Where is your schema?:',
|
18 | suffix: helpers_1.grey(' (path or url)'),
|
19 | default: 'http://localhost:4000',
|
20 | validate: (str) => str.length > 0
|
21 | },
|
22 | {
|
23 | type: 'input',
|
24 | name: 'documents',
|
25 | message: 'Where are your operations and fragments?:',
|
26 | when: answers => {
|
27 |
|
28 |
|
29 | answers.targets = normalizeTargets(answers.targets);
|
30 | return answers.targets.includes(types_1.Tags.browser);
|
31 | },
|
32 | default: '**/*.graphql',
|
33 | validate: (str) => str.length > 0
|
34 | },
|
35 | {
|
36 | type: 'checkbox',
|
37 | name: 'plugins',
|
38 | message: 'Pick plugins:',
|
39 | choices: getPluginChoices,
|
40 | validate: (plugins) => plugins.length > 0
|
41 | },
|
42 | {
|
43 | type: 'input',
|
44 | name: 'output',
|
45 | message: 'Where to write the output:',
|
46 | default: 'src/generated/graphql.ts',
|
47 | validate: (str) => str.length > 0
|
48 | },
|
49 | {
|
50 | type: 'confirm',
|
51 | name: 'introspection',
|
52 | message: 'Do you want to generate an introspection file?'
|
53 | },
|
54 | {
|
55 | type: 'input',
|
56 | name: 'config',
|
57 | message: 'How to name the config file?',
|
58 | default: 'codegen.yml',
|
59 | validate: (str) => {
|
60 | const isNotEmpty = str.length > 0;
|
61 | const hasCorrectExtension = ['json', 'yml', 'yaml'].some(ext => str.toLocaleLowerCase().endsWith(`.${ext}`));
|
62 | return isNotEmpty && hasCorrectExtension;
|
63 | }
|
64 | },
|
65 | {
|
66 | type: 'input',
|
67 | name: 'script',
|
68 | message: 'What script in package.json should run the codegen?',
|
69 | validate: (str) => str.length > 0
|
70 | }
|
71 | ];
|
72 | }
|
73 | exports.getQuestions = getQuestions;
|
74 | function getApplicationTypeChoices(possibleTargets) {
|
75 | function withFlowOrTypescript(tags) {
|
76 | if (possibleTargets.TypeScript) {
|
77 | tags.push(types_1.Tags.typescript);
|
78 | }
|
79 | else if (possibleTargets.Flow) {
|
80 | tags.push(types_1.Tags.flow);
|
81 | }
|
82 | else {
|
83 | tags.push(types_1.Tags.flow, types_1.Tags.typescript);
|
84 | }
|
85 | return tags;
|
86 | }
|
87 | return [
|
88 | {
|
89 | name: 'Backend - API or server',
|
90 | key: 'backend',
|
91 | value: withFlowOrTypescript([types_1.Tags.node]),
|
92 | checked: possibleTargets.Node
|
93 | },
|
94 | {
|
95 | name: 'Application built with Angular',
|
96 | key: 'angular',
|
97 | value: [types_1.Tags.angular, types_1.Tags.browser, types_1.Tags.typescript],
|
98 | checked: possibleTargets.Angular
|
99 | },
|
100 | {
|
101 | name: 'Application built with React',
|
102 | key: 'react',
|
103 | value: withFlowOrTypescript([types_1.Tags.react, types_1.Tags.browser]),
|
104 | checked: possibleTargets.React
|
105 | },
|
106 | {
|
107 | name: 'Application built with Stencil',
|
108 | key: 'stencil',
|
109 | value: [types_1.Tags.stencil, types_1.Tags.browser, types_1.Tags.typescript],
|
110 | checked: possibleTargets.Stencil
|
111 | },
|
112 | {
|
113 | name: 'Application built with other framework or vanilla JS',
|
114 | key: 'client',
|
115 | value: [types_1.Tags.browser, types_1.Tags.typescript, types_1.Tags.flow],
|
116 | checked: possibleTargets.Browser && !possibleTargets.Angular && !possibleTargets.React && !possibleTargets.Stencil
|
117 | }
|
118 | ];
|
119 | }
|
120 | exports.getApplicationTypeChoices = getApplicationTypeChoices;
|
121 | function getPluginChoices(answers) {
|
122 | return plugins_1.plugins
|
123 | .filter(p => p.available(answers.targets))
|
124 | .map(p => {
|
125 | return {
|
126 | name: p.name,
|
127 | value: p,
|
128 | checked: p.shouldBeSelected(answers.targets)
|
129 | };
|
130 | });
|
131 | }
|
132 | exports.getPluginChoices = getPluginChoices;
|
133 | function normalizeTargets(targets) {
|
134 | return [].concat(...targets);
|
135 | }
|
136 |
|
\ | No newline at end of file |