elysia-autoload 0.1.1 → 0.1.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/README.md +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
@@ -65,11 +65,11 @@ Guide how `elysia-autoload` match routes
|
|
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
@@ -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
|
}
|