-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlook-for-deprecated-bs4-classes.mjs
39 lines (30 loc) · 1.24 KB
/
look-for-deprecated-bs4-classes.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
import { readdir, readFile } from 'node:fs';
const path = './_site';
const options = {
recursive: true
}
const htmlFileRegExp = /.+\.(html)$/;
// const jsFileRegExp = /.+\.(js)$/;
const deprecatedClassRegExp = /["\s]([pm][lr](?:-(?:sm|md|lg|xl))?-[0-5]|(?:text|float)(?:-(?:sm|md|lg|xl))?-(?:left|right)|sr-only|text-muted|close|table-responsive)["\s]/;
const deprecatedClassRegExpGlobal = /["\s]([pm][lr](?:-(?:sm|md|lg|xl))?-[0-5]|(?:text|float)(?:-(?:sm|md|lg|xl))?-(?:left|right)|sr-only|text-muted|close|table-responsive)["\s]/g;
console.log(`\n==== [SEARCHING in: ${path}] ====`);
readdir(path, options, (err, files) => {
if (err) {
console.error("Could not list the directory.", err);
process.exit(1);
}
const htmlFiles = files.filter(file => !file.search(htmlFileRegExp));
htmlFiles.forEach(file => {
readFile(`${path}/${file}`, 'utf8', (err, data) => {
if (err) {
console.error("Could not read file.", err);
process.exit(1);
}
if (data.search(deprecatedClassRegExp) !== -1) {
const classArr = data.match(deprecatedClassRegExpGlobal);
classArr.forEach(match => console.log(`[FOUND]: ${match} in ${file}`));
}
});
});
});
console.log(`\n==== [RESULTS] ====`);