@brand-map/generator 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brand-map/generator",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Renderer",
5
5
  "license": "MIT",
6
6
  "author": "Brand-Map Team",
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "scripts": {
14
- "format": "oxfmt",
14
+ "fmt": "oxfmt .",
15
15
  "lint:fix": "oxlint --fix"
16
16
  },
17
17
  "dependencies": {
@@ -55,6 +55,51 @@ export async function loadTemplates(
55
55
  };
56
56
  }
57
57
 
58
+ export async function templates(
59
+ teamplatesPath: string,
60
+ config?: {
61
+ filters?: (template: any) => boolean;
62
+ },
63
+ ): Promise<{ templates: Record<string, TemplateData> }> {
64
+ if (!teamplatesPath || typeof teamplatesPath !== "string") {
65
+ throw new Error(`Invalid templates path provided. Try string`);
66
+ }
67
+
68
+ const record = {} as Record<string, TemplateData>;
69
+
70
+ const resolvedPath = resolve(teamplatesPath);
71
+
72
+ const filters = config?.filters;
73
+
74
+ for await (const templatePath of walkDir(resolvedPath)) {
75
+ if (path.basename(templatePath).startsWith("_")) {
76
+ continue;
77
+ }
78
+
79
+ if (filters && !filters(templatePath)) {
80
+ continue;
81
+ }
82
+
83
+ const relative = path.relative(resolvedPath, templatePath).replace(".hbs", "").replace(".vto", "");
84
+
85
+ const contentRaw = await readFile(path.resolve(resolvedPath, templatePath));
86
+
87
+ const data: TemplateData = {
88
+ content: new TextDecoder().decode(contentRaw),
89
+ path: templatePath,
90
+ relative,
91
+ };
92
+
93
+ if (data.relative.startsWith("_")) {
94
+ continue;
95
+ }
96
+
97
+ Object.assign(record, { [relative]: data });
98
+ }
99
+
100
+ return { templates: record };
101
+ }
102
+
58
103
  async function* walkDir(dir: string): AsyncGenerator<string, void, void> {
59
104
  const entries = await readdir(dir, { withFileTypes: true });
60
105
 
package/src/exports.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Genrator } from "./generator";
2
- export { loadTemplates } from "./actions/load-templates";
2
+ export { loadTemplates, templates } from "./actions/load-templates";
3
+ export { VentoRenderer } from "./renderer-vento";