-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.ts
42 lines (41 loc) · 1.06 KB
/
render.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {
basename,
join,
resolve,
} from "https://deno.land/std@0.146.0/path/mod.ts";
import {
compile,
render as etaRender,
templates,
} from "https://deno.land/x/eta@v1.12.3/mod.ts";
export const render = async (
readmeFilePath: string,
readmeDirectoryPath: string,
readmeTemplate: string,
templatesPath: string,
error: (message: string, error?: Error) => void,
): Promise<string | void> => {
for await (const template of Deno.readDir(templatesPath)) {
if (template.isFile && template.name.endsWith(".template.md")) {
templates.define(
template.name,
compile(
await Deno.readTextFile(resolve(join(templatesPath, template.name))),
),
);
}
}
try {
return etaRender(
'<%~ include("README.template.md", {...it}) %>',
{
name: basename(readmeDirectoryPath),
readmeFilePath,
readmeDirectoryPath,
readme: readmeTemplate,
},
) as Promise<string>;
} catch (e) {
error(`Something went wrong rendering the README ${readmeFilePath}`, e);
}
};