UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

48 lines (47 loc) 3.75 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var generateRouteTypes_exports = {}; __export(generateRouteTypes_exports, { generateRouteTypes: () => generateRouteTypes }); module.exports = __toCommonJS(generateRouteTypes_exports); var import_promises = require("node:fs/promises"), import_node_path = require("node:path"), import_fs_extra = __toESM(require("fs-extra"), 1), import_micromatch = __toESM(require("micromatch"), 1), import_matchers = require("../router/matchers"), import_useViteRoutes = require("../router/useViteRoutes"), import_globDir = require("../utils/globDir"), import_getTypedRoutesDeclarationFile = require("./getTypedRoutesDeclarationFile"), import_injectRouteHelpers = require("./injectRouteHelpers"); async function generateRouteTypes(outFile, routerRoot, ignoredRouteFiles, typedRoutesMode) { let routePaths = (0, import_globDir.globDir)(routerRoot); ignoredRouteFiles && ignoredRouteFiles.length > 0 && (routePaths = import_micromatch.default.not(routePaths, ignoredRouteFiles, { // The path starts with './', such as './foo/bar/baz.test.tsx', and ignoredRouteFiles is like ['**/*.test.*'], so we need matchBase here. matchBase: !0 })); const routes = routePaths.reduce((acc, cur) => (acc[cur] = {}, acc), {}), context = (0, import_useViteRoutes.globbedRoutesToRouteContext)(routes, routerRoot), declarations = (0, import_getTypedRoutesDeclarationFile.getTypedRoutesDeclarationFile)(context), outDir = (0, import_node_path.dirname)(outFile); if (await import_fs_extra.default.ensureDir(outDir), await (0, import_promises.writeFile)(outFile, declarations), typedRoutesMode) { const mode = typedRoutesMode === "type" ? "type" : "runtime"; for (const routePath of routePaths) { if (routePath.includes("_layout") || routePath.includes("+api") || routePath.startsWith("_") || routePath.endsWith(".d.ts")) continue; const fullPath = (0, import_node_path.join)(process.cwd(), routerRoot, routePath), routeName = routePath.replace(/^\.\//, "").replace(/\+[^/]*$/, "").replace(/\/index$/, "").replace(/index$/, ""); let cleanRouteName = (0, import_matchers.removeSupportedExtensions)(routeName).replace(/\/?index$/, ""); cleanRouteName.startsWith("/") || (cleanRouteName = "/" + cleanRouteName), cleanRouteName.includes("[") && await (0, import_injectRouteHelpers.injectRouteHelpers)(fullPath, cleanRouteName, mode); } } } //# sourceMappingURL=generateRouteTypes.js.map