From 2c742b820558fd715de987178303c460f5871c29 Mon Sep 17 00:00:00 2001 From: Simone Corsi Date: Wed, 13 Apr 2022 13:22:40 +0200 Subject: [PATCH] feat(template): adds templates if an `TEMPLATE.ejs` file is found in the repo it will be used for rendering closes #14 --- CHANGELOG.md | 31 ++++++++++--------------------- package-lock.json | 4 ++-- src/index.ts | 25 ++++++++++++++++++++----- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8813623..9083830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,35 +1,24 @@ ## 1.0.45 (2022-01-17) -* build(deps): bump shelljs from 0.8.4 to 0.8.5 ([1da350a](https://github.com/simonecorsi/mawesome/commit/1da350a)) - - +- build(deps): bump shelljs from 0.8.4 to 0.8.5 ([1da350a](https://github.com/simonecorsi/mawesome/commit/1da350a)) ## 1.0.44 (2021-10-26) -* chore(release): v1.0.44 ([6ffe17f](https://github.com/simonecorsi/mawesome/commit/6ffe17f)) -* feat: git add multiple files at once ([4aef61f](https://github.com/simonecorsi/mawesome/commit/4aef61f)) - - +- chore(release): v1.0.44 ([6ffe17f](https://github.com/simonecorsi/mawesome/commit/6ffe17f)) +- feat: git add multiple files at once ([4aef61f](https://github.com/simonecorsi/mawesome/commit/4aef61f)) ## 1.0.43 (2021-10-15) -* chore(release): v1.0.43 ([5e0ef82](https://github.com/simonecorsi/mawesome/commit/5e0ef82)) -* feat: reduce json output size ([94635fe](https://github.com/simonecorsi/mawesome/commit/94635fe)) - - +- chore(release): v1.0.43 ([5e0ef82](https://github.com/simonecorsi/mawesome/commit/5e0ef82)) +- feat: reduce json output size ([94635fe](https://github.com/simonecorsi/mawesome/commit/94635fe)) ## 1.0.42 (2021-10-14) -* chore(release): v1.0.42 ([5b36813](https://github.com/simonecorsi/mawesome/commit/5b36813)) -* fix(paginator): last page now correctly matches rex ([dcf9898](https://github.com/simonecorsi/mawesome/commit/dcf9898)) - - +- chore(release): v1.0.42 ([5b36813](https://github.com/simonecorsi/mawesome/commit/5b36813)) +- fix(paginator): last page now correctly matches rex ([dcf9898](https://github.com/simonecorsi/mawesome/commit/dcf9898)) ## 1.0.41 (2021-10-14) -* chore(release): v1.0.41 ([884fc90](https://github.com/simonecorsi/mawesome/commit/884fc90)) -* test: fixs suite ([b97833f](https://github.com/simonecorsi/mawesome/commit/b97833f)) -* fix: should avoid index lock ([1d6848c](https://github.com/simonecorsi/mawesome/commit/1d6848c)) - - - +- chore(release): v1.0.41 ([884fc90](https://github.com/simonecorsi/mawesome/commit/884fc90)) +- test: fixs suite ([b97833f](https://github.com/simonecorsi/mawesome/commit/b97833f)) +- fix: should avoid index lock ([1d6848c](https://github.com/simonecorsi/mawesome/commit/1d6848c)) diff --git a/package-lock.json b/package-lock.json index 32879b2..0410360 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mawesome", - "version": "1.0.45", + "version": "1.1.0-next.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mawesome", - "version": "1.0.45", + "version": "1.1.0-next.1", "license": "MIT", "dependencies": { "@actions/core": "^1.8.0", diff --git a/src/index.ts b/src/index.ts index abc0552..ac01c45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { {} ); - 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);