-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_icon_list.js
39 lines (35 loc) · 1.11 KB
/
generate_icon_list.js
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
const fs = require('fs');
const path = require('path');
// Function to recursively find all files in a directory
function findFiles(dir, fileList = []) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
findFiles(filePath, fileList);
} else {
fileList.push(filePath);
}
});
return fileList;
}
// Function to generate the file list
function generateFileList(files, baseDir) {
return files.map((file, index) => {
const relativePath = path.relative(baseDir, file).replace(/\\/g, '/');
const key = path.basename(file, path.extname(file)).replace(/[-.]/g, '_');
const line = `\tXX(${key}, "${relativePath}")`;
return index === files.length - 1 ? line : `${line} \\`;
}).join('\n');
}
// Main function
function main() {
const baseDir = path.resolve(__dirname, 'dist/spa');
const files = findFiles(baseDir);
const fileList = generateFileList(files, baseDir);
console.log("#define FILE_LIST(XX) \\")
console.log(fileList);
}
// Run the main function
main();