@graphql-codegen/cli 2.7.0 → 2.8.0-alpha-36b27f965.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/bin.js +13 -0
- package/cjs/cli.js +60 -0
- package/cjs/codegen.js +332 -0
- package/cjs/config.js +303 -0
- package/cjs/generate-and-save.js +110 -0
- package/cjs/graphql-config.js +69 -0
- package/cjs/hooks.js +87 -0
- package/cjs/index.js +13 -0
- package/cjs/init/helpers.js +64 -0
- package/cjs/init/index.js +60 -0
- package/cjs/init/plugins.js +163 -0
- package/cjs/init/questions.js +147 -0
- package/cjs/init/targets.js +44 -0
- package/cjs/init/types.js +14 -0
- package/cjs/load.js +93 -0
- package/cjs/package.json +1 -0
- package/cjs/plugins.js +45 -0
- package/cjs/presets.js +46 -0
- package/cjs/utils/cli-error.js +25 -0
- package/cjs/utils/debugging.js +27 -0
- package/cjs/utils/file-system.js +26 -0
- package/cjs/utils/indentString.js +37 -0
- package/cjs/utils/listr-renderer.js +136 -0
- package/cjs/utils/logger.js +25 -0
- package/cjs/utils/watcher.js +140 -0
- package/esm/bin.js +11 -0
- package/esm/cli.js +32 -0
- package/esm/codegen.js +327 -0
- package/esm/config.js +290 -0
- package/esm/generate-and-save.js +105 -0
- package/esm/graphql-config.js +64 -0
- package/esm/hooks.js +83 -0
- package/esm/index.js +7 -0
- package/esm/init/helpers.js +55 -0
- package/esm/init/index.js +55 -0
- package/esm/init/plugins.js +160 -0
- package/esm/init/questions.js +140 -0
- package/esm/init/targets.js +40 -0
- package/esm/init/types.js +11 -0
- package/esm/load.js +88 -0
- package/esm/plugins.js +41 -0
- package/esm/presets.js +42 -0
- package/esm/utils/cli-error.js +20 -0
- package/esm/utils/debugging.js +21 -0
- package/esm/utils/file-system.js +19 -0
- package/esm/utils/indentString.js +33 -0
- package/esm/utils/listr-renderer.js +130 -0
- package/esm/utils/logger.js +18 -0
- package/esm/utils/watcher.js +135 -0
- package/package.json +31 -23
- package/typings/bin.d.ts +2 -0
- package/{cli.d.ts → typings/cli.d.ts} +0 -0
- package/{codegen.d.ts → typings/codegen.d.ts} +1 -1
- package/{config.d.ts → typings/config.d.ts} +0 -0
- package/{generate-and-save.d.ts → typings/generate-and-save.d.ts} +1 -1
- package/{graphql-config.d.ts → typings/graphql-config.d.ts} +0 -0
- package/{hooks.d.ts → typings/hooks.d.ts} +0 -0
- package/typings/index.d.ts +7 -0
- package/{init → typings/init}/helpers.d.ts +1 -1
- package/{init → typings/init}/index.d.ts +0 -0
- package/{init → typings/init}/plugins.d.ts +1 -1
- package/{init → typings/init}/questions.d.ts +1 -1
- package/{init → typings/init}/targets.d.ts +1 -1
- package/{init → typings/init}/types.d.ts +0 -0
- package/{load.d.ts → typings/load.d.ts} +0 -0
- package/{plugins.d.ts → typings/plugins.d.ts} +0 -0
- package/{presets.d.ts → typings/presets.d.ts} +0 -0
- package/{utils → typings/utils}/cli-error.d.ts +0 -0
- package/{utils → typings/utils}/debugging.d.ts +0 -0
- package/{utils → typings/utils}/file-system.d.ts +0 -0
- package/{utils → typings/utils}/indentString.d.ts +0 -0
- package/{utils → typings/utils}/listr-renderer.d.ts +0 -0
- package/{utils → typings/utils}/logger.d.ts +0 -0
- package/{utils → typings/utils}/watcher.d.ts +1 -1
- package/bin.d.ts +0 -1
- package/bin.js +0 -1891
- package/index.d.ts +0 -7
- package/index.js +0 -1902
- package/index.mjs +0 -1858
package/cjs/bin.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const cli_js_1 = require("./cli.js");
|
|
5
|
+
const cli_error_js_1 = require("./utils/cli-error.js");
|
|
6
|
+
const [, , cmd] = process.argv;
|
|
7
|
+
(0, cli_js_1.runCli)(cmd)
|
|
8
|
+
.then(() => {
|
|
9
|
+
process.exit(0);
|
|
10
|
+
})
|
|
11
|
+
.catch(error => {
|
|
12
|
+
(0, cli_error_js_1.cliError)(error);
|
|
13
|
+
});
|
package/cjs/cli.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ensureGraphQlPackage = exports.runCli = void 0;
|
|
27
|
+
const generate_and_save_js_1 = require("./generate-and-save.js");
|
|
28
|
+
const index_js_1 = require("./init/index.js");
|
|
29
|
+
const config_js_1 = require("./config.js");
|
|
30
|
+
const hooks_js_1 = require("./hooks.js");
|
|
31
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
32
|
+
async function runCli(cmd) {
|
|
33
|
+
await ensureGraphQlPackage();
|
|
34
|
+
if (cmd === 'init') {
|
|
35
|
+
return (0, index_js_1.init)();
|
|
36
|
+
}
|
|
37
|
+
const context = await (0, config_js_1.createContext)();
|
|
38
|
+
try {
|
|
39
|
+
return await (0, generate_and_save_js_1.generate)(context);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
await (0, hooks_js_1.lifecycleHooks)(context.getConfig().hooks).onError(error.toString());
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.runCli = runCli;
|
|
47
|
+
async function ensureGraphQlPackage() {
|
|
48
|
+
try {
|
|
49
|
+
await Promise.resolve().then(() => __importStar(require('graphql')));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new plugin_helpers_1.DetailedError(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`, `
|
|
53
|
+
To install "graphql", run:
|
|
54
|
+
yarn add graphql
|
|
55
|
+
Or, with NPM:
|
|
56
|
+
npm install --save graphql
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
package/cjs/codegen.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeCodegen = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
6
|
+
const core_1 = require("@graphql-codegen/core");
|
|
7
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
8
|
+
const listr_renderer_js_1 = require("./utils/listr-renderer.js");
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
10
|
+
const plugins_js_1 = require("./plugins.js");
|
|
11
|
+
const presets_js_1 = require("./presets.js");
|
|
12
|
+
const debugging_js_1 = require("./utils/debugging.js");
|
|
13
|
+
const config_js_1 = require("./config.js");
|
|
14
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
15
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
+
const os_1 = require("os");
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
const module_1 = require("module");
|
|
19
|
+
const listr_1 = tslib_1.__importDefault(require("listr"));
|
|
20
|
+
const cli_error_js_1 = require("./utils/cli-error.js");
|
|
21
|
+
const makeDefaultLoader = (from) => {
|
|
22
|
+
if (fs_1.default.statSync(from).isDirectory()) {
|
|
23
|
+
from = path_1.default.join(from, '__fake.js');
|
|
24
|
+
}
|
|
25
|
+
const relativeRequire = (0, module_1.createRequire)(from);
|
|
26
|
+
return (mod) => {
|
|
27
|
+
return Promise.resolve().then(() => tslib_1.__importStar(require(relativeRequire.resolve(mod))));
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
function createCache() {
|
|
31
|
+
const cache = new Map();
|
|
32
|
+
return function ensure(namespace, key, factory) {
|
|
33
|
+
const cacheKey = `${namespace}:${key}`;
|
|
34
|
+
const cachedValue = cache.get(cacheKey);
|
|
35
|
+
if (cachedValue) {
|
|
36
|
+
return cachedValue;
|
|
37
|
+
}
|
|
38
|
+
const value = factory();
|
|
39
|
+
cache.set(cacheKey, value);
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function executeCodegen(input) {
|
|
44
|
+
const context = (0, config_js_1.ensureContext)(input);
|
|
45
|
+
const config = context.getConfig();
|
|
46
|
+
const pluginContext = context.getPluginContext();
|
|
47
|
+
const result = [];
|
|
48
|
+
const commonListrOptions = {
|
|
49
|
+
exitOnError: true,
|
|
50
|
+
};
|
|
51
|
+
let listr;
|
|
52
|
+
if (process.env.VERBOSE) {
|
|
53
|
+
listr = new listr_1.default({
|
|
54
|
+
...commonListrOptions,
|
|
55
|
+
renderer: 'verbose',
|
|
56
|
+
nonTTYRenderer: 'verbose',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (process.env.NODE_ENV === 'test') {
|
|
60
|
+
listr = new listr_1.default({
|
|
61
|
+
...commonListrOptions,
|
|
62
|
+
renderer: 'silent',
|
|
63
|
+
nonTTYRenderer: 'silent',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
listr = new listr_1.default({
|
|
68
|
+
...commonListrOptions,
|
|
69
|
+
renderer: config.silent ? 'silent' : config.errorsOnly ? listr_renderer_js_1.ErrorRenderer : listr_renderer_js_1.Renderer,
|
|
70
|
+
nonTTYRenderer: config.silent ? 'silent' : 'default',
|
|
71
|
+
collapse: true,
|
|
72
|
+
clearOutput: false,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
let rootConfig = {};
|
|
76
|
+
let rootSchemas;
|
|
77
|
+
let rootDocuments;
|
|
78
|
+
const generates = {};
|
|
79
|
+
const cache = createCache();
|
|
80
|
+
function wrapTask(task, source, taskName) {
|
|
81
|
+
return () => {
|
|
82
|
+
return context.profiler.run(async () => {
|
|
83
|
+
try {
|
|
84
|
+
await Promise.resolve().then(() => task());
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (source && !(error instanceof graphql_1.GraphQLError)) {
|
|
88
|
+
error.source = source;
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}, taskName);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function normalize() {
|
|
96
|
+
/* Load Require extensions */
|
|
97
|
+
const requireExtensions = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.require);
|
|
98
|
+
const loader = makeDefaultLoader(context.cwd);
|
|
99
|
+
for (const mod of requireExtensions) {
|
|
100
|
+
await loader(mod);
|
|
101
|
+
}
|
|
102
|
+
/* Root plugin config */
|
|
103
|
+
rootConfig = config.config || {};
|
|
104
|
+
/* Normalize root "schema" field */
|
|
105
|
+
rootSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.schema);
|
|
106
|
+
/* Normalize root "documents" field */
|
|
107
|
+
rootDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.documents);
|
|
108
|
+
/* Normalize "generators" field */
|
|
109
|
+
const generateKeys = Object.keys(config.generates || {});
|
|
110
|
+
if (generateKeys.length === 0) {
|
|
111
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
112
|
+
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
|
|
113
|
+
|
|
114
|
+
It should looks like that:
|
|
115
|
+
|
|
116
|
+
schema:
|
|
117
|
+
- my-schema.graphql
|
|
118
|
+
generates:
|
|
119
|
+
my-file.ts:
|
|
120
|
+
- plugin1
|
|
121
|
+
- plugin2
|
|
122
|
+
- plugin3
|
|
123
|
+
`);
|
|
124
|
+
}
|
|
125
|
+
for (const filename of generateKeys) {
|
|
126
|
+
const output = (generates[filename] = (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]));
|
|
127
|
+
if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
|
|
128
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
129
|
+
Please make sure that your codegen config file has defined plugins list for output "${filename}".
|
|
130
|
+
|
|
131
|
+
It should looks like that:
|
|
132
|
+
|
|
133
|
+
schema:
|
|
134
|
+
- my-schema.graphql
|
|
135
|
+
generates:
|
|
136
|
+
my-file.ts:
|
|
137
|
+
- plugin1
|
|
138
|
+
- plugin2
|
|
139
|
+
- plugin3
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (rootSchemas.length === 0 &&
|
|
144
|
+
Object.keys(generates).some(filename => !generates[filename].schema || generates[filename].schema.length === 0)) {
|
|
145
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
146
|
+
Please make sure that your codegen config file contains either the "schema" field
|
|
147
|
+
or every generated file has its own "schema" field.
|
|
148
|
+
|
|
149
|
+
It should looks like that:
|
|
150
|
+
schema:
|
|
151
|
+
- my-schema.graphql
|
|
152
|
+
|
|
153
|
+
or:
|
|
154
|
+
generates:
|
|
155
|
+
path/to/output:
|
|
156
|
+
schema: my-schema.graphql
|
|
157
|
+
`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
listr.add({
|
|
161
|
+
title: 'Parse configuration',
|
|
162
|
+
task: () => normalize(),
|
|
163
|
+
});
|
|
164
|
+
listr.add({
|
|
165
|
+
title: 'Generate outputs',
|
|
166
|
+
task: () => {
|
|
167
|
+
return new listr_1.default(Object.keys(generates).map(filename => {
|
|
168
|
+
const outputConfig = generates[filename];
|
|
169
|
+
const hasPreset = !!outputConfig.preset;
|
|
170
|
+
return {
|
|
171
|
+
title: hasPreset
|
|
172
|
+
? `Generate to ${filename} (using EXPERIMENTAL preset "${outputConfig.preset}")`
|
|
173
|
+
: `Generate ${filename}`,
|
|
174
|
+
task: () => {
|
|
175
|
+
let outputSchemaAst;
|
|
176
|
+
let outputSchema;
|
|
177
|
+
const outputFileTemplateConfig = outputConfig.config || {};
|
|
178
|
+
let outputDocuments = [];
|
|
179
|
+
const outputSpecificSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.schema);
|
|
180
|
+
const outputSpecificDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.documents);
|
|
181
|
+
return new listr_1.default([
|
|
182
|
+
{
|
|
183
|
+
title: 'Load GraphQL schemas',
|
|
184
|
+
task: wrapTask(async () => {
|
|
185
|
+
(0, debugging_js_1.debugLog)(`[CLI] Loading Schemas`);
|
|
186
|
+
const schemaPointerMap = {};
|
|
187
|
+
const allSchemaUnnormalizedPointers = [...rootSchemas, ...outputSpecificSchemas];
|
|
188
|
+
for (const unnormalizedPtr of allSchemaUnnormalizedPointers) {
|
|
189
|
+
if (typeof unnormalizedPtr === 'string') {
|
|
190
|
+
schemaPointerMap[unnormalizedPtr] = {};
|
|
191
|
+
}
|
|
192
|
+
else if (typeof unnormalizedPtr === 'object') {
|
|
193
|
+
Object.assign(schemaPointerMap, unnormalizedPtr);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
197
|
+
const result = await cache('schema', hash, async () => {
|
|
198
|
+
const outputSchemaAst = await context.loadSchema(schemaPointerMap);
|
|
199
|
+
const outputSchema = (0, plugin_helpers_1.getCachedDocumentNodeFromSchema)(outputSchemaAst);
|
|
200
|
+
return {
|
|
201
|
+
outputSchemaAst,
|
|
202
|
+
outputSchema,
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
outputSchemaAst = await result.outputSchemaAst;
|
|
206
|
+
outputSchema = result.outputSchema;
|
|
207
|
+
}, filename, `Load GraphQL schemas: ${filename}`),
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
title: 'Load GraphQL documents',
|
|
211
|
+
task: wrapTask(async () => {
|
|
212
|
+
(0, debugging_js_1.debugLog)(`[CLI] Loading Documents`);
|
|
213
|
+
// get different cache for shared docs and output specific docs
|
|
214
|
+
const documentPointerMap = {};
|
|
215
|
+
const allDocumentsUnnormalizedPointers = [...rootDocuments, ...outputSpecificDocuments];
|
|
216
|
+
for (const unnormalizedPtr of allDocumentsUnnormalizedPointers) {
|
|
217
|
+
if (typeof unnormalizedPtr === 'string') {
|
|
218
|
+
documentPointerMap[unnormalizedPtr] = {};
|
|
219
|
+
}
|
|
220
|
+
else if (typeof unnormalizedPtr === 'object') {
|
|
221
|
+
Object.assign(documentPointerMap, unnormalizedPtr);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const hash = JSON.stringify(documentPointerMap);
|
|
225
|
+
const result = await cache('documents', hash, async () => {
|
|
226
|
+
const documents = await context.loadDocuments(documentPointerMap);
|
|
227
|
+
return {
|
|
228
|
+
documents,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
outputDocuments = await result.documents;
|
|
232
|
+
}, filename, `Load GraphQL documents: ${filename}`),
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
title: 'Generate',
|
|
236
|
+
task: wrapTask(async () => {
|
|
237
|
+
(0, debugging_js_1.debugLog)(`[CLI] Generating output`);
|
|
238
|
+
const normalizedPluginsArray = (0, plugin_helpers_1.normalizeConfig)(outputConfig.plugins);
|
|
239
|
+
const pluginLoader = config.pluginLoader || makeDefaultLoader(context.cwd);
|
|
240
|
+
const pluginPackages = await Promise.all(normalizedPluginsArray.map(plugin => (0, plugins_js_1.getPluginByName)(Object.keys(plugin)[0], pluginLoader)));
|
|
241
|
+
const pluginMap = {};
|
|
242
|
+
const preset = hasPreset
|
|
243
|
+
? typeof outputConfig.preset === 'string'
|
|
244
|
+
? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
|
|
245
|
+
: outputConfig.preset
|
|
246
|
+
: null;
|
|
247
|
+
pluginPackages.forEach((pluginPackage, i) => {
|
|
248
|
+
const plugin = normalizedPluginsArray[i];
|
|
249
|
+
const name = Object.keys(plugin)[0];
|
|
250
|
+
pluginMap[name] = pluginPackage;
|
|
251
|
+
});
|
|
252
|
+
const mergedConfig = {
|
|
253
|
+
...rootConfig,
|
|
254
|
+
...(typeof outputFileTemplateConfig === 'string'
|
|
255
|
+
? { value: outputFileTemplateConfig }
|
|
256
|
+
: outputFileTemplateConfig),
|
|
257
|
+
};
|
|
258
|
+
let outputs = [];
|
|
259
|
+
if (hasPreset) {
|
|
260
|
+
outputs = await context.profiler.run(async () => preset.buildGeneratesSection({
|
|
261
|
+
baseOutputDir: filename,
|
|
262
|
+
presetConfig: outputConfig.presetConfig || {},
|
|
263
|
+
plugins: normalizedPluginsArray,
|
|
264
|
+
schema: outputSchema,
|
|
265
|
+
schemaAst: outputSchemaAst,
|
|
266
|
+
documents: outputDocuments,
|
|
267
|
+
config: mergedConfig,
|
|
268
|
+
pluginMap,
|
|
269
|
+
pluginContext,
|
|
270
|
+
profiler: context.profiler,
|
|
271
|
+
}), `Build Generates Section: ${filename}`);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
outputs = [
|
|
275
|
+
{
|
|
276
|
+
filename,
|
|
277
|
+
plugins: normalizedPluginsArray,
|
|
278
|
+
schema: outputSchema,
|
|
279
|
+
schemaAst: outputSchemaAst,
|
|
280
|
+
documents: outputDocuments,
|
|
281
|
+
config: mergedConfig,
|
|
282
|
+
pluginMap,
|
|
283
|
+
pluginContext,
|
|
284
|
+
profiler: context.profiler,
|
|
285
|
+
},
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
const process = async (outputArgs) => {
|
|
289
|
+
const output = await (0, core_1.codegen)({
|
|
290
|
+
...outputArgs,
|
|
291
|
+
cache,
|
|
292
|
+
});
|
|
293
|
+
result.push({
|
|
294
|
+
filename: outputArgs.filename,
|
|
295
|
+
content: output,
|
|
296
|
+
hooks: outputConfig.hooks || {},
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
await context.profiler.run(() => Promise.all(outputs.map(process)), `Codegen: ${filename}`);
|
|
300
|
+
}, filename, `Generate: ${filename}`),
|
|
301
|
+
},
|
|
302
|
+
], {
|
|
303
|
+
// it stops when one of tasks failed
|
|
304
|
+
exitOnError: true,
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}), {
|
|
309
|
+
// it doesn't stop when one of tasks failed, to finish at least some of outputs
|
|
310
|
+
exitOnError: false,
|
|
311
|
+
concurrent: (0, os_1.cpus)().length,
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
try {
|
|
316
|
+
await listr.run();
|
|
317
|
+
}
|
|
318
|
+
catch (err) {
|
|
319
|
+
if ((0, cli_error_js_1.isListrError)(err)) {
|
|
320
|
+
const allErrs = err.errors.map(subErr => (0, plugin_helpers_1.isDetailedError)(subErr)
|
|
321
|
+
? `${subErr.message} for "${subErr.source}"${subErr.details}`
|
|
322
|
+
: subErr.message || subErr.toString());
|
|
323
|
+
const newErr = new utils_1.AggregateError(err.errors, `${err.message} ${allErrs.join('\n\n')}`);
|
|
324
|
+
// Best-effort to all stack traces for debugging
|
|
325
|
+
newErr.stack = `${newErr.stack}\n\n${err.errors.map(subErr => subErr.stack).join('\n\n')}`;
|
|
326
|
+
throw newErr;
|
|
327
|
+
}
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
exports.executeCodegen = executeCodegen;
|