nixos-configs/modules/desktop/display-manager/astal/js/utils.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-03-22 23:31:37 -04:00
const { execAsync, monitorFile } = Utils;
/** @param {string} host */
const watchAndCompileSass = (host) => {
const reloadCss = () => {
const scss = `${App.configDir}/scss/${host}.scss`;
const css = `/tmp/astal-${host}/style.css`;
execAsync(`sass ${scss} ${css}`).then(() => {
App.resetCss();
App.applyCss(css);
}).catch(print);
};
monitorFile(
`${App.configDir}/scss`,
reloadCss,
);
reloadCss();
};
/** @param {string} host */
export const transpileTypeScript = async(host) => {
const outPath = `/tmp/astal-${host}/index.js`;
await execAsync([
'bash', '-c',
// Create the dir if it doesn't exist
`mkdir -p /tmp/astal-${host}; ` +
2024-03-24 13:54:33 -04:00
// Let bun see tsconfig.json
`cd ${App.configDir};` +
2024-03-22 23:31:37 -04:00
`bun build ${App.configDir}/${host}.ts ` +
'--external resource:///* ' +
'--external gi://* ' +
'--external cairo ' +
2024-03-24 13:54:33 -04:00
// Since bun wants to write in cwd, we just redirect stdin instead
2024-03-22 23:31:37 -04:00
`> ${outPath}`,
]).catch(print);
2024-03-24 13:54:33 -04:00
watchAndCompileSass(host);
2024-03-22 23:31:37 -04:00
return await import(`file://${outPath}`);
};