forked from shadowfacts/shadowfacts.net
33 lines
818 B
TypeScript
33 lines
818 B
TypeScript
|
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");
|
||
|
}
|