elysia-autoload 0.1.1 → 0.1.3
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 +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -15
- package/package.json +8 -8
package/README.md
CHANGED
@@ -55,21 +55,21 @@ Guide how `elysia-autoload` match routes
|
|
55
55
|
|
56
56
|
## Options
|
57
57
|
|
58
|
-
| Key | Type | Default
|
59
|
-
| -------- | ------------------------------------------ |
|
60
|
-
| pattern? | string | "
|
61
|
-
| dir? | string | "./routes"
|
62
|
-
| prefix? | string |
|
63
|
-
| types? | boolean \| [Types Options](#types-options) | false
|
64
|
-
| schema? | Function |
|
58
|
+
| Key | Type | Default | Description |
|
59
|
+
| -------- | ------------------------------------------ | ------------------------------ | ----------------------------------------------------------------------------------- |
|
60
|
+
| pattern? | string | "\*\/.{ts,tsx,js,jsx,mjs,cjs}" | [Glob patterns](<https://en.wikipedia.org/wiki/Glob_(programming)>) |
|
61
|
+
| dir? | string | "./routes" | The folder where routes are located |
|
62
|
+
| prefix? | string | | Prefix for routes |
|
63
|
+
| types? | boolean \| [Types Options](#types-options) | false | Options to configure type code-generation. if boolean - enables/disables generation |
|
64
|
+
| schema? | Function | | Handler for providing routes guard schema |
|
65
65
|
|
66
66
|
### Types Options
|
67
67
|
|
68
|
-
| Key | Type
|
69
|
-
| ---------- |
|
70
|
-
| output? | string
|
71
|
-
| typeName? | string
|
72
|
-
| useExport? | boolean
|
68
|
+
| Key | Type | Default | Description |
|
69
|
+
| ---------- | ------------------ | ------------------- | --------------------------------------------------------------------------------------- |
|
70
|
+
| output? | string \| string[] | "./routes-types.ts" | Type code-generation output. It can be an array |
|
71
|
+
| typeName? | string | "Routes" | Name for code-generated global type for [Eden](https://elysiajs.com/eden/overview.html) |
|
72
|
+
| useExport? | boolean | false | Use export instead of global type |
|
73
73
|
|
74
74
|
### Usage of types code-generation for [Eden](https://elysiajs.com/eden/overview.html)
|
75
75
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -36,7 +36,7 @@ async function autoload({ pattern, dir, prefix, schema, types, } = {}) {
|
|
36
36
|
types,
|
37
37
|
},
|
38
38
|
});
|
39
|
-
const glob = new Bun.Glob(pattern || "**/*.{ts,js,mjs,cjs}");
|
39
|
+
const glob = new Bun.Glob(pattern || "**/*.{ts,tsx,js,jsx,mjs,cjs}");
|
40
40
|
const files = await Array.fromAsync(glob.scan({
|
41
41
|
cwd: directoryPath,
|
42
42
|
}));
|
@@ -58,20 +58,26 @@ async function autoload({ pattern, dir, prefix, schema, types, } = {}) {
|
|
58
58
|
}
|
59
59
|
if (types) {
|
60
60
|
const imports = paths.map((x, index) => `import Route${index} from "${directoryPath + x.replace(".ts", "")}";`);
|
61
|
-
await
|
62
|
-
? TYPES_OUTPUT_DEFAULT
|
63
|
-
: types.output)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
61
|
+
for await (const outputPath of types === true || !types.output
|
62
|
+
? [TYPES_OUTPUT_DEFAULT]
|
63
|
+
: Array.isArray(types.output)
|
64
|
+
? types.output
|
65
|
+
: [types.output]) {
|
66
|
+
await Bun.write((0, utils_1.getPath)(outputPath), [
|
67
|
+
`import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
|
68
|
+
imports.join("\n"),
|
69
|
+
"",
|
70
|
+
types === true || !types.useExport
|
71
|
+
? "declare global {"
|
72
|
+
: "",
|
73
|
+
` export type ${types === true || !types.typeName
|
74
|
+
? TYPES_TYPENAME_DEFAULT
|
75
|
+
: types.typeName} = ${paths
|
76
|
+
.map((x, index) => `ElysiaWithBaseUrl<"${(0, utils_1.transformToUrl)(x) || "/"}", ReturnType<typeof Route${index}>>`)
|
77
|
+
.join("\n & ")}`,
|
78
|
+
types === true || !types.useExport ? "}" : "",
|
79
|
+
].join("\n"));
|
80
|
+
}
|
75
81
|
}
|
76
82
|
return app;
|
77
83
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "elysia-autoload",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.3",
|
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",
|
@@ -27,14 +27,14 @@
|
|
27
27
|
"dist"
|
28
28
|
],
|
29
29
|
"devDependencies": {
|
30
|
-
"@elysiajs/eden": "^0.8.
|
31
|
-
"@elysiajs/swagger": "^0.8.
|
30
|
+
"@elysiajs/eden": "^0.8.1",
|
31
|
+
"@elysiajs/swagger": "^0.8.4",
|
32
32
|
"bun-types": "latest",
|
33
|
-
"elysia": "^0.8.
|
34
|
-
"eslint": "^8.
|
35
|
-
"eslint-kit": "^10.
|
36
|
-
"prettier": "^3.
|
37
|
-
"typescript": "^5.
|
33
|
+
"elysia": "^0.8.10",
|
34
|
+
"eslint": "^8.56.0",
|
35
|
+
"eslint-kit": "^10.7.0",
|
36
|
+
"prettier": "^3.2.4",
|
37
|
+
"typescript": "^5.3.3"
|
38
38
|
},
|
39
39
|
"peerDependencies": {
|
40
40
|
"elysia": "^0.8.0"
|