Switch to Node.JS stack

This commit is contained in:
Lucàs
2022-12-21 15:32:27 +01:00
parent 64ac979669
commit 6b87f411c6
17 changed files with 254 additions and 210 deletions
-5
View File
@@ -1,5 +0,0 @@
{
"template": "model/template.njk",
"data": "model/data.json",
"output": "README.md"
}
-9
View File
@@ -1,9 +0,0 @@
import denjucks from "https://deno.land/x/denjucks/mod.js";
let { template, data, output } = JSON.parse(await Deno.readTextFile("src/config.json"));
template = await Deno.readTextFile(template);
data = JSON.parse(await Deno.readTextFile(data));
const result = denjucks.renderString(template, data);
await Deno.writeTextFile(output, result);
+6
View File
@@ -0,0 +1,6 @@
type FooterBadge = {
title: string
shield: string
}
export default FooterBadge;
+7
View File
@@ -0,0 +1,7 @@
type Link = {
title: string
shield: string
url: string
}
export default Link;
+32
View File
@@ -0,0 +1,32 @@
class Log {
colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
};
private readonly logFunction: (message?: any, ...optionalParams: any[]) => void;
constructor(logFunction: (message?: any, ...optionalParams: any[]) => void) {
this.logFunction = logFunction;
}
info(message: string): void {
this.logFunction(message);
}
success(message: string): void {
this.logFunction(this.colors.green, message);
}
error(message: string): void {
this.logFunction(this.colors.red, message);
}
warning(message: string): void {
this.logFunction(this.colors.yellow, message);
}
}
const log = new Log(console.log);
export default log;
+38
View File
@@ -0,0 +1,38 @@
import {SimpleIcon} from 'simple-icons/types';
export default class Skill {
private title: string;
private slug: string;
private shield: string;
constructor(icon: SimpleIcon) {
this.title = icon.title;
this.slug = icon.slug;
this.shield = this.buildShield(icon);
}
private buildShield(icon: SimpleIcon): string {
const baseUrl = 'https://img.shields.io/static/v1';
const params = {
label: '',
message: icon.title,
color: icon.hex,
logo: icon.slug,
logoColor: 'white',
};
const shieldUrl = new URL(baseUrl);
Object.entries(params).forEach(param => {
const [key, value] = param;
shieldUrl.searchParams.append(key, value);
});
return shieldUrl.toString();
}
public static sortBySlug(a: Skill, b: Skill) {
if (a.slug < b.slug) return -1;
if (a.slug > b.slug) return 1;
return 0;
}
}
+18
View File
@@ -0,0 +1,18 @@
import FooterBadge from '../core/FooterBadge';
const footerBadges: FooterBadge[] = [
{
title: 'Profile Views',
shield: 'https://komarev.com/ghpvc/?username=lucasvbr&amp;label=Profile%20views&amp;color=0e75b6&amp;style=flat',
},
{
title: "FreeCodeCamp Points",
shield: "https://img.shields.io/freecodecamp/points/lucasvbr?label=FreeCodeCamp%20points"
},
{
title: "Made with love",
shield: "https://img.shields.io/badge/-made%20with%20%E2%9D%A4%EF%B8%8F-red"
}
];
export default footerBadges;
+31
View File
@@ -0,0 +1,31 @@
import Link from '../core/Link';
const links: Link[] = [
{
title: 'Portfolio',
shield: 'https://img.shields.io/badge/my_portfolio-000?style=for-the-badge&logo=ko-fi&logoColor=white',
url: 'https://lucasvbr.github.io/links/?portfolio',
},
{
title: 'Linkedin Profile',
shield: 'https://img.shields.io/badge/linkedin-0e76a8?style=for-the-badge&logo=linkedin&logoColor=white',
url: 'https://www.linkedin.com/in/lucasvbr',
},
{
title: 'FreeCodeCamp Profile',
shield: 'https://img.shields.io/badge/freecodecamp-0a0a23?style=for-the-badge&logo=freecodecamp&logoColor=white',
url: 'https://www.freecodecamp.org/LucasVbr',
},
{
title: 'OpenClassRooms Profile',
shield: 'https://img.shields.io/badge/openclassrooms-7451eb?style=for-the-badge&logo=openclassrooms&logoColor=white',
url: 'https://openclassrooms.com/fr/members/97j9zltv6225',
},
{
title: 'Exercism Profile',
shield: 'https://img.shields.io/badge/exercism-2e57e8?style=for-the-badge&logo=exercism&logoColor=white',
url: 'https://exercism.org/profiles/LucasVbr',
},
];
export default links;
+37
View File
@@ -0,0 +1,37 @@
import {SimpleIcon} from 'simple-icons/types';
import icons from 'simple-icons';
import Skill from '../core/Skill';
const LIST_OF_ICONS: SimpleIcon[] = [
icons.siAngular,
icons.siSymfony,
icons.siGit,
icons.siHtml5,
icons.siFigma,
icons.siJavascript,
icons.siGnubash,
icons.siAndroid,
icons.siBulma,
icons.siMariadb,
icons.siSqlite,
icons.siCss3,
icons.siMysql,
icons.siPython,
icons.siC,
icons.siPostgresql,
icons.siPhp,
icons.siBootstrap,
icons.siExpress,
icons.siNodedotjs,
icons.siDeno,
icons.siTypescript,
icons.siOcaml,
icons.siMongodb,
icons.siReact,
icons.siDocker,
];
export default function getSkills(): Skill[] {
return LIST_OF_ICONS.map((icon: SimpleIcon) => new Skill(icon)).
sort(Skill.sortBySlug);
}
+24
View File
@@ -0,0 +1,24 @@
import {writeFile} from 'fs/promises';
import nunjucks from 'nunjucks';
import getSkills from './data/skills';
import Skill from './core/Skill';
import log from './core/Log';
import links from './data/links';
import footerBadges from './data/footerBadges';
const TEMPLATE_FILE: string = 'README.njk';
const OUTPUT_FILE: string = 'README.md';
const skills: Skill[] = getSkills();
nunjucks.configure('views/');
nunjucks.render(TEMPLATE_FILE, {skills, links, footerBadges}, (err, renderView : string | null) => {
if (err) {
log.error(err.message)
return;
}
writeFile(OUTPUT_FILE, renderView ?? "")
.then(() => log.success(`${OUTPUT_FILE} successfully generated`))
.catch((err: string) => console.error(err));
});