ts-file-router 4.0.0 → 4.0.1
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 -2
- package/dist/plugins/vite.d.ts.map +1 -1
- package/dist/plugins/vite.js +4 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +39 -15
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- 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;AAMrE,eAAO,MAAM,cAAc,GAAI,qDAK5B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAMrE,eAAO,MAAM,cAAc,GAAI,qDAK5B,qBAAqB,SA6HvB,CAAC"}
|
package/dist/generator.js
CHANGED
|
@@ -25,7 +25,11 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
25
25
|
// Path to browser sync if necessary
|
|
26
26
|
const relativePath = '/' + path.relative(basePath, dir).replaceAll(/\\/g, '/');
|
|
27
27
|
// Normalize import path to esm pattern
|
|
28
|
-
const importPath = './' +
|
|
28
|
+
const importPath = './' +
|
|
29
|
+
path
|
|
30
|
+
.relative(basePath, fullPath)
|
|
31
|
+
.replaceAll(/\\/gi, '/')
|
|
32
|
+
.replaceAll(/.(tsx|ts|jsx|js)/gi, '');
|
|
29
33
|
// Remove extension from file to naming the route
|
|
30
34
|
const key = path.basename(file, path.extname(file));
|
|
31
35
|
if (dirInfo.isDirectory()) {
|
|
@@ -49,7 +53,7 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
49
53
|
// Create routes
|
|
50
54
|
const routes = await mapRoutes(basePath);
|
|
51
55
|
// Create ts file
|
|
52
|
-
serialize(routes, output);
|
|
56
|
+
await serialize(routes, output);
|
|
53
57
|
// Promise writeFile was successfully resolved
|
|
54
58
|
console.log('🚀 Routes generated successfully!\n');
|
|
55
59
|
if (options.exitCodeOnResolution) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/plugins/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,eAAO,MAAM,oBAAoB,GAAI,
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/plugins/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,eAAO,MAAM,oBAAoB,GAAI,sCAOlC,qBAAqB,KAAG,MAY1B,CAAC"}
|
package/dist/plugins/vite.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { generateRoutes } from '../generator.js';
|
|
2
|
-
export const generateRoutesPlugin = ({ baseFolder, outputFile, options = {
|
|
2
|
+
export const generateRoutesPlugin = ({ baseFolder, outputFile, options = {
|
|
3
|
+
watcher: { watch: true, debounce: 500 },
|
|
4
|
+
exitCodeOnResolution: false,
|
|
5
|
+
}, }) => {
|
|
3
6
|
return {
|
|
4
7
|
name: 'file-router-plugin',
|
|
5
8
|
apply: 'serve',
|
package/dist/serialize.d.ts
CHANGED
package/dist/serialize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA2C9C,eAAO,MAAM,SAAS,GAAU,QAAQ,WAAW,EAAE,YAAY,MAAM,kBActE,CAAC"}
|
package/dist/serialize.js
CHANGED
|
@@ -1,21 +1,45 @@
|
|
|
1
|
+
import { Biome, Distribution } from '@biomejs/js-api';
|
|
1
2
|
import * as fs from 'node:fs';
|
|
2
3
|
import * as path from 'node:path';
|
|
3
|
-
const
|
|
4
|
-
const spaces = ' '.repeat(indent);
|
|
5
|
-
const innerSpaces = ' '.repeat(indent + 2);
|
|
6
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
7
|
-
return JSON.stringify(obj);
|
|
8
|
-
}
|
|
4
|
+
const stringifyRoutes = (obj) => {
|
|
9
5
|
const entries = Object.entries(obj).map(([key, value]) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
if (typeof value === 'object' &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
'path' in value &&
|
|
9
|
+
'import' in value) {
|
|
10
|
+
return `'${key}': {
|
|
11
|
+
path: '${value.path}',
|
|
12
|
+
import: () => import('${value.import}')
|
|
13
|
+
}`;
|
|
14
|
+
}
|
|
15
|
+
return `'${key}': ${stringifyRoutes(value)}`;
|
|
16
|
+
});
|
|
17
|
+
return `{ ${entries.join(',\n')} }`;
|
|
18
|
+
};
|
|
19
|
+
const format = async (filePath, content) => {
|
|
20
|
+
const biome = await Biome.create({ distribution: Distribution.NODE });
|
|
21
|
+
const project = biome.openProject();
|
|
22
|
+
biome.applyConfiguration(project.projectKey, {
|
|
23
|
+
formatter: { enabled: true, indentStyle: 'space', lineWidth: 100 },
|
|
24
|
+
javascript: { formatter: { quoteStyle: 'single' } },
|
|
14
25
|
});
|
|
15
|
-
|
|
26
|
+
const formatted = biome.formatContent(project.projectKey, content, {
|
|
27
|
+
filePath: path.basename(filePath),
|
|
28
|
+
});
|
|
29
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
30
|
+
fs.writeFileSync(filePath, formatted.content, 'utf8');
|
|
16
31
|
};
|
|
17
|
-
export const serialize = (routes, outputPath) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
export const serialize = async (routes, outputPath) => {
|
|
33
|
+
const rawCode = `
|
|
34
|
+
// GENERATED WITH TS-FILE-ROUTER DO NOT EDIT
|
|
35
|
+
|
|
36
|
+
export const routes = ${stringifyRoutes(routes)} as const;
|
|
37
|
+
\n`;
|
|
38
|
+
try {
|
|
39
|
+
await format(path.resolve(outputPath), rawCode);
|
|
40
|
+
console.log('✨ File was parsed succesfully');
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.error('❌ Error parsing file:\n', err);
|
|
44
|
+
}
|
|
21
45
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
type TWatcherConfig = {
|
|
2
|
+
watch: boolean;
|
|
2
3
|
debounce?: number;
|
|
3
4
|
};
|
|
4
5
|
type TGenerateRoutesOptions = {
|
|
@@ -11,12 +12,12 @@ export type TGenerateRoutesConfig = {
|
|
|
11
12
|
routeFileName?: string;
|
|
12
13
|
options?: TGenerateRoutesOptions;
|
|
13
14
|
};
|
|
14
|
-
export type
|
|
15
|
+
export type TRouteLeaf = {
|
|
15
16
|
path: string;
|
|
16
17
|
import: string;
|
|
17
18
|
};
|
|
18
19
|
export type TRoutesTree = {
|
|
19
|
-
[key: string]:
|
|
20
|
+
[key: string]: TRouteLeaf | TRoutesTree;
|
|
20
21
|
};
|
|
21
22
|
export {};
|
|
22
23
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,CAAC;CACzC,CAAC"}
|