[Build] Improve treeWalker, renderer & wallpaper finder
This commit is contained in:
parent
527f2012de
commit
c9442acce8
@ -4,13 +4,16 @@ const fs = require( 'fs' );
|
|||||||
const path = require( 'path' );
|
const path = require( 'path' );
|
||||||
const os = require( 'os' );
|
const os = require( 'os' );
|
||||||
const render = require( './render' );
|
const render = require( './render' );
|
||||||
|
const { treeWalker } = require('./util');
|
||||||
|
|
||||||
|
|
||||||
// Prompt user to select a wallpaper (if no path is passed as argument)
|
// 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 = [];
|
const wallpaperChoices = [];
|
||||||
wallpapers.forEach(element => {
|
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,
|
chooseLockpaper,
|
||||||
chooseTheme
|
chooseTheme
|
||||||
] ).then( answers => {
|
] ).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 );
|
||||||
} );
|
} );
|
||||||
|
@ -57,13 +57,13 @@ const build = ( wallpaper, lockpaper, theme ) => {
|
|||||||
|
|
||||||
// recursively index files from config directory -> Maybe add a file to each
|
// recursively index files from config directory -> Maybe add a file to each
|
||||||
// directory to indicate whether or not to index files in it?
|
// 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 );
|
console.log( fileList );
|
||||||
for (let index = 0; index < fileList; index++) {
|
for (let index = 0; index < fileList.length; index++) {
|
||||||
try {
|
try {
|
||||||
render( fileList[ index ], view );
|
render( fileList[ index ], view );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
console.error( '=> Render failed for ' + fileList[ index ] );
|
console.error( '=> Render failed for ' + fileList[ index ] + ' with error ' + e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ).catch( e => {
|
} ).catch( e => {
|
||||||
@ -136,13 +136,16 @@ const yaziThemes = {
|
|||||||
*/
|
*/
|
||||||
const render = ( templatePath, view ) => {
|
const render = ( templatePath, view ) => {
|
||||||
// Load template from disk (all can be found in <project-root>/config)
|
// Load template from disk (all can be found in <project-root>/config)
|
||||||
const template = '' + fs.readFileSync( path.join( __dirname, '/../config/', templatePath ) );
|
// TODO: Make exclusion better plus copy other files maybe?
|
||||||
const outPath = path.join( __dirname, 'dist', templatePath )
|
const template = '' + fs.readFileSync( templatePath );
|
||||||
|
const outPath = path.join( templatePath.replace( 'config', 'dist' ) );
|
||||||
console.log( '=> Rendering to ' + outPath );
|
console.log( '=> Rendering to ' + outPath );
|
||||||
try {
|
try {
|
||||||
fs.mkdir( path.dirname( outPath ) );
|
fs.mkdirSync( path.dirname( outPath ), {
|
||||||
} catch ( _ ) {
|
recursive: true,
|
||||||
|
} );
|
||||||
|
} catch ( e ) {
|
||||||
|
console.error( e );
|
||||||
}
|
}
|
||||||
fs.writeFileSync( outPath, mustache.render( template, view ) );
|
fs.writeFileSync( outPath, mustache.render( template, view ) );
|
||||||
}
|
}
|
||||||
|
@ -3,27 +3,27 @@ const fs = require( 'fs' );
|
|||||||
const path = require( 'path' );
|
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} dir The directory to search. Either absolute or relative path
|
||||||
* @param {string} extension The file extension to look for
|
* @param {string} extension The file extension to look for
|
||||||
* @returns {string[]} returns a list of html files with their full path
|
* @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 ls = fs.readdirSync( dir );
|
||||||
const fileList = [];
|
const fileList = [];
|
||||||
for ( let file in ls ) {
|
for ( let file in ls ) {
|
||||||
if ( fs.statSync( path.join( dir, ls[ file ] ) ).isDirectory() ) {
|
if ( fs.statSync( path.join( dir, ls[ file ] ) ).isDirectory() ) {
|
||||||
const newFiles = treeWalker( path.join( dir, ls[ file ] ), extension );
|
// Filter ignored directories
|
||||||
// TODO: Ignore files in .gitignore, as well as .gitignore
|
if ( ignoreList === undefined || !ignoreList.includes( ls[ file ] ) ) {
|
||||||
if ( !newFiles.includes( '.configbuildignore' ) ) {
|
const newFiles = treeWalker( path.join( dir, ls[ file ] ), extension, ignoreList );
|
||||||
for ( let file in newFiles ) {
|
for (let file = 0; file < newFiles.length; file++) {
|
||||||
fileList.push( newFiles[ file ] );
|
fileList.push( newFiles[ file ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( extension == '*' ) {
|
} else if ( extension == '*' || ls[ file ].includes( extension ) ) {
|
||||||
fileList.push( path.join( dir, ls[ file ] ) );
|
if ( ignoreList === undefined || !ignoreList.includes( ls[ file ] ) ) {
|
||||||
} else if ( ls[ file ].includes( extension ) ) {
|
fileList.push( path.join( dir, ls[ file ] ) );
|
||||||
fileList.push( path.join( dir, ls[ file ] ) );
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user