|
|
@ -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(/<\/attributes><\/desc>/g, '>'); |
|
|
|
data = data.replace(/<\/attributes><\/desc>/g, '>'); |
|
|
|
data = data.replace(/"/g, '"'); |
|
|
|
data = data.replace(/"/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; |
|
|
|