UNPKG

@mini-umi/preset-umi

Version:
91 lines (89 loc) 3.04 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/commands/getRoutes.ts var getRoutes_exports = {}; __export(getRoutes_exports, { getRoutes: () => getRoutes }); module.exports = __toCommonJS(getRoutes_exports); var import_utils = require("@umijs/utils"); var import_path = require("path"); function getRoutes(opts = { dirPath: "./pages" }) { const routes = []; const cwd = process.cwd(); const routesDir = (0, import_path.isAbsolute)(opts.dirPath) ? opts.dirPath : (0, import_utils.winPath)((0, import_path.join)(cwd, opts.dirPath)); const dirname = (0, import_path.basename)(routesDir); function dps(pPath = "", dir = routesDir) { const alllFiles = import_utils.fsExtra.readdirSync(dir); const dirFiles = alllFiles.filter((item2) => !item2.includes(".")); const componentFiles = alllFiles.filter((item2) => item2.endsWith(".vue") || item2.endsWith(".tsx")); const tRoutesArray = []; componentFiles.forEach((item) => { const name = getName(item); let path = `${pPath}/${name}`; if (path === "/index") { tRoutesArray.push({ path: "/", name, component: eval(`() => import('../${dirname}${path}.vue')`) }); } else { if (pPath !== "") { path = `/${path}`; } tRoutesArray.push({ path, name, component: eval(`() => import('../${dirname}${path}.vue')`) }); } }); dirFiles.forEach((item) => { const name = getName(item); if (name.startsWith(":")) { let path = `${pPath}/${name}`; if (pPath !== "") { path = `/${path}`; } tRoutesArray.push({ path, name, component: eval(`() => import('../${dirname}${path}/index.vue')`) }); } else { const path2 = `${dir}/${name}`; tRoutesArray.push({ path: "", name: "", children: dps(name, path2) }); } }); return tRoutesArray; } routes.push(...dps()); function getName(fileName) { return fileName.replace(".vue", "").replace(".tsx", ""); } return routes; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getRoutes }); //# sourceMappingURL=getRoutes.js.map