From 5f63dc7c7d9feb431c9b45fefa764932b7aed75e Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Wed, 6 Oct 2021 19:27:32 +0200 Subject: [PATCH] improved build system, fixed special character escaping bug --- simulator/.project | 10 ++++++++++ simulator/tools/build.js | 7 ++++++- simulator/tools/embed.js | 10 +++++++--- simulator/tools/purify.js | 8 +++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/simulator/.project b/simulator/.project index 1d4832f..462a9d7 100644 --- a/simulator/.project +++ b/simulator/.project @@ -15,6 +15,16 @@ + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/build.launch + + + org.eclipse.wst.common.project.facet.core.nature diff --git a/simulator/tools/build.js b/simulator/tools/build.js index 47a7cd6..3c96ea9 100644 --- a/simulator/tools/build.js +++ b/simulator/tools/build.js @@ -25,11 +25,16 @@ let commands = [ let commandIdx = 0; function executeCommand(commandIdx) { + console.log("Executing: " + commands[commandIdx].toString().replace(/\(\) => child_process\.fork/g, '').replace(/\(|\)$/g, '')); let process = commands[commandIdx](); process.on('close', (exitCode) => { if(exitCode != 0) throw "Command " + commands[commandIdx] + " failed with code " + exitCode; commandIdx += 1; - if(commandIdx == commands.length) return; + if(commandIdx == commands.length) + { + console.log("Done."); + return; + } executeCommand(commandIdx); }); } diff --git a/simulator/tools/embed.js b/simulator/tools/embed.js index fce7702..bbfd105 100644 --- a/simulator/tools/embed.js +++ b/simulator/tools/embed.js @@ -1,10 +1,14 @@ let fs = require('fs') +function escapeTemplateLiteral(str) { + return str.replace(/([\\$`])/g, '\\$1'); +} + function embedHtml(src, dst) { fs.readFile(src, 'utf8', function(err, data) { if(err) throw err; - data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; + data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + escapeTemplateLiteral(data) + "`;"; fs.writeFile(dst, data, function(err) { if(err) throw err; @@ -16,7 +20,7 @@ function embedCss(src, dst) { fs.readFile(src, 'utf8', function(err, data) { if(err) throw err; - data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = ``;"; + data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = ``;"; data = data.replace(/"/g, "'"); fs.writeFile(dst, data, function(err) { @@ -36,7 +40,7 @@ function embedSvg(src, dst) { data = data.replace(/<\/attributes><\/desc>/g, '>'); data = data.replace(/"/g, '"'); - data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; + data = "(window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + escapeTemplateLiteral(data) + "`;"; fs.writeFile(dst, data, function(err) { if(err) throw err; diff --git a/simulator/tools/purify.js b/simulator/tools/purify.js index ecf0706..ff6d639 100644 --- a/simulator/tools/purify.js +++ b/simulator/tools/purify.js @@ -6,13 +6,11 @@ let content = ['./*.html']; // Reference of all CSS files from root directory let css = ['3rdparty/bulma/css/bulma.css', './app/app.css']; -let files = { +let options = { output: '../.intermediate/app.css', whitelist: ['is-multiple', 'is-loading', 'is-narrow', 'is-active', 'climate-zone'], minify: true, - info: true + info: false }; -purify(content, css, files, function (purifiedAndMinifiedResult) { - console.log(purifiedAndMinifiedResult); -}); +purify(content, css, options);