htmv 0.0.6 → 0.0.8

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/bun.lock CHANGED
@@ -6,7 +6,7 @@
6
6
  "dependencies": {
7
7
  "@elysiajs/node": "^1.4.2",
8
8
  "@elysiajs/static": "^1.4.6",
9
- "elysia": "^1.4.15",
9
+ "elysia": "^1.4.18",
10
10
  },
11
11
  "devDependencies": {
12
12
  "@biomejs/biome": "2.3.3",
@@ -56,7 +56,7 @@
56
56
 
57
57
  "bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
58
58
 
59
- "cookie": ["cookie@1.0.2", "", {}, "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA=="],
59
+ "cookie": ["cookie@1.1.1", "", {}, "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ=="],
60
60
 
61
61
  "crossws": ["crossws@0.4.1", "", { "peerDependencies": { "srvx": ">=0.7.1" }, "optionalPeers": ["srvx"] }, "sha512-E7WKBcHVhAVrY6JYD5kteNqVq1GSZxqGrdSiwXR9at+XHi43HJoCQKXcCczR5LBnBquFZPsB3o7HklulKoBU5w=="],
62
62
 
@@ -64,9 +64,9 @@
64
64
 
65
65
  "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
66
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=="],
67
+ "elysia": ["elysia@1.4.18", "", { "dependencies": { "cookie": "^1.1.1", "exact-mirror": "0.2.5", "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-A6BhlipmSvgCy69SBgWADYZSdDIj3fT2gk8/9iMAC8iD+aGcnCr0fitziX0xr36MFDs/fsvVp8dWqxeq1VCgKg=="],
68
68
 
69
- "exact-mirror": ["exact-mirror@0.2.2", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-CrGe+4QzHZlnrXZVlo/WbUZ4qQZq8C0uATQVGVgXIrNXgHDBBNFD1VRfssRA2C9t3RYvh3MadZSdg2Wy7HBoQA=="],
69
+ "exact-mirror": ["exact-mirror@0.2.5", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-u8Wu2lO8nio5lKSJubOydsdNtQmH8ENba5m0nbQYmTvsjksXKYIS1nSShdDlO8Uem+kbo+N6eD5I03cpZ+QsRQ=="],
70
70
 
71
71
  "fast-decode-uri-component": ["fast-decode-uri-component@1.0.1", "", {}, "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg=="],
72
72
 
package/dist/cli/cli.js CHANGED
@@ -15,7 +15,7 @@ const commands = {
15
15
  new: () => newCommand(commandArgs),
16
16
  };
17
17
  if (command in commands) {
18
- commands[command]();
18
+ await commands[command]();
19
19
  process.exit(0);
20
20
  }
21
21
  console.error("Unknown command. Available commands are:");
@@ -1,2 +1,2 @@
1
- declare const _default: (args: string[]) => void;
1
+ declare const _default: (args: string[]) => Promise<void>;
2
2
  export default _default;
@@ -1,4 +1,70 @@
1
- export default (args) => {
1
+ import childProcess from "node:child_process";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ export default async (args) => {
2
5
  const name = args[0];
3
- console.log(`Project ${name} created.`);
6
+ if (name === undefined)
7
+ return console.error("No name supplied. Project creation cancelled");
8
+ console.log("1. Starting project creation...");
9
+ const folderAlreadyExists = await fs.exists(name);
10
+ if (folderAlreadyExists)
11
+ return console.error("There already exists a folder with that name.");
12
+ const fullPath = path.resolve(name);
13
+ await fs.mkdir(name);
14
+ console.log("2. Creating a new bun project...");
15
+ await runCommand("bun init -y", {
16
+ cwd: fullPath,
17
+ });
18
+ console.log("3. Installing dependencies...");
19
+ await runCommand("bun add htmv", {
20
+ cwd: fullPath,
21
+ });
22
+ console.log("4. Scaffolding project structure...");
23
+ await fs.mkdir(path.join(fullPath, "public"));
24
+ await fs.mkdir(path.join(fullPath, "routes"));
25
+ await fs.mkdir(path.join(fullPath, "views"));
26
+ const indexContent = `import path from "node:path";
27
+ import { fileURLToPath } from "node:url";
28
+ import { setup } from "htmv";
29
+
30
+ const __filename = fileURLToPath(import.meta.url);
31
+ const dirPath = path.dirname(__filename);
32
+ setup({
33
+ routes: path.join(dirPath, "routes"),
34
+ views: path.join(dirPath, "views"),
35
+ public: path.join(dirPath, "public"),
36
+ port: 3000,
37
+ });`;
38
+ await fs.writeFile(path.join(fullPath, "index.ts"), indexContent);
39
+ const routeContent = `import { type RouteParams, view } from "htmv";
40
+
41
+ export default async (_params: RouteParams) => {
42
+ return await view("example", {
43
+ title: "Welcome to HTMV!",
44
+ });
4
45
  };
46
+ `;
47
+ await fs.writeFile(path.join(fullPath, "routes", "index.ts"), routeContent);
48
+ const viewContent = `<!DOCTYPE html>
49
+ <html lang="en">
50
+
51
+ <head>
52
+ <title>{title}</title>
53
+ </head>
54
+
55
+ <body>
56
+ <h1>{title}</h1>
57
+ </body>
58
+ </html>`;
59
+ await fs.writeFile(path.join(fullPath, "views", "example.html"), viewContent);
60
+ console.log(`All done! Project ${name} created.`);
61
+ console.log(`Now run cd ${name} and start building your next big project!`);
62
+ };
63
+ async function runCommand(command, options) {
64
+ const process = childProcess.exec(command, options);
65
+ return new Promise((resolve) => {
66
+ process.on("exit", () => {
67
+ resolve(1);
68
+ });
69
+ });
70
+ }
package/dist/index.js 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
  let viewsPath = "";
@@ -18,7 +17,7 @@ export async function view(view, props) {
18
17
  }
19
18
  export async function setup(paths) {
20
19
  viewsPath = paths.views;
21
- const app = new Elysia({ adapter: node() }).use(staticPlugin({
20
+ const app = new Elysia().use(staticPlugin({
22
21
  assets: paths.public,
23
22
  }));
24
23
  await registerRoutes(app, paths.routes);
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.6",
5
+ "version": "0.0.8",
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.15"
16
+ "elysia": "^1.4.18"
17
17
  },
18
18
  "bin": {
19
19
  "htmv": "dist/cli/cli.js"
package/src/cli/cli.ts CHANGED
@@ -18,7 +18,7 @@ const commands = {
18
18
  };
19
19
 
20
20
  if (command in commands) {
21
- commands[command as keyof typeof commands]();
21
+ await commands[command as keyof typeof commands]();
22
22
  process.exit(0);
23
23
  }
24
24
  console.error("Unknown command. Available commands are:");
@@ -1,4 +1,75 @@
1
- export default (args: string[]) => {
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
- console.log(`Project ${name} created.`);
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({ adapter: node() }).use(
37
+ const app = new Elysia().use(
39
38
  staticPlugin({
40
39
  assets: paths.public,
41
40
  }),