qwe/build.js

54 lines
1.3 KiB
JavaScript

// Usage: node build <platform> <[dev]/prod>
import Path from 'path'
import { copyFile } from 'fs/promises'
let [ platform, environment = 'dev' ] = process.argv.slice(2)
let projectRoot = Path.dirname(new URL(import.meta.url).pathname)
const indexTemplate = scripts => `\
<html>
<head>
<!-- <link rel="icon" href=".temp/editorapp/resources/icons/appIcon.png"> -->
${scripts.map(src => "<script async src=" + JSON.stringify(src) + "></script>").join('\n')}
<style id="stylesheet">
body { display: flex; flex-direction: column; margin: 0; height: 100vh; max-height: 100vh; font-size: 14px; }
nav { background: #f5f5f5; color: #6c6c6c; margin: 2px 5px }
nav input { all: unset; text-decoration: underline; font-family: sans-serif; }
.cm-editor { flex-grow: 1; outline: 1px solid #ddd; overflow-y: auto; }
</style>
</head>
</html>
`
let out
switch(environment) {
case 'dev':
out = indexTemplate([
Path.join('platforms', platform + '.js'),
'editor.js',
'build/libs.js'
])
break
case 'prod':
await copyFile(
Path.join(projectRoot, 'platforms', platform + '.js'),
Path.join(projectRoot, 'build', 'platform.js')
)
out = indexTemplate([
'platform.js',
'editor.js',
'libs.js'
])
break
}
process.stdout.write(out)