You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getRouteComponents = void 0;
function _react() {
const data = _interopRequireDefault(require("react"));
_react = function _react() {
return data;
};
return data;
}
function _umi() {
const data = require("umi");
_umi = function _umi() {
return data;
};
return data;
}
function _path() {
const data = require("path");
_path = function _path() {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const lodash = _umi().utils.lodash,
winPath = _umi().utils.winPath;
const getRouteComponents = ({
componentRoutes,
paths,
cwd
}) => {
const getComponents = routes => routes.reduce((memo, route) => {
var _route$component;
if (route.component && typeof route.component === 'string' && !route.component.startsWith('(') && !((_route$component = route.component) === null || _route$component === void 0 ? void 0 : _route$component.includes('node_modules'))) {
var _route$component2, _route$component2$rep;
const routeComponent = (_route$component2 = route.component) === null || _route$component2 === void 0 ? void 0 : (_route$component2$rep = _route$component2.replace('@@', paths.absTmpPath)) === null || _route$component2$rep === void 0 ? void 0 : _route$component2$rep.replace('@', paths.absSrcPath);
const component = (0, _path().isAbsolute)(routeComponent) ? require.resolve(routeComponent) : require.resolve((0, _path().join)(cwd, routeComponent));
memo.push(winPath(component));
}
if (route.routes) {
memo = memo.concat(getComponents(route.routes));
}
return memo;
}, []);
return lodash.uniq(getComponents(componentRoutes));
};
exports.getRouteComponents = getRouteComponents;