@tylix/core 0.5.1 → 0.5.2
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/package.json
CHANGED
|
@@ -2,16 +2,38 @@ import fs from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { requireAuth } from '../http/requireAuth.js'
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
// Written as the first line of every route file generated by make:feature.
|
|
6
|
+
export const FEATURE_ROUTE_MARKER = '// @tylix-feature'
|
|
7
|
+
|
|
8
|
+
const GENERATED_ACTIONS = ['index', 'store', 'show', 'update', 'destroy']
|
|
9
|
+
|
|
10
|
+
// A route file is "owned" by a feature only when make:feature wrote it.
|
|
11
|
+
// Hand-written files that merely share the table name (provisions.ts,
|
|
12
|
+
// sites.ts, ...) must NOT suppress the manifest routes.
|
|
13
|
+
function isFeatureRouteFile(filePath) {
|
|
14
|
+
let content
|
|
15
|
+
try {
|
|
16
|
+
content = fs.readFileSync(filePath, 'utf8')
|
|
17
|
+
} catch {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (content.includes(FEATURE_ROUTE_MARKER)) return true
|
|
22
|
+
|
|
23
|
+
// Legacy: files generated before the marker existed called all five
|
|
24
|
+
// controller actions as `controller.<action>(req, res)`.
|
|
25
|
+
return GENERATED_ACTIONS.every((action) =>
|
|
26
|
+
content.includes(`controller.${action}(req, res)`),
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
8
30
|
function hasRouteFile(baseDir, table) {
|
|
9
31
|
return ['js', 'ts'].some((ext) =>
|
|
10
|
-
|
|
32
|
+
isFeatureRouteFile(path.join(baseDir, 'app', 'routes', `${table}.${ext}`)),
|
|
11
33
|
)
|
|
12
34
|
}
|
|
13
35
|
|
|
14
|
-
// Returns the tables that were skipped because a route file owns them.
|
|
36
|
+
// Returns the tables that were skipped because a generated route file owns them.
|
|
15
37
|
export function registerFeatureRoutes(
|
|
16
38
|
router,
|
|
17
39
|
features,
|