htmv 0.0.12 → 0.0.14

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import gen from "./commands/gen.js";
2
3
  import help from "./commands/help.js";
3
4
  import newCommand from "./commands/new.js";
4
5
  import { AVAILABLE_COMMANDS } from "./consts.js";
@@ -13,6 +14,7 @@ const commandArgs = args.slice(1);
13
14
  const commands = {
14
15
  help,
15
16
  new: () => newCommand(commandArgs),
17
+ gen: () => gen(commandArgs),
16
18
  };
17
19
  if (command in commands) {
18
20
  await commands[command]();
@@ -0,0 +1,2 @@
1
+ declare const _default: (args: string[]) => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,63 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { exists } from "../utils.js";
4
+ export default async (args) => {
5
+ const [type, name, ...options] = args;
6
+ if (type === undefined || name === undefined)
7
+ return console.error("You must specify both a type and name of file to generate.\nCorrect usage: htmv gen {TYPE} {NAME} {OPTIONS}");
8
+ if (!["view", "route"].includes(type.toLowerCase()))
9
+ return console.error("Invalid type inputted. Valid types are: view, route");
10
+ if (type.toLowerCase() === "view") {
11
+ const viewsFolderPath = await validateOptions("views", ...options);
12
+ const viewsContents = `<!DOCTYPE html>
13
+ <html lang="en">
14
+
15
+ <head>
16
+ <title>${name} view</title>
17
+ </head>
18
+
19
+ <body>
20
+ <h1>This view was quickly generated with htmv gen.</h1>
21
+ </body>
22
+ </html>`;
23
+ await generateFile(path.join(viewsFolderPath, `${name}.ts`), viewsContents);
24
+ }
25
+ if (type.toLowerCase() === "route") {
26
+ const routesFolderPath = await validateOptions("route", ...options);
27
+ const routeContents = `import { type RouteParams } from "htmv";
28
+
29
+ export default (_params: RouteParams) => {
30
+ return "Just a simple ALL method.";
31
+ };
32
+
33
+ export function POST (_params: RouteParams) => {
34
+ return "Searching for something more specific? How about a POST method route?"
35
+ };
36
+ `;
37
+ await generateFile(path.join(routesFolderPath, `${name}.ts`), routeContents);
38
+ }
39
+ console.log(`${type} ${name} generated succesfully.`);
40
+ };
41
+ async function generateFile(_path, contents) {
42
+ await fs.writeFile(_path, contents);
43
+ }
44
+ async function validateOptions(folderName, optionName, optionValue) {
45
+ let folderPath = path.resolve(folderName);
46
+ if (optionName) {
47
+ if (optionName !== "--path") {
48
+ console.error("Invalid option provided. Valid options are: --path.");
49
+ process.exit(1);
50
+ }
51
+ if (optionValue === undefined) {
52
+ console.error("No option value provided.");
53
+ process.exit(1);
54
+ }
55
+ folderPath = path.resolve(optionValue);
56
+ }
57
+ const viewsFolderExists = await exists(folderPath);
58
+ if (!viewsFolderExists) {
59
+ console.error(`Unable to find ${folderName} folder. Did you change your ${folderName} folder's name? If so, did you pass the option --path with the corresponding path to it?`);
60
+ process.exit(1);
61
+ }
62
+ return folderPath;
63
+ }
@@ -1,6 +1,7 @@
1
1
  import childProcess from "node:child_process";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { exists } from "../utils.js";
4
5
  export default async (args) => {
5
6
  const name = args[0];
6
7
  if (name === undefined)
@@ -75,12 +76,3 @@ async function runCommand(command, options) {
75
76
  });
76
77
  });
77
78
  }
78
- async function exists(path) {
79
- try {
80
- await fs.access(path);
81
- return true;
82
- }
83
- catch {
84
- return false;
85
- }
86
- }
@@ -1 +1 @@
1
- export declare const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)";
1
+ export declare const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)\n3. htmv gen {TYPE} {NAME} {OPTIONS} (generates files for you)";
@@ -1 +1 @@
1
- export const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)";
1
+ export const AVAILABLE_COMMANDS = "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)\n3. htmv gen {TYPE} {NAME} {OPTIONS} (generates files for you)";
@@ -0,0 +1 @@
1
+ export declare function exists(path: string): Promise<boolean>;
@@ -0,0 +1,10 @@
1
+ import fs from "node:fs/promises";
2
+ export async function exists(path) {
3
+ try {
4
+ await fs.access(path);
5
+ return true;
6
+ }
7
+ catch {
8
+ return false;
9
+ }
10
+ }
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.12",
5
+ "version": "0.0.14",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "2.3.3",
8
8
  "@types/bun": "latest"
package/src/cli/consts.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const AVAILABLE_COMMANDS =
2
- "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)";
2
+ "1. htmv new {project_name} (creates a new HTMV project)\n2. htmv help (prints this page)\n3. htmv gen {TYPE} {NAME} {OPTIONS} (generates files for you)";