Browse Source

improved build system, fixed special character escaping bug

master
Youen Toupin 3 years ago
parent
commit
5f63dc7c7d
  1. 10
      simulator/.project
  2. 7
      simulator/tools/build.js
  3. 10
      simulator/tools/embed.js
  4. 8
      simulator/tools/purify.js

10
simulator/.project

@ -15,6 +15,16 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>auto,full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/build.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature>

7
simulator/tools/build.js

@ -25,11 +25,16 @@ let commands = [
let commandIdx = 0; let commandIdx = 0;
function executeCommand(commandIdx) { function executeCommand(commandIdx) {
console.log("Executing: " + commands[commandIdx].toString().replace(/\(\) => child_process\.fork/g, '').replace(/\(|\)$/g, ''));
let process = commands[commandIdx](); let process = commands[commandIdx]();
process.on('close', (exitCode) => { process.on('close', (exitCode) => {
if(exitCode != 0) throw "Command " + commands[commandIdx] + " failed with code " + exitCode; if(exitCode != 0) throw "Command " + commands[commandIdx] + " failed with code " + exitCode;
commandIdx += 1; commandIdx += 1;
if(commandIdx == commands.length) return; if(commandIdx == commands.length)
{
console.log("Done.");
return;
}
executeCommand(commandIdx); executeCommand(commandIdx);
}); });
} }

10
simulator/tools/embed.js

@ -1,10 +1,14 @@
let fs = require('fs') let fs = require('fs')
function escapeTemplateLiteral(str) {
return str.replace(/([\\$`])/g, '\\$1');
}
function embedHtml(src, dst) { function embedHtml(src, dst) {
fs.readFile(src, 'utf8', function(err, data) { fs.readFile(src, 'utf8', function(err, data) {
if(err) throw err; if(err) throw err;
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + escapeTemplateLiteral(data) + "`;";
fs.writeFile(dst, data, function(err) { fs.writeFile(dst, data, function(err) {
if(err) throw err; if(err) throw err;
@ -16,7 +20,7 @@ function embedCss(src, dst) {
fs.readFile(src, 'utf8', function(err, data) { fs.readFile(src, 'utf8', function(err, data) {
if(err) throw err; if(err) throw err;
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `<style>" + data + "</style>`;"; data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `<style>" + escapeTemplateLiteral(data) + "</style>`;";
data = data.replace(/"/g, "'"); data = data.replace(/"/g, "'");
fs.writeFile(dst, data, function(err) { fs.writeFile(dst, data, function(err) {
@ -36,7 +40,7 @@ function embedSvg(src, dst) {
data = data.replace(/&lt;\/attributes&gt;<\/desc>/g, '>'); data = data.replace(/&lt;\/attributes&gt;<\/desc>/g, '>');
data = data.replace(/&quot;/g, '"'); data = data.replace(/&quot;/g, '"');
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + escapeTemplateLiteral(data) + "`;";
fs.writeFile(dst, data, function(err) { fs.writeFile(dst, data, function(err) {
if(err) throw err; if(err) throw err;

8
simulator/tools/purify.js

@ -6,13 +6,11 @@ let content = ['./*.html'];
// Reference of all CSS files from root directory // Reference of all CSS files from root directory
let css = ['3rdparty/bulma/css/bulma.css', './app/app.css']; let css = ['3rdparty/bulma/css/bulma.css', './app/app.css'];
let files = { let options = {
output: '../.intermediate/app.css', output: '../.intermediate/app.css',
whitelist: ['is-multiple', 'is-loading', 'is-narrow', 'is-active', 'climate-zone'], whitelist: ['is-multiple', 'is-loading', 'is-narrow', 'is-active', 'climate-zone'],
minify: true, minify: true,
info: true info: false
}; };
purify(content, css, files, function (purifiedAndMinifiedResult) { purify(content, css, options);
console.log(purifiedAndMinifiedResult);
});

Loading…
Cancel
Save