蓝牙调试页面初步完成
This commit is contained in:
47
tools/find_unused_images.js
Normal file
47
tools/find_unused_images.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const root = path.resolve(__dirname, '..');
|
||||
|
||||
function walk(dir) {
|
||||
const res = [];
|
||||
const items = fs.readdirSync(dir, { withFileTypes: true });
|
||||
for (const it of items) {
|
||||
const full = path.join(dir, it.name);
|
||||
if (it.isDirectory()) {
|
||||
// skip virtual env and node_modules
|
||||
if (['.venv', 'node_modules', '.git'].includes(it.name)) continue;
|
||||
res.push(...walk(full));
|
||||
} else {
|
||||
res.push(full);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function isImage(f) {
|
||||
return /\.(png|jpe?g|gif|svg|webp|ico)$/i.test(f);
|
||||
}
|
||||
function isTextFile(f) {
|
||||
return /\.(js|jsx|ts|tsx|json|html|htm|wxml|wxss|css|md|vue|py|java|xml|txt|scss|less|styl|mdx|yaml|yml)$/i.test(f);
|
||||
}
|
||||
|
||||
const all = walk(root);
|
||||
const images = all.filter(isImage);
|
||||
const textFiles = all.filter(isTextFile);
|
||||
|
||||
const unused = [];
|
||||
for (const img of images) {
|
||||
const name = path.basename(img);
|
||||
let found = false;
|
||||
for (const tf of textFiles) {
|
||||
try {
|
||||
const content = fs.readFileSync(tf, 'utf8');
|
||||
if (content.indexOf(name) !== -1) { found = true; break; }
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (!found) unused.push(img);
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({ images: images, unused: unused }, null, 2));
|
||||
Reference in New Issue
Block a user