-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
83 lines (71 loc) · 3.32 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
const Mustache = require('mustache');
const utils = require('./lib/utils');
const fs = require('node:fs');
const MUSTACHE_TEMPLATE = './README.mustache';
const maintainers = JSON.parse(fs.readFileSync('maintainers.json'));
if (process.argv.indexOf('--update-readme') > -1) {
console.log('Updating README.md');
Promise.all([utils.collectCommunityRepos(), utils.getBetaRepository()])
.then(values => {
const [adapterList, betaRepo] = values;
const templateData = {
generatedAt: new Date().toISOString(),
adapters: [],
adaptersUnlisted: [],
};
for (const adapter of adapterList) {
console.log (` processing adapter ${adapter.name}`);
const adapterName = adapter.name.replace('ioBroker.', '').toLowerCase();
let maint = '-';
if (maintainers?.[adapter.name] === '!') {
maint = `![Need Maintanance](https://img.shields.io/badge/needs-MAINTENANCE-red)`;
} else if (maintainers[adapter.name] === 'DEPRECATED') {
maint = `![DEPRECATED](https://img.shields.io/badge/DEPRECATED-black)`;
} else if (maintainers?.[adapter.name]) {
maint = maintainers[adapter.name].map(m => `[${m}](https://github.com/${m}/)`).join(', ');
}
if (betaRepo?.[adapterName]) {
const adapterData = betaRepo[adapterName];
templateData.adapters.push({
name: adapter.name,
title: String(adapterData?.titleLang?.en ?? adapterData?.title).trim(),
icon: adapterData.extIcon,
url: adapter.html_url,
adapterName: adapterName,
maintainer: maint,
version: {
beta: adapterData.version ?? '??',
betaAge: Math.ceil(Math.abs(Date.now() - new Date(adapterData.versionDate).getTime()) / (1000 * 60 * 60 * 24)),
stable: adapterData?.stable ?? '??',
},
installations: adapterData?.stat,
});
} else {
templateData.adaptersUnlisted.push({
name: adapter.name,
url: adapter.html_url,
adapterName: adapterName,
maintainer: maint,
});
}
}
if (templateData.adapters.length > 0) {
try {
// Update README
const template = fs.readFileSync(MUSTACHE_TEMPLATE);
const output = Mustache.render(template.toString(), templateData);
fs.writeFileSync('README.md', output);
console.log('generated README...');
} catch (err) {
console.error(`Unable to render mustache file "${MUSTACHE_TEMPLATE}": ${err}`);
}
console.log('done.');
}
});
} else if (process.argv.indexOf('--check-npm-permissions') > -1) {
utils.collectRepos()
.then(adapterList => {
// TODO
});
}