UNPKG

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