UNPKG

one

Version:

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

19 lines (17 loc) 735 B
import FSExtra from 'fs-extra' import { writeFile } from 'node:fs/promises' import { dirname } from 'node:path' import { globbedRoutesToRouteContext } from '../router/useViteRoutes' import { globDir } from '../utils/globDir' import { getTypedRoutesDeclarationFile } from './getTypedRoutesDeclarationFile' export async function generateRouteTypes(outFile: string, routerRoot: string) { const routePaths = globDir(routerRoot) const routes = routePaths.reduce((acc, cur) => { acc[cur] = {} return acc }, {}) const context = globbedRoutesToRouteContext(routes, routerRoot) const declarations = getTypedRoutesDeclarationFile(context) await FSExtra.ensureDir(dirname(outFile)) await writeFile(outFile, declarations) }