-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcssHotLoad.ts
38 lines (30 loc) · 957 Bytes
/
cssHotLoad.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { App } from "astal/gtk3";
import { execAsync, monitorFile } from "astal";
/* CSS Hot Reload */
async function monitorStyle() {
const pathsToMonitor = [ // Paths to monitor
`${SRC}/style/globals`,
`${SRC}/style/components`,
`${SRC}/style/variables.scss`
];
const mainScss = `${SRC}/style/main.scss`; // SCSS input file to compile
const css = `/tmp/style.css`; // CSS output file
let isApplying = false;
async function transpileAndApply() {
if (isApplying) return;
isApplying = true;
try {
await execAsync(`sass ${mainScss} ${css}`);
App.apply_css(css, true);
print("CSS applied successfully!");
} catch (error) {
print("Error transpiling SCSS:", error);
execAsync(`notify-send -u critical "Error transpiling SCSS" "${error}"`);
} finally {
isApplying = false;
}
}
pathsToMonitor.forEach((path) => monitorFile(path, transpileAndApply));
return transpileAndApply();
}
export default monitorStyle();