elysia-autoload 0.1.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # elysia-autoload
2
2
 
3
- Plugin for [Elysia](https://elysiajs.com/) which autoload all routes in directory and code-generate types for Eden
3
+ Plugin for [Elysia](https://elysiajs.com/) which autoload all routes in directory and code-generate types for [Eden](https://elysiajs.com/eden/overview.html)
4
4
 
5
5
  ## Installation
6
6
 
@@ -55,22 +55,23 @@ Guide how `elysia-autoload` match routes
55
55
 
56
56
  ## Options
57
57
 
58
- | Key | Type | Default | Description |
59
- | -------- | --------------------------------------- | --------------------------- | ------------------------------------------------------------------- |
60
- | pattern? | string | "\*\*_/\*_.{ts,js,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? | true \| [Types Options](#types-options) | | Options to configure type code-generation. |
64
- | schema? | Function | | Handler for providing routes guard schema |
58
+ | Key | Type | Default | Description |
59
+ | -------- | ------------------------------------------ | --------------------------- | ----------------------------------------------------------------------------------- |
60
+ | pattern? | string | "\*\*_/\*_.{ts,js,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 | Default | Description |
69
- | --------- | ------ | ------------------- | -------------------------------------------- |
70
- | output? | string | "./routes-types.ts" | Type code-generation output |
71
- | typeName? | string | "Routes" | Name for code-generated global type for Eden |
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 |
72
73
 
73
- ### Usage of types code-generation for eden
74
+ ### Usage of types code-generation for [Eden](https://elysiajs.com/eden/overview.html)
74
75
 
75
76
  ```ts
76
77
  // app.ts
package/dist/index.d.ts CHANGED
@@ -4,8 +4,9 @@ type TSchemaHandler = ({ path, url, }: {
4
4
  url: string;
5
5
  }) => Parameters<InstanceType<typeof Elysia>["group"]>[1];
6
6
  export interface ITypesOptions {
7
- output?: string;
7
+ output?: string | string[];
8
8
  typeName?: string;
9
+ useExport?: boolean;
9
10
  }
10
11
  export interface IAutoloadOptions {
11
12
  pattern?: string;
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 Bun.write((0, utils_1.getPath)(types === true || !types.output
62
- ? TYPES_OUTPUT_DEFAULT
63
- : types.output), [
64
- `import type { ElysiaWithBaseUrl } from "elysia-autoload";`,
65
- imports.join("\n"),
66
- "",
67
- "declare global {",
68
- ` type ${types === true || !types.typeName
69
- ? TYPES_TYPENAME_DEFAULT
70
- : types.typeName} = ${paths
71
- .map((x, index) => `ElysiaWithBaseUrl<"${(0, utils_1.transformToUrl)(x) || "/"}", ReturnType<typeof Route${index}>>`)
72
- .join("\n & ")}`,
73
- "}",
74
- ].join("\n"));
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.0",
3
+ "version": "0.1.2",
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",
@@ -12,7 +12,11 @@
12
12
  "autoload",
13
13
  "nextjs",
14
14
  "filerouter",
15
- "autoroutes"
15
+ "autoroutes",
16
+ "eden",
17
+ "treaty",
18
+ "trpc",
19
+ "codegeneration"
16
20
  ],
17
21
  "scripts": {
18
22
  "prepublishOnly": "tsc",