-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathgenerate.mjs
51 lines (40 loc) · 1.84 KB
/
generate.mjs
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
import cssdb from 'cssdb';
import fs from 'node:fs/promises';
let featuresTable = '';
featuresTable = featuresTable + '| | ID | Feature | example | docs |\n';
featuresTable = featuresTable + '|:--- |:--- |:--- |:--- |:--- |\n';
const pluginsData = await fs.readFile('./scripts/plugins-data.json', 'utf8').then(JSON.parse);
pluginsData.sort((a, b) => a.id.localeCompare(b.id));
for (const pluginData of pluginsData) {
if (pluginData.omitDocs) {
continue;
}
const cssdbFeature = cssdb.find(feature => feature.id === pluginData.id);
const polyfills = cssdbFeature?.polyfills || [];
const cssdbPlugins = polyfills?.filter(polyfill => polyfill.type === 'PostCSS Plugin');
cssdbPlugins.sort((a) => {
if (a.link.indexOf('https://github.com/csstools') === 0) {
return -1;
}
if (a.link.indexOf('https://github.com/postcss') === 0) {
return -1;
}
return 1;
});
if (cssdbFeature && cssdbPlugins.length > 0) {
featuresTable = featuresTable + `| [<img alt="Baseline Status" src="https://cssdb.org/images/badges-baseline/${pluginData.id}.svg" height="18">](https://cssdb.org/#${pluginData.id}) `;
featuresTable = featuresTable + `| \`${pluginData.id}\` `;
featuresTable = featuresTable + `| ${cssdbFeature.title} `;
featuresTable = featuresTable + `| [example](https://preset-env.cssdb.org/features/#${pluginData.id}) `;
featuresTable = featuresTable + `| [docs](${cssdbPlugins[0].link}#readme) |\n`;
} else {
featuresTable = featuresTable + '| ';
featuresTable = featuresTable + `| \`${pluginData.id}\` `;
featuresTable = featuresTable + '| ';
featuresTable = featuresTable + '| ';
featuresTable = featuresTable + '| |\n';
}
}
let featuresDoc = (await fs.readFile('./docs/FEATURES.md', 'utf8')).toString();
featuresDoc = featuresDoc.replaceAll('<featuresTable>', featuresTable);
fs.writeFile('FEATURES.md', featuresDoc, 'utf8');