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.
package/dist/cli/commands/gen.js
CHANGED
|
@@ -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}.
|
|
23
|
+
const fileName = `${name}.htmv`;
|
|
24
24
|
const filePath = path.join(viewsFolderPath, fileName);
|
|
25
25
|
const fileAlreadyExists = await exists(filePath);
|
|
26
26
|
if (fileAlreadyExists)
|
package/dist/cli/commands/new.js
CHANGED
|
@@ -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.
|
|
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,
|
package/dist/views-registry.d.ts
CHANGED
package/dist/views-registry.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
}
|