forked from Leantime/leantime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateBlocklist.mjs
29 lines (24 loc) · 913 Bytes
/
generateBlocklist.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
import fs from 'fs';
import postcss from 'postcss';
import selectorParser from 'postcss-selector-parser';
import pjson from './package.json' assert { type: 'json' };
const css = fs.readFileSync(`./public/dist/css/app.${pjson.version}.min.css`, 'utf-8');
const classNames = new Set();
const addClassIfMatches = (classNode) => {
if (classNode.value.startsWith('tw-')) {
classNames.add(classNode.value);
}
};
const processSelectors = (rule) => {
selectorParser(selectors => {
selectors.walkClasses(addClassIfMatches);
}).processSync(rule);
};
const extractClassesPlugin = postcss.plugin('extract-classes', () => {
return (root) => {
root.walkRules(processSelectors);
};
});
await postcss([extractClassesPlugin]).process(css, { from: undefined });
const blocklist = Array.from(classNames);
fs.writeFileSync('./blocklist.json', JSON.stringify(blocklist, null, 2));