fix: better template management

This commit is contained in:
Simone Corsi
2021-01-16 11:25:07 +01:00
parent 0be94f1826
commit 9d06abc1f0
4 changed files with 17 additions and 9 deletions

View File

@@ -1,2 +0,0 @@
*
!dist/**/**

View File

@@ -55,7 +55,6 @@
"@actions/exec": "^1.0.4",
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"dotenv": "^8.2.0",
"ejs": "^3.1.5",
"got": "^11.8.1",
"remark": "^13.0.0",
@@ -64,4 +63,4 @@
"volta": {
"node": "14.15.4"
}
}
}

View File

@@ -1,6 +1,4 @@
import dotnenv from 'dotenv';
import fs from 'fs';
import ejs from 'ejs';
import remark from 'remark';
import toc from 'remark-toc';
@@ -8,8 +6,7 @@ import GithubApi from './api';
import link from './link';
import git from './git';
import * as core from '@actions/core';
const fsp = fs.promises;
import path from 'path';
import type {
SortedLanguageList,
@@ -19,6 +16,8 @@ import type {
ApiGetStarResponse,
} from './types';
const fsp = fs.promises;
const REPO_USERNAME = process.env.GITHUB_REPOSITORY?.split('/')[0];
const OUTPUT_FILENAME: string = core.getInput('output-filename') || 'README.md';
@@ -26,7 +25,8 @@ const API_STARRED_URL = `https://api.github.com/users/${REPO_USERNAME}/starred`;
const renderer = async (data: any) => {
try {
const MD_TEMPLATE = await fsp.readFile('fixtures/template.md.ejs', 'utf-8');
const p = path.resolve(process.cwd(), 'template.ejs');
const MD_TEMPLATE = await fsp.readFile(p, 'utf-8');
return ejs.render(MD_TEMPLATE, data);
} catch (error) {
core.error('#renderer');

11
template.ejs Normal file
View File

@@ -0,0 +1,11 @@
# <%= username %> Awesome List [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
## Table of Contents
<% for(let [language, repositories] of stars) { %>
## <%= language %>
<% for(let repo of repositories) { %>- [<%= repo.full_name %>](<%= repo.html_url %>) - <%= repo.description %>
<% } %>
<% } %>