@brand-map/generator 0.0.0-dev.14 → 0.1.1
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/.oxfmtrc.json +29 -0
- package/.oxlintrc.json +144 -0
- package/README.md +203 -7
- package/bun.lock +47 -19
- package/package.json +15 -20
- package/src/actions/load-templates.ts +70 -0
- package/src/exports.ts +2 -0
- package/src/generator.ts +138 -0
- package/{lib.ts → src/lib.ts} +4 -4
- package/src/renderer-handlebars.ts +27 -0
- package/src/renderer-vento.ts +21 -0
- package/{types.ts → src/types.ts} +6 -4
- package/tsconfig.json +1 -1
- package/TODO.md +0 -2
- package/actions/ai.ts +0 -7
- package/actions/answer.ts +0 -7
- package/actions/blank.ts +0 -55
- package/actions/combine.ts +0 -14
- package/actions/config.ts +0 -7
- package/actions/context/context.ts +0 -44
- package/actions/context.ts +0 -10
- package/actions/echo.ts +0 -19
- package/actions/exports.ts +0 -9
- package/actions/jargal-context.ts +0 -21
- package/actions/jargal-templates.ts +0 -82
- package/actions/jargal-write.ts +0 -46
- package/actions/load-templates.ts +0 -125
- package/actions/modify.ts +0 -7
- package/actions/parallel.ts +0 -16
- package/actions/pipe/pipe.ts +0 -993
- package/actions/pipe.ts +0 -7
- package/actions/prompt.ts +0 -134
- package/actions/render-template.ts +0 -39
- package/actions/run/run.ts +0 -20
- package/actions/select-generator.ts +0 -28
- package/actions/use.ts +0 -9
- package/actions/validate-answers.ts +0 -13
- package/actions/write/write.ts +0 -69
- package/actions/write.ts +0 -51
- package/biome.json +0 -35
- package/exports.ts +0 -8
- package/jargal.ts +0 -181
- package/renderer.ts +0 -100
- package/runner.test.ts +0 -24
- package/runner.ts +0 -99
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { ContextAction } from "../types.ts";
|
|
2
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
-
import path, { resolve } from "node:path";
|
|
4
|
-
|
|
5
|
-
type TemplateData = {
|
|
6
|
-
templatePath: string;
|
|
7
|
-
realativePath: string;
|
|
8
|
-
templateContent: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function loadTemplates(
|
|
12
|
-
templatesPath: string,
|
|
13
|
-
options: {
|
|
14
|
-
scope?: string;
|
|
15
|
-
hooks?: {
|
|
16
|
-
onDataReady?: ((path: string, data: TemplateData) => [path: string, data: TemplateData])[];
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
): ContextAction<{ templates: Record<string, Map<string, TemplateData>> }> {
|
|
20
|
-
return async function execute(params) {
|
|
21
|
-
const record = { ...params.context.templates } as any as Record<string, Map<string, TemplateData>>;
|
|
22
|
-
|
|
23
|
-
if (options.scope) {
|
|
24
|
-
Object.assign(record, { [options.scope]: new Map() });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for await (const templatePath of walkDir(templatesPath)) {
|
|
28
|
-
const realativePath = path.relative(templatesPath, templatePath);
|
|
29
|
-
|
|
30
|
-
const contentRaw = await readFile(path.resolve(templatesPath, templatePath));
|
|
31
|
-
const data: TemplateData = {
|
|
32
|
-
templateContent: new TextDecoder().decode(contentRaw),
|
|
33
|
-
templatePath,
|
|
34
|
-
realativePath,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (!options.hooks) {
|
|
38
|
-
record[options.scope ? options.scope : "templates"]?.set(realativePath, data);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (options.hooks?.onDataReady?.length) {
|
|
43
|
-
let path_ = realativePath;
|
|
44
|
-
let data_ = data;
|
|
45
|
-
|
|
46
|
-
for (const hook of options.hooks.onDataReady) {
|
|
47
|
-
[path_, data_] = hook(path_, data_);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
record[options.scope ? options.scope : "templates"]?.set(path_, data_);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return { templates: record };
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function templates<Scope extends string | undefined = undefined>(params: {
|
|
59
|
-
path: string;
|
|
60
|
-
scope?: Scope;
|
|
61
|
-
hooks?: {
|
|
62
|
-
onDataReady?: ((path: string, data: TemplateData) => [path: string, data: TemplateData])[];
|
|
63
|
-
};
|
|
64
|
-
}): Promise<
|
|
65
|
-
(ctx: Record<string, any>) => {
|
|
66
|
-
templates: Record<Scope extends undefined ? "default" : Scope, Map<string, TemplateData>>;
|
|
67
|
-
}
|
|
68
|
-
> {
|
|
69
|
-
let record: undefined | Record<string, Map<string, TemplateData>> = undefined;
|
|
70
|
-
|
|
71
|
-
if (params.scope) {
|
|
72
|
-
record = { [params.scope]: new Map() };
|
|
73
|
-
} else {
|
|
74
|
-
record = { default: new Map() };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const resolvedPath = resolve(params.path);
|
|
78
|
-
|
|
79
|
-
for await (const templatePath of walkDir(resolvedPath)) {
|
|
80
|
-
const realativePath = path.relative(resolvedPath, templatePath);
|
|
81
|
-
|
|
82
|
-
const contentRaw = await readFile(path.resolve(resolvedPath, templatePath));
|
|
83
|
-
const data: TemplateData = {
|
|
84
|
-
templateContent: new TextDecoder().decode(contentRaw),
|
|
85
|
-
templatePath,
|
|
86
|
-
realativePath,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
if (!params.hooks) {
|
|
90
|
-
record[params.scope ? params.scope : "default"]?.set(realativePath, data);
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (params.hooks?.onDataReady?.length) {
|
|
95
|
-
let path_ = realativePath;
|
|
96
|
-
let data_ = data;
|
|
97
|
-
|
|
98
|
-
for (const hook of params.hooks.onDataReady) {
|
|
99
|
-
[path_, data_] = hook(path_, data_);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
record[params.scope ? params.scope : "default"]?.set(path_, data_);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return function setter(_ctx: Record<string, any>): {
|
|
107
|
-
templates: Record<string, Map<string, TemplateData>>;
|
|
108
|
-
} {
|
|
109
|
-
return { templates: record };
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function* walkDir(dir: string): AsyncGenerator<string, void, void> {
|
|
114
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
115
|
-
|
|
116
|
-
for (const entry of entries) {
|
|
117
|
-
const templatePath = path.join(dir, entry.name);
|
|
118
|
-
|
|
119
|
-
if (entry.isDirectory()) {
|
|
120
|
-
yield* walkDir(templatePath);
|
|
121
|
-
} else if (entry.isFile()) {
|
|
122
|
-
yield templatePath;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
package/actions/modify.ts
DELETED
package/actions/parallel.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { executeAction } from "../runner.ts";
|
|
2
|
-
import type { Action } from "../types.ts";
|
|
3
|
-
|
|
4
|
-
export function parallel(actions: Action[]): Action {
|
|
5
|
-
return async function execute(params) {
|
|
6
|
-
await Promise.all(
|
|
7
|
-
actions.map((action) =>
|
|
8
|
-
executeAction({
|
|
9
|
-
action,
|
|
10
|
-
context: params.context,
|
|
11
|
-
renderer: params.renderer,
|
|
12
|
-
}),
|
|
13
|
-
),
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
}
|