-
Notifications
You must be signed in to change notification settings - Fork 5
/
compile-scss.cjs
45 lines (43 loc) · 1.45 KB
/
compile-scss.cjs
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
39
40
41
42
43
44
45
/* eslint-disable @typescript-eslint/no-var-requires */
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
/**
* Compile all SCSS files in their respective directories
* @author David Linhardt
*
* @param {string} dir
* @returns {void}
*/
function compileScssFile(dir) {
fs.readdir(dir, (err, files) => {
if (err) throw err;
files.forEach((file) => {
const filePath = path.join(dir, file);
const fileStat = fs.statSync(filePath);
if (fileStat.isDirectory()) {
compileScssFile(filePath);
} else if (path.extname(file) === '.scss') {
const cssFilePath = filePath.replace('.scss', '.css');
exec(
`sass ${filePath} ${cssFilePath}`,
(err, stdout, stderr) => {
if (err) {
console.error(
`Error compiling ${filePath}:`,
stderr
);
throw err;
} else {
console.log(
`Compiled ${filePath} to ${cssFilePath}`
);
}
console.log(stdout);
}
);
}
});
});
}
compileScssFile(path.join(__dirname, 'src'));