[Build] Improve rendering, add fs parsing
FS parsing needs a lot of improvements (namely ignoring gitignore files). Probably gonna migrate to a library for this
This commit is contained in:
		| @@ -50,7 +50,7 @@ const build = ( wallpaper, lockpaper, theme ) => { | ||||
|         console.log( view ); | ||||
|  | ||||
|         try { | ||||
|             fs.mkdir( path.join( __dirname + '../dist' ) ); | ||||
|             fs.mkdir( path.join( __dirname, '/dist' ) ); | ||||
|         } catch ( e ) { | ||||
|  | ||||
|         } | ||||
| @@ -58,6 +58,7 @@ 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/' ), '*' ); | ||||
|         console.log( fileList ); | ||||
|         for (let index = 0; index < fileList; index++) { | ||||
|             try { | ||||
|                 render( fileList[ index ], view ); | ||||
| @@ -65,7 +66,8 @@ const build = ( wallpaper, lockpaper, theme ) => { | ||||
|                 console.error( '=> Render failed for ' + fileList[ index ] ); | ||||
|             } | ||||
|         } | ||||
|     } ).catch( () => { | ||||
|     } ).catch( e => { | ||||
|         console.error( e ); | ||||
|         console.error( '\n=> Failed to load image or retrieve colour palette from it' ); | ||||
|     } ); | ||||
| } | ||||
| @@ -135,7 +137,13 @@ const yaziThemes = { | ||||
| const render = ( templatePath, view ) => { | ||||
|     // Load template from disk (all can be found in <project-root>/config) | ||||
|     const template = '' + fs.readFileSync( path.join( __dirname, '/../config/', templatePath ) ); | ||||
|     const outPath = ''; | ||||
|     const outPath = path.join( __dirname, 'dist', templatePath )  | ||||
|     console.log( '=> Rendering to ' + outPath ); | ||||
|     try { | ||||
|         fs.mkdir( path.dirname( outPath ) ); | ||||
|     } catch ( _ ) { | ||||
|  | ||||
|     } | ||||
|     fs.writeFileSync( outPath, mustache.render( template, view ) ); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,6 @@ | ||||
| const convert = require( 'color-convert' ); | ||||
| const fs = require( 'fs' ); | ||||
| const path = require( 'path' ); | ||||
|  | ||||
| /** | ||||
|  * Recursively find all HTML files in a directory | ||||
| @@ -10,15 +12,18 @@ 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 ] ); | ||||
|         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 ) { | ||||
|                     fileList.push( newFiles[ file ] ); | ||||
|                 } | ||||
|             } | ||||
|         } else if ( extension == '*' ) { | ||||
|             fileList.push( dir + '/' + ls[ file ] ); | ||||
|             fileList.push( path.join( dir, ls[ file ] ) ); | ||||
|         } else if ( ls[ file ].includes( extension ) ) { | ||||
|             fileList.push( dir + '/' + ls[ file ] ); | ||||
|             fileList.push( path.join( dir, ls[ file ] ) ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user