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";
|
|
|
|
|
2019-01-05 15:29:38 +00:00
|
|
|
function renderSass(data: string): Promise<SassResult> {
|
2019-01-04 18:14:53 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
sass.render({
|
|
|
|
data: data,
|
2019-01-05 15:29:38 +00:00
|
|
|
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
|
|
|
}
|