-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportImagePaths.js
More file actions
30 lines (22 loc) · 797 Bytes
/
Copy pathexportImagePaths.js
File metadata and controls
30 lines (22 loc) · 797 Bytes
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
/* eslint-disable @typescript-eslint/no-require-imports */
const fs = require('fs');
const path = require('path');
function getImagePaths(dir, fileList = []) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const fileStat = fs.statSync(filePath);
if (fileStat.isDirectory()) {
getImagePaths(filePath, fileList);
} else {
const ext = path.extname(file).toLowerCase();
if (['.svg', '.jpg', '.jpeg', '.png', '.ico'].includes(ext)) {
fileList.push(filePath.substring('public/'.length));
}
}
});
return fileList;
}
const imagePaths = getImagePaths('public');
fs.writeFileSync('public/image-paths.json', JSON.stringify(imagePaths));
console.log('Image paths exported successfully!');