1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const path_1 = require("path");
|
4 | const graphql_codegen_core_1 = require("graphql-codegen-core");
|
5 | async function getPluginByName(name, pluginLoader) {
|
6 | const possibleNames = [
|
7 | `graphql-codegen-${name}`,
|
8 | `graphql-codegen-${name}-template`,
|
9 | `codegen-${name}`,
|
10 | `codegen-${name}-template`,
|
11 | name
|
12 | ];
|
13 | const possibleModules = possibleNames.concat(path_1.resolve(process.cwd(), name));
|
14 | for (const moduleName of possibleModules) {
|
15 | try {
|
16 | return (await pluginLoader(moduleName));
|
17 | }
|
18 | catch (err) {
|
19 | if (err.message.indexOf(`Cannot find module '${moduleName}'`) === -1) {
|
20 | throw new graphql_codegen_core_1.DetailedError(`Unable to load template plugin matching ${name}`, `
|
21 | Unable to load template plugin matching '${name}'.
|
22 | Reason:
|
23 | ${err.message}
|
24 | `);
|
25 | }
|
26 | }
|
27 | }
|
28 | const possibleNamesMsg = possibleNames
|
29 | .map(name => `
|
30 | - ${name}
|
31 | `.trimRight())
|
32 | .join('');
|
33 | throw new graphql_codegen_core_1.DetailedError(`Unable to find template plugin matching ${name}`, `
|
34 | Unable to find template plugin matching '${name}'
|
35 | Install one of the following packages:
|
36 |
|
37 | ${possibleNamesMsg}
|
38 | `);
|
39 | }
|
40 | exports.getPluginByName = getPluginByName;
|
41 |
|
\ | No newline at end of file |