ts-file-router 2.0.2 → 3.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 +2 -2
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +29 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/vite.d.ts +4 -0
- package/dist/plugins/vite.d.ts.map +1 -0
- package/dist/plugins/vite.js +14 -0
- package/dist/serialize.d.ts.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/generatorWatcher.d.ts +0 -3
- package/dist/generatorWatcher.d.ts.map +0 -1
- package/dist/generatorWatcher.js +0 -21
- package/dist/plugin.d.ts +0 -4
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -13
package/dist/generator.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TGenerateRoutesConfig } from './types.js';
|
|
2
|
-
export declare const generateRoutes: ({ baseFolder, outputFile, routeFileName,
|
|
1
|
+
import type { TGenerateRoutesConfig } from './types.js';
|
|
2
|
+
export declare const generateRoutes: ({ baseFolder, outputFile, routeFileName, options, }: TGenerateRoutesConfig) => void;
|
|
3
3
|
//# sourceMappingURL=generator.d.ts.map
|
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"
|
|
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,SAyHvB,CAAC"}
|
package/dist/generator.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { serialize } from './serialize.js';
|
|
4
|
-
export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.tsx',
|
|
4
|
+
export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.tsx', options = { exitCodeOnResolution: true }, }) => {
|
|
5
5
|
// Get the pages dir to resolve routes
|
|
6
6
|
const basePath = path.resolve(process.cwd(), baseFolder);
|
|
7
7
|
// Output file for routes
|
|
@@ -52,18 +52,44 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
52
52
|
serialize(routes, output);
|
|
53
53
|
// Promise writeFile was successfully resolved
|
|
54
54
|
console.log('🚀 Routes generated successfully!\n');
|
|
55
|
-
if (exitCodeOnResolution) {
|
|
55
|
+
if (options.exitCodeOnResolution) {
|
|
56
56
|
// Code 0 to finish the process as success
|
|
57
57
|
process.exit(0);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
catch (err) {
|
|
61
61
|
console.error('❌ Error generating routes:\n', err);
|
|
62
|
-
if (exitCodeOnResolution) {
|
|
62
|
+
if (options.exitCodeOnResolution) {
|
|
63
63
|
// Code 1 to finish the process as error
|
|
64
64
|
process.exit(1);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
const watcher = async ({ debounce = 500 }) => {
|
|
69
|
+
const { watch } = await import('chokidar');
|
|
70
|
+
let timeoutId;
|
|
71
|
+
const watcher = watch(baseFolder, {
|
|
72
|
+
ignoreInitial: true,
|
|
73
|
+
ignored: `${baseFolder}/${outputFile}`,
|
|
74
|
+
persistent: true,
|
|
75
|
+
});
|
|
76
|
+
console.log(`👀 Watching folder: ${baseFolder} for changes...`);
|
|
77
|
+
const runFromWatcher = () => {
|
|
78
|
+
if (timeoutId) {
|
|
79
|
+
clearTimeout(timeoutId);
|
|
80
|
+
}
|
|
81
|
+
timeoutId = setTimeout(() => {
|
|
82
|
+
createRoutes();
|
|
83
|
+
}, debounce);
|
|
84
|
+
};
|
|
85
|
+
watcher.on('add', runFromWatcher);
|
|
86
|
+
watcher.on('unlink', runFromWatcher);
|
|
87
|
+
watcher.on('unlinkDir', runFromWatcher);
|
|
88
|
+
return () => watcher.close();
|
|
89
|
+
};
|
|
90
|
+
if (!!options.watcher) {
|
|
91
|
+
watcher(options.watcher);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
68
94
|
createRoutes();
|
|
69
95
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export { generateRoutes } from './generator.js';
|
|
2
|
-
export {
|
|
3
|
-
export { generateRoutesPlugin } from './plugin.js';
|
|
4
|
-
export { TGenerateRoutesConfig } from './types.js';
|
|
2
|
+
export { generateRoutesPlugin } from './plugins/index.js';
|
|
5
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vite.js';
|
|
@@ -0,0 +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,sCAIlC,qBAAqB,KAAG,MAY1B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generateRoutes } from '../generator.js';
|
|
2
|
+
export const generateRoutesPlugin = ({ baseFolder, outputFile, options = { watcher: { debounce: 500 }, exitCodeOnResolution: false }, }) => {
|
|
3
|
+
return {
|
|
4
|
+
name: 'file-router-plugin',
|
|
5
|
+
apply: 'serve',
|
|
6
|
+
buildStart() {
|
|
7
|
+
generateRoutes({
|
|
8
|
+
baseFolder,
|
|
9
|
+
outputFile,
|
|
10
|
+
options,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
package/dist/serialize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsB9C,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,YAAY,MAAM,SAMhE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
type
|
|
1
|
+
type TWatcherConfig = {
|
|
2
2
|
debounce?: number;
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type TGenerateRoutesOptions = {
|
|
5
|
+
watcher?: TWatcherConfig;
|
|
6
|
+
exitCodeOnResolution?: boolean;
|
|
7
7
|
};
|
|
8
8
|
export type TGenerateRoutesConfig = {
|
|
9
9
|
baseFolder: string;
|
|
10
10
|
outputFile: string;
|
|
11
11
|
routeFileName?: string;
|
|
12
|
-
|
|
12
|
+
options?: TGenerateRoutesOptions;
|
|
13
13
|
};
|
|
14
14
|
export type TRoute = {
|
|
15
15
|
path: string;
|
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,
|
|
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,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;CACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generatorWatcher.d.ts","sourceRoot":"","sources":["../src/generatorWatcher.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,yBAAyB,GAAU,qBAG7C,cAAc,iCA0BhB,CAAC"}
|
package/dist/generatorWatcher.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { generateRoutes } from './generator.js';
|
|
2
|
-
export const generateRoutesWithWatcher = async ({ input, options = { debounce: 500 }, }) => {
|
|
3
|
-
const { watch } = await import('chokidar');
|
|
4
|
-
let timeoutId;
|
|
5
|
-
const runFromWatcher = () => {
|
|
6
|
-
if (timeoutId) {
|
|
7
|
-
clearTimeout(timeoutId);
|
|
8
|
-
}
|
|
9
|
-
timeoutId = setTimeout(() => {
|
|
10
|
-
generateRoutes(input);
|
|
11
|
-
}, options.debounce);
|
|
12
|
-
};
|
|
13
|
-
const watcher = watch(input.baseFolder, {
|
|
14
|
-
ignoreInitial: true,
|
|
15
|
-
ignored: `${input.baseFolder}/${input.outputFile}`,
|
|
16
|
-
persistent: true,
|
|
17
|
-
});
|
|
18
|
-
console.log(`👀 Watching folder: ${input.baseFolder} for changes...`);
|
|
19
|
-
watcher.on('add', runFromWatcher);
|
|
20
|
-
return () => watcher.close();
|
|
21
|
-
};
|
package/dist/plugin.d.ts
DELETED
package/dist/plugin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,eAAO,MAAM,oBAAoB,GAAI,mDAIlC,qBAAqB,KAAG,MAW1B,CAAC"}
|
package/dist/plugin.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { generateRoutesWithWatcher } from './generatorWatcher.js';
|
|
2
|
-
export const generateRoutesPlugin = ({ baseFolder, outputFile, exitCodeOnResolution = false, }) => {
|
|
3
|
-
return {
|
|
4
|
-
name: 'file-router-plugin',
|
|
5
|
-
apply: 'serve',
|
|
6
|
-
buildStart() {
|
|
7
|
-
generateRoutesWithWatcher({
|
|
8
|
-
input: { baseFolder, outputFile, exitCodeOnResolution },
|
|
9
|
-
options: { debounce: 500 },
|
|
10
|
-
});
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
};
|