Files
coffeechat/scripts/write-readme.js
2024-05-21 14:02:01 -04:00

51 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict;";
const fs = require("fs");
const appRoot = require("app-root-path");
let path = require("path");
//Get the data
path = path.parse(appRoot.path);
parentFolderPath = path.dir.split(path.sep).pop();
const data = fs.readFileSync(`${parentFolderPath}/people.json`);
const json = JSON.parse(data);
// Table header
const header = `|Name|URLs|Work|Languages|Topics|
|---|---|---|---|---|
`;
//Order by name
json.people.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
//Generate with proper formating
const peopleList = json.people
.map(
(person) => {
let socials = [];
['Website', 'LinkedIn', 'Twitter', 'Mastodon', 'GitHub'].forEach(social => {
if (person.hasOwnProperty(social.toLowerCase()) && person[social.toLowerCase()].length > 0) {
socials.push(`[${social}](${person[social.toLowerCase()]})`);
}
});
//Order the languages
person.languages.sort();
//Order the topics
person.topics.sort();
return `| **[${person.name}](${person.scheduling})** | ${socials.join('<br/>')} | ${person.title} at ${person.company} | ${person.languages.join('<br/>')} | ${person.topics.join('<br/>')} |`
}
)
.join("\r\n");
//Write README.md
const template = fs.readFileSync(`${appRoot}/README-TEMPLATE.md`, "utf8");
fs.writeFileSync(
`${parentFolderPath}/README.md`,
template.replace("PLACEHOLDER", [header, peopleList].join(""))
);