|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sass = require("sass"); |
|
|
const sass = require("sass"); |
|
|
const SASS_PATH = path.join(__dirname, "sass"); |
|
|
const SASS_PATH = path.join(__dirname, "sass"); |
|
|
const CSS_PATH = path.join(__dirname, "app/css"); |
|
|
|
|
|
|
|
|
const SASS_FILE = "style.scss"; |
|
|
|
|
|
|
|
|
const watcher = require("chokidar").watch(SASS_PATH, {ignored: /[\/\\]\./, persistent: true}); |
|
|
const watcher = require("chokidar").watch(SASS_PATH, {ignored: /[\/\\]\./, persistent: true}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sslCertPath = process.env.SSLCERTPATH || null; |
|
|
var sslCertPath = process.env.SSLCERTPATH || null; |
|
|
var sslCaPath = process.env.SSLCAPATH || null; |
|
|
var sslCaPath = process.env.SSLCAPATH || null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var css_output = "" // Used to hold dynamic css. |
|
|
|
|
|
|
|
|
var css_output = ""; // Used to hold dynamic css. |
|
|
|
|
|
|
|
|
// ------------------------------------------------------- |
|
|
// ------------------------------------------------------- |
|
|
// Simple helper function |
|
|
// Simple helper function |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var generateCSS = debounce(function(src, dst, cb){ |
|
|
|
|
|
|
|
|
var generateCSS = debounce(function(src, cb){ |
|
|
sass.render({file: src}, (err, res)=>{ |
|
|
sass.render({file: src}, (err, res)=>{ |
|
|
if (err){ |
|
|
if (err){ |
|
|
cb("Failed to generate css - " + err.toString()); |
|
|
cb("Failed to generate css - " + err.toString()); |
|
|
|
|
|
|
|
|
// ---------------------------------------------------- |
|
|
// ---------------------------------------------------- |
|
|
// Watching for any needed file updates (to minimize the need to restart the server. |
|
|
// Watching for any needed file updates (to minimize the need to restart the server. |
|
|
watcher.on('ready', () => { |
|
|
watcher.on('ready', () => { |
|
|
var dst = path.join(CSS_PATH, "nespaint.css"); |
|
|
|
|
|
fs.access(dst, fs.constants.F_OK, (err) => { |
|
|
|
|
|
// Only try generating a new CSS if one doesn't already exists, or FORCECSSREGEN is true |
|
|
|
|
|
if (err || forceCSSRegen){ |
|
|
|
|
|
generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { |
|
|
|
|
|
if (err){ |
|
|
|
|
|
console.log("ERROR: " + err); |
|
|
|
|
|
exit(); |
|
|
|
|
|
} else { |
|
|
|
|
|
startServer(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
startServer(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
generateCSS(path.join(SASS_PATH, SASS_FILE), (err) => { |
|
|
|
|
|
if (err){ |
|
|
|
|
|
console.log("ERROR: " + err); |
|
|
|
|
|
exit(); |
|
|
|
|
|
} else { |
|
|
|
|
|
startServer(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
watcher.on('change', (fpath) => { |
|
|
watcher.on('change', (fpath) => { |
|
|
generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { |
|
|
|
|
|
|
|
|
generateCSS(path.join(SASS_PATH, SASS_FILE), (err) => { |
|
|
if (err) |
|
|
if (err) |
|
|
console.log("WARNING: " + err); |
|
|
console.log("WARNING: " + err); |
|
|
}); |
|
|
}); |