@tanstack/router-generator 1.166.9 → 1.166.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +111 -147
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +224 -303
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/physical/rootPathId.cjs +5 -4
- package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/config.cjs +32 -30
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +164 -209
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -1
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +9 -8
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -1
- package/dist/cjs/generator.cjs +766 -1106
- package/dist/cjs/generator.cjs.map +1 -1
- package/dist/cjs/index.cjs +32 -34
- package/dist/cjs/logger.cjs +28 -34
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/template.cjs +144 -151
- package/dist/cjs/template.cjs.map +1 -1
- package/dist/cjs/transform/transform.cjs +287 -426
- package/dist/cjs/transform/transform.cjs.map +1 -1
- package/dist/cjs/transform/utils.cjs +31 -33
- package/dist/cjs/transform/utils.cjs.map +1 -1
- package/dist/cjs/utils.cjs +534 -544
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/validate-route-params.cjs +66 -51
- package/dist/cjs/validate-route-params.cjs.map +1 -1
- package/dist/esm/config.js +106 -147
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/filesystem/physical/getRouteNodes.js +220 -286
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/physical/rootPathId.js +6 -5
- package/dist/esm/filesystem/physical/rootPathId.js.map +1 -1
- package/dist/esm/filesystem/virtual/config.js +31 -30
- package/dist/esm/filesystem/virtual/config.js.map +1 -1
- package/dist/esm/filesystem/virtual/getRouteNodes.js +161 -208
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -1
- package/dist/esm/filesystem/virtual/loadConfigFile.js +7 -7
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -1
- package/dist/esm/generator.js +756 -1083
- package/dist/esm/generator.js.map +1 -1
- package/dist/esm/index.js +4 -31
- package/dist/esm/logger.js +29 -35
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/template.js +144 -152
- package/dist/esm/template.js.map +1 -1
- package/dist/esm/transform/transform.js +285 -425
- package/dist/esm/transform/transform.js.map +1 -1
- package/dist/esm/transform/utils.js +31 -33
- package/dist/esm/transform/utils.js.map +1 -1
- package/dist/esm/utils.js +529 -564
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/validate-route-params.js +67 -52
- package/dist/esm/validate-route-params.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
package/dist/esm/template.js
CHANGED
|
@@ -1,157 +1,149 @@
|
|
|
1
1
|
import { format } from "./utils.js";
|
|
2
|
+
//#region src/template.ts
|
|
2
3
|
function fillTemplate(config, template, values) {
|
|
3
|
-
|
|
4
|
-
/%%(\w+)%%/g,
|
|
5
|
-
(_, key) => values[key] || ""
|
|
6
|
-
);
|
|
7
|
-
return format(replaced, config);
|
|
4
|
+
return format(template.replace(/%%(\w+)%%/g, (_, key) => values[key] || ""), config);
|
|
8
5
|
}
|
|
9
6
|
function getTargetTemplate(config) {
|
|
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
|
-
default:
|
|
150
|
-
throw new Error(`router-generator: Unknown target type: ${target}`);
|
|
151
|
-
}
|
|
7
|
+
const target = config.target;
|
|
8
|
+
switch (target) {
|
|
9
|
+
case "react": return {
|
|
10
|
+
fullPkg: "@tanstack/react-router",
|
|
11
|
+
subPkg: "react-router",
|
|
12
|
+
rootRoute: {
|
|
13
|
+
template: () => [
|
|
14
|
+
"import * as React from \"react\"\n",
|
|
15
|
+
"%%tsrImports%%",
|
|
16
|
+
"\n\n",
|
|
17
|
+
"%%tsrExportStart%%{\n component: RootComponent\n }%%tsrExportEnd%%\n\n",
|
|
18
|
+
"function RootComponent() { return (<React.Fragment><div>Hello \"%%tsrPath%%\"!</div><Outlet /></React.Fragment>) };\n"
|
|
19
|
+
].join(""),
|
|
20
|
+
imports: {
|
|
21
|
+
tsrImports: () => "import { Outlet, createRootRoute } from '@tanstack/react-router';",
|
|
22
|
+
tsrExportStart: () => "export const Route = createRootRoute(",
|
|
23
|
+
tsrExportEnd: () => ");"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
route: {
|
|
27
|
+
template: () => [
|
|
28
|
+
"%%tsrImports%%",
|
|
29
|
+
"\n\n",
|
|
30
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
31
|
+
"function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\n"
|
|
32
|
+
].join(""),
|
|
33
|
+
imports: {
|
|
34
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createFileRoute } from '@tanstack/react-router';",
|
|
35
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createFileRoute(" : `export const Route = createFileRoute('${routePath}')(`,
|
|
36
|
+
tsrExportEnd: () => ");"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
lazyRoute: {
|
|
40
|
+
template: () => [
|
|
41
|
+
"%%tsrImports%%",
|
|
42
|
+
"\n\n",
|
|
43
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
44
|
+
"function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\n"
|
|
45
|
+
].join(""),
|
|
46
|
+
imports: {
|
|
47
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createLazyFileRoute } from '@tanstack/react-router';",
|
|
48
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createLazyFileRoute(" : `export const Route = createLazyFileRoute('${routePath}')(`,
|
|
49
|
+
tsrExportEnd: () => ");"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
case "solid": return {
|
|
54
|
+
fullPkg: "@tanstack/solid-router",
|
|
55
|
+
subPkg: "solid-router",
|
|
56
|
+
rootRoute: {
|
|
57
|
+
template: () => [
|
|
58
|
+
"import * as Solid from \"solid-js\"\n",
|
|
59
|
+
"%%tsrImports%%",
|
|
60
|
+
"\n\n",
|
|
61
|
+
"%%tsrExportStart%%{\n component: RootComponent\n }%%tsrExportEnd%%\n\n",
|
|
62
|
+
"function RootComponent() { return (<><div>Hello \"%%tsrPath%%\"!</div><Outlet /></>) };\n"
|
|
63
|
+
].join(""),
|
|
64
|
+
imports: {
|
|
65
|
+
tsrImports: () => "import { Outlet, createRootRoute } from '@tanstack/solid-router';",
|
|
66
|
+
tsrExportStart: () => "export const Route = createRootRoute(",
|
|
67
|
+
tsrExportEnd: () => ");"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
route: {
|
|
71
|
+
template: () => [
|
|
72
|
+
"%%tsrImports%%",
|
|
73
|
+
"\n\n",
|
|
74
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
75
|
+
"function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\n"
|
|
76
|
+
].join(""),
|
|
77
|
+
imports: {
|
|
78
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createFileRoute } from '@tanstack/solid-router';",
|
|
79
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createFileRoute(" : `export const Route = createFileRoute('${routePath}')(`,
|
|
80
|
+
tsrExportEnd: () => ");"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
lazyRoute: {
|
|
84
|
+
template: () => [
|
|
85
|
+
"%%tsrImports%%",
|
|
86
|
+
"\n\n",
|
|
87
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
88
|
+
"function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\n"
|
|
89
|
+
].join(""),
|
|
90
|
+
imports: {
|
|
91
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createLazyFileRoute } from '@tanstack/solid-router';",
|
|
92
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createLazyFileRoute(" : `export const Route = createLazyFileRoute('${routePath}')(`,
|
|
93
|
+
tsrExportEnd: () => ");"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
case "vue": return {
|
|
98
|
+
fullPkg: "@tanstack/vue-router",
|
|
99
|
+
subPkg: "vue-router",
|
|
100
|
+
rootRoute: {
|
|
101
|
+
template: () => [
|
|
102
|
+
"import { h } from \"vue\"\n",
|
|
103
|
+
"%%tsrImports%%",
|
|
104
|
+
"\n\n",
|
|
105
|
+
"%%tsrExportStart%%{\n component: RootComponent\n }%%tsrExportEnd%%\n\n",
|
|
106
|
+
"function RootComponent() { return h(\"div\", {}, [\"Hello \\\"%%tsrPath%%\\\"!\", h(Outlet)]) };\n"
|
|
107
|
+
].join(""),
|
|
108
|
+
imports: {
|
|
109
|
+
tsrImports: () => "import { Outlet, createRootRoute } from '@tanstack/vue-router';",
|
|
110
|
+
tsrExportStart: () => "export const Route = createRootRoute(",
|
|
111
|
+
tsrExportEnd: () => ");"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
route: {
|
|
115
|
+
template: () => [
|
|
116
|
+
"import { h } from \"vue\"\n",
|
|
117
|
+
"%%tsrImports%%",
|
|
118
|
+
"\n\n",
|
|
119
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
120
|
+
"function RouteComponent() { return h(\"div\", {}, \"Hello \\\"%%tsrPath%%\\\"!\") };\n"
|
|
121
|
+
].join(""),
|
|
122
|
+
imports: {
|
|
123
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createFileRoute } from '@tanstack/vue-router';",
|
|
124
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createFileRoute(" : `export const Route = createFileRoute('${routePath}')(`,
|
|
125
|
+
tsrExportEnd: () => ");"
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
lazyRoute: {
|
|
129
|
+
template: () => [
|
|
130
|
+
"import { h } from \"vue\"\n",
|
|
131
|
+
"%%tsrImports%%",
|
|
132
|
+
"\n\n",
|
|
133
|
+
"%%tsrExportStart%%{\n component: RouteComponent\n }%%tsrExportEnd%%\n\n",
|
|
134
|
+
"function RouteComponent() { return h(\"div\", {}, \"Hello \\\"%%tsrPath%%\\\"!\") };\n"
|
|
135
|
+
].join(""),
|
|
136
|
+
imports: {
|
|
137
|
+
tsrImports: () => config.verboseFileRoutes === false ? "" : "import { createLazyFileRoute } from '@tanstack/vue-router';",
|
|
138
|
+
tsrExportStart: (routePath) => config.verboseFileRoutes === false ? "export const Route = createLazyFileRoute(" : `export const Route = createLazyFileRoute('${routePath}')(`,
|
|
139
|
+
tsrExportEnd: () => ");"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
default: throw new Error(`router-generator: Unknown target type: ${target}`);
|
|
144
|
+
}
|
|
152
145
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//# sourceMappingURL=template.js.map
|
|
146
|
+
//#endregion
|
|
147
|
+
export { fillTemplate, getTargetTemplate };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=template.js.map
|
package/dist/esm/template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sources":["../../src/template.ts"],"sourcesContent":["import { format } from './utils'\nimport type { Config } from './config'\n\ntype TemplateTag = 'tsrImports' | 'tsrPath' | 'tsrExportStart' | 'tsrExportEnd'\n\nexport function fillTemplate(\n config: Config,\n template: string,\n values: Record<TemplateTag, string>,\n) {\n const replaced = template.replace(\n /%%(\\w+)%%/g,\n (_, key) => values[key as TemplateTag] || '',\n )\n return format(replaced, config)\n}\n\nexport type TargetTemplate = {\n fullPkg: string\n subPkg: string\n rootRoute: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: () => string\n tsrExportEnd: () => string\n }\n }\n route: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: (routePath: string) => string\n tsrExportEnd: () => string\n }\n }\n lazyRoute: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: (routePath: string) => string\n tsrExportEnd: () => string\n }\n }\n}\n\nexport function getTargetTemplate(config: Config): TargetTemplate {\n const target = config.target\n switch (target) {\n case 'react':\n return {\n fullPkg: '@tanstack/react-router',\n subPkg: 'react-router',\n rootRoute: {\n template: () =>\n [\n 'import * as React from \"react\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return (<React.Fragment><div>Hello \"%%tsrPath%%\"!</div><Outlet /></React.Fragment>) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/react-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/react-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/react-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n }\n case 'solid':\n return {\n fullPkg: '@tanstack/solid-router',\n subPkg: 'solid-router',\n rootRoute: {\n template: () =>\n [\n 'import * as Solid from \"solid-js\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return (<><div>Hello \"%%tsrPath%%\"!</div><Outlet /></>) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/solid-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/solid-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/solid-router';\",\n\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n\n tsrExportEnd: () => ');',\n },\n },\n }\n case 'vue':\n return {\n fullPkg: '@tanstack/vue-router',\n subPkg: 'vue-router',\n rootRoute: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return h(\"div\", {}, [\"Hello \\\\\"%%tsrPath%%\\\\\"!\", h(Outlet)]) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/vue-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return h(\"div\", {}, \"Hello \\\\\"%%tsrPath%%\\\\\"!\") };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/vue-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return h(\"div\", {}, \"Hello \\\\\"%%tsrPath%%\\\\\"!\") };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/vue-router';\",\n\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n\n tsrExportEnd: () => ');',\n },\n },\n }\n default:\n throw new Error(`router-generator: Unknown target type: ${target}`)\n }\n}\n"],"names":[],"mappings":";AAKO,SAAS,aACd,QACA,UACA,QACA;AACA,QAAM,WAAW,SAAS;AAAA,IACxB;AAAA,IACA,CAAC,GAAG,QAAQ,OAAO,GAAkB,KAAK;AAAA,EAAA;AAE5C,SAAO,OAAO,UAAU,MAAM;AAChC;AA+BO,SAAS,kBAAkB,QAAgC;AAChE,QAAM,SAAS,OAAO;AACtB,UAAQ,QAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,QACL,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,WAAW;AAAA,UACT,UAAU,MACR;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YAC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gB,CAAC,cACf,OAAO,sBAAsB,QACzB,8CACA,6CAA6C,SAAS;AAAA,YAE5D,cAAc,MAAM;AAAA,UAAA;AAAA,QACtB;AAAA,MACF;AAAA,IAEJ;AACE,YAAM,IAAI,MAAM,0CAA0C,MAAM,EAAE;AAAA,EAAA;AAExE;"}
|
|
1
|
+
{"version":3,"file":"template.js","names":[],"sources":["../../src/template.ts"],"sourcesContent":["import { format } from './utils'\nimport type { Config } from './config'\n\ntype TemplateTag = 'tsrImports' | 'tsrPath' | 'tsrExportStart' | 'tsrExportEnd'\n\nexport function fillTemplate(\n config: Config,\n template: string,\n values: Record<TemplateTag, string>,\n) {\n const replaced = template.replace(\n /%%(\\w+)%%/g,\n (_, key) => values[key as TemplateTag] || '',\n )\n return format(replaced, config)\n}\n\nexport type TargetTemplate = {\n fullPkg: string\n subPkg: string\n rootRoute: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: () => string\n tsrExportEnd: () => string\n }\n }\n route: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: (routePath: string) => string\n tsrExportEnd: () => string\n }\n }\n lazyRoute: {\n template: () => string\n imports: {\n tsrImports: () => string\n tsrExportStart: (routePath: string) => string\n tsrExportEnd: () => string\n }\n }\n}\n\nexport function getTargetTemplate(config: Config): TargetTemplate {\n const target = config.target\n switch (target) {\n case 'react':\n return {\n fullPkg: '@tanstack/react-router',\n subPkg: 'react-router',\n rootRoute: {\n template: () =>\n [\n 'import * as React from \"react\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return (<React.Fragment><div>Hello \"%%tsrPath%%\"!</div><Outlet /></React.Fragment>) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/react-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/react-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/react-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n }\n case 'solid':\n return {\n fullPkg: '@tanstack/solid-router',\n subPkg: 'solid-router',\n rootRoute: {\n template: () =>\n [\n 'import * as Solid from \"solid-js\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return (<><div>Hello \"%%tsrPath%%\"!</div><Outlet /></>) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/solid-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/solid-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return <div>Hello \"%%tsrPath%%\"!</div> };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/solid-router';\",\n\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n\n tsrExportEnd: () => ');',\n },\n },\n }\n case 'vue':\n return {\n fullPkg: '@tanstack/vue-router',\n subPkg: 'vue-router',\n rootRoute: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RootComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RootComponent() { return h(\"div\", {}, [\"Hello \\\\\"%%tsrPath%%\\\\\"!\", h(Outlet)]) };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n \"import { Outlet, createRootRoute } from '@tanstack/vue-router';\",\n tsrExportStart: () => 'export const Route = createRootRoute(',\n tsrExportEnd: () => ');',\n },\n },\n route: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return h(\"div\", {}, \"Hello \\\\\"%%tsrPath%%\\\\\"!\") };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createFileRoute } from '@tanstack/vue-router';\",\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createFileRoute('\n : `export const Route = createFileRoute('${routePath}')(`,\n tsrExportEnd: () => ');',\n },\n },\n lazyRoute: {\n template: () =>\n [\n 'import { h } from \"vue\"\\n',\n '%%tsrImports%%',\n '\\n\\n',\n '%%tsrExportStart%%{\\n component: RouteComponent\\n }%%tsrExportEnd%%\\n\\n',\n 'function RouteComponent() { return h(\"div\", {}, \"Hello \\\\\"%%tsrPath%%\\\\\"!\") };\\n',\n ].join(''),\n imports: {\n tsrImports: () =>\n config.verboseFileRoutes === false\n ? ''\n : \"import { createLazyFileRoute } from '@tanstack/vue-router';\",\n\n tsrExportStart: (routePath) =>\n config.verboseFileRoutes === false\n ? 'export const Route = createLazyFileRoute('\n : `export const Route = createLazyFileRoute('${routePath}')(`,\n\n tsrExportEnd: () => ');',\n },\n },\n }\n default:\n throw new Error(`router-generator: Unknown target type: ${target}`)\n }\n}\n"],"mappings":";;AAKA,SAAgB,aACd,QACA,UACA,QACA;AAKA,QAAO,OAJU,SAAS,QACxB,eACC,GAAG,QAAQ,OAAO,QAAuB,GAC3C,EACuB,OAAO;;AAgCjC,SAAgB,kBAAkB,QAAgC;CAChE,MAAM,SAAS,OAAO;AACtB,SAAQ,QAAR;EACE,KAAK,QACH,QAAO;GACL,SAAS;GACT,QAAQ;GACR,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE;KACF,sBAAsB;KACtB,oBAAoB;KACrB;IACF;GACD,OAAO;IACL,gBACE;KACE;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KACN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,0CACA,yCAAyC,UAAU;KACzD,oBAAoB;KACrB;IACF;GACD,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KACN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,8CACA,6CAA6C,UAAU;KAC7D,oBAAoB;KACrB;IACF;GACF;EACH,KAAK,QACH,QAAO;GACL,SAAS;GACT,QAAQ;GACR,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE;KACF,sBAAsB;KACtB,oBAAoB;KACrB;IACF;GACD,OAAO;IACL,gBACE;KACE;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KACN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,0CACA,yCAAyC,UAAU;KACzD,oBAAoB;KACrB;IACF;GACD,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KAEN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,8CACA,6CAA6C,UAAU;KAE7D,oBAAoB;KACrB;IACF;GACF;EACH,KAAK,MACH,QAAO;GACL,SAAS;GACT,QAAQ;GACR,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE;KACF,sBAAsB;KACtB,oBAAoB;KACrB;IACF;GACD,OAAO;IACL,gBACE;KACE;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KACN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,0CACA,yCAAyC,UAAU;KACzD,oBAAoB;KACrB;IACF;GACD,WAAW;IACT,gBACE;KACE;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,GAAG;IACZ,SAAS;KACP,kBACE,OAAO,sBAAsB,QACzB,KACA;KAEN,iBAAiB,cACf,OAAO,sBAAsB,QACzB,8CACA,6CAA6C,UAAU;KAE7D,oBAAoB;KACrB;IACF;GACF;EACH,QACE,OAAM,IAAI,MAAM,0CAA0C,SAAS"}
|