htmv 0.0.6 → 0.0.7
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/dist/cli/cli.js +1 -1
- package/package.json +2 -2
- package/src/cli/cli.ts +1 -1
- package/src/cli/commands/new.ts +73 -2
- package/src/index.ts +1 -2
- package/bun.lock +0 -97
- package/dist/cli/cli.d.ts +0 -2
- package/dist/cli/commands/help.d.ts +0 -2
- package/dist/cli/commands/help.js +0 -4
- package/dist/cli/commands/new.d.ts +0 -2
- package/dist/cli/commands/new.js +0 -4
- package/dist/cli/consts.d.ts +0 -1
- package/dist/cli/consts.js +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -64
package/dist/cli/cli.js
CHANGED
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.
|
|
5
|
+
"version": "0.0.7",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@biomejs/biome": "2.3.3",
|
|
8
8
|
"@types/bun": "latest"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@elysiajs/node": "^1.4.2",
|
|
15
15
|
"@elysiajs/static": "^1.4.6",
|
|
16
|
-
"elysia": "^1.4.
|
|
16
|
+
"elysia": "^1.4.18"
|
|
17
17
|
},
|
|
18
18
|
"bin": {
|
|
19
19
|
"htmv": "dist/cli/cli.js"
|
package/src/cli/cli.ts
CHANGED
package/src/cli/commands/new.ts
CHANGED
|
@@ -1,4 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
import childProcess from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export default async (args: string[]) => {
|
|
2
6
|
const name = args[0];
|
|
3
|
-
|
|
7
|
+
if (name === undefined)
|
|
8
|
+
return console.error("No name supplied. Project creation cancelled");
|
|
9
|
+
console.log("1. Starting project creation...");
|
|
10
|
+
const folderAlreadyExists = await fs.exists(name);
|
|
11
|
+
if (folderAlreadyExists)
|
|
12
|
+
return console.error("There already exists a folder with that name.");
|
|
13
|
+
const fullPath = path.resolve(name);
|
|
14
|
+
await fs.mkdir(name);
|
|
15
|
+
console.log("2. Creating a new bun project...");
|
|
16
|
+
await runCommand("bun init -y", {
|
|
17
|
+
cwd: fullPath,
|
|
18
|
+
});
|
|
19
|
+
console.log("3. Installing dependencies...");
|
|
20
|
+
await runCommand("bun add htmv", {
|
|
21
|
+
cwd: fullPath,
|
|
22
|
+
});
|
|
23
|
+
console.log("4. Scaffolding project structure...");
|
|
24
|
+
await fs.mkdir(path.join(fullPath, "public"));
|
|
25
|
+
await fs.mkdir(path.join(fullPath, "routes"));
|
|
26
|
+
await fs.mkdir(path.join(fullPath, "views"));
|
|
27
|
+
const indexContent = `import path from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
import { setup } from "htmv";
|
|
30
|
+
|
|
31
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
32
|
+
const dirPath = path.dirname(__filename);
|
|
33
|
+
setup({
|
|
34
|
+
routes: path.join(dirPath, "routes"),
|
|
35
|
+
views: path.join(dirPath, "views"),
|
|
36
|
+
public: path.join(dirPath, "public"),
|
|
37
|
+
port: 3000,
|
|
38
|
+
});`;
|
|
39
|
+
await fs.writeFile(path.join(fullPath, "index.ts"), indexContent);
|
|
40
|
+
const routeContent = `import { type RouteParams, view } from "htmv";
|
|
41
|
+
|
|
42
|
+
export default async (_params: RouteParams) => {
|
|
43
|
+
return await view("example", {
|
|
44
|
+
title: "Welcome to HTMV!",
|
|
45
|
+
});
|
|
4
46
|
};
|
|
47
|
+
`;
|
|
48
|
+
await fs.writeFile(path.join(fullPath, "routes", "index.ts"), routeContent);
|
|
49
|
+
const viewContent = `<!DOCTYPE html>
|
|
50
|
+
<html lang="en">
|
|
51
|
+
|
|
52
|
+
<head>
|
|
53
|
+
<title>{title}</title>
|
|
54
|
+
</head>
|
|
55
|
+
|
|
56
|
+
<body>
|
|
57
|
+
<h1>{title}</h1>
|
|
58
|
+
</body>
|
|
59
|
+
</html>`;
|
|
60
|
+
await fs.writeFile(path.join(fullPath, "views", "example.html"), viewContent);
|
|
61
|
+
console.log(`All done! Project ${name} created.`);
|
|
62
|
+
console.log(`Now run cd ${name} and start building your next big project!`);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
async function runCommand(
|
|
66
|
+
command: string,
|
|
67
|
+
options?: childProcess.ExecOptionsWithStringEncoding,
|
|
68
|
+
) {
|
|
69
|
+
const process = childProcess.exec(command, options);
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
process.on("exit", () => {
|
|
72
|
+
resolve(1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { node } from "@elysiajs/node";
|
|
4
3
|
import staticPlugin from "@elysiajs/static";
|
|
5
4
|
import { Elysia } from "elysia";
|
|
6
5
|
|
|
@@ -35,7 +34,7 @@ type Paths = {
|
|
|
35
34
|
};
|
|
36
35
|
export async function setup(paths: Paths) {
|
|
37
36
|
viewsPath = paths.views;
|
|
38
|
-
const app = new Elysia(
|
|
37
|
+
const app = new Elysia().use(
|
|
39
38
|
staticPlugin({
|
|
40
39
|
assets: paths.public,
|
|
41
40
|
}),
|
package/bun.lock
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"lockfileVersion": 1,
|
|
3
|
-
"workspaces": {
|
|
4
|
-
"": {
|
|
5
|
-
"name": "htmv",
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"@elysiajs/node": "^1.4.2",
|
|
8
|
-
"@elysiajs/static": "^1.4.6",
|
|
9
|
-
"elysia": "^1.4.15",
|
|
10
|
-
},
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@biomejs/biome": "2.3.3",
|
|
13
|
-
"@types/bun": "latest",
|
|
14
|
-
},
|
|
15
|
-
"peerDependencies": {
|
|
16
|
-
"typescript": "^5",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
"packages": {
|
|
21
|
-
"@biomejs/biome": ["@biomejs/biome@2.3.3", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.3.3", "@biomejs/cli-darwin-x64": "2.3.3", "@biomejs/cli-linux-arm64": "2.3.3", "@biomejs/cli-linux-arm64-musl": "2.3.3", "@biomejs/cli-linux-x64": "2.3.3", "@biomejs/cli-linux-x64-musl": "2.3.3", "@biomejs/cli-win32-arm64": "2.3.3", "@biomejs/cli-win32-x64": "2.3.3" }, "bin": { "biome": "bin/biome" } }, "sha512-zn/P1pRBCpDdhi+VNSMnpczOz9DnqzOA2c48K8xgxjDODvi5O8gs3a2H233rck/5HXpkFj6TmyoqVvxirZUnvg=="],
|
|
22
|
-
|
|
23
|
-
"@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.3.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-5+JtW6RKmjqL9un0UtHV0ezOslAyYBzyl5ZhYiu7GHesX2x8NCDl6tXYrenv9m7e1RLbkO5E5Kh04kseMtz6lw=="],
|
|
24
|
-
|
|
25
|
-
"@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.3.3", "", { "os": "darwin", "cpu": "x64" }, "sha512-UPmKRalkHicvIpeccuKqq+/gA2HYV8FUnAEDJnqYBlGlycKqe6xrovWqvWTE4TTNpIFf4UQyuaDzLkN6Kz6tbA=="],
|
|
26
|
-
|
|
27
|
-
"@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.3.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-zeiKwALNB/hax7+LLhCYqhqzlWdTfgE9BGkX2Z8S4VmCYnGFrf2fON/ec6KCos7mra5MDm6fYICsEWN2+HKZhw=="],
|
|
28
|
-
|
|
29
|
-
"@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.3.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-KhCDMV+V7Yu72v40ssGJTHuv/j0n7JQ6l0s/c+EMcX5zPYLMLr4XpmI+WXhp4Vfkz0T5Xnh5wbrTBI3f2UTpjQ=="],
|
|
30
|
-
|
|
31
|
-
"@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.3.3", "", { "os": "linux", "cpu": "x64" }, "sha512-05CjPLbvVVU8J6eaO6iSEoA0FXKy2l6ddL+1h/VpiosCmIp3HxRKLOa1hhC1n+D13Z8g9b1DtnglGtM5U3sTag=="],
|
|
32
|
-
|
|
33
|
-
"@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.3.3", "", { "os": "linux", "cpu": "x64" }, "sha512-IyqQ+jYzU5MVy9CK5NV0U+NnUMPUAhYMrB/x4QgL/Dl1MqzBVc61bHeyhLnKM6DSEk73/TQYrk/8/QmVHudLdQ=="],
|
|
34
|
-
|
|
35
|
-
"@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.3.3", "", { "os": "win32", "cpu": "arm64" }, "sha512-NtlLs3pdFqFAQYZjlEHKOwJEn3GEaz7rtR2oCrzaLT2Xt3Cfd55/VvodQ5V+X+KepLa956QJagckJrNL+DmumQ=="],
|
|
36
|
-
|
|
37
|
-
"@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.3.3", "", { "os": "win32", "cpu": "x64" }, "sha512-klJKPPQvUk9Rlp0Dd56gQw/+Wt6uUprHdHWtbDC93f3Iv+knA2tLWpcYoOZJgPV+9s+RBmYv0DGy4mUlr20esg=="],
|
|
38
|
-
|
|
39
|
-
"@borewit/text-codec": ["@borewit/text-codec@0.1.1", "", {}, "sha512-5L/uBxmjaCIX5h8Z+uu+kA9BQLkc/Wl06UGR5ajNRxu+/XjonB5i8JpgFMrPj3LXTCPA0pv8yxUvbUi+QthGGA=="],
|
|
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
|
-
|
|
43
|
-
"@elysiajs/static": ["@elysiajs/static@1.4.6", "", { "peerDependencies": { "elysia": ">= 1.4.0" } }, "sha512-cd61aY/DHOVhlnBjzTBX8E1XANIrsCH8MwEGHeLMaZzNrz0gD4Q8Qsde2dFMzu81I7ZDaaZ2Rim9blSLtUrYBg=="],
|
|
44
|
-
|
|
45
|
-
"@sinclair/typebox": ["@sinclair/typebox@0.34.41", "", {}, "sha512-6gS8pZzSXdyRHTIqoqSVknxolr1kzfy4/CeDnrzsVz8TTIWUbOBr6gnzOmTYJ3eXQNh4IYHIGi5aIL7sOZ2G/g=="],
|
|
46
|
-
|
|
47
|
-
"@tokenizer/inflate": ["@tokenizer/inflate@0.2.7", "", { "dependencies": { "debug": "^4.4.0", "fflate": "^0.8.2", "token-types": "^6.0.0" } }, "sha512-MADQgmZT1eKjp06jpI2yozxaU9uVs4GzzgSL+uEq7bVcJ9V1ZXQkeGNql1fsSI0gMy1vhvNTNbUqrx+pZfJVmg=="],
|
|
48
|
-
|
|
49
|
-
"@tokenizer/token": ["@tokenizer/token@0.3.0", "", {}, "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A=="],
|
|
50
|
-
|
|
51
|
-
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
|
|
52
|
-
|
|
53
|
-
"@types/node": ["@types/node@24.10.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-qzQZRBqkFsYyaSWXuEHc2WR9c0a0CXwiE5FWUvn7ZM+vdy1uZLfCunD38UzhuB7YN/J11ndbDBcTmOdxJo9Q7A=="],
|
|
54
|
-
|
|
55
|
-
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
|
|
56
|
-
|
|
57
|
-
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
|
|
58
|
-
|
|
59
|
-
"cookie": ["cookie@1.0.2", "", {}, "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA=="],
|
|
60
|
-
|
|
61
|
-
"crossws": ["crossws@0.4.1", "", { "peerDependencies": { "srvx": ">=0.7.1" }, "optionalPeers": ["srvx"] }, "sha512-E7WKBcHVhAVrY6JYD5kteNqVq1GSZxqGrdSiwXR9at+XHi43HJoCQKXcCczR5LBnBquFZPsB3o7HklulKoBU5w=="],
|
|
62
|
-
|
|
63
|
-
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
|
|
64
|
-
|
|
65
|
-
"debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
|
|
66
|
-
|
|
67
|
-
"elysia": ["elysia@1.4.15", "", { "dependencies": { "cookie": "^1.0.2", "exact-mirror": "0.2.2", "fast-decode-uri-component": "^1.0.1", "memoirist": "^0.4.0" }, "peerDependencies": { "@sinclair/typebox": ">= 0.34.0 < 1", "@types/bun": ">= 1.2.0", "file-type": ">= 20.0.0", "openapi-types": ">= 12.0.0", "typescript": ">= 5.0.0" }, "optionalPeers": ["@types/bun", "typescript"] }, "sha512-RaDqqZdLuC4UJetfVRQ4Z5aVpGgEtQ+pZnsbI4ZzEaf3l/MzuHcqSVoL/Fue3d6qE4RV9HMB2rAZaHyPIxkyzg=="],
|
|
68
|
-
|
|
69
|
-
"exact-mirror": ["exact-mirror@0.2.2", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-CrGe+4QzHZlnrXZVlo/WbUZ4qQZq8C0uATQVGVgXIrNXgHDBBNFD1VRfssRA2C9t3RYvh3MadZSdg2Wy7HBoQA=="],
|
|
70
|
-
|
|
71
|
-
"fast-decode-uri-component": ["fast-decode-uri-component@1.0.1", "", {}, "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg=="],
|
|
72
|
-
|
|
73
|
-
"fflate": ["fflate@0.8.2", "", {}, "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="],
|
|
74
|
-
|
|
75
|
-
"file-type": ["file-type@21.0.0", "", { "dependencies": { "@tokenizer/inflate": "^0.2.7", "strtok3": "^10.2.2", "token-types": "^6.0.0", "uint8array-extras": "^1.4.0" } }, "sha512-ek5xNX2YBYlXhiUXui3D/BXa3LdqPmoLJ7rqEx2bKJ7EAUEfmXgW0Das7Dc6Nr9MvqaOnIqiPV0mZk/r/UpNAg=="],
|
|
76
|
-
|
|
77
|
-
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
|
78
|
-
|
|
79
|
-
"memoirist": ["memoirist@0.4.0", "", {}, "sha512-zxTgA0mSYELa66DimuNQDvyLq36AwDlTuVRbnQtB+VuTcKWm5Qc4z3WkSpgsFWHNhexqkIooqpv4hdcqrX5Nmg=="],
|
|
80
|
-
|
|
81
|
-
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
|
82
|
-
|
|
83
|
-
"openapi-types": ["openapi-types@12.1.3", "", {}, "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw=="],
|
|
84
|
-
|
|
85
|
-
"srvx": ["srvx@0.9.5", "", { "bin": { "srvx": "bin/srvx.mjs" } }, "sha512-nQsA2c8q3XwbSn6kTxVQjz0zS096rV+Be2pzJwrYEAdtnYszLw4MTy8JWJjz1XEGBZwP0qW51SUIX3WdjdRemQ=="],
|
|
86
|
-
|
|
87
|
-
"strtok3": ["strtok3@10.3.4", "", { "dependencies": { "@tokenizer/token": "^0.3.0" } }, "sha512-KIy5nylvC5le1OdaaoCJ07L+8iQzJHGH6pWDuzS+d07Cu7n1MZ2x26P8ZKIWfbK02+XIL8Mp4RkWeqdUCrDMfg=="],
|
|
88
|
-
|
|
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=="],
|
|
90
|
-
|
|
91
|
-
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
92
|
-
|
|
93
|
-
"uint8array-extras": ["uint8array-extras@1.5.0", "", {}, "sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A=="],
|
|
94
|
-
|
|
95
|
-
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
|
96
|
-
}
|
|
97
|
-
}
|
package/dist/cli/cli.d.ts
DELETED
package/dist/cli/commands/new.js
DELETED
package/dist/cli/consts.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)";
|
package/dist/cli/consts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)";
|
package/dist/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare function view(view: string, props: Record<string, unknown>): Promise<Response>;
|
|
2
|
-
export type RouteParams = {
|
|
3
|
-
query: Record<string, string>;
|
|
4
|
-
request: Request;
|
|
5
|
-
params: Record<string, string>;
|
|
6
|
-
};
|
|
7
|
-
type Paths = {
|
|
8
|
-
routes: string;
|
|
9
|
-
views: string;
|
|
10
|
-
public: string;
|
|
11
|
-
port: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function setup(paths: Paths): Promise<void>;
|
|
14
|
-
export {};
|
package/dist/index.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { node } from "@elysiajs/node";
|
|
4
|
-
import staticPlugin from "@elysiajs/static";
|
|
5
|
-
import { Elysia } from "elysia";
|
|
6
|
-
let viewsPath = "";
|
|
7
|
-
export async function view(view, props) {
|
|
8
|
-
if (viewsPath === "")
|
|
9
|
-
throw new Error("Views folder path not yet configured. Use `Htmv.setup` before rendering a view.");
|
|
10
|
-
const filePath = path.join(viewsPath, `${view}.html`);
|
|
11
|
-
const code = await fs.readFile(filePath, "utf-8");
|
|
12
|
-
const replacedCode = code.replace(/{(.+)}/g, (_, propName) => {
|
|
13
|
-
return props[propName];
|
|
14
|
-
});
|
|
15
|
-
return new Response(replacedCode, {
|
|
16
|
-
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export async function setup(paths) {
|
|
20
|
-
viewsPath = paths.views;
|
|
21
|
-
const app = new Elysia({ adapter: node() }).use(staticPlugin({
|
|
22
|
-
assets: paths.public,
|
|
23
|
-
}));
|
|
24
|
-
await registerRoutes(app, paths.routes);
|
|
25
|
-
app.listen(paths.port);
|
|
26
|
-
console.log("");
|
|
27
|
-
console.log(`HTMV running on port ${paths.port}! 🎉`);
|
|
28
|
-
console.log(`http://localhost:${paths.port}`);
|
|
29
|
-
}
|
|
30
|
-
async function registerRoutes(app, baseDir, prefix = "/") {
|
|
31
|
-
const entries = await fs.readdir(baseDir, { withFileTypes: true });
|
|
32
|
-
for (const entry of entries) {
|
|
33
|
-
const fullPath = path.join(baseDir, entry.name);
|
|
34
|
-
if (entry.isDirectory()) {
|
|
35
|
-
await registerRoutes(app, fullPath, path.join(prefix, entry.name));
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (entry.name !== "index.ts")
|
|
39
|
-
continue;
|
|
40
|
-
const module = (await import(fullPath));
|
|
41
|
-
const defaultFn = module.default;
|
|
42
|
-
if (defaultFn && typeof defaultFn === "function") {
|
|
43
|
-
app.all(prefix, async ({ request, query, params }) => {
|
|
44
|
-
const result = await defaultFn({ request, query, params });
|
|
45
|
-
return result;
|
|
46
|
-
});
|
|
47
|
-
console.log(`Registered ${fullPath} on ${prefix} route with method all`);
|
|
48
|
-
}
|
|
49
|
-
for (const propName in module) {
|
|
50
|
-
const prop = module[propName];
|
|
51
|
-
if (typeof prop !== "function")
|
|
52
|
-
continue;
|
|
53
|
-
const fn = prop;
|
|
54
|
-
const name = fn.name.toLowerCase();
|
|
55
|
-
if (!["get", "post", "put", "patch", "delete"].includes(name))
|
|
56
|
-
continue;
|
|
57
|
-
app[name](prefix, async ({ request, query, params }) => {
|
|
58
|
-
const result = await fn({ request, query, params });
|
|
59
|
-
return result;
|
|
60
|
-
});
|
|
61
|
-
console.log(`Registered ${fullPath} on ${prefix} route with method ${name}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|