shadowfacts.net/lib/generate/css.ts

33 lines
843 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): Promise<SassResult> {
2019-01-04 18:14:53 +00:00
return new Promise((resolve, reject) => {
sass.render({
data: data,
outputStyle: process.env.MINIFY_CSS ? "compressed" : "expanded"
2019-01-04 18:14:53 +00:00
}, (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();
2019-01-05 02:59:52 +00:00
sass = util.render(sass, {}, filename);
2019-01-04 18:14:53 +00:00
const result = await renderSass(sass);
util.write(`css/${theme}.css`, result.css);
}
export default async function css() {
await generate("light");
await generate("dark");
2019-06-28 19:28:00 +00:00
require("fs").watch("site/css/", css);
2019-01-04 18:14:53 +00:00
}