36 lines
1001 B
TypeScript
Raw Normal View History

2019-01-04 13:14:53 -05:00
import { promises as fs } from "fs";
import * as util from "../util";
import sass, { Result as SassResult } from "sass";
2019-01-04 13:14:53 -05:00
function renderSass(data: string): Promise<SassResult> {
2019-01-04 13:14:53 -05:00
return new Promise((resolve, reject) => {
sass.render({
data: data,
2019-09-17 17:02:31 -04:00
outputStyle: process.env.NODE_ENV === "development" ? "expanded" : "compressed"
2019-01-04 13:14:53 -05: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-04 21:59:52 -05:00
sass = util.render(sass, {}, filename);
2019-06-28 15:51:26 -04: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 13:14:53 -05:00
2019-06-28 15:51:26 -04:00
util.write(`css/${theme}.css`, css);
2019-01-04 13:14:53 -05:00
}
export default async function css() {
2020-07-09 14:10:39 -04:00
generate("light");
generate("dark");
generate("auto");
}