-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathgenerateDTS.ts
59 lines (53 loc) · 1.39 KB
/
generateDTS.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
import { ts } from '../utils'
/**
* Removes empty lines and indent by two spaces to match the rest of the file.
*/
function normalizeLines(code: string) {
return code
.split('\n')
.filter((line) => line.length !== 0)
.map((line) => ' ' + line)
.join('\n')
}
export function generateDTS({
routesModule,
routeNamedMap,
filePathToRouteNamesMap,
}: {
vueRouterModule: string
routesModule: string
routeNamedMap: string
filePathToRouteNamesMap: string
}) {
return ts`
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️
// It's recommended to commit this file.
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.
declare module '${routesModule}' {
import type {
RouteRecordInfo,
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
} from 'vue-router'
/**
* Route name map generated by unplugin-vue-router
*/
${normalizeLines(routeNamedMap)}
/**
* File path to route names map by unplugin-vue-router
*/
${normalizeLines(filePathToRouteNamesMap)}
/**
* Get a route's name by file path
*/
export type GetRouteNameByPath<T extends string> = T extends keyof FilePathToRouteNamesMap
? FilePathToRouteNamesMap[T]
: keyof import('vue-router/auto-routes').RouteNamedMap
}
`.trimStart()
}