elysia-autoload 0.1.4 → 0.1.5
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/README.md +18 -3
- package/dist/index.js +2 -4
- package/dist/utils.js +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
@@ -4,6 +4,16 @@ Plugin for [Elysia](https://elysiajs.com/) which autoload all routes in director
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
### Start new project with [create-elysiajs](https://github.com/kravetsone/create-elysiajs)
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bun create elysiajs <directory-name>
|
11
|
+
```
|
12
|
+
|
13
|
+
and select `Autoload` in plugins
|
14
|
+
|
15
|
+
### Manual
|
16
|
+
|
7
17
|
```bash
|
8
18
|
bun install elysia-autoload
|
9
19
|
```
|
@@ -42,7 +52,12 @@ Guide how `elysia-autoload` match routes
|
|
42
52
|
├── index.ts
|
43
53
|
└── [id].ts // dynamic params
|
44
54
|
├── likes
|
45
|
-
|
55
|
+
└── [...].ts // wildcard
|
56
|
+
├── domains
|
57
|
+
├── @[...] // wildcard with @ prefix
|
58
|
+
└──index.ts
|
59
|
+
├── frontend
|
60
|
+
└──index.tsx // usage of tsx extension
|
46
61
|
└── users.ts
|
47
62
|
└── package.json
|
48
63
|
```
|
@@ -52,6 +67,8 @@ Guide how `elysia-autoload` match routes
|
|
52
67
|
- /routes/posts/[id].ts → /posts/:id
|
53
68
|
- /routes/users.ts → /users
|
54
69
|
- /routes/likes/[...].ts → /likes/\*
|
70
|
+
- /routes/domains/@[...]/index.ts → /domains/@\*
|
71
|
+
- /routes/frontend/index.tsx → /frontend
|
55
72
|
|
56
73
|
## Options
|
57
74
|
|
@@ -143,5 +160,3 @@ export type ElysiaApp = typeof app;
|
|
143
160
|
|
144
161
|
app.listen(3001, console.log);
|
145
162
|
```
|
146
|
-
|
147
|
-
### Thanks [https://github.com/wobsoriano/elysia-autoroutes](elysia-autoroutes) for some ideas
|
package/dist/index.js
CHANGED
@@ -15,9 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
exports.autoload = void 0;
|
18
|
-
const elysia_1 = require("elysia");
|
19
18
|
const node_fs_1 = require("node:fs");
|
20
19
|
const node_path_1 = require("node:path");
|
20
|
+
const elysia_1 = require("elysia");
|
21
21
|
const utils_1 = require("./utils");
|
22
22
|
const TYPES_OUTPUT_DEFAULT = "./routes-types.ts";
|
23
23
|
const TYPES_TYPENAME_DEFAULT = "Routes";
|
@@ -67,9 +67,7 @@ async function autoload({ pattern, dir, prefix, schema, types, } = {}) {
|
|
67
67
|
`import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
|
68
68
|
imports.join("\n"),
|
69
69
|
"",
|
70
|
-
types === true || !types.useExport
|
71
|
-
? "declare global {"
|
72
|
-
: "",
|
70
|
+
types === true || !types.useExport ? "declare global {" : "",
|
73
71
|
` export type ${types === true || !types.typeName
|
74
72
|
? TYPES_TYPENAME_DEFAULT
|
75
73
|
: types.typeName} = ${paths
|
package/dist/utils.js
CHANGED
@@ -35,7 +35,7 @@ function transformToUrl(path) {
|
|
35
35
|
for (const { regex, replacement } of replacements) {
|
36
36
|
url = url.replace(regex, replacement);
|
37
37
|
}
|
38
|
-
return url;
|
38
|
+
return url.length ? url : "/";
|
39
39
|
}
|
40
40
|
exports.transformToUrl = transformToUrl;
|
41
41
|
function getParamsCount(path) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "elysia-autoload",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.5",
|
4
4
|
"author": "kravetsone",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"description": "Plugin for Elysia which autoload all routes in directory and code-generate types for Eden",
|
@@ -19,22 +19,22 @@
|
|
19
19
|
"codegeneration"
|
20
20
|
],
|
21
21
|
"scripts": {
|
22
|
-
"prepublishOnly": "tsc",
|
23
|
-
"lint": "
|
24
|
-
"lint:fix": "
|
22
|
+
"prepublishOnly": "bun test && rm -rf dist && tsc",
|
23
|
+
"lint": "bunx @biomejs/biome check src",
|
24
|
+
"lint:fix": "bun lint --apply",
|
25
|
+
"prepare": "bunx husky install"
|
25
26
|
},
|
26
27
|
"files": [
|
27
28
|
"dist"
|
28
29
|
],
|
29
30
|
"devDependencies": {
|
31
|
+
"@biomejs/biome": "1.5.3",
|
30
32
|
"@elysiajs/eden": "^0.8.1",
|
31
33
|
"@elysiajs/swagger": "^0.8.4",
|
32
|
-
"bun
|
34
|
+
"@types/bun": "^1.0.4",
|
33
35
|
"elysia": "^0.8.10",
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"prettier": "^3.2.4",
|
37
|
-
"typescript": "^5.3.3"
|
36
|
+
"typescript": "^5.3.3",
|
37
|
+
"husky": "^8.0.0"
|
38
38
|
},
|
39
39
|
"peerDependencies": {
|
40
40
|
"elysia": "^0.8.0"
|