@@ -9,6 +9,7 @@ import { createConfigLoader } from "../config/config";
9
9
import { generate } from "./generate" ;
10
10
import type { Context } from "./context" ;
11
11
import { getTypesDir , getTypesPath } from "./paths" ;
12
+ import type { RouteManifestEntry } from "../config/routes" ;
12
13
13
14
export async function run ( rootDirectory : string ) {
14
15
const ctx = await createContext ( { rootDirectory, watch : false } ) ;
@@ -71,14 +72,27 @@ async function createContext({
71
72
} ;
72
73
}
73
74
75
+ function isRouteInAppDirectory ( ctx : Context , route : RouteManifestEntry ) {
76
+ const absoluteRoutePath = Path . isAbsolute ( route . file )
77
+ ? route . file
78
+ : Path . resolve ( ctx . config . appDirectory , route . file ) ;
79
+
80
+ return absoluteRoutePath . startsWith ( ctx . config . appDirectory ) ;
81
+ }
82
+
74
83
async function writeAll ( ctx : Context ) : Promise < void > {
75
84
const typegenDir = getTypesDir ( ctx ) ;
76
85
77
86
fs . rmSync ( typegenDir , { recursive : true , force : true } ) ;
78
- Object . values ( ctx . config . routes ) . forEach ( ( route ) => {
79
- const typesPath = getTypesPath ( ctx , route ) ;
80
- const content = generate ( ctx , route ) ;
81
- fs . mkdirSync ( Path . dirname ( typesPath ) , { recursive : true } ) ;
82
- fs . writeFileSync ( typesPath , content ) ;
83
- } ) ;
87
+ Object . values ( ctx . config . routes )
88
+ . filter ( ( route ) => {
89
+ // Only generate types for routes in the app directory
90
+ return isRouteInAppDirectory ( ctx , route ) ;
91
+ } )
92
+ . forEach ( ( route ) => {
93
+ const typesPath = getTypesPath ( ctx , route ) ;
94
+ const content = generate ( ctx , route ) ;
95
+ fs . mkdirSync ( Path . dirname ( typesPath ) , { recursive : true } ) ;
96
+ fs . writeFileSync ( typesPath , content ) ;
97
+ } ) ;
84
98
}
0 commit comments