-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtypes.ts
180 lines (169 loc) · 4.19 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import type { Awaitable } from '@antfu/utils'
import type { PageContext } from './context'
import type { ReactRoute, SolidRoute, VueRoute } from './resolvers'
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>
export type ImportMode = 'sync' | 'async'
export type ImportModeResolver = (filepath: string, pluginOptions: ResolvedOptions) => ImportMode
export interface ParsedJSX {
value: string
loc: {
start: {
line: number
}
}
}
export type CustomBlock = Record<string, any>
export type InternalPageResolvers = 'vue' | 'react' | 'solid'
export interface PageOptions {
/**
* Page base directory.
* @default 'src/pages'
*/
dir: string
/**
* Page base route.
*/
baseRoute: string
/**
* @deprecated use `filePattern` instead
*/
filePatern?: string
/**
* Page file pattern.
* @example `**\/*.page.vue`
*/
filePattern?: string
}
export interface PageResolver {
resolveModuleIds: () => string[]
resolveExtensions: () => string[]
resolveRoutes: (ctx: PageContext) => Awaitable<string>
getComputedRoutes: (ctx: PageContext) => Awaitable<VueRoute[] | ReactRoute[] | SolidRoute[]>
stringify?: {
dynamicImport?: (importPath: string) => string
component?: (importName: string) => string
final?: (code: string) => string
}
hmr?: {
added?: (ctx: PageContext, path: string) => Awaitable<void>
removed?: (ctx: PageContext, path: string) => Awaitable<void>
changed?: (ctx: PageContext, path: string) => Awaitable<void>
}
}
/**
* Plugin options.
*/
interface Options {
/**
* Paths to the directory to search for page components.
* @default 'src/pages'
*/
dirs: string | (string | PageOptions)[]
/**
* Valid file extensions for page components.
* @default ['vue', 'js']
*/
extensions: string[]
/**
* List of path globs to exclude when resolving pages.
*/
exclude: string[]
/**
* Import routes directly or as async components
* @default 'root index file => "sync", others => "async"'
*/
importMode: ImportMode | ImportModeResolver
/**
* Import page components from absolute or relative paths.
* @default 'relative'
*/
importPath: 'absolute' | 'relative'
/**
* Sync load top level index file
* @default true
* @deprecated use `importMode` instead
*/
syncIndex: boolean
/**
* Use Nuxt.js style route naming
* @default false
* @deprecated use `routeStyle` instead
*/
nuxtStyle: boolean
/**
* Routing style
* @default false
*/
routeStyle: 'next' | 'nuxt' | 'remix'
/**
* Separator for generated route names.
* @default -
*/
routeNameSeparator: string
/**
* Case for route paths
* @default false
*/
caseSensitive: boolean
/**
* Set the default route block parser, or use `<route lang=xxx>` in SFC route block
* @default 'json5'
*/
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml'
/**
* Module id for routes import
* @default '~pages'
*/
moduleId: string
/**
* Generate React Route
* @default 'auto detect'
*/
resolver: InternalPageResolvers | PageResolver
/**
* Extend route records
*/
extendRoute?: (route: any, parent: any | undefined) => any | void
/**
* Custom generated routes
*/
onRoutesGenerated?: (routes: any[]) => Awaitable<any[] | void>
/**
* Custom generated client code
*/
onClientGenerated?: (clientCode: string) => Awaitable<string | void>
/**
* Paths to the directory to search for page components.
* @deprecated use `dirs` instead
*/
pagesDir: string | (string | PageOptions)[]
/**
* Replace '[]' to '_' in bundle filename
* @deprecated issue #122
*/
replaceSquareBrackets: never
}
export type UserOptions = Partial<Options>
export interface ResolvedOptions extends Omit<Options, 'pagesDir' | 'replaceSquareBrackets' | 'nuxtStyle' | 'syncIndex' | 'moduleId'> {
/**
* Resolves to the `root` value from Vite config.
* @default config.root
*/
root: string
/**
* Resolved page dirs
*/
dirs: PageOptions[]
/**
* Resolved page resolver
*/
resolver: PageResolver
/**
* RegExp to match extensions
*/
extensionsRE: RegExp
/**
* Module IDs for routes import
*/
moduleIds: string[]
}