t-comm
Version:
专业、稳定、纯粹的工具库
81 lines (78 loc) • 2.18 kB
JavaScript
import { _ as __assign } from '../tslib.es6-096fffdd.js';
import { I as IImportType } from '../types-f29b26c8.js';
function parseOneReplaceConfig(config) {
if (typeof config === 'string') {
return {
sourceName: config,
sourceType: IImportType.ImportSpecifier,
targetName: config,
targetType: IImportType.ImportSpecifier
};
}
if (Array.isArray(config)) {
return {
sourceName: config[0],
sourceType: IImportType.ImportSpecifier,
targetName: config[1] || config[0],
targetType: IImportType.ImportSpecifier
};
}
return {
sourceName: config.sourceName || '',
sourceType: config.sourceType || IImportType.ImportSpecifier,
targetName: config.targetName || config.sourceName || '',
targetType: config.targetType || config.sourceType || IImportType.ImportSpecifier
};
}
/**
* 解析替换配置
*
* @param {Array<IReplaceConfig>} configList 配置列表
* @returns {array} 处理后的配置列表
*
* @example
* ```ts
* parseReplaceConfig([{
* source: '',
* target: '',
* }])
* ```
*/
function parseReplaceConfig(configList) {
var result = configList.reduce(function (acc, item) {
var importedList = item.importedList,
source = item.source,
target = item.target;
var newSource = Array.isArray(source) ? source : [source];
var list = importedList.map(function (item) {
return __assign({
source: newSource,
target: target
}, parseOneReplaceConfig(item));
});
if (!importedList.length) {
acc.push(__assign(__assign({}, item), {
source: newSource,
sourceName: 'FAKE',
targetName: 'FAKE',
sourceType: IImportType.FAKE,
targetType: IImportType.FAKE
}));
} else {
acc.push.apply(acc, list);
}
return acc;
}, []);
var newResult = result.reduce(function (acc, item) {
var source = item.source;
var list = source.map(function (sourceItem) {
return __assign(__assign({}, item), {
source: sourceItem
});
});
acc.push.apply(acc, list);
return acc;
}, []);
return newResult;
}
export { parseReplaceConfig };