You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2KB

  1. const { ipcRenderer } = require('electron')
  2. const sass = require('sass');
  3. const path = require('path');
  4. const fs = require('fs');
  5. const SASS_BASE_PATH = 'view/sass';
  6. // TODO: Once configs are setup, make this section more dynamic!!
  7. var VARS = {
  8. COLOR_LIGHTER: "#fffcf2",
  9. COLOR_LIGHT: "#ccc5b9",
  10. COLOR_DARK: "#403d39",
  11. COLOR_DARKER: "#252422",
  12. COLOR_HIGHLIGHT: "#eb5e28",
  13. UI_SCALE: 1.0
  14. };
  15. console.log(ipcRenderer.sendSync("getPath", "app"));
  16. function handleFileLoad(url, prev, done){
  17. let apppath = ipcRenderer.sendSync("getPath", "app");
  18. let filepath = path.join(apppath, SASS_BASE_PATH, url + ".scss");
  19. console.log("Attempting to load ", filepath);
  20. fs.readFile(filepath, 'utf-8', (err, data) => {
  21. if (err){
  22. done(err);
  23. } else {
  24. done({contents: data.toString()});
  25. }
  26. });
  27. }
  28. function buildSASSVars(){
  29. let res = "";
  30. Object.keys(VARS).forEach((key)=>{
  31. res = res + "$" + key + ": " + VARS[key] + ";\n";
  32. });
  33. return res;
  34. }
  35. function render(entryfile){
  36. return new Promise((res, rej) => {
  37. let entry = buildSASSVars() + "@import '" + entryfile + "';\n";
  38. sass.render({data: entry, importer:handleFileLoad}, (err, data) => {
  39. if (err){rej(err);}
  40. res(data);
  41. });
  42. });
  43. }
  44. module.exports = {
  45. render
  46. };