diff --git a/build/build.js b/build/build.js index 8bffb5b..d775909 100644 --- a/build/build.js +++ b/build/build.js @@ -4,13 +4,16 @@ const fs = require( 'fs' ); const path = require( 'path' ); const os = require( 'os' ); const render = require( './render' ); +const { treeWalker } = require('./util'); // Prompt user to select a wallpaper (if no path is passed as argument) -const wallpapers = fs.readdirSync( path.join( os.homedir(), '/NextCloud/Wallpapers' ) ); +const wallpapers = treeWalker( path.join( os.homedir(), '/NextCloud/Wallpapers' ), '*' ); +// const wallpapers = fs.readdirSync( path.join( os.homedir(), '/NextCloud/Wallpapers' ) ); const wallpaperChoices = []; wallpapers.forEach(element => { - wallpaperChoices.push( { 'name': element.split( '.' )[ 0 ], 'value': element } ); + const name = element.split( '/' ); + wallpaperChoices.push( { 'name': name[ name.length - 1 ].split( '.' )[ 0 ], 'value': element } ); }); @@ -49,5 +52,5 @@ inquirer.default.prompt( [ chooseLockpaper, chooseTheme ] ).then( answers => { - render( path.join( os.homedir(), '/NextCloud/Wallpapers', answers.wallpaper ), path.join( os.homedir(), '/NextCloud/Wallpapers', answers.lockpaper ), answers.theme ); + render( answers.wallpaper, answers.lockpaper, answers.theme ); } ); diff --git a/build/render.js b/build/render.js index 879b4b9..2be0e97 100644 --- a/build/render.js +++ b/build/render.js @@ -57,13 +57,13 @@ const build = ( wallpaper, lockpaper, theme ) => { // recursively index files from config directory -> Maybe add a file to each // directory to indicate whether or not to index files in it? - const fileList = util.treeWalker( path.join( __dirname, '/../config/' ), '*' ); + const fileList = util.treeWalker( path.join( __dirname, '/../config/' ), '*', [ 'node_modules', '@girs', '.gitignore', '.git' ] ); console.log( fileList ); - for (let index = 0; index < fileList; index++) { + for (let index = 0; index < fileList.length; index++) { try { render( fileList[ index ], view ); } catch ( e ) { - console.error( '=> Render failed for ' + fileList[ index ] ); + console.error( '=> Render failed for ' + fileList[ index ] + ' with error ' + e ); } } } ).catch( e => { @@ -136,13 +136,16 @@ const yaziThemes = { */ const render = ( templatePath, view ) => { // Load template from disk (all can be found in /config) - const template = '' + fs.readFileSync( path.join( __dirname, '/../config/', templatePath ) ); - const outPath = path.join( __dirname, 'dist', templatePath ) + // TODO: Make exclusion better plus copy other files maybe? + const template = '' + fs.readFileSync( templatePath ); + const outPath = path.join( templatePath.replace( 'config', 'dist' ) ); console.log( '=> Rendering to ' + outPath ); try { - fs.mkdir( path.dirname( outPath ) ); - } catch ( _ ) { - + fs.mkdirSync( path.dirname( outPath ), { + recursive: true, + } ); + } catch ( e ) { + console.error( e ); } fs.writeFileSync( outPath, mustache.render( template, view ) ); } diff --git a/build/util.js b/build/util.js index cae1b7f..2b53548 100644 --- a/build/util.js +++ b/build/util.js @@ -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 ] ) ); + } } } diff --git a/collect b/collect index 9584893..2359d03 100755 --- a/collect +++ b/collect @@ -1,3 +1,7 @@ #!/bin/sh # Read file in ~/.config and check if on laptop or desktop +# hyprpm update +# hyprpm add https://github.com/micha4w/Hypr-DarkWindow +# hyprpm enable Hypr-DarkWindow +# hyprpm reload