archive
/
givemoneyto.me
Archived
1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
givemoneyto.me/index.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-06-29 13:26:43 +01:00
import Bundler from 'parcel-bundler';
2019-06-29 16:23:38 +01:00
import { join, dirname } from 'path';
2019-06-29 13:26:43 +01:00
import rimraf from 'rimraf';
2019-06-29 16:23:38 +01:00
import { readFileSync, writeFileSync } from 'fs';
import Handlebars from 'handlebars';
import mkdirp from 'mkdirp';
2019-06-29 16:35:41 +01:00
import { range } from 'underscore';
2019-06-29 13:26:43 +01:00
const BUILD_DIR = join(__dirname, 'build');
const SRC_DIR = join(__dirname, 'src');
const BUNDLER_OPTIONS = {
outDir: BUILD_DIR,
watch: false,
minify: true,
};
2019-06-29 16:23:38 +01:00
function writeTemplate(content: string, value: string) {
const outputFile = join(BUILD_DIR, value, 'index.html');
mkdirp.sync(dirname(outputFile));
writeFileSync(outputFile, content);
}
function renderTemplate(template: HandlebarsTemplateDelegate, value: number) {
const html = template({value});
writeTemplate(html, value.toString());
}
2019-06-29 13:26:43 +01:00
(async function() {
rimraf.sync(BUILD_DIR);
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
await bundler.bundle();
2019-06-29 16:23:38 +01:00
const template = Handlebars.compile(readFileSync(join(BUILD_DIR, 'template.html')).toString());
2019-06-29 16:35:41 +01:00
range(0, 10, 0.5).forEach((i) => {
console.log(i);
renderTemplate(template, i);
});
2019-06-29 13:26:43 +01:00
})();