44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import {promises as fsp} from 'fs';
|
|
import {join} from 'path';
|
|
import Zip from 'jszip';
|
|
import nunjucks from 'nunjucks';
|
|
import {generateLove, LoveVariant} from './love';
|
|
|
|
export async function entry(): Promise<void> {
|
|
const themeDirectory: string = join(__dirname, '../kitty/');
|
|
// Configure Nunjucks to use the templates for `source/kitty/`.
|
|
nunjucks.configure(themeDirectory, {
|
|
lstripBlocks: true,
|
|
trimBlocks: true,
|
|
throwOnUndefined: true
|
|
});
|
|
|
|
// 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
|
|
});
|
|
|
|
// 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) {
|
|
entry();
|
|
}
|