@tanstack/router-cli 1.5.2 → 1.5.4

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.
@@ -10,11 +10,11 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- var generator = require('./generator.js');
13
+ var routerGenerator = require('@tanstack/router-generator');
14
14
 
15
15
  async function generate(config) {
16
16
  try {
17
- await generator.generator(config);
17
+ await routerGenerator.generator(config);
18
18
  process.exit(0);
19
19
  } catch (err) {
20
20
  console.error(err);
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sources":["../../src/generate.ts"],"sourcesContent":["import { generator } from './generator'\nimport { Config } from './config'\n\nexport async function generate(config: Config) {\n try {\n await generator(config)\n process.exit(0)\n } catch (err) {\n console.error(err)\n process.exit(1)\n }\n}\n"],"names":["generate","config","generator","process","exit","err","console","error"],"mappings":";;;;;;;;;;;;;;AAGO,eAAeA,QAAQA,CAACC,MAAc,EAAE;EAC7C,IAAI;IACF,MAAMC,mBAAS,CAACD,MAAM,CAAC,CAAA;AACvBE,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAAA;GAChB,CAAC,OAAOC,GAAG,EAAE;AACZC,IAAAA,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC,CAAA;AAClBF,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"generate.js","sources":["../../src/generate.ts"],"sourcesContent":["import { Config, generator } from '@tanstack/router-generator'\n\nexport async function generate(config: Config) {\n try {\n await generator(config)\n process.exit(0)\n } catch (err) {\n console.error(err)\n process.exit(1)\n }\n}\n"],"names":["generate","config","generator","process","exit","err","console","error"],"mappings":";;;;;;;;;;;;;;AAEO,eAAeA,QAAQA,CAACC,MAAc,EAAE;EAC7C,IAAI;IACF,MAAMC,yBAAS,CAACD,MAAM,CAAC,CAAA;AACvBE,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAAA;GAChB,CAAC,OAAOC,GAAG,EAAE;AACZC,IAAAA,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC,CAAA;AAClBF,IAAAA,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,GAAA;AACF;;;;"}
@@ -11,7 +11,7 @@
11
11
  'use strict';
12
12
 
13
13
  var yargs = require('yargs');
14
- var config = require('./config.js');
14
+ var routerGenerator = require('@tanstack/router-generator');
15
15
  var generate = require('./generate.js');
16
16
  var watch = require('./watch.js');
17
17
 
@@ -37,8 +37,8 @@ var yargs__namespace = /*#__PURE__*/_interopNamespaceDefault(yargs);
37
37
  main();
38
38
  function main() {
39
39
  yargs__namespace.scriptName('tsr').usage('$0 <cmd> [args]').command('generate', 'Generate the routes for a project', async argv => {
40
- const config$1 = await config.getConfig();
41
- await generate.generate(config$1);
40
+ const config = await routerGenerator.getConfig();
41
+ await generate.generate(config);
42
42
  }).command('watch', 'Continuously watch and generate the routes for a project', async argv => {
43
43
  watch.watch();
44
44
  }).help().argv;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import * as yargs from 'yargs'\nimport { getConfig } from './config'\nimport { generate } from './generate'\nimport { watch } from './watch'\n\nmain()\n\nexport function main() {\n yargs\n .scriptName('tsr')\n .usage('$0 <cmd> [args]')\n .command('generate', 'Generate the routes for a project', async (argv) => {\n const config = await getConfig()\n await generate(config)\n })\n .command(\n 'watch',\n 'Continuously watch and generate the routes for a project',\n async (argv) => {\n watch()\n },\n )\n .help().argv\n}\n"],"names":["main","yargs","scriptName","usage","command","argv","config","getConfig","generate","watch","help"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKAA,IAAI,EAAE,CAAA;AAEC,SAASA,IAAIA,GAAG;AACrBC,EAAAA,gBAAK,CACFC,UAAU,CAAC,KAAK,CAAC,CACjBC,KAAK,CAAC,iBAAiB,CAAC,CACxBC,OAAO,CAAC,UAAU,EAAE,mCAAmC,EAAE,MAAOC,IAAI,IAAK;AACxE,IAAA,MAAMC,QAAM,GAAG,MAAMC,gBAAS,EAAE,CAAA;IAChC,MAAMC,iBAAQ,CAACF,QAAM,CAAC,CAAA;GACvB,CAAC,CACDF,OAAO,CACN,OAAO,EACP,0DAA0D,EAC1D,MAAOC,IAAI,IAAK;AACdI,IAAAA,WAAK,EAAE,CAAA;AACT,GACF,CAAC,CACAC,IAAI,EAAE,CAACL,IAAI,CAAA;AAChB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import * as yargs from 'yargs'\nimport { getConfig } from '@tanstack/router-generator'\nimport { generate } from './generate'\nimport { watch } from './watch'\n\nmain()\n\nexport function main() {\n yargs\n .scriptName('tsr')\n .usage('$0 <cmd> [args]')\n .command('generate', 'Generate the routes for a project', async (argv) => {\n const config = await getConfig()\n await generate(config)\n })\n .command(\n 'watch',\n 'Continuously watch and generate the routes for a project',\n async (argv) => {\n watch()\n },\n )\n .help().argv\n}\n"],"names":["main","yargs","scriptName","usage","command","argv","config","getConfig","generate","watch","help"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKAA,IAAI,EAAE,CAAA;AAEC,SAASA,IAAIA,GAAG;AACrBC,EAAAA,gBAAK,CACFC,UAAU,CAAC,KAAK,CAAC,CACjBC,KAAK,CAAC,iBAAiB,CAAC,CACxBC,OAAO,CAAC,UAAU,EAAE,mCAAmC,EAAE,MAAOC,IAAI,IAAK;AACxE,IAAA,MAAMC,MAAM,GAAG,MAAMC,yBAAS,EAAE,CAAA;IAChC,MAAMC,iBAAQ,CAACF,MAAM,CAAC,CAAA;GACvB,CAAC,CACDF,OAAO,CACN,OAAO,EACP,0DAA0D,EAC1D,MAAOC,IAAI,IAAK;AACdI,IAAAA,WAAK,EAAE,CAAA;AACT,GACF,CAAC,CACAC,IAAI,EAAE,CAACL,IAAI,CAAA;AAChB;;;;"}
@@ -12,21 +12,20 @@
12
12
 
13
13
  var chokidar = require('chokidar');
14
14
  var path = require('path');
15
- var config = require('./config.js');
16
- var generator = require('./generator.js');
15
+ var routerGenerator = require('@tanstack/router-generator');
17
16
 
18
17
  async function watch() {
19
18
  const configWatcher = chokidar.watch(path.resolve(process.cwd(), 'tsr.config.json'));
20
19
  let watcher = new chokidar.FSWatcher({});
21
20
  const generatorWatcher = async () => {
22
- const config$1 = await config.getConfig();
21
+ const config = await routerGenerator.getConfig();
23
22
  watcher.close();
24
- console.info(`TSR: Watching routes (${config$1.routesDirectory})...`);
25
- watcher = chokidar.watch(config$1.routesDirectory);
23
+ console.info(`TSR: Watching routes (${config.routesDirectory})...`);
24
+ watcher = chokidar.watch(config.routesDirectory);
26
25
  watcher.on('ready', async () => {
27
26
  const handle = async () => {
28
27
  try {
29
- await generator.generator(config$1);
28
+ await routerGenerator.generator(config);
30
29
  } catch (err) {
31
30
  console.error(err);
32
31
  console.info();
@@ -1 +1 @@
1
- {"version":3,"file":"watch.js","sources":["../../src/watch.ts"],"sourcesContent":["import chokidar from 'chokidar'\nimport path from 'path'\nimport { getConfig } from './config'\nimport { generator } from './generator'\n\nexport async function watch() {\n const configWatcher = chokidar.watch(\n path.resolve(process.cwd(), 'tsr.config.json'),\n )\n\n let watcher = new chokidar.FSWatcher({})\n\n const generatorWatcher = async () => {\n const config = await getConfig()\n\n watcher.close()\n\n console.info(`TSR: Watching routes (${config.routesDirectory})...`)\n watcher = chokidar.watch(config.routesDirectory)\n\n watcher.on('ready', async () => {\n const handle = async () => {\n try {\n await generator(config)\n } catch (err) {\n console.error(err)\n console.info()\n }\n }\n\n await handle()\n\n let timeout: ReturnType<typeof setTimeout>\n\n const deduped = (file: string) => {\n if (timeout) {\n clearTimeout(timeout)\n }\n\n timeout = setTimeout(handle, 10)\n }\n\n watcher.on('change', deduped)\n watcher.on('add', deduped)\n watcher.on('unlink', deduped)\n })\n }\n\n configWatcher.on('ready', generatorWatcher)\n configWatcher.on('change', generatorWatcher)\n}\n"],"names":["watch","configWatcher","chokidar","path","resolve","process","cwd","watcher","FSWatcher","generatorWatcher","config","getConfig","close","console","info","routesDirectory","on","handle","generator","err","error","timeout","deduped","file","clearTimeout","setTimeout"],"mappings":";;;;;;;;;;;;;;;;;AAKO,eAAeA,KAAKA,GAAG;AAC5B,EAAA,MAAMC,aAAa,GAAGC,QAAQ,CAACF,KAAK,CAClCG,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,GAAG,EAAE,EAAE,iBAAiB,CAC/C,CAAC,CAAA;EAED,IAAIC,OAAO,GAAG,IAAIL,QAAQ,CAACM,SAAS,CAAC,EAAE,CAAC,CAAA;AAExC,EAAA,MAAMC,gBAAgB,GAAG,YAAY;AACnC,IAAA,MAAMC,QAAM,GAAG,MAAMC,gBAAS,EAAE,CAAA;IAEhCJ,OAAO,CAACK,KAAK,EAAE,CAAA;IAEfC,OAAO,CAACC,IAAI,CAAE,CAAA,sBAAA,EAAwBJ,QAAM,CAACK,eAAgB,MAAK,CAAC,CAAA;IACnER,OAAO,GAAGL,QAAQ,CAACF,KAAK,CAACU,QAAM,CAACK,eAAe,CAAC,CAAA;AAEhDR,IAAAA,OAAO,CAACS,EAAE,CAAC,OAAO,EAAE,YAAY;AAC9B,MAAA,MAAMC,MAAM,GAAG,YAAY;QACzB,IAAI;UACF,MAAMC,mBAAS,CAACR,QAAM,CAAC,CAAA;SACxB,CAAC,OAAOS,GAAG,EAAE;AACZN,UAAAA,OAAO,CAACO,KAAK,CAACD,GAAG,CAAC,CAAA;UAClBN,OAAO,CAACC,IAAI,EAAE,CAAA;AAChB,SAAA;OACD,CAAA;MAED,MAAMG,MAAM,EAAE,CAAA;AAEd,MAAA,IAAII,OAAsC,CAAA;MAE1C,MAAMC,OAAO,GAAIC,IAAY,IAAK;AAChC,QAAA,IAAIF,OAAO,EAAE;UACXG,YAAY,CAACH,OAAO,CAAC,CAAA;AACvB,SAAA;AAEAA,QAAAA,OAAO,GAAGI,UAAU,CAACR,MAAM,EAAE,EAAE,CAAC,CAAA;OACjC,CAAA;AAEDV,MAAAA,OAAO,CAACS,EAAE,CAAC,QAAQ,EAAEM,OAAO,CAAC,CAAA;AAC7Bf,MAAAA,OAAO,CAACS,EAAE,CAAC,KAAK,EAAEM,OAAO,CAAC,CAAA;AAC1Bf,MAAAA,OAAO,CAACS,EAAE,CAAC,QAAQ,EAAEM,OAAO,CAAC,CAAA;AAC/B,KAAC,CAAC,CAAA;GACH,CAAA;AAEDrB,EAAAA,aAAa,CAACe,EAAE,CAAC,OAAO,EAAEP,gBAAgB,CAAC,CAAA;AAC3CR,EAAAA,aAAa,CAACe,EAAE,CAAC,QAAQ,EAAEP,gBAAgB,CAAC,CAAA;AAC9C;;;;"}
1
+ {"version":3,"file":"watch.js","sources":["../../src/watch.ts"],"sourcesContent":["import chokidar from 'chokidar'\nimport path from 'path'\nimport { getConfig, generator } from '@tanstack/router-generator'\n\nexport async function watch() {\n const configWatcher = chokidar.watch(\n path.resolve(process.cwd(), 'tsr.config.json'),\n )\n\n let watcher = new chokidar.FSWatcher({})\n\n const generatorWatcher = async () => {\n const config = await getConfig()\n\n watcher.close()\n\n console.info(`TSR: Watching routes (${config.routesDirectory})...`)\n watcher = chokidar.watch(config.routesDirectory)\n\n watcher.on('ready', async () => {\n const handle = async () => {\n try {\n await generator(config)\n } catch (err) {\n console.error(err)\n console.info()\n }\n }\n\n await handle()\n\n let timeout: ReturnType<typeof setTimeout>\n\n const deduped = (file: string) => {\n if (timeout) {\n clearTimeout(timeout)\n }\n\n timeout = setTimeout(handle, 10)\n }\n\n watcher.on('change', deduped)\n watcher.on('add', deduped)\n watcher.on('unlink', deduped)\n })\n }\n\n configWatcher.on('ready', generatorWatcher)\n configWatcher.on('change', generatorWatcher)\n}\n"],"names":["watch","configWatcher","chokidar","path","resolve","process","cwd","watcher","FSWatcher","generatorWatcher","config","getConfig","close","console","info","routesDirectory","on","handle","generator","err","error","timeout","deduped","file","clearTimeout","setTimeout"],"mappings":";;;;;;;;;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,EAAEM,OAAO,CAAC,CAAA;AAC1Bf,MAAAA,OAAO,CAACS,EAAE,CAAC,QAAQ,EAAEM,OAAO,CAAC,CAAA;AAC/B,KAAC,CAAC,CAAA;GACH,CAAA;AAEDrB,EAAAA,aAAa,CAACe,EAAE,CAAC,OAAO,EAAEP,gBAAgB,CAAC,CAAA;AAC3CR,EAAAA,aAAa,CAACe,EAAE,CAAC,QAAQ,EAAEP,gBAAgB,CAAC,CAAA;AAC9C;;;;"}
@@ -1,2 +1,2 @@
1
- import { Config } from './config';
1
+ import { Config } from '@tanstack/router-generator';
2
2
  export declare function generate(config: Config): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-cli",
3
3
  "author": "Tanner Linsley",
4
- "version": "1.5.2",
4
+ "version": "1.5.4",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -38,27 +38,13 @@
38
38
  "module": "bin/tsr.js",
39
39
  "main": "bin/tsr.js",
40
40
  "browser": "bin/tsr.js",
41
- "types": "build/types/index.d.ts",
42
41
  "dependencies": {
43
- "@babel/core": "^7.20.2",
44
- "@babel/plugin-syntax-jsx": "^7.18.6",
45
- "@babel/plugin-syntax-typescript": "^7.20.0",
46
- "@babel/preset-env": "^7.20.2",
47
- "@babel/template": "^7.18.10",
48
- "@babel/types": "^7.20.2",
49
- "@types/fs-extra": "^9.0.13",
50
- "@types/klaw": "^3.0.3",
51
- "@types/through2": "^2.0.38",
52
- "@types/yargs": "^17.0.15",
53
42
  "chokidar": "^3.5.3",
54
- "dedent": "^0.7.0",
55
- "klaw": "^4.0.1",
56
- "nodemon": "^2.0.20",
57
- "prettier": "^3.0.2",
58
- "through2": "^4.0.2",
59
43
  "yargs": "^17.6.2",
60
- "zod": "^3.19.1",
61
- "@tanstack/react-router": "1.5.2"
44
+ "@tanstack/router-generator": "1.5.4"
45
+ },
46
+ "devDependencies": {
47
+ "@types/yargs": "^17.0.15"
62
48
  },
63
49
  "scripts": {
64
50
  "build": "rollup --config rollup.config.js"
package/src/generate.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { generator } from './generator'
2
- import { Config } from './config'
1
+ import { Config, generator } from '@tanstack/router-generator'
3
2
 
4
3
  export async function generate(config: Config) {
5
4
  try {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as yargs from 'yargs'
2
- import { getConfig } from './config'
2
+ import { getConfig } from '@tanstack/router-generator'
3
3
  import { generate } from './generate'
4
4
  import { watch } from './watch'
5
5
 
package/src/watch.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import chokidar from 'chokidar'
2
2
  import path from 'path'
3
- import { getConfig } from './config'
4
- import { generator } from './generator'
3
+ import { getConfig, generator } from '@tanstack/router-generator'
5
4
 
6
5
  export async function watch() {
7
6
  const configWatcher = chokidar.watch(
@@ -1,35 +0,0 @@
1
- /**
2
- * @tanstack/router-cli/src/index.ts
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- var path = require('path');
14
- var fs = require('fs');
15
- var zod = require('zod');
16
-
17
- const configSchema = zod.z.object({
18
- routeFilePrefix: zod.z.string().optional(),
19
- routeFileIgnorePrefix: zod.z.string().optional().default('-'),
20
- routesDirectory: zod.z.string().optional().default('./src/routes'),
21
- generatedRouteTree: zod.z.string().optional().default('./src/routeTree.gen.ts'),
22
- quoteStyle: zod.z.enum(['single', 'double']).optional().default('single')
23
- });
24
- const configFilePathJson = path.resolve(process.cwd(), 'tsr.config.json');
25
- async function getConfig() {
26
- const exists = fs.existsSync(configFilePathJson);
27
- if (exists) {
28
- return configSchema.parse(JSON.parse(fs.readFileSync(configFilePathJson, 'utf-8')));
29
- }
30
- return configSchema.parse({});
31
- }
32
-
33
- exports.configSchema = configSchema;
34
- exports.getConfig = getConfig;
35
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sources":["../../src/config.ts"],"sourcesContent":["import path from 'path'\nimport { readFileSync, existsSync } 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().optional().default('./src/routes'),\n generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),\n quoteStyle: z.enum(['single', 'double']).optional().default('single'),\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 const exists = existsSync(configFilePathJson)\n\n if (exists) {\n return configSchema.parse(\n JSON.parse(readFileSync(configFilePathJson, 'utf-8')),\n )\n }\n\n return configSchema.parse({})\n}\n"],"names":["configSchema","z","object","routeFilePrefix","string","optional","routeFileIgnorePrefix","default","routesDirectory","generatedRouteTree","quoteStyle","enum","configFilePathJson","path","resolve","process","cwd","getConfig","exists","existsSync","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,CAACC,QAAQ,EAAE,CAACE,OAAO,CAAC,cAAc,CAAC;AAC9DE,EAAAA,kBAAkB,EAAER,KAAC,CAACG,MAAM,EAAE,CAACC,QAAQ,EAAE,CAACE,OAAO,CAAC,wBAAwB,CAAC;AAC3EG,EAAAA,UAAU,EAAET,KAAC,CAACU,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAACN,QAAQ,EAAE,CAACE,OAAO,CAAC,QAAQ,CAAA;AACtE,CAAC,EAAC;AAIF,MAAMK,kBAAkB,GAAGC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAA;AAElE,eAAeC,SAASA,GAAoB;AACjD,EAAA,MAAMC,MAAM,GAAGC,aAAU,CAACP,kBAAkB,CAAC,CAAA;AAE7C,EAAA,IAAIM,MAAM,EAAE;AACV,IAAA,OAAOlB,YAAY,CAACoB,KAAK,CACvBC,IAAI,CAACD,KAAK,CAACE,eAAY,CAACV,kBAAkB,EAAE,OAAO,CAAC,CACtD,CAAC,CAAA;AACH,GAAA;AAEA,EAAA,OAAOZ,YAAY,CAACoB,KAAK,CAAC,EAAE,CAAC,CAAA;AAC/B;;;;;"}
@@ -1,318 +0,0 @@
1
- /**
2
- * @tanstack/router-cli/src/index.ts
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- var path = require('path');
14
- var fs = require('fs/promises');
15
- var prettier = require('prettier');
16
- var reactRouter = require('@tanstack/react-router');
17
-
18
- function _interopNamespaceDefault(e) {
19
- var n = Object.create(null);
20
- if (e) {
21
- Object.keys(e).forEach(function (k) {
22
- if (k !== 'default') {
23
- var d = Object.getOwnPropertyDescriptor(e, k);
24
- Object.defineProperty(n, k, d.get ? d : {
25
- enumerable: true,
26
- get: function () { return e[k]; }
27
- });
28
- }
29
- });
30
- }
31
- n.default = e;
32
- return Object.freeze(n);
33
- }
34
-
35
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
36
- var prettier__namespace = /*#__PURE__*/_interopNamespaceDefault(prettier);
37
-
38
- let latestTask = 0;
39
- const rootPathId = '__root';
40
- const fileRouteRegex = /new\s+FileRoute\(([^)]*)\)/g;
41
- async function getRouteNodes(config) {
42
- const {
43
- routeFilePrefix,
44
- routeFileIgnorePrefix
45
- } = config;
46
- let routeNodes = [];
47
- async function recurse(dir) {
48
- const fullDir = path.resolve(config.routesDirectory, dir);
49
- let dirList = await fs__namespace.readdir(fullDir, {
50
- withFileTypes: true
51
- });
52
- dirList = dirList.filter(d => {
53
- if (d.name.startsWith('.') || routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix)) {
54
- return false;
55
- }
56
- if (routeFilePrefix) {
57
- return d.name.startsWith(routeFilePrefix);
58
- }
59
- return true;
60
- });
61
- await Promise.all(dirList.map(async dirent => {
62
- const fullPath = path.join(fullDir, dirent.name);
63
- const relativePath = path.join(dir, dirent.name);
64
- if (dirent.isDirectory()) {
65
- await recurse(relativePath);
66
- } else if (fullPath.match(/\.(tsx|ts|jsx|js)$/)) {
67
- const filePath = replaceBackslash(path.join(dir, dirent.name));
68
- const filePathNoExt = removeExt(filePath);
69
- let routePath = reactRouter.cleanPath(`/${filePathNoExt.split('.').join('/')}`) || '';
70
- const variableName = routePathToVariable(routePath);
71
-
72
- // Remove the index from the route path and
73
- // if the route path is empty, use `/'
74
-
75
- let isRoute = routePath?.endsWith('/route');
76
- let isComponent = routePath?.endsWith('/component');
77
- let isErrorComponent = routePath?.endsWith('/errorComponent');
78
- let isPendingComponent = routePath?.endsWith('/pendingComponent');
79
- let isLoader = routePath?.endsWith('/loader');
80
- routePath = routePath?.replace(/\/(component|errorComponent|pendingComponent|loader|route)$/, '');
81
- if (routePath === 'index') {
82
- routePath = '/';
83
- }
84
- routePath = routePath.replace(/\/index$/, '/') || '/';
85
- routeNodes.push({
86
- filePath,
87
- fullPath,
88
- routePath,
89
- variableName,
90
- isRoute,
91
- isComponent,
92
- isErrorComponent,
93
- isPendingComponent,
94
- isLoader
95
- });
96
- }
97
- }));
98
- return routeNodes;
99
- }
100
- await recurse('./');
101
- return routeNodes;
102
- }
103
- let first = false;
104
- let skipMessage = false;
105
- async function generator(config) {
106
- console.log();
107
- if (!first) {
108
- console.log('🔄 Generating routes...');
109
- first = true;
110
- } else if (skipMessage) {
111
- skipMessage = false;
112
- } else {
113
- console.log('♻️ Regenerating routes...');
114
- }
115
- const taskId = latestTask + 1;
116
- latestTask = taskId;
117
- const checkLatest = () => {
118
- if (latestTask !== taskId) {
119
- skipMessage = true;
120
- return false;
121
- }
122
- return true;
123
- };
124
- const start = Date.now();
125
- const routePathIdPrefix = config.routeFilePrefix ?? '';
126
- const preRouteNodes = multiSortBy(await getRouteNodes(config), [d => d.routePath === '/' ? -1 : 1, d => d.routePath?.split('/').length, d => d.filePath?.match(/[./]index[.]/) ? 1 : -1, d => d.filePath?.match(/[./](component|errorComponent|pendingComponent|loader)[.]/) ? 1 : -1, d => d.filePath?.match(/[./]route[.]/) ? -1 : 1, d => d.routePath?.endsWith('/') ? -1 : 1, d => d.routePath]).filter(d => ![`/${routePathIdPrefix + rootPathId}`].includes(d.routePath || ''));
127
- const routeTree = [];
128
- const routePiecesByPath = {};
129
-
130
- // Loop over the flat list of routeNodes and
131
- // build up a tree based on the routeNodes' routePath
132
- let routeNodes = [];
133
- const handleNode = node => {
134
- const parentRoute = hasParentRoute(routeNodes, node.routePath);
135
- if (parentRoute) node.parent = parentRoute;
136
- node.path = node.parent ? node.routePath?.replace(node.parent.routePath, '') || '/' : node.routePath;
137
- const trimmedPath = reactRouter.trimPathLeft(node.path ?? '');
138
- const split = trimmedPath?.split('/') ?? [];
139
- let first = split[0] ?? trimmedPath ?? '';
140
- node.isNonPath = first.startsWith('_');
141
- node.isNonLayout = first.endsWith('_');
142
- node.cleanedPath = removeUnderscores(node.path) ?? '';
143
- if (!node.isVirtual && (node.isLoader || node.isComponent || node.isErrorComponent || node.isPendingComponent)) {
144
- routePiecesByPath[node.routePath] = routePiecesByPath[node.routePath] || {};
145
- routePiecesByPath[node.routePath][node.isLoader ? 'loader' : node.isErrorComponent ? 'errorComponent' : node.isPendingComponent ? 'pendingComponent' : 'component'] = node;
146
- const anchorRoute = routeNodes.find(d => d.routePath === node.routePath);
147
- if (!anchorRoute) {
148
- handleNode({
149
- ...node,
150
- isVirtual: true,
151
- isLoader: false,
152
- isComponent: false,
153
- isErrorComponent: false,
154
- isPendingComponent: false
155
- });
156
- }
157
- return;
158
- }
159
- if (node.parent) {
160
- node.parent.children = node.parent.children ?? [];
161
- node.parent.children.push(node);
162
- } else {
163
- routeTree.push(node);
164
- }
165
- routeNodes.push(node);
166
- };
167
- preRouteNodes.forEach(node => handleNode(node));
168
- async function buildRouteConfig(nodes, depth = 1) {
169
- const children = nodes.map(async node => {
170
- const routeCode = await fs__namespace.readFile(node.fullPath, 'utf-8');
171
-
172
- // Ensure the boilerplate for the route exists
173
- if (node.isRoot) {
174
- return;
175
- }
176
-
177
- // Ensure that new FileRoute(anything?) is replaced with FileRoute(${node.routePath})
178
- // routePath can contain $ characters, which have special meaning when used in replace
179
- // so we have to escape it by turning all $ into $$. But since we do it through a replace call
180
- // we have to double escape it into $$$$. For more information, see
181
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement
182
- const escapedRoutePath = removeTrailingUnderscores(node.routePath?.replaceAll('$', '$$$$') ?? '');
183
- const quote = config.quoteStyle === 'single' ? `'` : `"`;
184
- const replaced = routeCode.replace(fileRouteRegex, `new FileRoute(${quote}${escapedRoutePath}${quote})`);
185
- if (replaced !== routeCode) {
186
- await fs__namespace.writeFile(node.fullPath, replaced);
187
- }
188
- const route = `${node.variableName}Route`;
189
- if (node.children?.length) {
190
- const childConfigs = await buildRouteConfig(node.children, depth + 1);
191
- return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`;
192
- }
193
- return route;
194
- });
195
- return (await Promise.all(children)).filter(Boolean).join(`,`);
196
- }
197
- const routeConfigChildrenText = await buildRouteConfig(routeTree);
198
- 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]);
199
- const imports = Object.entries({
200
- FileRoute: sortedRouteNodes.some(d => d.isVirtual),
201
- lazyFn: sortedRouteNodes.some(node => routePiecesByPath[node.routePath]?.loader),
202
- lazyRouteComponent: sortedRouteNodes.some(node => routePiecesByPath[node.routePath]?.component || routePiecesByPath[node.routePath]?.errorComponent || routePiecesByPath[node.routePath]?.pendingComponent)
203
- }).filter(d => d[1]).map(d => d[0]);
204
- const virtualRouteNodes = sortedRouteNodes.filter(d => d.isVirtual);
205
- const routeImports = ['// This file is auto-generated by TanStack Router', imports.length ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\n` : '', '// Import Routes', [`import { Route as rootRoute } from './${replaceBackslash(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, routePathIdPrefix + rootPathId)))}'`, ...sortedRouteNodes.filter(d => !d.isVirtual).map(node => {
206
- return `import { Route as ${node.variableName}Import } from './${replaceBackslash(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, node.filePath))))}'`;
207
- })].join('\n'), virtualRouteNodes.length ? '// Create Virtual Routes' : '', virtualRouteNodes.map(node => {
208
- return `const ${node.variableName}Import = new FileRoute('${removeTrailingUnderscores(node.routePath)}').createRoute()`;
209
- }).join('\n'), '// Create/Update Routes', sortedRouteNodes.map(node => {
210
- const loaderNode = routePiecesByPath[node.routePath]?.loader;
211
- const componentNode = routePiecesByPath[node.routePath]?.component;
212
- const errorComponentNode = routePiecesByPath[node.routePath]?.errorComponent;
213
- const pendingComponentNode = routePiecesByPath[node.routePath]?.pendingComponent;
214
- return [`const ${node.variableName}Route = ${node.variableName}Import.update({
215
- ${[node.isNonPath ? `id: '${node.path}'` : `path: '${node.cleanedPath}'`, `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`].filter(Boolean).join(',')}
216
- } as any)`, loaderNode ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, loaderNode.filePath))))}'), 'loader') })` : '', componentNode || errorComponentNode || pendingComponentNode ? `.update({
217
- ${[['component', componentNode], ['errorComponent', errorComponentNode], ['pendingComponent', pendingComponentNode]].filter(d => d[1]).map(d => {
218
- return `${d[0]}: lazyRouteComponent(() => import('./${replaceBackslash(removeExt(path.relative(path.dirname(config.generatedRouteTree), path.resolve(config.routesDirectory, d[1].filePath))))}'), '${d[0]}')`;
219
- }).join('\n,')}
220
- })` : ''].join('');
221
- }).join('\n\n'), '// Populate the FileRoutesByPath interface', `declare module '@tanstack/react-router' {
222
- interface FileRoutesByPath {
223
- ${routeNodes.map(routeNode => {
224
- return `'${removeTrailingUnderscores(routeNode.routePath)}': {
225
- preLoaderRoute: typeof ${routeNode.variableName}Import
226
- parentRoute: typeof ${routeNode.parent?.variableName ? `${routeNode.parent?.variableName}Import` : 'rootRoute'}
227
- }`;
228
- }).join('\n')}
229
- }
230
- }`, '// Create and export the route tree', `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`].filter(Boolean).join('\n\n');
231
- const routeConfigFileContent = await prettier__namespace.format(routeImports, {
232
- semi: false,
233
- singleQuote: config.quoteStyle === 'single',
234
- parser: 'typescript'
235
- });
236
- const routeTreeContent = await fs__namespace.readFile(path.resolve(config.generatedRouteTree), 'utf-8').catch(err => {
237
- if (err.code === 'ENOENT') {
238
- return undefined;
239
- }
240
- throw err;
241
- });
242
- if (!checkLatest()) return;
243
- if (routeTreeContent !== routeConfigFileContent) {
244
- await fs__namespace.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {
245
- recursive: true
246
- });
247
- if (!checkLatest()) return;
248
- await fs__namespace.writeFile(path.resolve(config.generatedRouteTree), routeConfigFileContent);
249
- }
250
- console.log(`🌲 Processed ${routeNodes.length} routes in ${Date.now() - start}ms`);
251
- }
252
- function routePathToVariable(d) {
253
- return removeUnderscores(d)?.replace(/\/\$\//g, '/splat/')?.replace(/\$$/g, 'splat')?.replace(/\$/g, '')?.split(/[/-]/g).map((d, i) => i > 0 ? capitalize(d) : d).join('').replace(/([^a-zA-Z0-9]|[\.])/gm, '') ?? '';
254
- }
255
- function removeExt(d) {
256
- return d.substring(0, d.lastIndexOf('.')) || d;
257
- }
258
- function spaces(d) {
259
- return Array.from({
260
- length: d
261
- }).map(() => ' ').join('');
262
- }
263
- function multiSortBy(arr, accessors = [d => d]) {
264
- return arr.map((d, i) => [d, i]).sort(([a, ai], [b, bi]) => {
265
- for (const accessor of accessors) {
266
- const ao = accessor(a);
267
- const bo = accessor(b);
268
- if (typeof ao === 'undefined') {
269
- if (typeof bo === 'undefined') {
270
- continue;
271
- }
272
- return 1;
273
- }
274
- if (ao === bo) {
275
- continue;
276
- }
277
- return ao > bo ? 1 : -1;
278
- }
279
- return ai - bi;
280
- }).map(([d]) => d);
281
- }
282
- function capitalize(s) {
283
- if (typeof s !== 'string') return '';
284
- return s.charAt(0).toUpperCase() + s.slice(1);
285
- }
286
- function removeUnderscores(s) {
287
- return s?.replace(/(^_|_$)/, '').replace(/(\/_|_\/)/, '/');
288
- }
289
- function removeTrailingUnderscores(s) {
290
- return s?.replace(/(_$)/, '').replace(/(_\/)/, '/');
291
- }
292
- function replaceBackslash(s) {
293
- return s.replace(/\\/gi, '/');
294
- }
295
- function hasParentRoute(routes, routePathToCheck) {
296
- if (!routePathToCheck || routePathToCheck === '/') {
297
- return null;
298
- }
299
- const sortedNodes = multiSortBy(routes, [d => d.routePath.length * -1, d => d.variableName]).filter(d => d.routePath !== `/${rootPathId}`);
300
- for (const route of sortedNodes) {
301
- if (route.routePath === '/') continue;
302
- if (routePathToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routePathToCheck) {
303
- return route;
304
- }
305
- }
306
- const segments = routePathToCheck.split('/');
307
- segments.pop(); // Remove the last segment
308
- const parentRoutePath = segments.join('/');
309
- return hasParentRoute(routes, parentRoutePath);
310
- }
311
-
312
- exports.fileRouteRegex = fileRouteRegex;
313
- exports.generator = generator;
314
- exports.hasParentRoute = hasParentRoute;
315
- exports.multiSortBy = multiSortBy;
316
- exports.removeExt = removeExt;
317
- exports.rootPathId = rootPathId;
318
- //# sourceMappingURL=generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator.js","sources":["../../src/generator.ts"],"sourcesContent":["import path from 'path'\nimport * as fs from 'fs/promises'\nimport * as prettier from 'prettier'\nimport { Config } from './config'\nimport { cleanPath, trimPathLeft } from '@tanstack/react-router'\nimport { existsSync } from 'fs'\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 isErrorComponent?: boolean\n isPendingComponent?: 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, { withFileTypes: true })\n\n dirList = dirList.filter((d) => {\n if (\n d.name.startsWith('.') ||\n (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))\n ) {\n return false\n }\n\n if (routeFilePrefix) {\n return d.name.startsWith(routeFilePrefix)\n }\n\n return true\n })\n\n await Promise.all(\n dirList.map(async (dirent) => {\n const fullPath = path.join(fullDir, dirent.name)\n const relativePath = path.join(dir, dirent.name)\n\n if (dirent.isDirectory()) {\n await recurse(relativePath)\n } else if (fullPath.match(/\\.(tsx|ts|jsx|js)$/)) {\n const filePath = replaceBackslash(path.join(dir, dirent.name))\n const filePathNoExt = removeExt(filePath)\n let routePath =\n cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''\n const variableName = routePathToVariable(routePath)\n\n // Remove the index from the route path and\n // if the route path is empty, use `/'\n\n let isRoute = routePath?.endsWith('/route')\n let isComponent = routePath?.endsWith('/component')\n let isErrorComponent = routePath?.endsWith('/errorComponent')\n let isPendingComponent = routePath?.endsWith('/pendingComponent')\n let isLoader = routePath?.endsWith('/loader')\n\n routePath = routePath?.replace(\n /\\/(component|errorComponent|pendingComponent|loader|route)$/,\n '',\n )\n\n if (routePath === 'index') {\n routePath = '/'\n }\n\n routePath = routePath.replace(/\\/index$/, '/') || '/'\n\n routeNodes.push({\n filePath,\n fullPath,\n routePath,\n variableName,\n isRoute,\n isComponent,\n isErrorComponent,\n isPendingComponent,\n isLoader,\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 errorComponent?: RouteNode\n pendingComponent?: 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 const preRouteNodes = multiSortBy(await getRouteNodes(config), [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),\n (d) =>\n d.filePath?.match(\n /[./](component|errorComponent|pendingComponent|loader)[.]/,\n )\n ? 1\n : -1,\n (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter(\n (d) => ![`/${routePathIdPrefix + rootPathId}`].includes(d.routePath || ''),\n )\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 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 (\n !node.isVirtual &&\n (node.isLoader ||\n node.isComponent ||\n node.isErrorComponent ||\n node.isPendingComponent)\n ) {\n routePiecesByPath[node.routePath!] =\n routePiecesByPath[node.routePath!] || {}\n\n routePiecesByPath[node.routePath!]![\n node.isLoader\n ? 'loader'\n : node.isErrorComponent\n ? 'errorComponent'\n : node.isPendingComponent\n ? 'pendingComponent'\n : 'component'\n ] = node\n\n const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)\n\n if (!anchorRoute) {\n handleNode({\n ...node,\n isVirtual: true,\n isLoader: false,\n isComponent: false,\n isErrorComponent: false,\n isPendingComponent: false,\n })\n }\n return\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 = removeTrailingUnderscores(\n node.routePath?.replaceAll('$', '$$$$') ?? '',\n )\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) =>\n routePiecesByPath[node.routePath!]?.component ||\n routePiecesByPath[node.routePath!]?.errorComponent ||\n routePiecesByPath[node.routePath!]?.pendingComponent,\n ),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n const routeImports = [\n '// This file is auto-generated by TanStack Router',\n imports.length\n ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\\n`\n : '',\n '// Import Routes',\n [\n `import { Route as rootRoute } from './${replaceBackslash(\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 './${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }Import = new FileRoute('${removeTrailingUnderscores(\n node.routePath,\n )}').createRoute()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n sortedRouteNodes\n .map((node) => {\n const loaderNode = routePiecesByPath[node.routePath!]?.loader\n const componentNode = routePiecesByPath[node.routePath!]?.component\n const errorComponentNode =\n routePiecesByPath[node.routePath!]?.errorComponent\n const pendingComponentNode =\n routePiecesByPath[node.routePath!]?.pendingComponent\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('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, loaderNode.filePath),\n ),\n ),\n )}'), 'loader') })`\n : '',\n componentNode || errorComponentNode || pendingComponentNode\n ? `.update({\n ${(\n [\n ['component', componentNode],\n ['errorComponent', errorComponentNode],\n ['pendingComponent', pendingComponentNode],\n ] as const\n )\n .filter((d) => d[1])\n .map((d) => {\n return `${\n d[0]\n }: lazyRouteComponent(() => import('./${replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(config.generatedRouteTree),\n path.resolve(config.routesDirectory, d[1]!.filePath),\n ),\n ),\n )}'), '${d[0]}')`\n })\n .join('\\n,')}\n })`\n : '',\n ].join('')\n })\n .join('\\n\\n'),\n '// Populate the FileRoutesByPath interface',\n `declare module '@tanstack/react-router' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n return `'${removeTrailingUnderscores(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 '// Create and export the route tree',\n `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const routeConfigFileContent = await prettier.format(routeImports, {\n semi: false,\n singleQuote: config.quoteStyle === 'single',\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.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {\n recursive: true,\n })\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 routePathToVariable(d: string): string {\n return (\n removeUnderscores(d)\n ?.replace(/\\/\\$\\//g, '/splat/')\n ?.replace(/\\$$/g, 'splat')\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 removeUnderscores(s?: string) {\n return s?.replace(/(^_|_$)/, '').replace(/(\\/_|_\\/)/, '/')\n}\n\nfunction removeTrailingUnderscores(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","withFileTypes","filter","d","name","startsWith","Promise","all","map","dirent","fullPath","join","relativePath","isDirectory","match","filePath","replaceBackslash","filePathNoExt","removeExt","routePath","cleanPath","split","variableName","routePathToVariable","isRoute","endsWith","isComponent","isErrorComponent","isPendingComponent","isLoader","replace","push","first","skipMessage","generator","console","log","taskId","checkLatest","start","Date","now","routePathIdPrefix","preRouteNodes","multiSortBy","length","includes","routeTree","routePiecesByPath","handleNode","node","parentRoute","hasParentRoute","parent","trimmedPath","trimPathLeft","isNonPath","isNonLayout","cleanedPath","removeUnderscores","isVirtual","anchorRoute","find","children","forEach","buildRouteConfig","nodes","depth","routeCode","readFile","isRoot","escapedRoutePath","removeTrailingUnderscores","replaceAll","quote","quoteStyle","replaced","writeFile","route","childConfigs","spaces","Boolean","routeConfigChildrenText","sortedRouteNodes","imports","Object","entries","FileRoute","some","lazyFn","loader","lazyRouteComponent","component","errorComponent","pendingComponent","virtualRouteNodes","routeImports","relative","dirname","generatedRouteTree","loaderNode","componentNode","errorComponentNode","pendingComponentNode","routeNode","routeConfigFileContent","prettier","format","semi","singleQuote","parser","routeTreeContent","catch","err","code","undefined","mkdir","recursive","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAIA,UAAU,GAAG,CAAC,CAAA;AACX,MAAMC,UAAU,GAAG,SAAQ;AAC3B,MAAMC,cAAc,GAAG,8BAA6B;AAsB3D,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,EAAE;AAAEO,MAAAA,aAAa,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAEhEH,IAAAA,OAAO,GAAGA,OAAO,CAACI,MAAM,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AAAA,EAAAA,UAAW,EAAC,CAAC,CAAA;AAElD,EAAA,KAAK,MAAM6F,KAAK,IAAI8D,WAAW,EAAE;AAC/B,IAAA,IAAI9D,KAAK,CAAC3D,SAAS,KAAK,GAAG,EAAE,SAAA;AAE7B,IAAA,IACEwH,gBAAgB,CAACtI,UAAU,CAAE,CAAA,EAAEyE,KAAK,CAAC3D,SAAU,CAAE,CAAA,CAAA,CAAC,IAClD2D,KAAK,CAAC3D,SAAS,KAAKwH,gBAAgB,EACpC;AACA,MAAA,OAAO7D,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,MAAM+D,QAAQ,GAAGF,gBAAgB,CAACtH,KAAK,CAAC,GAAG,CAAC,CAAA;AAC5CwH,EAAAA,QAAQ,CAACC,GAAG,EAAE,CAAC;AACf,EAAA,MAAMC,eAAe,GAAGF,QAAQ,CAAClI,IAAI,CAAC,GAAG,CAAC,CAAA;AAE1C,EAAA,OAAOyC,cAAc,CAACsF,MAAM,EAAEK,eAAe,CAAC,CAAA;AAChD;;;;;;;;;"}
@@ -1,22 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const configSchema: z.ZodObject<{
3
- routeFilePrefix: z.ZodOptional<z.ZodString>;
4
- routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
5
- routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
6
- generatedRouteTree: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
- quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
8
- }, "strip", z.ZodTypeAny, {
9
- routeFileIgnorePrefix: string;
10
- routesDirectory: string;
11
- generatedRouteTree: string;
12
- quoteStyle: "single" | "double";
13
- routeFilePrefix?: string | undefined;
14
- }, {
15
- routeFilePrefix?: string | undefined;
16
- routeFileIgnorePrefix?: string | undefined;
17
- routesDirectory?: string | undefined;
18
- generatedRouteTree?: string | undefined;
19
- quoteStyle?: "single" | "double" | undefined;
20
- }>;
21
- export type Config = z.infer<typeof configSchema>;
22
- export declare function getConfig(): Promise<Config>;
@@ -1,26 +0,0 @@
1
- import { Config } from './config';
2
- export declare const rootPathId = "__root";
3
- export declare const fileRouteRegex: RegExp;
4
- export type RouteNode = {
5
- filePath: string;
6
- fullPath: string;
7
- variableName: string;
8
- routePath?: string;
9
- cleanedPath?: string;
10
- path?: string;
11
- isNonPath?: boolean;
12
- isNonLayout?: boolean;
13
- isRoute?: boolean;
14
- isLoader?: boolean;
15
- isComponent?: boolean;
16
- isErrorComponent?: boolean;
17
- isPendingComponent?: boolean;
18
- isVirtual?: boolean;
19
- isRoot?: boolean;
20
- children?: RouteNode[];
21
- parent?: RouteNode;
22
- };
23
- export declare function generator(config: Config): Promise<void>;
24
- export declare function removeExt(d: string): string;
25
- export declare function multiSortBy<T>(arr: T[], accessors?: ((item: T) => any)[]): T[];
26
- export declare function hasParentRoute(routes: RouteNode[], routePathToCheck: string | undefined): RouteNode | null;
package/src/config.ts DELETED
@@ -1,27 +0,0 @@
1
- import path from 'path'
2
- import { readFileSync, existsSync } from 'fs'
3
- import { z } from 'zod'
4
-
5
- export const configSchema = z.object({
6
- routeFilePrefix: z.string().optional(),
7
- routeFileIgnorePrefix: z.string().optional().default('-'),
8
- routesDirectory: z.string().optional().default('./src/routes'),
9
- generatedRouteTree: z.string().optional().default('./src/routeTree.gen.ts'),
10
- quoteStyle: z.enum(['single', 'double']).optional().default('single'),
11
- })
12
-
13
- export type Config = z.infer<typeof configSchema>
14
-
15
- const configFilePathJson = path.resolve(process.cwd(), 'tsr.config.json')
16
-
17
- export async function getConfig(): Promise<Config> {
18
- const exists = existsSync(configFilePathJson)
19
-
20
- if (exists) {
21
- return configSchema.parse(
22
- JSON.parse(readFileSync(configFilePathJson, 'utf-8')),
23
- )
24
- }
25
-
26
- return configSchema.parse({})
27
- }
package/src/generator.ts DELETED
@@ -1,560 +0,0 @@
1
- import path from 'path'
2
- import * as fs from 'fs/promises'
3
- import * as prettier from 'prettier'
4
- import { Config } from './config'
5
- import { cleanPath, trimPathLeft } from '@tanstack/react-router'
6
- import { existsSync } from 'fs'
7
-
8
- let latestTask = 0
9
- export const rootPathId = '__root'
10
- export const fileRouteRegex = /new\s+FileRoute\(([^)]*)\)/g
11
-
12
- export type RouteNode = {
13
- filePath: string
14
- fullPath: string
15
- variableName: string
16
- routePath?: string
17
- cleanedPath?: string
18
- path?: string
19
- isNonPath?: boolean
20
- isNonLayout?: boolean
21
- isRoute?: boolean
22
- isLoader?: boolean
23
- isComponent?: boolean
24
- isErrorComponent?: boolean
25
- isPendingComponent?: boolean
26
- isVirtual?: boolean
27
- isRoot?: boolean
28
- children?: RouteNode[]
29
- parent?: RouteNode
30
- }
31
-
32
- async function getRouteNodes(config: Config) {
33
- const { routeFilePrefix, routeFileIgnorePrefix } = config
34
-
35
- let routeNodes: RouteNode[] = []
36
-
37
- async function recurse(dir: string) {
38
- const fullDir = path.resolve(config.routesDirectory, dir)
39
- let dirList = await fs.readdir(fullDir, { withFileTypes: true })
40
-
41
- dirList = dirList.filter((d) => {
42
- if (
43
- d.name.startsWith('.') ||
44
- (routeFileIgnorePrefix && d.name.startsWith(routeFileIgnorePrefix))
45
- ) {
46
- return false
47
- }
48
-
49
- if (routeFilePrefix) {
50
- return d.name.startsWith(routeFilePrefix)
51
- }
52
-
53
- return true
54
- })
55
-
56
- await Promise.all(
57
- dirList.map(async (dirent) => {
58
- const fullPath = path.join(fullDir, dirent.name)
59
- const relativePath = path.join(dir, dirent.name)
60
-
61
- if (dirent.isDirectory()) {
62
- await recurse(relativePath)
63
- } else if (fullPath.match(/\.(tsx|ts|jsx|js)$/)) {
64
- const filePath = replaceBackslash(path.join(dir, dirent.name))
65
- const filePathNoExt = removeExt(filePath)
66
- let routePath =
67
- cleanPath(`/${filePathNoExt.split('.').join('/')}`) || ''
68
- const variableName = routePathToVariable(routePath)
69
-
70
- // Remove the index from the route path and
71
- // if the route path is empty, use `/'
72
-
73
- let isRoute = routePath?.endsWith('/route')
74
- let isComponent = routePath?.endsWith('/component')
75
- let isErrorComponent = routePath?.endsWith('/errorComponent')
76
- let isPendingComponent = routePath?.endsWith('/pendingComponent')
77
- let isLoader = routePath?.endsWith('/loader')
78
-
79
- routePath = routePath?.replace(
80
- /\/(component|errorComponent|pendingComponent|loader|route)$/,
81
- '',
82
- )
83
-
84
- if (routePath === 'index') {
85
- routePath = '/'
86
- }
87
-
88
- routePath = routePath.replace(/\/index$/, '/') || '/'
89
-
90
- routeNodes.push({
91
- filePath,
92
- fullPath,
93
- routePath,
94
- variableName,
95
- isRoute,
96
- isComponent,
97
- isErrorComponent,
98
- isPendingComponent,
99
- isLoader,
100
- })
101
- }
102
- }),
103
- )
104
-
105
- return routeNodes
106
- }
107
-
108
- await recurse('./')
109
-
110
- return routeNodes
111
- }
112
-
113
- let first = false
114
- let skipMessage = false
115
-
116
- type RouteSubNode = {
117
- component?: RouteNode
118
- errorComponent?: RouteNode
119
- pendingComponent?: RouteNode
120
- loader?: RouteNode
121
- }
122
-
123
- export async function generator(config: Config) {
124
- console.log()
125
-
126
- if (!first) {
127
- console.log('🔄 Generating routes...')
128
- first = true
129
- } else if (skipMessage) {
130
- skipMessage = false
131
- } else {
132
- console.log('♻️ Regenerating routes...')
133
- }
134
-
135
- const taskId = latestTask + 1
136
- latestTask = taskId
137
-
138
- const checkLatest = () => {
139
- if (latestTask !== taskId) {
140
- skipMessage = true
141
- return false
142
- }
143
-
144
- return true
145
- }
146
-
147
- const start = Date.now()
148
- const routePathIdPrefix = config.routeFilePrefix ?? ''
149
-
150
- const preRouteNodes = multiSortBy(await getRouteNodes(config), [
151
- (d) => (d.routePath === '/' ? -1 : 1),
152
- (d) => d.routePath?.split('/').length,
153
- (d) => (d.filePath?.match(/[./]index[.]/) ? 1 : -1),
154
- (d) =>
155
- d.filePath?.match(
156
- /[./](component|errorComponent|pendingComponent|loader)[.]/,
157
- )
158
- ? 1
159
- : -1,
160
- (d) => (d.filePath?.match(/[./]route[.]/) ? -1 : 1),
161
- (d) => (d.routePath?.endsWith('/') ? -1 : 1),
162
- (d) => d.routePath,
163
- ]).filter(
164
- (d) => ![`/${routePathIdPrefix + rootPathId}`].includes(d.routePath || ''),
165
- )
166
-
167
- const routeTree: RouteNode[] = []
168
- const routePiecesByPath: Record<string, RouteSubNode> = {}
169
-
170
- // Loop over the flat list of routeNodes and
171
- // build up a tree based on the routeNodes' routePath
172
- let routeNodes: RouteNode[] = []
173
-
174
- const handleNode = (node: RouteNode) => {
175
- const parentRoute = hasParentRoute(routeNodes, node.routePath)
176
- if (parentRoute) node.parent = parentRoute
177
-
178
- node.path = node.parent
179
- ? node.routePath?.replace(node.parent.routePath!, '') || '/'
180
- : node.routePath
181
-
182
- const trimmedPath = trimPathLeft(node.path ?? '')
183
-
184
- const split = trimmedPath?.split('/') ?? []
185
- let first = split[0] ?? trimmedPath ?? ''
186
-
187
- node.isNonPath = first.startsWith('_')
188
- node.isNonLayout = first.endsWith('_')
189
-
190
- node.cleanedPath = removeUnderscores(node.path) ?? ''
191
-
192
- if (
193
- !node.isVirtual &&
194
- (node.isLoader ||
195
- node.isComponent ||
196
- node.isErrorComponent ||
197
- node.isPendingComponent)
198
- ) {
199
- routePiecesByPath[node.routePath!] =
200
- routePiecesByPath[node.routePath!] || {}
201
-
202
- routePiecesByPath[node.routePath!]![
203
- node.isLoader
204
- ? 'loader'
205
- : node.isErrorComponent
206
- ? 'errorComponent'
207
- : node.isPendingComponent
208
- ? 'pendingComponent'
209
- : 'component'
210
- ] = node
211
-
212
- const anchorRoute = routeNodes.find((d) => d.routePath === node.routePath)
213
-
214
- if (!anchorRoute) {
215
- handleNode({
216
- ...node,
217
- isVirtual: true,
218
- isLoader: false,
219
- isComponent: false,
220
- isErrorComponent: false,
221
- isPendingComponent: false,
222
- })
223
- }
224
- return
225
- }
226
-
227
- if (node.parent) {
228
- node.parent.children = node.parent.children ?? []
229
- node.parent.children.push(node)
230
- } else {
231
- routeTree.push(node)
232
- }
233
-
234
- routeNodes.push(node)
235
- }
236
-
237
- preRouteNodes.forEach((node) => handleNode(node))
238
-
239
- async function buildRouteConfig(
240
- nodes: RouteNode[],
241
- depth = 1,
242
- ): Promise<string> {
243
- const children = nodes.map(async (node) => {
244
- const routeCode = await fs.readFile(node.fullPath, 'utf-8')
245
-
246
- // Ensure the boilerplate for the route exists
247
- if (node.isRoot) {
248
- return
249
- }
250
-
251
- // Ensure that new FileRoute(anything?) is replaced with FileRoute(${node.routePath})
252
- // routePath can contain $ characters, which have special meaning when used in replace
253
- // so we have to escape it by turning all $ into $$. But since we do it through a replace call
254
- // we have to double escape it into $$$$. For more information, see
255
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement
256
- const escapedRoutePath = removeTrailingUnderscores(
257
- node.routePath?.replaceAll('$', '$$$$') ?? '',
258
- )
259
- const quote = config.quoteStyle === 'single' ? `'` : `"`
260
- const replaced = routeCode.replace(
261
- fileRouteRegex,
262
- `new FileRoute(${quote}${escapedRoutePath}${quote})`,
263
- )
264
-
265
- if (replaced !== routeCode) {
266
- await fs.writeFile(node.fullPath, replaced)
267
- }
268
-
269
- const route = `${node.variableName}Route`
270
-
271
- if (node.children?.length) {
272
- const childConfigs = await buildRouteConfig(node.children, depth + 1)
273
- return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`
274
- }
275
-
276
- return route
277
- })
278
-
279
- return (await Promise.all(children)).filter(Boolean).join(`,`)
280
- }
281
-
282
- const routeConfigChildrenText = await buildRouteConfig(routeTree)
283
-
284
- const sortedRouteNodes = multiSortBy(routeNodes, [
285
- (d) =>
286
- d.routePath?.includes(`/${routePathIdPrefix + rootPathId}`) ? -1 : 1,
287
- (d) => d.routePath?.split('/').length,
288
- (d) => (d.routePath?.endsWith("index'") ? -1 : 1),
289
- (d) => d,
290
- ])
291
-
292
- const imports = Object.entries({
293
- FileRoute: sortedRouteNodes.some((d) => d.isVirtual),
294
- lazyFn: sortedRouteNodes.some(
295
- (node) => routePiecesByPath[node.routePath!]?.loader,
296
- ),
297
- lazyRouteComponent: sortedRouteNodes.some(
298
- (node) =>
299
- routePiecesByPath[node.routePath!]?.component ||
300
- routePiecesByPath[node.routePath!]?.errorComponent ||
301
- routePiecesByPath[node.routePath!]?.pendingComponent,
302
- ),
303
- })
304
- .filter((d) => d[1])
305
- .map((d) => d[0])
306
-
307
- const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)
308
-
309
- const routeImports = [
310
- '// This file is auto-generated by TanStack Router',
311
- imports.length
312
- ? `import { ${imports.join(', ')} } from '@tanstack/react-router'\n`
313
- : '',
314
- '// Import Routes',
315
- [
316
- `import { Route as rootRoute } from './${replaceBackslash(
317
- path.relative(
318
- path.dirname(config.generatedRouteTree),
319
- path.resolve(config.routesDirectory, routePathIdPrefix + rootPathId),
320
- ),
321
- )}'`,
322
- ...sortedRouteNodes
323
- .filter((d) => !d.isVirtual)
324
- .map((node) => {
325
- return `import { Route as ${
326
- node.variableName
327
- }Import } from './${replaceBackslash(
328
- removeExt(
329
- path.relative(
330
- path.dirname(config.generatedRouteTree),
331
- path.resolve(config.routesDirectory, node.filePath),
332
- ),
333
- ),
334
- )}'`
335
- }),
336
- ].join('\n'),
337
- virtualRouteNodes.length ? '// Create Virtual Routes' : '',
338
- virtualRouteNodes
339
- .map((node) => {
340
- return `const ${
341
- node.variableName
342
- }Import = new FileRoute('${removeTrailingUnderscores(
343
- node.routePath,
344
- )}').createRoute()`
345
- })
346
- .join('\n'),
347
- '// Create/Update Routes',
348
- sortedRouteNodes
349
- .map((node) => {
350
- const loaderNode = routePiecesByPath[node.routePath!]?.loader
351
- const componentNode = routePiecesByPath[node.routePath!]?.component
352
- const errorComponentNode =
353
- routePiecesByPath[node.routePath!]?.errorComponent
354
- const pendingComponentNode =
355
- routePiecesByPath[node.routePath!]?.pendingComponent
356
-
357
- return [
358
- `const ${node.variableName}Route = ${node.variableName}Import.update({
359
- ${[
360
- node.isNonPath
361
- ? `id: '${node.path}'`
362
- : `path: '${node.cleanedPath}'`,
363
- `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,
364
- ]
365
- .filter(Boolean)
366
- .join(',')}
367
- } as any)`,
368
- loaderNode
369
- ? `.updateLoader({ loader: lazyFn(() => import('./${replaceBackslash(
370
- removeExt(
371
- path.relative(
372
- path.dirname(config.generatedRouteTree),
373
- path.resolve(config.routesDirectory, loaderNode.filePath),
374
- ),
375
- ),
376
- )}'), 'loader') })`
377
- : '',
378
- componentNode || errorComponentNode || pendingComponentNode
379
- ? `.update({
380
- ${(
381
- [
382
- ['component', componentNode],
383
- ['errorComponent', errorComponentNode],
384
- ['pendingComponent', pendingComponentNode],
385
- ] as const
386
- )
387
- .filter((d) => d[1])
388
- .map((d) => {
389
- return `${
390
- d[0]
391
- }: lazyRouteComponent(() => import('./${replaceBackslash(
392
- removeExt(
393
- path.relative(
394
- path.dirname(config.generatedRouteTree),
395
- path.resolve(config.routesDirectory, d[1]!.filePath),
396
- ),
397
- ),
398
- )}'), '${d[0]}')`
399
- })
400
- .join('\n,')}
401
- })`
402
- : '',
403
- ].join('')
404
- })
405
- .join('\n\n'),
406
- '// Populate the FileRoutesByPath interface',
407
- `declare module '@tanstack/react-router' {
408
- interface FileRoutesByPath {
409
- ${routeNodes
410
- .map((routeNode) => {
411
- return `'${removeTrailingUnderscores(routeNode.routePath)}': {
412
- preLoaderRoute: typeof ${routeNode.variableName}Import
413
- parentRoute: typeof ${
414
- routeNode.parent?.variableName
415
- ? `${routeNode.parent?.variableName}Import`
416
- : 'rootRoute'
417
- }
418
- }`
419
- })
420
- .join('\n')}
421
- }
422
- }`,
423
- '// Create and export the route tree',
424
- `export const routeTree = rootRoute.addChildren([${routeConfigChildrenText}])`,
425
- ]
426
- .filter(Boolean)
427
- .join('\n\n')
428
-
429
- const routeConfigFileContent = await prettier.format(routeImports, {
430
- semi: false,
431
- singleQuote: config.quoteStyle === 'single',
432
- parser: 'typescript',
433
- })
434
-
435
- const routeTreeContent = await fs
436
- .readFile(path.resolve(config.generatedRouteTree), 'utf-8')
437
- .catch((err: any) => {
438
- if (err.code === 'ENOENT') {
439
- return undefined
440
- }
441
- throw err
442
- })
443
-
444
- if (!checkLatest()) return
445
-
446
- if (routeTreeContent !== routeConfigFileContent) {
447
- await fs.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), {
448
- recursive: true,
449
- })
450
- if (!checkLatest()) return
451
- await fs.writeFile(
452
- path.resolve(config.generatedRouteTree),
453
- routeConfigFileContent,
454
- )
455
- }
456
-
457
- console.log(
458
- `🌲 Processed ${routeNodes.length} routes in ${Date.now() - start}ms`,
459
- )
460
- }
461
-
462
- function routePathToVariable(d: string): string {
463
- return (
464
- removeUnderscores(d)
465
- ?.replace(/\/\$\//g, '/splat/')
466
- ?.replace(/\$$/g, 'splat')
467
- ?.replace(/\$/g, '')
468
- ?.split(/[/-]/g)
469
- .map((d, i) => (i > 0 ? capitalize(d) : d))
470
- .join('')
471
- .replace(/([^a-zA-Z0-9]|[\.])/gm, '') ?? ''
472
- )
473
- }
474
-
475
- export function removeExt(d: string) {
476
- return d.substring(0, d.lastIndexOf('.')) || d
477
- }
478
-
479
- function spaces(d: number): string {
480
- return Array.from({ length: d })
481
- .map(() => ' ')
482
- .join('')
483
- }
484
-
485
- export function multiSortBy<T>(
486
- arr: T[],
487
- accessors: ((item: T) => any)[] = [(d) => d],
488
- ): T[] {
489
- return arr
490
- .map((d, i) => [d, i] as const)
491
- .sort(([a, ai], [b, bi]) => {
492
- for (const accessor of accessors) {
493
- const ao = accessor(a)
494
- const bo = accessor(b)
495
-
496
- if (typeof ao === 'undefined') {
497
- if (typeof bo === 'undefined') {
498
- continue
499
- }
500
- return 1
501
- }
502
-
503
- if (ao === bo) {
504
- continue
505
- }
506
-
507
- return ao > bo ? 1 : -1
508
- }
509
-
510
- return ai - bi
511
- })
512
- .map(([d]) => d)
513
- }
514
-
515
- function capitalize(s: string) {
516
- if (typeof s !== 'string') return ''
517
- return s.charAt(0).toUpperCase() + s.slice(1)
518
- }
519
-
520
- function removeUnderscores(s?: string) {
521
- return s?.replace(/(^_|_$)/, '').replace(/(\/_|_\/)/, '/')
522
- }
523
-
524
- function removeTrailingUnderscores(s?: string) {
525
- return s?.replace(/(_$)/, '').replace(/(_\/)/, '/')
526
- }
527
-
528
- function replaceBackslash(s: string) {
529
- return s.replace(/\\/gi, '/')
530
- }
531
-
532
- export function hasParentRoute(
533
- routes: RouteNode[],
534
- routePathToCheck: string | undefined,
535
- ): RouteNode | null {
536
- if (!routePathToCheck || routePathToCheck === '/') {
537
- return null
538
- }
539
-
540
- const sortedNodes = multiSortBy(routes, [
541
- (d) => d.routePath!.length * -1,
542
- (d) => d.variableName,
543
- ]).filter((d) => d.routePath !== `/${rootPathId}`)
544
-
545
- for (const route of sortedNodes) {
546
- if (route.routePath === '/') continue
547
-
548
- if (
549
- routePathToCheck.startsWith(`${route.routePath}/`) &&
550
- route.routePath !== routePathToCheck
551
- ) {
552
- return route
553
- }
554
- }
555
- const segments = routePathToCheck.split('/')
556
- segments.pop() // Remove the last segment
557
- const parentRoutePath = segments.join('/')
558
-
559
- return hasParentRoute(routes, parentRoutePath)
560
- }