You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.4 KiB
84 lines
2.4 KiB
let fs = require('fs') |
|
|
|
function embedHtml(src, dst) { |
|
fs.readFile(src, 'utf8', function(err, data) { |
|
if(err) throw err; |
|
|
|
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; |
|
|
|
fs.writeFile(dst, data, function(err) { |
|
if(err) throw err; |
|
}); |
|
}); |
|
} |
|
|
|
function embedCss(src, dst) { |
|
fs.readFile(src, 'utf8', function(err, data) { |
|
if(err) throw err; |
|
|
|
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `<style>" + data + "</style>`;"; |
|
data = data.replace(/"/g, "'"); |
|
|
|
fs.writeFile(dst, data, function(err) { |
|
if(err) throw err; |
|
}); |
|
}); |
|
} |
|
|
|
function embedSvg(src, dst) { |
|
fs.readFile(src, 'utf8', function(err, data) { |
|
if(err) throw err; |
|
data = data.replace(/<\?xml[^\?]*\?>[\r\n]*/g, ''); |
|
data = data.replace(/<svg[^>]*>[\r\n]*/g, ''); |
|
data = data.replace(/<\/svg>[\r\n]*/g, ''); |
|
|
|
data = data.replace(/>\s*<desc[^>]*><attributes>/g, ' '); |
|
data = data.replace(/<\/attributes><\/desc>/g, '>'); |
|
data = data.replace(/"/g, '"'); |
|
|
|
data = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = `" + data + "`;"; |
|
|
|
fs.writeFile(dst, data, function(err) { |
|
if(err) throw err; |
|
}); |
|
}); |
|
} |
|
|
|
function embedCsv(src, dst) { |
|
fs.readFile(src, 'utf8', function(err, csvData) { |
|
if(err) throw err; |
|
|
|
let csvLines = csvData.split('\n').map(str => str.split(';')); |
|
|
|
let jsData = {}; |
|
|
|
let zones = csvLines[0]; |
|
for(let zoneIdx = 0; zoneIdx < zones.length; ++zoneIdx) { |
|
let zoneName = zones[zoneIdx]; |
|
let zoneData = []; |
|
|
|
for(let lineIdx = 1; lineIdx < csvLines.length; ++lineIdx) { |
|
zoneData[lineIdx-1] = Math.round(Number(csvLines[lineIdx][zoneIdx])); |
|
} |
|
|
|
jsData[zoneName] = zoneData; |
|
} |
|
|
|
let content = "(<any>window)['"+src.replace(/^.*[\\\/]/, '')+"'] = " + JSON.stringify(jsData) + ";"; |
|
|
|
fs.writeFile(dst, content, function(err) { |
|
if(err) throw err; |
|
}); |
|
}); |
|
} |
|
|
|
let toolsDir = __dirname; |
|
let dataDir = toolsDir + "/../data"; |
|
let srcDir = toolsDir + "/../src"; |
|
let intermediateDir = toolsDir + "/../.intermediate"; |
|
|
|
embedHtml(srcDir+'/simulator.html', intermediateDir+'/simulator.html.ts'); |
|
embedCss(intermediateDir+'/app.css', intermediateDir+'/app/app.css.ts'); |
|
embedCss(srcDir+'/simulator-in-iframe.css', intermediateDir+'/simulator-in-iframe.css.ts'); |
|
embedSvg(dataDir+'/climate-zones-map.svg', intermediateDir+'/app/climate-zones-map.svg.ts'); |
|
embedCsv(dataDir+'/climate-zones-data.csv', intermediateDir+'/app/climate-zones-data.ts');
|
|
|