mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2026-01-14 05:47:50 -06:00
v1.198.1
This commit is contained in:
44
node/find-mergable-scripts.js
Normal file
44
node/find-mergable-scripts.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Can be used to inspect which HTML files depend on which scripts.
|
||||
*/
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as ut from "./util.js";
|
||||
import "../js/utils.js";
|
||||
|
||||
const files = ut.listFiles({
|
||||
dir: ".",
|
||||
allowlistDirs: [],
|
||||
allowlistFileExts: [".html"],
|
||||
});
|
||||
|
||||
const ALL_JS_FILES = new Set([]);
|
||||
const FILE_TO_JS_FILES = {};
|
||||
|
||||
files.forEach(file => {
|
||||
const cleanFilename = file.replace("./", "");
|
||||
const html = fs.readFileSync(file, "utf-8");
|
||||
html.replace(/src="js\/(.*?\.js)"/g, (...m) => {
|
||||
ALL_JS_FILES.add(m[1]);
|
||||
(FILE_TO_JS_FILES[cleanFilename] = FILE_TO_JS_FILES[cleanFilename] || [])
|
||||
.push(m[1]);
|
||||
});
|
||||
});
|
||||
|
||||
const out = [];
|
||||
const numFiles = Object.keys(FILE_TO_JS_FILES).length;
|
||||
[...ALL_JS_FILES].sort(SortUtil.ascSortLower).forEach(file => {
|
||||
const total = Object.values(FILE_TO_JS_FILES).filter(it => it.includes(file)).length;
|
||||
out.push({file, total});
|
||||
});
|
||||
|
||||
out.sort((a, b) => SortUtil.ascSort(b.total, a.total))
|
||||
.forEach(it => {
|
||||
if (it.total > numFiles / 2 && it.total < numFiles) {
|
||||
const notSeenIn = Object.keys(FILE_TO_JS_FILES).filter(k => !FILE_TO_JS_FILES[k].includes(it.file));
|
||||
console.log(`${it.total}/${numFiles} ${it.file} -- missing from:`);
|
||||
notSeenIn.forEach(it => console.log(`\t${it}`));
|
||||
} else {
|
||||
console.log(`${it.total}/${numFiles} ${it.file}`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user