[Build] Tons of improvements
This commit is contained in:
40
build/util.js
Normal file
40
build/util.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const convert = require( 'color-convert' );
|
||||
|
||||
/**
|
||||
* Recursively find all HTML files 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 ls = fs.readdirSync( dir );
|
||||
const fileList = [];
|
||||
for ( let file in ls ) {
|
||||
if ( !ls[ file ].includes( '.' ) ) {
|
||||
const newFiles = treeWalker( dir + '/' + ls[ file ], extension );
|
||||
for ( let file in newFiles ) {
|
||||
fileList.push( newFiles[ file ] );
|
||||
}
|
||||
} else if ( extension == '*' ) {
|
||||
fileList.push( dir + '/' + ls[ file ] );
|
||||
} else if ( ls[ file ].includes( extension ) ) {
|
||||
fileList.push( dir + '/' + ls[ file ] );
|
||||
}
|
||||
}
|
||||
|
||||
return fileList;
|
||||
}
|
||||
|
||||
const renderColourAsHex = ( colour ) => {
|
||||
return '#' + convert.default.rgb.hex( colour[ 0 ], colour[ 1 ], colour[ 2 ] );
|
||||
}
|
||||
|
||||
const renderColourAsRGB = ( colour ) => {
|
||||
return `rgb( ${ colour[ 0 ] }, ${ colour[ 1 ] }, ${ colour[ 2 ] } )`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
treeWalker,
|
||||
renderColourAsHex,
|
||||
renderColourAsRGB
|
||||
}
|
||||
Reference in New Issue
Block a user