| var sslCaPath = process.env.SSLCAPATH || null; | var sslCaPath = process.env.SSLCAPATH || null; | ||||
| var css_output = "" // Used to hold dynamic css. | |||||
| // ------------------------------------------------------- | // ------------------------------------------------------- | ||||
| // Simple helper function | // Simple helper function | ||||
| function debounce(func, delay, scope){ | function debounce(func, delay, scope){ | ||||
| if (err){ | if (err){ | ||||
| cb("Failed to generate css - " + err.toString()); | cb("Failed to generate css - " + err.toString()); | ||||
| } else { | } else { | ||||
| fs.writeFile(path.join(CSS_PATH, "nespaint.css"), res.css.toString(), (err) => { | |||||
| if (err) | |||||
| cb("Failed to write file '" + path.join(CSS_PATH, "nespaint.css") + "' - " + err.toString()); | |||||
| else | |||||
| cb(); | |||||
| }); | |||||
| css_output = res.css.toString(); | |||||
| cb(); | |||||
| } | } | ||||
| }); | }); | ||||
| }, 1000); | }, 1000); | ||||
| app.engine('html', require('ejs').renderFile); | app.engine('html', require('ejs').renderFile); | ||||
| app.set('view engine', 'html'); | app.set('view engine', 'html'); | ||||
| app.use("/app", express.static(path.join(__dirname, "/app"))); | app.use("/app", express.static(path.join(__dirname, "/app"))); | ||||
| app.use("/app/css/nespaint.css", function(req, res){ | |||||
| res.set("Content-Type", "text/css"); | |||||
| res.send(new Buffer.from(css_output)); | |||||
| }); | |||||
| app.get('/', function(req, res){ | app.get('/', function(req, res){ | ||||
| res.render('index.html', {version:version, author:package.author}); | res.render('index.html', {version:version, author:package.author}); | ||||
| }); | }); | ||||
| // ---------------------------------------------------- | // ---------------------------------------------------- | ||||
| // 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', () => { | ||||
| // console.log("Watching path " + SASS_PATH); | |||||
| var dst = path.join(CSS_PATH, "nespaint.css"); | var dst = path.join(CSS_PATH, "nespaint.css"); | ||||
| fs.access(dst, fs.constants.F_OK, (err) => { | fs.access(dst, fs.constants.F_OK, (err) => { | ||||
| // Only try generating a new CSS if one doesn't already exists, or FORCECSSREGEN is true | // Only try generating a new CSS if one doesn't already exists, or FORCECSSREGEN is true | ||||
| if (err || forceCSSRegen){ | if (err || forceCSSRegen){ | ||||
| if (!fs.existsSync(CSS_PATH)){ | |||||
| try { | |||||
| fs.mkdirSync(CSS_PATH); | |||||
| } catch (e) { | |||||
| conosle.log("ERROR: " + e.toString()); | |||||
| exit(); | |||||
| } | |||||
| } | |||||
| generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { | generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { | ||||
| if (err){ | if (err){ | ||||
| console.log("ERROR: " + err); | console.log("ERROR: " + err); | ||||
| }); | }); | ||||
| }); | }); | ||||
| watcher.on('change', (fpath) => { | watcher.on('change', (fpath) => { | ||||
| // console.log("File " + fpath + " changed!"); | |||||
| generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { | generateCSS(path.join(SASS_PATH, "nespaint.scss"), path.join(CSS_PATH, "nespaint.css"), (err) => { | ||||
| if (err) | if (err) | ||||
| console.log("WARNING: " + err); | console.log("WARNING: " + err); |