import {promises as fsp} from 'fs'; import {join} from 'path'; import Zip from 'jszip'; import nunjucks from 'nunjucks'; import {generateLove, LoveVariant} from './love'; import {getVersions, Versions} from './version'; export async function main(): Promise { const themeDirectory: string = join(__dirname, '../kitty/'); // Configure Nunjucks to use the templates for `source/kitty/`. nunjucks.configure(themeDirectory, { lstripBlocks: true, trimBlocks: true, throwOnUndefined: true }); const versions: Versions = await getVersions(); // Create a new zip archive. const kittyPackage: Zip = new Zip(); // Generate the Love variants. const love: LoveVariant[] = generateLove(); for (const variant of love) { const themeName = `love-${variant.name}.conf`; const outputPath: string = join(themeDirectory, themeName); // Render the template. const theme: string = nunjucks.render('love-template.conf', { love: variant, version: versions.kitty }); // Write the theme to file and add it to the zip archive. await fsp.writeFile(outputPath, theme); kittyPackage.file(themeName, theme); } // Write the zip archive to file. const zip: Buffer = await kittyPackage.generateAsync({type: 'nodebuffer'}); await fsp.writeFile(join(themeDirectory, 'love-kitty.zip'), zip); } if (require.main === module) { void main(); }