1 | export function isOutputConfigArray(type) {
|
2 | return Array.isArray(type);
|
3 | }
|
4 | export function isConfiguredOutput(type) {
|
5 | return typeof type === 'object' && type['plugins'];
|
6 | }
|
7 | export function normalizeOutputParam(config) {
|
8 | if (isOutputConfigArray(config)) {
|
9 | return {
|
10 | documents: [],
|
11 | schema: [],
|
12 | plugins: config
|
13 | };
|
14 | }
|
15 | else if (isConfiguredOutput(config)) {
|
16 | return config;
|
17 | }
|
18 | else {
|
19 | throw new Error(`Invalid "generates" config!`);
|
20 | }
|
21 | }
|
22 | export function normalizeInstanceOrArray(type) {
|
23 | if (Array.isArray(type)) {
|
24 | return type;
|
25 | }
|
26 | else if (!type) {
|
27 | return [];
|
28 | }
|
29 | return [type];
|
30 | }
|
31 | export function normalizeConfig(config) {
|
32 | if (typeof config === 'string') {
|
33 | return [{ [config]: {} }];
|
34 | }
|
35 | else if (Array.isArray(config)) {
|
36 | return config.map(plugin => (typeof plugin === 'string' ? { [plugin]: {} } : plugin));
|
37 | }
|
38 | else if (typeof config === 'object') {
|
39 | return Object.keys(config).reduce((prev, pluginName) => [...prev, { [pluginName]: config[pluginName] }], []);
|
40 | }
|
41 | else {
|
42 | return [];
|
43 | }
|
44 | }
|
45 |
|
\ | No newline at end of file |