ts-file-router 4.1.0 → 4.1.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 +12 -10
- package/package.json +3 -2
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;AAarE,eAAO,MAAM,cAAc,GAAI,qDAK5B,qBAAqB,SAiJvB,CAAC"}
|
package/dist/generator.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { serialize } from './serialize.js';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
const getIgnoredOutputFile = (file, output) => file.includes(output);
|
|
5
|
+
const getIgnoredFiles = (file, output) => file.includes('index') ||
|
|
6
|
+
file.startsWith('_') ||
|
|
7
|
+
getIgnoredOutputFile(file, output);
|
|
4
8
|
export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.tsx', options = { exitCodeOnResolution: true }, }) => {
|
|
5
9
|
// Get the pages dir to resolve routes
|
|
6
10
|
const basePath = path.resolve(process.cwd(), baseFolder);
|
|
@@ -14,9 +18,7 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
14
18
|
}
|
|
15
19
|
for (const file of directory) {
|
|
16
20
|
// ignore index files, underscore marked, or route file generated
|
|
17
|
-
if (file
|
|
18
|
-
file.startsWith('_') ||
|
|
19
|
-
file.includes(outputFile)) {
|
|
21
|
+
if (getIgnoredFiles(file, outputFile)) {
|
|
20
22
|
continue;
|
|
21
23
|
}
|
|
22
24
|
const fullPath = path.join(dir, file);
|
|
@@ -71,26 +73,24 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
71
73
|
};
|
|
72
74
|
const watcher = async ({ debounce = 500 }) => {
|
|
73
75
|
const { watch } = await import('chokidar');
|
|
74
|
-
const output = path.resolve(baseFolder, outputFile);
|
|
75
76
|
let timeoutId;
|
|
76
77
|
const watcher = watch(baseFolder, {
|
|
77
78
|
ignoreInitial: false,
|
|
78
79
|
persistent: true,
|
|
79
80
|
});
|
|
80
|
-
console.log(`👀 Watching folder: ${baseFolder} for changes...`);
|
|
81
|
+
console.log(`👀 Watching folder: "${baseFolder}" for changes...`);
|
|
81
82
|
const runFromWatcher = () => {
|
|
82
83
|
if (timeoutId) {
|
|
83
84
|
clearTimeout(timeoutId);
|
|
84
85
|
}
|
|
85
86
|
timeoutId = setTimeout(() => {
|
|
86
|
-
console.log(`👀 Files changed, regenerating routes...`);
|
|
87
87
|
createRoutes();
|
|
88
88
|
}, debounce);
|
|
89
89
|
};
|
|
90
90
|
watcher.on('all', (ev, file) => {
|
|
91
|
-
const
|
|
91
|
+
const ignoredOuput = getIgnoredOutputFile(file, outputFile);
|
|
92
92
|
// If output file as deleted regenerate it
|
|
93
|
-
if (
|
|
93
|
+
if (ignoredOuput && ev === 'unlink') {
|
|
94
94
|
console.log(`🚨 ${outputFile} was deleted, regenerating...`);
|
|
95
95
|
runFromWatcher();
|
|
96
96
|
return;
|
|
@@ -101,8 +101,10 @@ export const generateRoutes = ({ baseFolder, outputFile, routeFileName = 'page.t
|
|
|
101
101
|
'unlink',
|
|
102
102
|
'unlinkDir',
|
|
103
103
|
];
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const ignoredGeneralFiles = getIgnoredFiles(file, outputFile);
|
|
105
|
+
// If added, or change (renamed) or deleted, update routes
|
|
106
|
+
if (watchOnEvents.includes(ev) && !ignoredGeneralFiles) {
|
|
107
|
+
console.log(`👀 Watching files from path: "${file}" for changes...`);
|
|
106
108
|
runFromWatcher();
|
|
107
109
|
}
|
|
108
110
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-file-router",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "router based on project files using typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "tsx ./src/generator.ts",
|
|
13
13
|
"prebuild": "rimraf dist",
|
|
14
|
-
"build": "tsc"
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"publish:package": "npm run build && npm publish"
|
|
15
16
|
},
|
|
16
17
|
"author": "MatheusF10",
|
|
17
18
|
"license": "ISC",
|