feat(template): adds templates

if an `TEMPLATE.ejs` file is found in the repo it will be used for rendering

closes #14
This commit is contained in:
Simone Corsi
2022-04-13 13:22:40 +02:00
parent 9d140076f7
commit 2c742b8205
3 changed files with 32 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import { readdir, readFile } from 'fs/promises';
import {
renderer,
@@ -27,11 +28,25 @@ export async function main(): Promise<any> {
{}
);
const rendered = await renderer({
username: REPO_USERNAME,
stars: Object.entries(sortedByLanguages),
updatedAt: Date.now(),
});
// get template if found in the repo
let template;
try {
const dir = await readdir('./');
core.info(dir.join('\n'));
template = await readFile('TEMPLATE.ejs', 'utf8');
core.info(template);
} catch {
core.warning("Couldn't find template file, using default");
}
const rendered = await renderer(
{
username: REPO_USERNAME,
stars: Object.entries(sortedByLanguages),
updatedAt: Date.now(),
},
template
);
const markdown: string = await generateMd(rendered);