-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
update-readme.js
37 lines (28 loc) · 1.47 KB
/
update-readme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const Mustache = require('mustache');
const templateDir = path.join(__dirname, './templates/');
const targetDirs = [path.join(__dirname, './docs/de/'), path.join(__dirname, './docs/en/')];
const providerJumomind = require('./lib/provider/api-jumomind');
const providerAbfallio = require('./lib/provider/api-abfallio');
const providerAwido = require('./lib/provider/api-awido');
function generateProviders() {
const MUSTACHE_TEMPLATE = path.join(templateDir, 'providers.mustache');
const templateData = {
jumomind: Object.keys(providerJumomind).map((k) => ({ title: providerJumomind[k].title, cities: providerJumomind[k].cities.map((c) => `\t- ${c}`).join('\n') })),
abfallio: Object.keys(providerAbfallio).map((k) => ({ title: providerAbfallio[k].title, cities: providerAbfallio[k].cities.map((c) => `\t- ${c}`).join('\n') })),
awido: Object.keys(providerAwido).map((k) => ({ title: providerAwido[k].title })),
};
try {
const template = fs.readFileSync(MUSTACHE_TEMPLATE);
const output = Mustache.render(template.toString(), templateData);
for (const targetDir of targetDirs) {
fs.writeFileSync(path.join(targetDir, 'providers.md'), output);
}
console.log('generated providers.md');
} catch (err) {
console.error(`Unable to render mustache file "${MUSTACHE_TEMPLATE}": ${err}`);
}
}
generateProviders();