shadowfacts.net/lib/generate/css.ts

33 lines
818 B
TypeScript
Raw Normal View History

2019-01-04 18:14:53 +00:00
import { promises as fs } from "fs";
import * as util from "../util";
import sass, { Result as SassResult } from "node-sass";
import ejs from "ejs";
function renderSass(data: string, minify = false): Promise<SassResult> {
return new Promise((resolve, reject) => {
sass.render({
data: data,
outputStyle: minify ? "compressed" : "expanded"
}, (error, result) => {
if (error) reject(error);
else resolve(result);
});
});
}
async function generate(theme: string) {
const filename = `site/css/${theme}.scss`;
let sass = (await fs.readFile(filename)).toString();
sass = ejs.render(sass, {}, {
filename: filename
});
const result = await renderSass(sass);
util.write(`css/${theme}.css`, result.css);
}
export default async function css() {
await generate("light");
await generate("dark");
}