htmv 0.0.65 → 0.0.66

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.
@@ -20,7 +20,7 @@ export default async (args) => {
20
20
  <h1>This view was quickly generated with htmv gen.</h1>
21
21
  </body>
22
22
  </html>`;
23
- const fileName = `${name}.html`;
23
+ const fileName = `${name}.htmv`;
24
24
  const filePath = path.join(viewsFolderPath, fileName);
25
25
  const fileAlreadyExists = await exists(filePath);
26
26
  if (fileAlreadyExists)
@@ -57,7 +57,7 @@ export default async (_params: RouteParams) => {
57
57
  <h1>{title}</h1>
58
58
  </body>
59
59
  </html>`;
60
- await fs.writeFile(path.join(fullPath, "views", "example.html"), viewContent);
60
+ await fs.writeFile(path.join(fullPath, "views", "example.htmv"), viewContent);
61
61
  console.log("5. Creating run scripts...");
62
62
  await runCommand(`npm pkg set scripts.dev="bun --watch ."`, {
63
63
  cwd: fullPath,
@@ -1,3 +1,2 @@
1
1
  export declare const viewRegistry: Record<string, string>;
2
- export declare function addToViewRegistry(name: string, code: string): void;
3
2
  export declare function registerViews(): Promise<void>;
@@ -2,17 +2,25 @@ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { viewsPath } from "./views";
4
4
  export const viewRegistry = {};
5
- export function addToViewRegistry(name, code) {
5
+ /**
6
+ * Placing .HTMV last gives it priority
7
+ * This means, if there is both example.html and example.htmv in same subdir,
8
+ * example.htmv will take priority.
9
+ */
10
+ const SUPPORTED_FILE_EXTENSIONS = ["html", "htmv"];
11
+ function addToViewRegistry(name, code) {
6
12
  viewRegistry[name] = code;
7
13
  }
8
14
  export async function registerViews() {
9
15
  const files = await deepReadDir(viewsPath);
10
16
  for (const file of files) {
11
- if (file.endsWith(".html")) {
12
- const relativePath = path.relative(viewsPath, file);
13
- const name = relativePath.slice(0, -".html".length);
14
- const code = await fs.readFile(file, "utf-8");
15
- addToViewRegistry(name, code);
17
+ for (const extension in SUPPORTED_FILE_EXTENSIONS) {
18
+ if (file.endsWith(`.${extension}`)) {
19
+ const relativePath = path.relative(viewsPath, file);
20
+ const name = relativePath.slice(0, -`.${extension}`.length);
21
+ const code = await fs.readFile(file, "utf-8");
22
+ addToViewRegistry(name, code);
23
+ }
16
24
  }
17
25
  }
18
26
  }
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.65",
5
+ "version": "0.0.66",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",