2019-01-04 18:14:53 +00:00
|
|
|
import { promises as fs } from "fs";
|
|
|
|
import * as util from "../util";
|
2020-07-01 02:48:12 +00:00
|
|
|
import sass, { Result as SassResult } from "sass";
|
2019-01-04 18:14:53 +00:00
|
|
|
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-09-17 21:02:31 +00:00
|
|
|
outputStyle: process.env.NODE_ENV === "development" ? "expanded" : "compressed"
|
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-06-28 19:51:26 +00:00
|
|
|
let css = (await renderSass(sass)).css.toString();
|
|
|
|
css += "\n";
|
|
|
|
let mainSass = (await fs.readFile("site/css/main.scss")).toString();
|
|
|
|
mainSass = util.render(mainSass, {}, "site/css/main.scss");
|
|
|
|
css += (await renderSass(mainSass)).css.toString();
|
2019-01-04 18:14:53 +00:00
|
|
|
|
2019-06-28 19:51:26 +00:00
|
|
|
util.write(`css/${theme}.css`, css);
|
2019-01-04 18:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default async function css() {
|
2020-07-09 18:10:39 +00:00
|
|
|
generate("light");
|
|
|
|
generate("dark");
|
|
|
|
generate("auto");
|
2019-06-28 19:28:00 +00:00
|
|
|
|
2019-09-17 19:34:48 +00:00
|
|
|
if (process.env.NODE_ENV === "development") {
|
|
|
|
require("fs").watch("site/css/", css);
|
|
|
|
}
|
|
|
|
}
|