improved build system, fixed special character escaping bug

This commit is contained in:
Youen Toupin 2021-10-06 19:27:32 +02:00
parent 9de822f5a2
commit 5f63dc7c7d
4 changed files with 26 additions and 9 deletions

View File

@ -15,6 +15,16 @@
<arguments>
</arguments>
</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>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>

View File

@ -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);
});
}

View File

@ -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 = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;";
data = "(<any>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 = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `<style>" + data + "</style>`;";
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `<style>" + escapeTemplateLiteral(data) + "</style>`;";
data = data.replace(/"/g, "'");
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(/&quot;/g, '"');
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;";
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + escapeTemplateLiteral(data) + "`;";
fs.writeFile(dst, data, function(err) {
if(err) throw err;

View File

@ -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);