Create build step for the web server (#289)

* Create build step for the web server

* Update bskyweb routes and 404 behavior
This commit is contained in:
Paul Frazee 2023-03-14 17:30:15 -05:00 committed by GitHub
parent 8629e167cd
commit 8d2e649b4d
9 changed files with 169 additions and 27 deletions

27
scripts/post-web-build.js Normal file
View file

@ -0,0 +1,27 @@
const path = require('path')
const fs = require('fs')
const projectRoot = path.join(__dirname, '..')
const webBuildJs = path.join(projectRoot, 'web-build', 'static', 'js')
const templateFile = path.join(
projectRoot,
'bskyweb',
'templates',
'scripts.html',
)
const jsFiles = fs.readdirSync(webBuildJs).filter(name => name.endsWith('.js'))
jsFiles.sort((a, b) => {
// make sure main is written last
if (a.startsWith('main')) return 1
if (b.startsWith('main')) return -1
return a.localeCompare(b)
})
console.log(`Found ${jsFiles.length} js files in web-build`)
console.log(`Writing ${templateFile}`)
const outputFile = jsFiles
.map(name => `<script defer="defer" src="/static/js/${name}"></script>`)
.join('\n')
fs.writeFileSync(templateFile, outputFile)