@tanstack/router-cli 1.1.11 → 1.2.0
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/build/cjs/config.js +4 -7
- package/build/cjs/config.js.map +1 -1
- package/build/cjs/generator.js +31 -28
- package/build/cjs/generator.js.map +1 -1
- package/build/types/config.d.ts +3 -4
- package/package.json +2 -2
- package/src/config.ts +6 -6
- package/src/generator.ts +45 -32
package/build/cjs/config.js
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
var path = require('path');
|
|
14
|
-
var fs = require('fs
|
|
14
|
+
var fs = require('fs');
|
|
15
15
|
var zod = require('zod');
|
|
16
16
|
|
|
17
17
|
const configSchema = zod.z.object({
|
|
18
18
|
routeFilePrefix: zod.z.string().optional(),
|
|
19
|
-
routeFileIgnorePrefix: zod.z.string().optional(),
|
|
19
|
+
routeFileIgnorePrefix: zod.z.string().optional().default('-'),
|
|
20
20
|
routesDirectory: zod.z.string(),
|
|
21
21
|
generatedRouteTree: zod.z.string(),
|
|
22
22
|
quoteStyle: zod.z.enum(['single', 'double']).optional().default('single'),
|
|
@@ -26,12 +26,9 @@ const configSchema = zod.z.object({
|
|
|
26
26
|
});
|
|
27
27
|
const configFilePathJson = path.resolve(process.cwd(), 'tsr.config.json');
|
|
28
28
|
async function getConfig() {
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
routeFileIgnorePrefix: '-',
|
|
32
|
-
...configSchema.parse(config)
|
|
33
|
-
};
|
|
29
|
+
return configSchema.parse(JSON.parse(fs.readFileSync(configFilePathJson, 'utf-8')));
|
|
34
30
|
}
|
|
35
31
|
|
|
32
|
+
exports.configSchema = configSchema;
|
|
36
33
|
exports.getConfig = getConfig;
|
|
37
34
|
//# sourceMappingURL=config.js.map
|
package/build/cjs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import path from 'path'\nimport
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import path from 'path'\nimport { readFileSync } from 'fs'\nimport { z } from 'zod'\n\nexport const configSchema = z.object({\n routeFilePrefix: z.string().optional(),\n routeFileIgnorePrefix: z.string().optional().default('-'),\n routesDirectory: z.string(),\n generatedRouteTree: z.string(),\n quoteStyle: z.enum(['single', 'double']).optional().default('single'),\n future: z\n .object({\n unstable_codeSplitting: z.boolean().optional(),\n })\n .optional(),\n})\n\nexport type Config = z.infer<typeof configSchema>\n\nconst configFilePathJson = path.resolve(process.cwd(), 'tsr.config.json')\n\nexport async function getConfig(): Promise<Config> {\n return configSchema.parse(\n JSON.parse(readFileSync(configFilePathJson, 'utf-8')),\n )\n}\n"],"names":["configSchema","z","object","routeFilePrefix","string","optional","routeFileIgnorePrefix","default","routesDirectory","generatedRouteTree","quoteStyle","enum","future","unstable_codeSplitting","boolean","configFilePathJson","path","resolve","process","cwd","getConfig","parse","JSON","readFileSync"],"mappings":";;;;;;;;;;;;;;;;MAIaA,YAAY,GAAGC,KAAC,CAACC,MAAM,CAAC;EACnCC,eAAe,EAAEF,KAAC,CAACG,MAAM,EAAE,CAACC,QAAQ,EAAE;AACtCC,EAAAA,qBAAqB,EAAEL,KAAC,CAACG,MAAM,EAAE,CAACC,QAAQ,EAAE,CAACE,OAAO,CAAC,GAAG,CAAC;AACzDC,EAAAA,eAAe,EAAEP,KAAC,CAACG,MAAM,EAAE;AAC3BK,EAAAA,kBAAkB,EAAER,KAAC,CAACG,MAAM,EAAE;AAC9BM,EAAAA,UAAU,EAAET,KAAC,CAACU,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAACN,QAAQ,EAAE,CAACE,OAAO,CAAC,QAAQ,CAAC;AACrEK,EAAAA,MAAM,EAAEX,KAAC,CACNC,MAAM,CAAC;IACNW,sBAAsB,EAAEZ,KAAC,CAACa,OAAO,EAAE,CAACT,QAAQ,EAAC;GAC9C,CAAC,CACDA,QAAQ,EAAC;AACd,CAAC,EAAC;AAIF,MAAMU,kBAAkB,GAAGC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAA;AAElE,eAAeC,SAASA,GAAoB;AACjD,EAAA,OAAOpB,YAAY,CAACqB,KAAK,CACvBC,IAAI,CAACD,KAAK,CAACE,eAAY,CAACR,kBAAkB,EAAE,OAAO,CAAC,CACtD,CAAC,CAAA;AACH;;;;;"}
|
package/build/cjs/generator.js
CHANGED
|
@@ -32,6 +32,7 @@ function _interopNamespaceDefault(e) {
|
|
|
32
32
|
return Object.freeze(n);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
35
36
|
var prettier__namespace = /*#__PURE__*/_interopNamespaceDefault(prettier);
|
|
36
37
|
|
|
37
38
|
let latestTask = 0;
|
|
@@ -45,7 +46,7 @@ async function getRouteNodes(config) {
|
|
|
45
46
|
let routeNodes = [];
|
|
46
47
|
async function recurse(dir) {
|
|
47
48
|
const fullDir = path.resolve(config.routesDirectory, dir);
|
|
48
|
-
let dirList = await
|
|
49
|
+
let dirList = await fs__namespace.readdir(fullDir);
|
|
49
50
|
dirList = dirList.filter(d => {
|
|
50
51
|
if (d.startsWith('.') || routeFileIgnorePrefix && d.startsWith(routeFileIgnorePrefix)) {
|
|
51
52
|
return false;
|
|
@@ -58,7 +59,7 @@ async function getRouteNodes(config) {
|
|
|
58
59
|
await Promise.all(dirList.map(async fileName => {
|
|
59
60
|
const fullPath = path.join(fullDir, fileName);
|
|
60
61
|
const relativePath = path.join(dir, fileName);
|
|
61
|
-
const stat = await
|
|
62
|
+
const stat = await fs__namespace.stat(fullPath);
|
|
62
63
|
if (stat.isDirectory()) {
|
|
63
64
|
await recurse(relativePath);
|
|
64
65
|
} else {
|
|
@@ -112,7 +113,7 @@ async function generator(config) {
|
|
|
112
113
|
const routePathIdPrefix = config.routeFilePrefix ?? '';
|
|
113
114
|
let preRouteNodes = await getRouteNodes(config);
|
|
114
115
|
const sortRouteNodes = nodes => {
|
|
115
|
-
return multiSortBy(nodes, [d => d.routePath === '/' ? -1 : 1, d => d.routePath?.split('/').length, d => d.routePath?.endsWith('/') ? -1 : 1, d => d.routePath]).filter(d => d.routePath !== `/${routePathIdPrefix + rootPathId}`);
|
|
116
|
+
return multiSortBy(nodes, [d => d.routePath === '/' ? -1 : 1, d => d.routePath?.split('/').length, d => d.filePath?.match(/[./]index[.]/) ? 1 : -1, d => d.filePath?.match(/[./]route[.]/) ? -1 : 1, d => d.routePath?.endsWith('/') ? -1 : 1, d => d.routePath]).filter(d => d.routePath !== `/${routePathIdPrefix + rootPathId}`);
|
|
116
117
|
};
|
|
117
118
|
preRouteNodes = sortRouteNodes(preRouteNodes);
|
|
118
119
|
const routeTree = [];
|
|
@@ -143,6 +144,18 @@ async function generator(config) {
|
|
|
143
144
|
if (node.isLoader || node.isComponent) {
|
|
144
145
|
routePiecesByPath[node.routePath] = routePiecesByPath[node.routePath] || {};
|
|
145
146
|
routePiecesByPath[node.routePath][node.isLoader ? 'loader' : 'component'] = node;
|
|
147
|
+
const anchorRoute = routeNodes.find(d => d.routePath === node.routePath);
|
|
148
|
+
if (!anchorRoute) {
|
|
149
|
+
handleNode({
|
|
150
|
+
...node,
|
|
151
|
+
isVirtual: true
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// if (!node.parent) {
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
// componentOrLoader.isVirtual = true
|
|
158
|
+
// handleNode(componentOrLoader)
|
|
146
159
|
return;
|
|
147
160
|
}
|
|
148
161
|
}
|
|
@@ -155,22 +168,9 @@ async function generator(config) {
|
|
|
155
168
|
routeNodes.push(node);
|
|
156
169
|
};
|
|
157
170
|
preRouteNodes.forEach(node => handleNode(node));
|
|
158
|
-
if (config.future?.unstable_codeSplitting) {
|
|
159
|
-
Object.keys(routePiecesByPath).forEach(routePath => {
|
|
160
|
-
const found = routeNodes.find(d => d.routePath === routePath);
|
|
161
|
-
if (!found) {
|
|
162
|
-
const pieces = routePiecesByPath[routePath];
|
|
163
|
-
const componentOrLoader = pieces.component || pieces.loader;
|
|
164
|
-
if (componentOrLoader) {
|
|
165
|
-
componentOrLoader.isVirtual = true;
|
|
166
|
-
handleNode(componentOrLoader);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
171
|
async function buildRouteConfig(nodes, depth = 1) {
|
|
172
172
|
const children = nodes.map(async node => {
|
|
173
|
-
const routeCode = await
|
|
173
|
+
const routeCode = await fs__namespace.readFile(node.fullPath, 'utf-8');
|
|
174
174
|
|
|
175
175
|
// Ensure the boilerplate for the route exists
|
|
176
176
|
if (node.isRoot) {
|
|
@@ -186,7 +186,7 @@ async function generator(config) {
|
|
|
186
186
|
const quote = config.quoteStyle === 'single' ? `'` : `"`;
|
|
187
187
|
const replaced = routeCode.replace(fileRouteRegex, `new FileRoute(${quote}${escapedRoutePath}${quote})`);
|
|
188
188
|
if (replaced !== routeCode) {
|
|
189
|
-
await
|
|
189
|
+
await fs__namespace.writeFile(node.fullPath, replaced);
|
|
190
190
|
}
|
|
191
191
|
const route = `${node.variableName}Route`;
|
|
192
192
|
if (node.children?.length) {
|
|
@@ -199,7 +199,12 @@ async function generator(config) {
|
|
|
199
199
|
}
|
|
200
200
|
const routeConfigChildrenText = await buildRouteConfig(routeTree);
|
|
201
201
|
const sortedRouteNodes = multiSortBy(routeNodes, [d => d.routePath?.includes(`/${routePathIdPrefix + rootPathId}`) ? -1 : 1, d => d.routePath?.split('/').length, d => d.routePath?.endsWith("index'") ? -1 : 1, d => d]);
|
|
202
|
-
const
|
|
202
|
+
const imports = Object.entries({
|
|
203
|
+
FileRoute: sortedRouteNodes.some(d => d.isVirtual),
|
|
204
|
+
lazyFn: sortedRouteNodes.some(node => routePiecesByPath[node.routePath]?.loader),
|
|
205
|
+
lazyRouteComponent: sortedRouteNodes.some(node => routePiecesByPath[node.routePath]?.component)
|
|
206
|
+
}).filter(d => d[1]).map(d => d[0]);
|
|
207
|
+
const routeImports = [imports.length ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\n` : '', `import { Route as rootRoute } from './${sanitize(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, routePathIdPrefix + rootPathId)))}'`, ...sortedRouteNodes.filter(d => !d.isVirtual).map(node => {
|
|
203
208
|
return `import { Route as ${node.variableName}Import } from './${sanitize(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, node.filePath))))}'`;
|
|
204
209
|
}), '\n', sortedRouteNodes.filter(d => d.isVirtual).map(node => {
|
|
205
210
|
return `const ${node.variableName}Import = new FileRoute('${node.routePath}').createRoute()`;
|
|
@@ -209,23 +214,21 @@ async function generator(config) {
|
|
|
209
214
|
return [`const ${node.variableName}Route = ${node.variableName}Import.update({
|
|
210
215
|
${[node.isNonPath ? `id: '${node.path}'` : `path: '${node.cleanedPath}'`, `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`].filter(Boolean).join(',')}
|
|
211
216
|
} as any)`, loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${sanitize(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, loaderNode.filePath))))}'), 'loader') })` : '', componentNode ? `.update({ component: lazyRouteComponent(() => import('./${sanitize(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, componentNode.filePath))))}'), 'component') })` : ''].join('');
|
|
212
|
-
}).join('\n\n')
|
|
213
|
-
const routeTypes = `declare module '@tanstack/react-router' {
|
|
217
|
+
}).join('\n\n'), `declare module '@tanstack/react-router' {
|
|
214
218
|
interface FileRoutesByPath {
|
|
215
219
|
${routeNodes.map(routeNode => {
|
|
216
220
|
return `'${routeNode.routePath}': {
|
|
217
221
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
218
|
-
parentRoute: typeof ${routeNode.parent?.variableName
|
|
222
|
+
parentRoute: typeof ${routeNode.parent?.variableName ? `${routeNode.parent?.variableName}Import` : 'rootRoute'}
|
|
219
223
|
}`;
|
|
220
224
|
}).join('\n')}
|
|
221
225
|
}
|
|
222
|
-
}
|
|
223
|
-
const
|
|
224
|
-
const routeConfigFileContent = await prettier__namespace.format([routeImports, routeTypes, routeConfig].join('\n\n'), {
|
|
226
|
+
}`, `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`].join('\n');
|
|
227
|
+
const routeConfigFileContent = await prettier__namespace.format(routeImports, {
|
|
225
228
|
semi: false,
|
|
226
229
|
parser: 'typescript'
|
|
227
230
|
});
|
|
228
|
-
const routeTreeContent = await
|
|
231
|
+
const routeTreeContent = await fs__namespace.readFile(path.resolve(config.generatedRouteTree), 'utf-8').catch(err => {
|
|
229
232
|
if (err.code === 'ENOENT') {
|
|
230
233
|
return undefined;
|
|
231
234
|
}
|
|
@@ -233,9 +236,9 @@ async function generator(config) {
|
|
|
233
236
|
});
|
|
234
237
|
if (!checkLatest()) return;
|
|
235
238
|
if (routeTreeContent !== routeConfigFileContent) {
|
|
236
|
-
await
|
|
239
|
+
await fs__namespace.ensureDir(path.dirname(path.resolve(config.generatedRouteTree)));
|
|
237
240
|
if (!checkLatest()) return;
|
|
238
|
-
await
|
|
241
|
+
await fs__namespace.writeFile(path.resolve(config.generatedRouteTree), routeConfigFileContent);
|
|
239
242
|
}
|
|
240
243
|
console.log(`🌲 Processed ${routeNodes.length} routes in ${Date.now() - start}ms`);
|
|
241
244
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs-extra'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, trimPathLeft } from '@tanstack/react-router'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nexport const fileRouteRegex = /new\\s+FileRoute\\(([^)]*)\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isVirtual?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fs.readdir(fullDir)\n\n dirList = dirList.filter((d) => {\n if (\n d.startsWith('.') ||\n (routeFileIgnorePrefix && d.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (fileName) => {\n const fullPath = path.join(fullDir, fileName)\n const relativePath = path.join(dir, fileName)\n const stat = await fs.stat(fullPath)\n\n if (stat.isDirectory()) {\n await recurse(relativePath)\n } else {\n const filePath = path.join(dir, fileName)\n const filePathNoExt = removeExt(filePath)\n let routePath =\n replaceBackslash(\n cleanPath(`/${filePathNoExt.split('.').join('/')}`),\n ) ?? ''\n const variableName = fileToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n if (routePath === 'index') {\n routePath = '/'\n } else if (routePath.endsWith('/index')) {\n routePath = routePath.replace(/\\/index$/, '/')\n }\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n loader?: RouteNode\n}\n\nexport async function generator(config: Config) {\n console.log()\n\n if (!first) {\n console.log('🔄 Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n console.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n\n let preRouteNodes = await getRouteNodes(config)\n\n const sortRouteNodes = (nodes: RouteNode[]): RouteNode[] => {\n return multiSortBy(nodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => d.routePath !== `/${routePathIdPrefix + rootPathId}`)\n }\n\n preRouteNodes = sortRouteNodes(preRouteNodes)\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = (node: RouteNode) => {\n if (config.future?.unstable_codeSplitting) {\n node.isRoute = node.routePath?.endsWith('/route')\n node.isComponent = node.routePath?.endsWith('/component')\n node.isLoader = node.routePath?.endsWith('/loader')\n\n if (node.isComponent || node.isLoader || node.isRoute) {\n node.routePath = node.routePath?.replace(\n /\\/(component|loader|route)$/,\n '',\n )\n }\n }\n\n const parentRoute = hasParentRoute(routeNodes, node.routePath)\n if (parentRoute) node.parent = parentRoute\n\n node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n\n node.isNonPath = first.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeUnderscores(node.path) ?? ''\n\n if (config.future?.unstable_codeSplitting) {\n if (node.isLoader || node.isComponent) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLoader ? 'loader' : 'component'\n ] = node\n\n return\n }\n }\n\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n preRouteNodes.forEach((node) => handleNode(node))\n\n if (config.future?.unstable_codeSplitting) {\n Object.keys(routePiecesByPath).forEach((routePath) => {\n const found = routeNodes.find((d) => d.routePath === routePath)\n\n if (!found) {\n const pieces = routePiecesByPath[routePath]!\n const componentOrLoader = pieces.component || pieces.loader\n if (componentOrLoader) {\n componentOrLoader.isVirtual = true\n handleNode(componentOrLoader)\n }\n }\n })\n }\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n const routeCode = await fs.readFile(node.fullPath, 'utf-8')\n\n // Ensure the boilerplate for the route exists\n if (node.isRoot) {\n return\n }\n\n // Ensure that new FileRoute(anything?) is replaced with FileRoute(${node.routePath})\n // routePath can contain $ characters, which have special meaning when used in replace\n // so we have to escape it by turning all $ into $$. But since we do it through a replace call\n // we have to double escape it into $$$$. For more information, see\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$$$') ?? ''\n const quote = config.quoteStyle === 'single' ? `'` : `\"`\n const replaced = routeCode.replace(\n fileRouteRegex,\n `new FileRoute(${quote}${escapedRoutePath}${quote})`,\n )\n\n if (replaced !== routeCode) {\n await fs.writeFile(node.fullPath, replaced)\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) =>\n d.routePath?.includes(`/${routePathIdPrefix + rootPathId}`) ? -1 : 1,\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const routeImports = [\n `import { FileRoute, lazyFn, lazyRouteComponent } from '@tanstack/react-router'`,\n '\\n',\n `import { Route as rootRoute } from './${sanitize(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, routePathIdPrefix + rootPathId),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )}'`\n }),\n '\\n',\n sortedRouteNodes\n .filter((d) => d.isVirtual)\n .map((node) => {\n return `const ${node.variableName}Import = new FileRoute('${node.routePath}').createRoute()`\n })\n .join('\\n'),\n '\\n',\n sortedRouteNodes\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n ),\n )}'), 'loader') })`\n : '',\n componentNode\n ? `.update({ component: lazyRouteComponent(() => import('./${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n componentNode.filePath,\n ),\n ),\n ),\n )}'), 'component') })`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n ].join('\\n')\n\n const routeTypes = `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${routeNode.routePath}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${routeNode.parent?.variableName ?? 'root'}Route\n }`\n })\n .join('\\n')}\n }\n}`\n\n const routeConfig = `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`\n\n const routeConfigFileContent = await prettier.format(\n [routeImports, routeTypes, routeConfig].join('\\n\\n'),\n {\n semi: false,\n parser: 'typescript',\n },\n )\n\n const routeTreeContent = await fs\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fs.ensureDir(path.dirname(path.resolve(config.generatedRouteTree)))\n if (!checkLatest()) return\n await fs.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n console.log(\n `🌲 Processed ${routeNodes.length} routes in ${Date.now() - start}ms`,\n )\n}\n\nfunction fileToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '') ?? ''\n )\n}\n\nexport function removeExt(d: string) {\n return d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction sanitize(s?: string) {\n return replaceBackslash(s?.replace(/\\\\index/gi, ''))\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replace(/(^_|_$)/, '').replace(/(\\/_|_\\/)/, '/')\n}\n\nfunction replaceBackslash(s?: string) {\n return s?.replace(/\\\\/gi, '/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, parentRoutePath)\n}\n"],"names":["latestTask","rootPathId","fileRouteRegex","getRouteNodes","config","routeFilePrefix","routeFileIgnorePrefix","routeNodes","recurse","dir","fullDir","path","resolve","routesDirectory","dirList","fs","readdir","filter","d","startsWith","Promise","all","map","fileName","fullPath","join","relativePath","stat","isDirectory","filePath","filePathNoExt","removeExt","routePath","replaceBackslash","cleanPath","split","variableName","fileToVariable","endsWith","replace","push","first","skipMessage","generator","console","log","taskId","checkLatest","start","Date","now","routePathIdPrefix","preRouteNodes","sortRouteNodes","nodes","multiSortBy","length","routeTree","routePiecesByPath","handleNode","node","future","unstable_codeSplitting","isRoute","isComponent","isLoader","parentRoute","hasParentRoute","parent","trimmedPath","trimPathLeft","isNonPath","isNonLayout","cleanedPath","removeUnderscores","children","forEach","Object","keys","found","find","pieces","componentOrLoader","component","loader","isVirtual","buildRouteConfig","depth","routeCode","readFile","isRoot","escapedRoutePath","replaceAll","quote","quoteStyle","replaced","writeFile","route","childConfigs","spaces","Boolean","routeConfigChildrenText","sortedRouteNodes","includes","routeImports","sanitize","relative","dirname","generatedRouteTree","loaderNode","componentNode","routeTypes","routeNode","routeConfig","routeConfigFileContent","prettier","format","semi","parser","routeTreeContent","catch","err","code","undefined","ensureDir","i","capitalize","substring","lastIndexOf","Array","from","arr","accessors","sort","a","ai","b","bi","accessor","ao","bo","s","charAt","toUpperCase","slice","routes","routePathToCheck","sortedNodes","segments","pop","parentRoutePath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAIA,UAAU,GAAG,CAAC,CAAA;AACX,MAAMC,UAAU,GAAG,SAAQ;AAC3B,MAAMC,cAAc,GAAG,8BAA6B;AAoB3D,eAAeC,aAAaA,CAACC,MAAc,EAAE;EAC3C,MAAM;IAAEC,eAAe;AAAEC,IAAAA,qBAAAA;AAAsB,GAAC,GAAGF,MAAM,CAAA;EAEzD,IAAIG,UAAuB,GAAG,EAAE,CAAA;EAEhC,eAAeC,OAAOA,CAACC,GAAW,EAAE;IAClC,MAAMC,OAAO,GAAGC,IAAI,CAACC,OAAO,CAACR,MAAM,CAACS,eAAe,EAAEJ,GAAG,CAAC,CAAA;IACzD,IAAIK,OAAO,GAAG,MAAMC,EAAE,CAACC,OAAO,CAACN,OAAO,CAAC,CAAA;AAEvCI,IAAAA,OAAO,GAAGA,OAAO,CAACG,MAAM,CAAEC,CAAC,IAAK;AAC9B,MAAA,IACEA,CAAC,CAACC,UAAU,CAAC,GAAG,CAAC,IAChBb,qBAAqB,IAAIY,CAAC,CAACC,UAAU,CAACb,qBAAqB,CAAE,EAC9D;AACA,QAAA,OAAO,KAAK,CAAA;AACd,OAAA;AAEA,MAAA,IAAID,eAAe,EAAE;AACnB,QAAA,OAAOa,CAAC,CAACC,UAAU,CAACd,eAAe,CAAC,CAAA;AACtC,OAAA;AAEA,MAAA,OAAO,IAAI,CAAA;AACb,KAAC,CAAC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,CAAC,CAACc,SAAS,CAAEwB,MAAM,GAAG,CAAC,CAAC,EAC9BtC,CAAC,IAAKA,CAAC,CAACkB,YAAY,CACtB,CAAC,CAACnB,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACc,SAAS,KAAM,CAAG/B,CAAAA,EAAAA,UAAW,EAAC,CAAC,CAAA;AAElD,EAAA,KAAK,MAAMgG,KAAK,IAAIkD,WAAW,EAAE;AAC/B,IAAA,IAAIlD,KAAK,CAACjE,SAAS,KAAK,GAAG,EAAE,SAAA;AAE7B,IAAA,IACEkH,gBAAgB,CAAC/H,UAAU,CAAE,CAAA,EAAE8E,KAAK,CAACjE,SAAU,CAAE,CAAA,CAAA,CAAC,IAClDiE,KAAK,CAACjE,SAAS,KAAKkH,gBAAgB,EACpC;AACA,MAAA,OAAOjD,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,MAAMmD,QAAQ,GAAGF,gBAAgB,CAAC/G,KAAK,CAAC,GAAG,CAAC,CAAA;AAC5CiH,EAAAA,QAAQ,CAACC,GAAG,EAAE,CAAC;AACf,EAAA,MAAMC,eAAe,GAAGF,QAAQ,CAAC3H,IAAI,CAAC,GAAG,CAAC,CAAA;AAE1C,EAAA,OAAO0C,cAAc,CAAC8E,MAAM,EAAEK,eAAe,CAAC,CAAA;AAChD;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"generator.js","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs-extra'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, trimPathLeft } from '@tanstack/react-router'\n\nlet latestTask = 0\nexport const rootPathId = '__root'\nexport const fileRouteRegex = /new\\s+FileRoute\\(([^)]*)\\)/g\n\nexport type RouteNode = {\n filePath: string\n fullPath: string\n variableName: string\n routePath?: string\n cleanedPath?: string\n path?: string\n isNonPath?: boolean\n isNonLayout?: boolean\n isRoute?: boolean\n isLoader?: boolean\n isComponent?: boolean\n isVirtual?: boolean\n isRoot?: boolean\n children?: RouteNode[]\n parent?: RouteNode\n}\n\nasync function getRouteNodes(config: Config) {\n const { routeFilePrefix, routeFileIgnorePrefix } = config\n\n let routeNodes: RouteNode[] = []\n\n async function recurse(dir: string) {\n const fullDir = path.resolve(config.routesDirectory, dir)\n let dirList = await fs.readdir(fullDir)\n\n dirList = dirList.filter((d) => {\n if (\n d.startsWith('.') ||\n (routeFileIgnorePrefix && d.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (fileName) => {\n const fullPath = path.join(fullDir, fileName)\n const relativePath = path.join(dir, fileName)\n const stat = await fs.stat(fullPath)\n\n if (stat.isDirectory()) {\n await recurse(relativePath)\n } else {\n const filePath = path.join(dir, fileName)\n const filePathNoExt = removeExt(filePath)\n let routePath =\n replaceBackslash(\n cleanPath(`/${filePathNoExt.split('.').join('/')}`),\n ) ?? ''\n const variableName = fileToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n if (routePath === 'index') {\n routePath = '/'\n } else if (routePath.endsWith('/index')) {\n routePath = routePath.replace(/\\/index$/, '/')\n }\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n })\n }\n }),\n )\n\n return routeNodes\n }\n\n await recurse('./')\n\n return routeNodes\n}\n\nlet first = false\nlet skipMessage = false\n\ntype RouteSubNode = {\n component?: RouteNode\n loader?: RouteNode\n}\n\nexport async function generator(config: Config) {\n console.log()\n\n if (!first) {\n console.log('🔄 Generating routes...')\n first = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n console.log('♻️ Regenerating routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n const routePathIdPrefix = config.routeFilePrefix ?? ''\n\n let preRouteNodes = await getRouteNodes(config)\n\n const sortRouteNodes = (nodes: RouteNode[]): RouteNode[] => {\n return multiSortBy(nodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => d.routePath !== `/${routePathIdPrefix + rootPathId}`)\n }\n\n preRouteNodes = sortRouteNodes(preRouteNodes)\n\n const routeTree: RouteNode[] = []\n const routePiecesByPath: Record<string, RouteSubNode> = {}\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n let routeNodes: RouteNode[] = []\n\n const handleNode = (node: RouteNode) => {\n if (config.future?.unstable_codeSplitting) {\n node.isRoute = node.routePath?.endsWith('/route')\n node.isComponent = node.routePath?.endsWith('/component')\n node.isLoader = node.routePath?.endsWith('/loader')\n\n if (node.isComponent || node.isLoader || node.isRoute) {\n node.routePath = node.routePath?.replace(\n /\\/(component|loader|route)$/,\n '',\n )\n }\n }\n\n const parentRoute = hasParentRoute(routeNodes, node.routePath)\n if (parentRoute) node.parent = parentRoute\n\n node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath!, '') || '/'\n : node.routePath\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath?.split('/') ?? []\n let first = split[0] ?? trimmedPath ?? ''\n\n node.isNonPath = first.startsWith('_')\n node.isNonLayout = first.endsWith('_')\n\n node.cleanedPath = removeUnderscores(node.path) ?? ''\n\n if (config.future?.unstable_codeSplitting) {\n if (node.isLoader || node.isComponent) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLoader ? 'loader' : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === node.routePath,\n )\n if (!anchorRoute) {\n handleNode({\n ...node,\n isVirtual: true,\n })\n }\n // if (!node.parent) {\n // }\n\n // componentOrLoader.isVirtual = true\n // handleNode(componentOrLoader)\n return\n }\n }\n\n if (node.parent) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n preRouteNodes.forEach((node) => handleNode(node))\n\n async function buildRouteConfig(\n nodes: RouteNode[],\n depth = 1,\n ): Promise<string> {\n const children = nodes.map(async (node) => {\n const routeCode = await fs.readFile(node.fullPath, 'utf-8')\n\n // Ensure the boilerplate for the route exists\n if (node.isRoot) {\n return\n }\n\n // Ensure that new FileRoute(anything?) is replaced with FileRoute(${node.routePath})\n // routePath can contain $ characters, which have special meaning when used in replace\n // so we have to escape it by turning all $ into $$. But since we do it through a replace call\n // we have to double escape it into $$$$. For more information, see\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement\n const escapedRoutePath = node.routePath?.replaceAll('$', '$$$$') ?? ''\n const quote = config.quoteStyle === 'single' ? `'` : `\"`\n const replaced = routeCode.replace(\n fileRouteRegex,\n `new FileRoute(${quote}${escapedRoutePath}${quote})`,\n )\n\n if (replaced !== routeCode) {\n await fs.writeFile(node.fullPath, replaced)\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = await buildRouteConfig(node.children, depth + 1)\n return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`\n }\n\n return route\n })\n\n return (await Promise.all(children)).filter(Boolean).join(`,`)\n }\n\n const routeConfigChildrenText = await buildRouteConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) =>\n d.routePath?.includes(`/${routePathIdPrefix + rootPathId}`) ? -1 : 1,\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(\"index'\") ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n FileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n lazyFn: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.loader,\n ),\n lazyRouteComponent: sortedRouteNodes.some(\n (node) => routePiecesByPath[node.routePath!]?.component,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const routeImports = [\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n `import { Route as rootRoute } from './${sanitize(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, routePathIdPrefix + rootPathId),\n ),\n )}'`,\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { Route as ${\n node.variableName\n }Import } from './${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )}'`\n }),\n '\\n',\n sortedRouteNodes\n .filter((d) => d.isVirtual)\n .map((node) => {\n return `const ${node.variableName}Import = new FileRoute('${node.routePath}').createRoute()`\n })\n .join('\\n'),\n '\\n',\n sortedRouteNodes\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n\n return [\n `const ${node.variableName}Route = ${node.variableName}Import.update({\n ${[\n node.isNonPath\n ? `id: '${node.path}'`\n : `path: '${node.cleanedPath}'`,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n loaderNode\n ? `.updateLoader({ loader: lazyFn(() => import('./${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n ),\n )}'), 'loader') })`\n : '',\n componentNode\n ? `.update({ component: lazyRouteComponent(() => import('./${sanitize(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(\n config.routesDirectory,\n componentNode.filePath,\n ),\n ),\n ),\n )}'), 'component') })`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${routeNode.routePath}': {\n preLoaderRoute: typeof ${routeNode.variableName}Import\n parentRoute: typeof ${\n routeNode.parent?.variableName\n ? `${routeNode.parent?.variableName}Import`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n ].join('\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n parser: 'typescript',\n })\n\n const routeTreeContent = await fs\n .readFile(path.resolve(config.generatedRouteTree), 'utf-8')\n .catch((err: any) => {\n if (err.code === 'ENOENT') {\n return undefined\n }\n throw err\n })\n\n if (!checkLatest()) return\n\n if (routeTreeContent !== routeConfigFileContent) {\n await fs.ensureDir(path.dirname(path.resolve(config.generatedRouteTree)))\n if (!checkLatest()) return\n await fs.writeFile(\n path.resolve(config.generatedRouteTree),\n routeConfigFileContent,\n )\n }\n\n console.log(\n `🌲 Processed ${routeNodes.length} routes in ${Date.now() - start}ms`,\n )\n}\n\nfunction fileToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\$/g, '')\n ?.split(/[/-]/g)\n .map((d, i) => (i > 0 ? capitalize(d) : d))\n .join('')\n .replace(/([^a-zA-Z0-9]|[\\.])/gm, '') ?? ''\n )\n}\n\nexport function removeExt(d: string) {\n return d.substring(0, d.lastIndexOf('.')) || d\n}\n\nfunction spaces(d: number): string {\n return Array.from({ length: d })\n .map(() => ' ')\n .join('')\n}\n\nexport function multiSortBy<T>(\n arr: T[],\n accessors: ((item: T) => any)[] = [(d) => d],\n): T[] {\n return arr\n .map((d, i) => [d, i] as const)\n .sort(([a, ai], [b, bi]) => {\n for (const accessor of accessors) {\n const ao = accessor(a)\n const bo = accessor(b)\n\n if (typeof ao === 'undefined') {\n if (typeof bo === 'undefined') {\n continue\n }\n return 1\n }\n\n if (ao === bo) {\n continue\n }\n\n return ao > bo ? 1 : -1\n }\n\n return ai - bi\n })\n .map(([d]) => d)\n}\n\nfunction capitalize(s: string) {\n if (typeof s !== 'string') return ''\n return s.charAt(0).toUpperCase() + s.slice(1)\n}\n\nfunction sanitize(s?: string) {\n return replaceBackslash(s?.replace(/\\\\index/gi, ''))\n}\n\nfunction removeUnderscores(s?: string) {\n return s?.replace(/(^_|_$)/, '').replace(/(\\/_|_\\/)/, '/')\n}\n\nfunction replaceBackslash(s?: string) {\n return s?.replace(/\\\\/gi, '/')\n}\n\nexport function hasParentRoute(\n routes: RouteNode[],\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, parentRoutePath)\n}\n"],"names":["latestTask","rootPathId","fileRouteRegex","getRouteNodes","config","routeFilePrefix","routeFileIgnorePrefix","routeNodes","recurse","dir","fullDir","path","resolve","routesDirectory","dirList","fs","readdir","filter","d","startsWith","Promise","all","map","fileName","fullPath","join","relativePath","stat","isDirectory","filePath","filePathNoExt","removeExt","routePath","replaceBackslash","cleanPath","split","variableName","fileToVariable","endsWith","replace","push","first","skipMessage","generator","console","log","taskId","checkLatest","start","Date","now","routePathIdPrefix","preRouteNodes","sortRouteNodes","nodes","multiSortBy","length","match","routeTree","routePiecesByPath","handleNode","node","future","unstable_codeSplitting","isRoute","isComponent","isLoader","parentRoute","hasParentRoute","parent","trimmedPath","trimPathLeft","isNonPath","isNonLayout","cleanedPath","removeUnderscores","anchorRoute","find","isVirtual","children","forEach","buildRouteConfig","depth","routeCode","readFile","isRoot","escapedRoutePath","replaceAll","quote","quoteStyle","replaced","writeFile","route","childConfigs","spaces","Boolean","routeConfigChildrenText","sortedRouteNodes","includes","imports","Object","entries","FileRoute","some","lazyFn","loader","lazyRouteComponent","component","routeImports","sanitize","relative","dirname","generatedRouteTree","loaderNode","componentNode","routeNode","routeConfigFileContent","prettier","format","semi","parser","routeTreeContent","catch","err","code","undefined","ensureDir","i","capitalize","substring","lastIndexOf","Array","from","arr","accessors","sort","a","ai","b","bi","accessor","ao","bo","s","charAt","toUpperCase","slice","routes","routePathToCheck","sortedNodes","segments","pop","parentRoutePath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAIA,UAAU,GAAG,CAAC,CAAA;AACX,MAAMC,UAAU,GAAG,SAAQ;AAC3B,MAAMC,cAAc,GAAG,8BAA6B;AAoB3D,eAAeC,aAAaA,CAACC,MAAc,EAAE;EAC3C,MAAM;IAAEC,eAAe;AAAEC,IAAAA,qBAAAA;AAAsB,GAAC,GAAGF,MAAM,CAAA;EAEzD,IAAIG,UAAuB,GAAG,EAAE,CAAA;EAEhC,eAAeC,OAAOA,CAACC,GAAW,EAAE;IAClC,MAAMC,OAAO,GAAGC,IAAI,CAACC,OAAO,CAACR,MAAM,CAACS,eAAe,EAAEJ,GAAG,CAAC,CAAA;IACzD,IAAIK,OAAO,GAAG,MAAMC,aAAE,CAACC,OAAO,CAACN,OAAO,CAAC,CAAA;AAEvCI,IAAAA,OAAO,GAAGA,OAAO,CAACG,MAAM,CAAEC,CAAC,IAAK;AAC9B,MAAA,IACEA,CAAC,CAACC,UAAU,CAAC,GAAG,CAAC,IAChBb,qBAAqB,IAAIY,CAAC,CAACC,UAAU,CAACb,qBAAqB,CAAE,EAC9D;AACA,QAAA,OAAO,KAAK,CAAA;AACd,OAAA;AAEA,MAAA,IAAID,eAAe,EAAE;AACnB,QAAA,OAAOa,CAAC,CAACC,UAAU,CAACd,eAAe,CAAC,CAAA;AACtC,OAAA;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AC,GAAG,CAAC,CAAA;AAE1C,EAAA,OAAO2C,cAAc,CAAC+E,MAAM,EAAEK,eAAe,CAAC,CAAA;AAChD;;;;;;;;;"}
|
package/build/types/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
declare const configSchema: z.ZodObject<{
|
|
2
|
+
export declare const configSchema: z.ZodObject<{
|
|
3
3
|
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
4
|
-
routeFileIgnorePrefix: z.ZodOptional<z.ZodString
|
|
4
|
+
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
5
5
|
routesDirectory: z.ZodString;
|
|
6
6
|
generatedRouteTree: z.ZodString;
|
|
7
7
|
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
@@ -13,11 +13,11 @@ declare const configSchema: z.ZodObject<{
|
|
|
13
13
|
unstable_codeSplitting?: boolean | undefined;
|
|
14
14
|
}>>;
|
|
15
15
|
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
routeFileIgnorePrefix: string;
|
|
16
17
|
routesDirectory: string;
|
|
17
18
|
generatedRouteTree: string;
|
|
18
19
|
quoteStyle: "single" | "double";
|
|
19
20
|
routeFilePrefix?: string | undefined;
|
|
20
|
-
routeFileIgnorePrefix?: string | undefined;
|
|
21
21
|
future?: {
|
|
22
22
|
unstable_codeSplitting?: boolean | undefined;
|
|
23
23
|
} | undefined;
|
|
@@ -33,4 +33,3 @@ declare const configSchema: z.ZodObject<{
|
|
|
33
33
|
}>;
|
|
34
34
|
export type Config = z.infer<typeof configSchema>;
|
|
35
35
|
export declare function getConfig(): Promise<Config>;
|
|
36
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-cli",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/router",
|
|
7
7
|
"homepage": "https://tanstack.com/router",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"through2": "^4.0.2",
|
|
60
60
|
"yargs": "^17.6.2",
|
|
61
61
|
"zod": "^3.19.1",
|
|
62
|
-
"@tanstack/react-router": "1.
|
|
62
|
+
"@tanstack/react-router": "1.2.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "rollup --config rollup.config.js"
|
package/src/config.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import
|
|
2
|
+
import { readFileSync } from 'fs'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
-
const configSchema = z.object({
|
|
5
|
+
export const configSchema = z.object({
|
|
6
6
|
routeFilePrefix: z.string().optional(),
|
|
7
|
-
routeFileIgnorePrefix: z.string().optional(),
|
|
7
|
+
routeFileIgnorePrefix: z.string().optional().default('-'),
|
|
8
8
|
routesDirectory: z.string(),
|
|
9
9
|
generatedRouteTree: z.string(),
|
|
10
10
|
quoteStyle: z.enum(['single', 'double']).optional().default('single'),
|
|
@@ -20,7 +20,7 @@ export type Config = z.infer<typeof configSchema>
|
|
|
20
20
|
const configFilePathJson = path.resolve(process.cwd(), 'tsr.config.json')
|
|
21
21
|
|
|
22
22
|
export async function getConfig(): Promise<Config> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
return configSchema.parse(
|
|
24
|
+
JSON.parse(readFileSync(configFilePathJson, 'utf-8')),
|
|
25
|
+
)
|
|
26
26
|
}
|
package/src/generator.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import fs from 'fs-extra'
|
|
2
|
+
import * as fs from 'fs-extra'
|
|
3
3
|
import * as prettier from 'prettier'
|
|
4
4
|
import { Config } from './config'
|
|
5
5
|
import { cleanPath, trimPathLeft } from '@tanstack/react-router'
|
|
@@ -134,6 +134,8 @@ export async function generator(config: Config) {
|
|
|
134
134
|
return multiSortBy(nodes, [
|
|
135
135
|
(d) => (d.routePath === '/' ? -1 : 1),
|
|
136
136
|
(d) => d.routePath?.split('/').length,
|
|
137
|
+
(d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),
|
|
138
|
+
(d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),
|
|
137
139
|
(d) => (d.routePath?.endsWith('/') ? -1 : 1),
|
|
138
140
|
(d) => d.routePath,
|
|
139
141
|
]).filter((d) => d.routePath !== `/${routePathIdPrefix + rootPathId}`)
|
|
@@ -188,6 +190,20 @@ export async function generator(config: Config) {
|
|
|
188
190
|
node.isLoader ? 'loader' : 'component'
|
|
189
191
|
] = node
|
|
190
192
|
|
|
193
|
+
const anchorRoute = routeNodes.find(
|
|
194
|
+
(d) => d.routePath === node.routePath,
|
|
195
|
+
)
|
|
196
|
+
if (!anchorRoute) {
|
|
197
|
+
handleNode({
|
|
198
|
+
...node,
|
|
199
|
+
isVirtual: true,
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
// if (!node.parent) {
|
|
203
|
+
// }
|
|
204
|
+
|
|
205
|
+
// componentOrLoader.isVirtual = true
|
|
206
|
+
// handleNode(componentOrLoader)
|
|
191
207
|
return
|
|
192
208
|
}
|
|
193
209
|
}
|
|
@@ -204,21 +220,6 @@ export async function generator(config: Config) {
|
|
|
204
220
|
|
|
205
221
|
preRouteNodes.forEach((node) => handleNode(node))
|
|
206
222
|
|
|
207
|
-
if (config.future?.unstable_codeSplitting) {
|
|
208
|
-
Object.keys(routePiecesByPath).forEach((routePath) => {
|
|
209
|
-
const found = routeNodes.find((d) => d.routePath === routePath)
|
|
210
|
-
|
|
211
|
-
if (!found) {
|
|
212
|
-
const pieces = routePiecesByPath[routePath]!
|
|
213
|
-
const componentOrLoader = pieces.component || pieces.loader
|
|
214
|
-
if (componentOrLoader) {
|
|
215
|
-
componentOrLoader.isVirtual = true
|
|
216
|
-
handleNode(componentOrLoader)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
}
|
|
221
|
-
|
|
222
223
|
async function buildRouteConfig(
|
|
223
224
|
nodes: RouteNode[],
|
|
224
225
|
depth = 1,
|
|
@@ -270,9 +271,22 @@ export async function generator(config: Config) {
|
|
|
270
271
|
(d) => d,
|
|
271
272
|
])
|
|
272
273
|
|
|
274
|
+
const imports = Object.entries({
|
|
275
|
+
FileRoute: sortedRouteNodes.some((d) => d.isVirtual),
|
|
276
|
+
lazyFn: sortedRouteNodes.some(
|
|
277
|
+
(node) => routePiecesByPath[node.routePath!]?.loader,
|
|
278
|
+
),
|
|
279
|
+
lazyRouteComponent: sortedRouteNodes.some(
|
|
280
|
+
(node) => routePiecesByPath[node.routePath!]?.component,
|
|
281
|
+
),
|
|
282
|
+
})
|
|
283
|
+
.filter((d) => d[1])
|
|
284
|
+
.map((d) => d[0])
|
|
285
|
+
|
|
273
286
|
const routeImports = [
|
|
274
|
-
|
|
275
|
-
|
|
287
|
+
imports.length
|
|
288
|
+
? `import { ${imports.join(', ')} } from '@tanstack/react-router'\n`
|
|
289
|
+
: '',
|
|
276
290
|
`import { Route as rootRoute } from './${sanitize(
|
|
277
291
|
path.relative(
|
|
278
292
|
path.dirname(config.generatedRouteTree),
|
|
@@ -343,30 +357,29 @@ export async function generator(config: Config) {
|
|
|
343
357
|
].join('')
|
|
344
358
|
})
|
|
345
359
|
.join('\n\n'),
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const routeTypes = `declare module '@tanstack/react-router' {
|
|
360
|
+
`declare module '@tanstack/react-router' {
|
|
349
361
|
interface FileRoutesByPath {
|
|
350
362
|
${routeNodes
|
|
351
363
|
.map((routeNode) => {
|
|
352
364
|
return `'${routeNode.routePath}': {
|
|
353
365
|
preLoaderRoute: typeof ${routeNode.variableName}Import
|
|
354
|
-
parentRoute: typeof ${
|
|
366
|
+
parentRoute: typeof ${
|
|
367
|
+
routeNode.parent?.variableName
|
|
368
|
+
? `${routeNode.parent?.variableName}Import`
|
|
369
|
+
: 'rootRoute'
|
|
370
|
+
}
|
|
355
371
|
}`
|
|
356
372
|
})
|
|
357
373
|
.join('\n')}
|
|
358
374
|
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
375
|
+
}`,
|
|
376
|
+
`export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,
|
|
377
|
+
].join('\n')
|
|
362
378
|
|
|
363
|
-
const routeConfigFileContent = await prettier.format(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
parser: 'typescript',
|
|
368
|
-
},
|
|
369
|
-
)
|
|
379
|
+
const routeConfigFileContent = await prettier.format(routeImports, {
|
|
380
|
+
semi: false,
|
|
381
|
+
parser: 'typescript',
|
|
382
|
+
})
|
|
370
383
|
|
|
371
384
|
const routeTreeContent = await fs
|
|
372
385
|
.readFile(path.resolve(config.generatedRouteTree), 'utf-8')
|