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';
|
2020-04-26 22:05:19 +00:00
|
|
|
import {getVersions, Versions} from './version';
|
2020-04-15 21:18:16 +00:00
|
|
|
|
2020-08-06 12:47:06 +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
|
|
|
|
});
|
|
|
|
|
2020-04-26 22:05:19 +00:00
|
|
|
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', {
|
2020-04-26 22:05:19 +00:00
|
|
|
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) {
|
2020-08-06 12:47:06 +00:00
|
|
|
void main();
|
2020-04-15 21:18:16 +00:00
|
|
|
}
|