-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
47 lines (43 loc) · 1.31 KB
/
utils.js
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
46
47
const fs = require("fs");
const path = require("path");
const sass = require("sass");
const readFile = function (path, json = false) {
// The boll its used for json parsing
if (json) {
return JSON.parse(fs.readFileSync(path, "utf-8"));
}
return fs.readFileSync(path, "utf-8");
};
const createCss = function (obj, modified) {
if (!modified) {
console.log("No need to recompile styles ");
return;
}
const colors = readFile(
path.join(__dirname, "./src/_data/colors.json"),
true
);
const my_scss = `$primary:${colors.primary};\n$secondary:${colors.secondary};\n `;
fs.writeFileSync(
`${path.join(__dirname, "./src/assets/sass/colors.scss")}`,
`${my_scss}`
);
// This is for compiling the sass to css with the custom colors prop
const css = sass.compile(
`${path.join(__dirname, "./src/assets/sass/style.scss")}`,
{ OutputStyle: "compressed" }
);
// This is for writing all the css into the style.css
fs.writeFileSync(
`${path.join(__dirname, "./src/assets/css/style.css")}`,
`${css.css}`
);
// This will prevent this function to run at every build
obj.modified = false;
fs.writeFileSync(
`${path.join(__dirname, "./src/_data/colors.json")}`,
`${JSON.stringify(obj)}`
);
console.log("Done compiling");
};
module.exports = { readFile, createCss };