htmv 0.0.4 → 0.0.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
@@ -1,25 +1,7 @@
1
1
  # HTMV
2
- Welcome to HTMV. A simple yet fast web framework currently in work in progress. Installation and usage guide can be found below.
3
-
4
- # Precautions
5
- HTMV was made to be used with [Bun](https://bun.com/). It has not been tested and is not guaranted to work on Node.js. Please ensure you have Bun installed before continuing reading.
2
+ HTMV. A simple yet fast web framework currently in work in progress. Installation and usage guide can be found below.
6
3
 
7
4
  # Installation
8
- ## Linking the library
9
- It's not yet uploaded on NPM so you'll have to link it yourself to your project.
10
- 1. Get the repo
11
- ```bash
12
- $ git clone https://github.com/Fabrisdev/htmv.git
13
- ```
14
- 2. cd into it
15
- ```bash
16
- $ cd htmv
17
- ```
18
- 3. Add it to your local registry of packages
19
- ```bash
20
- $ bun link
21
- ```
22
- Setup of the library is finished! 🎉 Now onto creating your first **HTMV** project!
23
5
  ## Creating your first project
24
6
  1. Leave that folder and create a new folder for your project
25
7
  ```bash
@@ -29,7 +11,7 @@ $ mkdir my-first-htmv-project
29
11
  2. Create an empty bun project and add HTMV as a dependency
30
12
  ```bash
31
13
  bun init # when prompted for the type, choose EMPTY
32
- bun link htmv # Adds HTMV dependency
14
+ bun add htmv # Adds HTMV dependency
33
15
  ```
34
16
  3. Create two folders. One for routes and the other for views (You can choose any name)
35
17
  4. Now in the `index.ts` add this
package/bun.lock CHANGED
@@ -4,6 +4,7 @@
4
4
  "": {
5
5
  "name": "htmv",
6
6
  "dependencies": {
7
+ "@elysiajs/node": "^1.4.2",
7
8
  "@elysiajs/static": "^1.4.6",
8
9
  "elysia": "^1.4.15",
9
10
  },
@@ -37,6 +38,8 @@
37
38
 
38
39
  "@borewit/text-codec": ["@borewit/text-codec@0.1.1", "", {}, "sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA=="],
39
40
 
41
+ "@elysiajs/node": ["@elysiajs/node@1.4.2", "", { "dependencies": { "crossws": "^0.4.1", "srvx": "^0.9.4" }, "peerDependencies": { "elysia": ">= 1.4.0" } }, "sha512-zqeBAV4/faCcmIEjCp3g6jRwsbaWsd5HqmlEf3CirD9HkTWQNo4T+GN/qGZi7zgd84D3Kzxsny7ZTMXEfrDSXQ=="],
42
+
40
43
  "@elysiajs/static": ["@elysiajs/static@1.4.6", "", { "peerDependencies": { "elysia": ">= 1.4.0" } }, "sha512-cd61aY/DHOVhlnBjzTBX8E1XANIrsCH8MwEGHeLMaZzNrz0gD4Q8Qsde2dFMzu81I7ZDaaZ2Rim9blSLtUrYBg=="],
41
44
 
42
45
  "@sinclair/typebox": ["@sinclair/typebox@0.34.41", "", {}, "sha512-6gS8pZzSXdyRHTIqoqSVknxolr1kzfy4/CeDnrzsVz8TTIWUbOBr6gnzOmTYJ3eXQNh4IYHIGi5aIL7sOZ2G/g=="],
@@ -55,6 +58,8 @@
55
58
 
56
59
  "cookie": ["cookie@1.0.2", "", {}, "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA=="],
57
60
 
61
+ "crossws": ["crossws@0.4.1", "", { "peerDependencies": { "srvx": ">=0.7.1" }, "optionalPeers": ["srvx"] }, "sha512-E7WKBcHVhAVrY6JYD5kteNqVq1GSZxqGrdSiwXR9at+XHi43HJoCQKXcCczR5LBnBquFZPsB3o7HklulKoBU5w=="],
62
+
58
63
  "csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
59
64
 
60
65
  "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
@@ -77,6 +82,8 @@
77
82
 
78
83
  "openapi-types": ["openapi-types@12.1.3", "", {}, "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw=="],
79
84
 
85
+ "srvx": ["srvx@0.9.5", "", { "bin": { "srvx": "bin/srvx.mjs" } }, "sha512-nQsA2c8q3XwbSn6kTxVQjz0zS096rV+Be2pzJwrYEAdtnYszLw4MTy8JWJjz1XEGBZwP0qW51SUIX3WdjdRemQ=="],
86
+
80
87
  "strtok3": ["strtok3@10.3.4", "", { "dependencies": { "@tokenizer/token": "^0.3.0" } }, "sha512-KIy5nylvC5le1OdaaoCJ07L+8iQzJHGH6pWDuzS+d07Cu7n1MZ2x26P8ZKIWfbK02+XIL8Mp4RkWeqdUCrDMfg=="],
81
88
 
82
89
  "token-types": ["token-types@6.1.1", "", { "dependencies": { "@borewit/text-codec": "^0.1.0", "@tokenizer/token": "^0.3.0", "ieee754": "^1.2.1" } }, "sha512-kh9LVIWH5CnL63Ipf0jhlBIy0UsrMj/NJDfpsy1SqOXlLKEVyXXYrnFxFT1yOOYVGBSApeVnjPw/sBz5BfEjAQ=="],
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import node from "@elysiajs/node";
3
4
  import staticPlugin from "@elysiajs/static";
4
5
  import { Elysia } from "elysia";
5
6
  let viewsPath = "";
6
7
  export async function view(view, props) {
7
8
  if (viewsPath === "")
8
9
  throw new Error("Views folder path not yet configured. Use `Htmv.setup` before rendering a view.");
9
- const file = Bun.file(path.join(viewsPath, `${view}.html`));
10
- const code = await file.text();
10
+ const filePath = path.join(viewsPath, `${view}.html`);
11
+ const code = await fs.readFile(filePath, "utf-8");
11
12
  const replacedCode = code.replace(/{(.+)}/g, (_, propName) => {
12
13
  return props[propName];
13
14
  });
@@ -17,7 +18,7 @@ export async function view(view, props) {
17
18
  }
18
19
  export async function setup(paths) {
19
20
  viewsPath = paths.views;
20
- const app = new Elysia().use(staticPlugin({
21
+ const app = new Elysia({ adapter: node() }).use(staticPlugin({
21
22
  assets: paths.public,
22
23
  }));
23
24
  await registerRoutes(app, paths.routes);
@@ -34,7 +35,7 @@ async function registerRoutes(app, baseDir, prefix = "/") {
34
35
  await registerRoutes(app, fullPath, path.join(prefix, entry.name));
35
36
  continue;
36
37
  }
37
- if (entry.name !== "index.ts" && entry.name !== "index.tsx")
38
+ if (entry.name !== "index.ts")
38
39
  continue;
39
40
  const module = (await import(fullPath));
40
41
  const defaultFn = module.default;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "htmv",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.4",
5
+ "version": "0.0.5",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "2.3.3",
8
8
  "@types/bun": "latest"
@@ -11,6 +11,7 @@
11
11
  "typescript": "^5"
12
12
  },
13
13
  "dependencies": {
14
+ "@elysiajs/node": "^1.4.2",
14
15
  "@elysiajs/static": "^1.4.6",
15
16
  "elysia": "^1.4.15"
16
17
  },
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
+ import node from "@elysiajs/node";
3
4
  import staticPlugin from "@elysiajs/static";
4
5
  import { Elysia } from "elysia";
5
6
 
@@ -10,8 +11,8 @@ export async function view(view: string, props: Record<string, unknown>) {
10
11
  throw new Error(
11
12
  "Views folder path not yet configured. Use `Htmv.setup` before rendering a view.",
12
13
  );
13
- const file = Bun.file(path.join(viewsPath, `${view}.html`));
14
- const code = await file.text();
14
+ const filePath = path.join(viewsPath, `${view}.html`);
15
+ const code = await fs.readFile(filePath, "utf-8");
15
16
  const replacedCode = code.replace(/{(.+)}/g, (_, propName) => {
16
17
  return props[propName] as string;
17
18
  });
@@ -34,7 +35,7 @@ type Paths = {
34
35
  };
35
36
  export async function setup(paths: Paths) {
36
37
  viewsPath = paths.views;
37
- const app = new Elysia().use(
38
+ const app = new Elysia({ adapter: node() }).use(
38
39
  staticPlugin({
39
40
  assets: paths.public,
40
41
  }),
@@ -55,7 +56,7 @@ async function registerRoutes(app: Elysia, baseDir: string, prefix = "/") {
55
56
  await registerRoutes(app, fullPath, path.join(prefix, entry.name));
56
57
  continue;
57
58
  }
58
- if (entry.name !== "index.ts" && entry.name !== "index.tsx") continue;
59
+ if (entry.name !== "index.ts") continue;
59
60
  const module = (await import(fullPath)) as Record<string, unknown>;
60
61
  const defaultFn = module.default;
61
62
  if (defaultFn && typeof defaultFn === "function") {