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 CHANGED
@@ -65,11 +65,11 @@ Guide how `elysia-autoload` match routes
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](https://elysiajs.com/eden/overview.html) |
72
- | useExport? | boolean | false | Use export instead of global type |
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
@@ -4,7 +4,7 @@ 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
9
  useExport?: boolean;
10
10
  }
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
- types === true || !types.useExport ? "declare global {" : "",
68
- ` export 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
- types === true || !types.useExport ? "}" : "",
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.1",
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",