156 lines
5.5 KiB
JavaScript
156 lines
5.5 KiB
JavaScript
const mustache = require( 'mustache' );
|
|
const colorThief = require( '@janishutz/colorthief' );
|
|
const fs = require( 'fs' );
|
|
const path = require( 'path' );
|
|
const util = require( './util' );
|
|
const renderColourAsRGB = util.renderColourAsRGB;
|
|
const renderColourAsHex = util.renderColourAsHex;
|
|
|
|
const build = ( wallpaper, lockpaper, theme ) => {
|
|
console.log( '\n=> Extracting colours' );
|
|
// Extract colour palette from chosen wallpaper using Color-Thief
|
|
colorThief.getPalette( wallpaper ).then( palette => {
|
|
// Define view options (for rendering with mustache)
|
|
console.log( palette );
|
|
const view = {
|
|
'wallpaper-path': wallpaper,
|
|
'lockpaper-path': lockpaper,
|
|
|
|
// Colours
|
|
'colour-foreground-hex': renderColourAsHex( palette[ 0 ] ),
|
|
'colour-foreground-rgb': renderColourAsRGB( palette[ 0 ] ),
|
|
'colour-accent-hex': renderColourAsHex( palette[ 1 ] ),
|
|
'colour-accent-rgb': renderColourAsRGB( palette[ 1 ] ),
|
|
'colour-accent-2-hex': renderColourAsHex( palette[ 2 ] ),
|
|
'colour-accent-2-rgb': renderColourAsRGB( palette[ 2 ] ),
|
|
'colour-accent-3-hex': renderColourAsHex( palette[ 3 ] ),
|
|
'colour-accent-3-rgb': renderColourAsRGB( palette[ 3 ] ),
|
|
'colour-background-hex': renderColourAsHex( colours.background[ theme ] ),
|
|
'colour-background-rgb': renderColourAsRGB( colours.background[ theme ] ),
|
|
'colour-shadow-hex': renderColourAsHex( colours.shadow[ theme ] ),
|
|
'colour-shadow-rgb': renderColourAsRGB( colours.shadow[ theme ] ),
|
|
'colour-inavtive-hex': renderColourAsHex( colours.inactive[ theme ] ),
|
|
'colour-inavtive-rgb': renderColourAsRGB( colours.inactive[ theme ] ),
|
|
|
|
// Fonts
|
|
'font-primary': fonts.primary[ theme ],
|
|
'font-accent': fonts.accent[ theme ],
|
|
'font-mono': fonts.mono[ theme ],
|
|
|
|
// yazi theme
|
|
'yazi-theme': yaziThemes[ theme ],
|
|
|
|
// Path to this repo on disk
|
|
'path-to-dotfiles': __dirname.slice(0, __dirname.length - 5),
|
|
}
|
|
|
|
// TODO: Maybe bar config? Reordering? Same for quick actions?
|
|
// Those will be read by AGS components though, but generated by
|
|
// this script
|
|
console.log( view );
|
|
|
|
try {
|
|
fs.mkdir( path.join( __dirname, '/dist' ) );
|
|
} catch ( e ) {
|
|
|
|
}
|
|
|
|
// 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/' ), '*', [ 'node_modules', '@girs', '.gitignore', '.git', 'flavours' ] );
|
|
|
|
// TODO: Copy missing files over directly
|
|
console.log( fileList );
|
|
for (let index = 0; index < fileList.length; index++) {
|
|
try {
|
|
render( fileList[ index ], view );
|
|
} catch ( e ) {
|
|
console.error( '=> Render failed for ' + fileList[ index ] + ' with error ' + e );
|
|
}
|
|
}
|
|
} ).catch( e => {
|
|
console.error( e );
|
|
console.error( '\n=> Failed to load image or retrieve colour palette from it' );
|
|
} );
|
|
}
|
|
|
|
const colours = {
|
|
background: {
|
|
'nordic': [ 10, 0, 60 ],
|
|
'deep-dark': [ 20, 20, 20 ],
|
|
'material': [ 30, 30, 30 ], // TODO: Will be calculated by material theme generator
|
|
'light': [ 230, 230, 230 ],
|
|
'bright': [ 255, 255, 255 ]
|
|
},
|
|
shadow: {
|
|
'nordic': [ 10, 0, 60 ],
|
|
'deep-dark': [ 20, 20, 20 ],
|
|
'material': [ 30, 30, 30 ], // TODO: Will be calculated by material theme generator
|
|
'light': [ 230, 230, 230 ],
|
|
'bright': [ 255, 255, 255 ]
|
|
},
|
|
inactive: {
|
|
'nordic': [ 200, 200, 200 ],
|
|
'deep-dark': [ 200, 200, 200 ],
|
|
'material': [ 200, 200, 200 ], // TODO: Will be calculated by material theme generator
|
|
'light': [ 65, 65, 65 ],
|
|
'bright': [ 60, 60, 60 ]
|
|
}
|
|
}
|
|
|
|
const fonts = {
|
|
'primary': {
|
|
'nordic': 'Comfortaa',
|
|
'deep-dark': 'Comfortaa',
|
|
'material': 'Comfortaa',
|
|
'light': 'Adwaita Sans',
|
|
'bright': 'Adwaita Sans Extralight'
|
|
},
|
|
'accent': {
|
|
'nordic': 'Adwaita Sans',
|
|
'deep-dark': 'Adwaita Sans',
|
|
'material': 'Adwaita Sans',
|
|
'light': 'Cantarell',
|
|
'bright': 'Contarell Thin'
|
|
},
|
|
'mono': {
|
|
'nordic': 'Source Code Pro',
|
|
'deep-dark': 'Source Code Pro',
|
|
'material': 'Source Code Pro',
|
|
'light': 'Jetbrains Mono',
|
|
'bright': 'Jetbrains Mono',
|
|
}
|
|
}
|
|
|
|
// TODO
|
|
const yaziThemes = {
|
|
'nordic': 'tokyo-night',
|
|
'deep-dark': 'vscode-dark-modern',
|
|
'material': 'dracula',
|
|
'light': 'vscode-light-modern',
|
|
'bright': 'vscode-light-modern',
|
|
}
|
|
|
|
|
|
/**
|
|
* @param {string} templatePath - Path relative to config root
|
|
* @param {object} view - View rendering config
|
|
*/
|
|
const render = ( templatePath, view ) => {
|
|
// Load template from disk (all can be found in <project-root>/config)
|
|
// 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.mkdirSync( path.dirname( outPath ), {
|
|
recursive: true,
|
|
} );
|
|
} catch ( e ) {
|
|
console.error( e );
|
|
}
|
|
fs.writeFileSync( outPath, mustache.render( template, view ) );
|
|
}
|
|
|
|
module.exports = build;
|