love/source/scripts/kitty.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-04-15 21:18:16 +00:00
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';
2020-04-15 21:18:16 +00:00
export async function main(): Promise<void> {
2020-04-15 21:18:16 +00:00
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();
2020-04-15 21:18:16 +00:00
// 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
2020-04-15 21:18:16 +00:00
});
// 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();
2020-04-15 21:18:16 +00:00
}