elysia-autoload 0.1.3 → 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 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
- ├── [...].ts
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,16 +67,18 @@ 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
 
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 |
75
+ | Key | Type | Default | Description |
76
+ | -------- | ------------------------------------------ | ---------------------------------- | ----------------------------------------------------------------------------------- |
77
+ | pattern? | string | "\*\*\/\*.{ts,tsx,js,jsx,mjs,cjs}" | [Glob patterns](<https://en.wikipedia.org/wiki/Glob_(programming)>) |
78
+ | dir? | string | "./routes" | The folder where routes are located |
79
+ | prefix? | string | | Prefix for routes |
80
+ | types? | boolean \| [Types Options](#types-options) | false | Options to configure type code-generation. if boolean - enables/disables generation |
81
+ | schema? | Function | | Handler for providing routes guard schema |
65
82
 
66
83
  ### Types Options
67
84
 
@@ -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";
@@ -57,7 +57,7 @@ async function autoload({ pattern, dir, prefix, schema, types, } = {}) {
57
57
  paths.push(fullPath.replace(directoryPath, ""));
58
58
  }
59
59
  if (types) {
60
- const imports = paths.map((x, index) => `import Route${index} from "${directoryPath + x.replace(".ts", "")}";`);
60
+ const imports = paths.map((x, index) => `import Route${index} from "${directoryPath + x.replace(".ts", "").replace(".tsx", "")}";`);
61
61
  for await (const outputPath of types === true || !types.output
62
62
  ? [TYPES_OUTPUT_DEFAULT]
63
63
  : Array.isArray(types.output)
@@ -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
@@ -14,7 +14,7 @@ exports.getPath = getPath;
14
14
  function transformToUrl(path) {
15
15
  const replacements = [
16
16
  // Clean the url extensions
17
- { regex: /\.(ts|js|mjs|cjs)$/u, replacement: "" },
17
+ { regex: /\.(ts|tsx|js|jsx|mjs|cjs)$/u, replacement: "" },
18
18
  // Handle wild card based routes - users/[...id]/profile.ts -> users/*/profile
19
19
  { regex: /\[\.\.\..*\]/gu, replacement: "*" },
20
20
  // Handle generic square bracket based routes - users/[id]/index.ts -> users/:id
@@ -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",
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": "eslint \"{src,example}/**/*.{ts,tsx,js,mjs,cjs}\"",
24
- "lint:fix": "eslint \"{src,example}/**/*.{ts,tsx,js,mjs,cjs}\" --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-types": "latest",
34
+ "@types/bun": "^1.0.4",
33
35
  "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"
36
+ "typescript": "^5.3.3",
37
+ "husky": "^8.0.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "elysia": "^0.8.0"