ts-file-router 4.1.1 → 5.0.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/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +6 -9
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +8 -5
- package/package.json +1 -1
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAgBrE,eAAO,MAAM,cAAc,GAAI,qDAK5B,qBAAqB,SA2IvB,CAAC"}
|
package/dist/generator.js
CHANGED
|
@@ -5,6 +5,7 @@ const getIgnoredOutputFile = (file, output) => file.includes(output);
|
|
|
5
5
|
const getIgnoredFiles = (file, output) => file.includes('index') ||
|
|
6
6
|
file.startsWith('_') ||
|
|
7
7
|
getIgnoredOutputFile(file, output);
|
|
8
|
+
const cleanPaths = (path) => path.replaceAll(/\\/gi, '/').replaceAll(/.(tsx|ts|jsx|js)/gi, '');
|
|
8
9
|
export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.tsx', options = { exitCodeOnResolution: true }, }) => {
|
|
9
10
|
// Get the pages dir to resolve routes
|
|
10
11
|
const basePath = path.resolve(process.cwd(), baseFolder);
|
|
@@ -25,13 +26,9 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
25
26
|
// Get directory info to control file or folder
|
|
26
27
|
const dirInfo = await fs.stat(fullPath);
|
|
27
28
|
// Path to browser sync if necessary
|
|
28
|
-
const relativePath = '/' + path.relative(basePath, dir)
|
|
29
|
+
const relativePath = '/' + path.relative(basePath, dir);
|
|
29
30
|
// Normalize import path to esm pattern
|
|
30
|
-
const importPath = './' +
|
|
31
|
-
path
|
|
32
|
-
.relative(basePath, fullPath)
|
|
33
|
-
.replaceAll(/\\/gi, '/')
|
|
34
|
-
.replaceAll(/.(tsx|ts|jsx|js)/gi, '');
|
|
31
|
+
const importPath = './' + path.relative(basePath, fullPath);
|
|
35
32
|
// Remove extension from file to naming the route
|
|
36
33
|
const key = path.basename(file, path.extname(file));
|
|
37
34
|
if (dirInfo.isDirectory()) {
|
|
@@ -44,8 +41,8 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
44
41
|
// Mount the route object with path like "/folder" and import
|
|
45
42
|
// import will be like "(./baseFolder/file or ./baseFolder/folders).extension"
|
|
46
43
|
routes[key] = {
|
|
47
|
-
path: relativePath,
|
|
48
|
-
import: importPath,
|
|
44
|
+
path: cleanPaths(relativePath),
|
|
45
|
+
import: cleanPaths(importPath),
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
48
|
return routes;
|
|
@@ -104,7 +101,7 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
104
101
|
const ignoredGeneralFiles = getIgnoredFiles(file, outputFile);
|
|
105
102
|
// If added, or change (renamed) or deleted, update routes
|
|
106
103
|
if (watchOnEvents.includes(ev) && !ignoredGeneralFiles) {
|
|
107
|
-
console.log(
|
|
104
|
+
console.log(`🔎 Watching files from path: "${file}" for changes...`);
|
|
108
105
|
runFromWatcher();
|
|
109
106
|
}
|
|
110
107
|
});
|
package/dist/serialize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AAmD1D,eAAO,MAAM,SAAS,GAAU,QAAQ,WAAW,EAAE,YAAY,MAAM,kBActE,CAAC"}
|
package/dist/serialize.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Biome, Distribution } from '@biomejs/js-api';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
+
const isRouteLeaf = (value) => {
|
|
5
|
+
return (typeof value === 'object' &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
'path' in value &&
|
|
8
|
+
'import' in value);
|
|
9
|
+
};
|
|
4
10
|
const stringifyRoutes = (obj) => {
|
|
5
11
|
const entries = Object.entries(obj).map(([key, value]) => {
|
|
6
|
-
if (
|
|
7
|
-
value !== null &&
|
|
8
|
-
'path' in value &&
|
|
9
|
-
'import' in value) {
|
|
12
|
+
if (isRouteLeaf(value)) {
|
|
10
13
|
return `'${key}': {
|
|
11
14
|
path: '${value.path}',
|
|
12
|
-
import:
|
|
15
|
+
import: import('${value.import}')
|
|
13
16
|
}`;
|
|
14
17
|
}
|
|
15
18
|
return `'${key}': ${stringifyRoutes(value)}`;
|