one
Version:
One is a new React Framework that makes Vite serve both native and web.
27 lines (26 loc) • 1.46 kB
JavaScript
import { dirname, join } from "node:path";
import { debounce } from "perfect-debounce";
import { generateRouteTypes } from "../../typed-routes/generateRouteTypes.native.js";
import { getRouterRootFromOneOptions } from "../../utils/getRouterRootFromOneOptions.native.js";
function generateFileSystemRouteTypesPlugin(options) {
return {
name: "one-generate-fs-route-types",
enforce: "post",
apply: "serve",
configureServer(server) {
var appDir = join(process.cwd(), getRouterRootFromOneOptions(options)),
outFile = function () {
return dirname(appDir) !== process.cwd() ? (console.warn("Seems that the router root has been customized and is in a nested folder. For now we will generate the routes.d.ts file beside the app folder. This behavior might be changed in the future."), join(dirname(appDir), "routes.d.ts")) : join(process.cwd(), "routes.d.ts");
}(),
routerRoot = getRouterRootFromOneOptions(options),
fileWatcherChangeListener = debounce(async function (type, path) {
(type === "add" || type === "delete") && path.startsWith(appDir) && generateRouteTypes(outFile, routerRoot);
}, 100);
return server.watcher.addListener("all", fileWatcherChangeListener), function () {
generateRouteTypes(outFile, routerRoot);
};
}
};
}
export { generateFileSystemRouteTypesPlugin };
//# sourceMappingURL=generateFileSystemRouteTypesPlugin.native.js.map