[Build] Improve treeWalker, renderer & wallpaper finder

This commit is contained in:
2025-03-29 10:30:08 +01:00
parent 527f2012de
commit c9442acce8
4 changed files with 31 additions and 21 deletions

View File

@@ -3,27 +3,27 @@ const fs = require( 'fs' );
const path = require( 'path' );
/**
* Recursively find all HTML files in a directory
* Recursively find all files with extension in a directory
* @param {string} dir The directory to search. Either absolute or relative path
* @param {string} extension The file extension to look for
* @returns {string[]} returns a list of html files with their full path
*/
const treeWalker = ( dir, extension ) => {
const treeWalker = ( dir, extension, ignoreList ) => {
const ls = fs.readdirSync( dir );
const fileList = [];
for ( let file in ls ) {
if ( fs.statSync( path.join( dir, ls[ file ] ) ).isDirectory() ) {
const newFiles = treeWalker( path.join( dir, ls[ file ] ), extension );
// TODO: Ignore files in .gitignore, as well as .gitignore
if ( !newFiles.includes( '.configbuildignore' ) ) {
for ( let file in newFiles ) {
// Filter ignored directories
if ( ignoreList === undefined || !ignoreList.includes( ls[ file ] ) ) {
const newFiles = treeWalker( path.join( dir, ls[ file ] ), extension, ignoreList );
for (let file = 0; file < newFiles.length; file++) {
fileList.push( newFiles[ file ] );
}
}
} else if ( extension == '*' ) {
fileList.push( path.join( dir, ls[ file ] ) );
} else if ( ls[ file ].includes( extension ) ) {
fileList.push( path.join( dir, ls[ file ] ) );
} else if ( extension == '*' || ls[ file ].includes( extension ) ) {
if ( ignoreList === undefined || !ignoreList.includes( ls[ file ] ) ) {
fileList.push( path.join( dir, ls[ file ] ) );
}
}
}