| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | exports.__esModule = true;
|
|---|
| 4 | exports.resolveConfig = resolveConfig;
|
|---|
| 5 | exports.resolveConfigFile = resolveConfigFile;
|
|---|
| 6 | exports.loadConfig = loadConfig;
|
|---|
| 7 | exports.DEFAULT_CONFIG = void 0;
|
|---|
| 8 |
|
|---|
| 9 | var _cosmiconfig = require("cosmiconfig");
|
|---|
| 10 |
|
|---|
| 11 | const DEFAULT_CONFIG = {
|
|---|
| 12 | dimensions: true,
|
|---|
| 13 | expandProps: 'end',
|
|---|
| 14 | icon: false,
|
|---|
| 15 | native: false,
|
|---|
| 16 | typescript: false,
|
|---|
| 17 | prettier: true,
|
|---|
| 18 | prettierConfig: null,
|
|---|
| 19 | memo: false,
|
|---|
| 20 | ref: false,
|
|---|
| 21 | replaceAttrValues: null,
|
|---|
| 22 | svgProps: null,
|
|---|
| 23 | svgo: true,
|
|---|
| 24 | svgoConfig: null,
|
|---|
| 25 | template: null,
|
|---|
| 26 | titleProp: false,
|
|---|
| 27 | runtimeConfig: true,
|
|---|
| 28 | plugins: null,
|
|---|
| 29 | namedExport: 'ReactComponent'
|
|---|
| 30 | };
|
|---|
| 31 | exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|---|
| 32 | const explorer = (0, _cosmiconfig.cosmiconfig)('svgr', {
|
|---|
| 33 | sync: true,
|
|---|
| 34 | cache: true,
|
|---|
| 35 | rcExtensions: true
|
|---|
| 36 | });
|
|---|
| 37 | const explorerSync = (0, _cosmiconfig.cosmiconfigSync)('svgr', {
|
|---|
| 38 | sync: true,
|
|---|
| 39 | cache: true,
|
|---|
| 40 | rcExtensions: true
|
|---|
| 41 | });
|
|---|
| 42 |
|
|---|
| 43 | async function resolveConfig(searchFrom, configFile) {
|
|---|
| 44 | if (configFile == null) {
|
|---|
| 45 | const result = await explorer.search(searchFrom);
|
|---|
| 46 | return result ? result.config : null;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | const result = await explorer.load(configFile);
|
|---|
| 50 | return result ? result.config : null;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | resolveConfig.sync = (searchFrom, configFile) => {
|
|---|
| 54 | if (configFile == null) {
|
|---|
| 55 | const result = explorerSync.search(searchFrom);
|
|---|
| 56 | return result ? result.config : null;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | const result = explorerSync.load(configFile);
|
|---|
| 60 | return result ? result.config : null;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | async function resolveConfigFile(filePath) {
|
|---|
| 64 | const result = await explorer.search(filePath);
|
|---|
| 65 | return result ? result.filepath : null;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | resolveConfigFile.sync = filePath => {
|
|---|
| 69 | const result = explorerSync.search(filePath);
|
|---|
| 70 | return result ? result.filepath : null;
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | async function loadConfig({
|
|---|
| 74 | configFile,
|
|---|
| 75 | ...baseConfig
|
|---|
| 76 | }, state = {}) {
|
|---|
| 77 | const rcConfig = state.filePath && baseConfig.runtimeConfig !== false ? await resolveConfig(state.filePath, configFile) : {};
|
|---|
| 78 | return { ...DEFAULT_CONFIG,
|
|---|
| 79 | ...rcConfig,
|
|---|
| 80 | ...baseConfig
|
|---|
| 81 | };
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | loadConfig.sync = ({
|
|---|
| 85 | configFile,
|
|---|
| 86 | ...baseConfig
|
|---|
| 87 | }, state = {}) => {
|
|---|
| 88 | const rcConfig = state.filePath && baseConfig.runtimeConfig !== false ? resolveConfig.sync(state.filePath, configFile) : {};
|
|---|
| 89 | return { ...DEFAULT_CONFIG,
|
|---|
| 90 | ...rcConfig,
|
|---|
| 91 | ...baseConfig
|
|---|
| 92 | };
|
|---|
| 93 | }; |
|---|