|
|
@ -28,7 +28,7 @@ html { |
|
|
const defaultIntro = ` |
|
|
const defaultIntro = ` |
|
|
|
|
|
|
|
|
window.Macchiato = { |
|
|
window.Macchiato = { |
|
|
location: new MLocation(), |
|
|
modules: {}, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
`.trim()
|
|
|
`.trim()
|
|
|
@ -38,6 +38,12 @@ export class Builder { |
|
|
this.files = files |
|
|
this.files = files |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
buildStyle(file) { |
|
|
|
|
|
const style = document.createElement('style') |
|
|
|
|
|
style.textContent = file.data |
|
|
|
|
|
return style.outerHTML |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
buildModule(file) { |
|
|
buildModule(file) { |
|
|
const script = document.createElement('script') |
|
|
const script = document.createElement('script') |
|
|
script.setAttribute('type', 'module') |
|
|
script.setAttribute('type', 'module') |
|
|
@ -113,14 +119,35 @@ export class Builder { |
|
|
data: replace(file.data), |
|
|
data: replace(file.data), |
|
|
}) |
|
|
}) |
|
|
)) |
|
|
)) |
|
|
const html = ( |
|
|
const styles = this.files.filter(({name}) => ( |
|
|
|
|
|
name.endsWith('.css') |
|
|
|
|
|
)).map(file => ( |
|
|
|
|
|
this.buildStyle(file) |
|
|
|
|
|
)) |
|
|
|
|
|
let html = ( |
|
|
'index.html' in filesMap ? |
|
|
'index.html' in filesMap ? |
|
|
filesMap['index.html'] : |
|
|
filesMap['index.html'] : |
|
|
defaultHtml |
|
|
defaultHtml |
|
|
) |
|
|
) |
|
|
return html.replace( |
|
|
let replaced = false |
|
|
|
|
|
html = html.replace(/\s*<\/head>/, match => { |
|
|
|
|
|
replaced = true |
|
|
|
|
|
return styles.join("\n") + "\n" + match |
|
|
|
|
|
}) |
|
|
|
|
|
if (!replaced) { |
|
|
|
|
|
html = styles.join("\n") + "\n" + html |
|
|
|
|
|
} |
|
|
|
|
|
replaced = false |
|
|
|
|
|
html = html.replace( |
|
|
'<' + 'script type="module" src="/app.js"><' + '/script>', |
|
|
'<' + 'script type="module" src="/app.js"><' + '/script>', |
|
|
intro + "\n" + modules.join("\n") |
|
|
() => { |
|
|
|
|
|
replaced = true |
|
|
|
|
|
return intro + "\n" + modules.join("\n") |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
if (!replaced) { |
|
|
|
|
|
html += "\n" + intro + "\n" + modules.join("\n") |
|
|
|
|
|
} |
|
|
|
|
|
return html |
|
|
} |
|
|
} |
|
|
} |
|
|
} |