mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-29 22:02:46 -07:00
feat(packages/tuono-(router|fs-router-vite-plugin)): replace __route with __layout (#283)
This commit is contained in:
committed by
GitHub
parent
cf56b3a53e
commit
0ef1252e1f
@@ -18,7 +18,11 @@ import {
|
||||
} from './utils'
|
||||
|
||||
import type { Config, RouteNode } from './types'
|
||||
import { ROUTES_FOLDER, ROOT_PATH_ID, GENERATED_ROUTE_TREE } from './constants'
|
||||
import {
|
||||
ROUTES_FOLDER,
|
||||
LAYOUT_PATH_ID,
|
||||
GENERATED_ROUTE_TREE,
|
||||
} from './constants'
|
||||
|
||||
import { sortRouteNodes } from './sort-route-nodes'
|
||||
import isDefaultExported from './utils/is-default-exported'
|
||||
@@ -154,7 +158,7 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
const routeConfigChildrenText = buildRouteConfig(routeNodes)
|
||||
|
||||
const sortedRouteNodes = multiSortBy(routeNodes, [
|
||||
(d): number => (d.routePath.includes(`/${ROOT_PATH_ID}`) ? -1 : 1),
|
||||
(d): number => (d.routePath.includes(`/${LAYOUT_PATH_ID}`) ? -1 : 1),
|
||||
(d): number => d.routePath.split('/').length,
|
||||
(d): number => (d.routePath.endsWith("index'") ? -1 : 1),
|
||||
(d): RouteNode => d,
|
||||
@@ -179,7 +183,7 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
|
||||
const createRoutes = [
|
||||
...sortedRouteNodes.map((node) => {
|
||||
const isRoot = node.routePath.endsWith(ROOT_PATH_ID)
|
||||
const isRoot = node.routePath.endsWith(LAYOUT_PATH_ID)
|
||||
const rootDeclaration = isRoot ? ', isRoot: true' : ''
|
||||
const variableName = node.variableName as string
|
||||
|
||||
@@ -195,7 +199,7 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
return [
|
||||
`const ${variableName}Route = ${variableName}.update({
|
||||
${[
|
||||
!node.path?.endsWith(ROOT_PATH_ID) && `path: '${cleanedPath}'`,
|
||||
!node.path?.endsWith(LAYOUT_PATH_ID) && `path: '${cleanedPath}'`,
|
||||
`getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,
|
||||
rustHandlersNodes.includes(node.path || '')
|
||||
? 'hasHandler: true'
|
||||
@@ -213,15 +217,15 @@ export async function routeGenerator(config = defaultConfig): Promise<void> {
|
||||
'// This file is auto-generated by Tuono',
|
||||
"import { createRoute, dynamic } from 'tuono'",
|
||||
[
|
||||
`import RootImport from './${replaceBackslash(
|
||||
`import RootLayoutImport from './${replaceBackslash(
|
||||
path.relative(
|
||||
path.dirname(config.generatedRouteTree),
|
||||
path.resolve(config.folderName, ROOT_PATH_ID),
|
||||
path.resolve(config.folderName, LAYOUT_PATH_ID),
|
||||
),
|
||||
)}'`,
|
||||
].join('\n'),
|
||||
imports,
|
||||
'const rootRoute = createRoute({ isRoot: true, component: RootImport });',
|
||||
'const rootRoute = createRoute({ isRoot: true, component: RootLayoutImport });',
|
||||
createRoutes,
|
||||
'// Create/Update Routes',
|
||||
createRouteUpdates,
|
||||
|
||||
Reference in New Issue
Block a user