diff --git a/gulp/publish-frontend.mjs b/gulp/publish-frontend.mjs index e37486d..0042b5a 100644 --- a/gulp/publish-frontend.mjs +++ b/gulp/publish-frontend.mjs @@ -96,6 +96,19 @@ const buildJs = () => src(mjsSources) .pipe(webpack(webpackOptions)) .pipe(dest(RESOURCES_PATH)); +const workerSources = [ + 'server/scripts/modules/radar-worker.mjs', +]; + +const buildWorkers = () => { + // update the file name in the webpack options + const output = { filename: 'radar-worker.mjs' }; + const workerWebpackOptions = { ...webpackOptions, output }; + return src(workerSources) + .pipe(webpack(workerWebpackOptions)) + .pipe(dest(RESOURCES_PATH)); +}; + const cssSources = [ 'server/styles/main.css', ]; @@ -189,7 +202,7 @@ const buildPlaylist = async () => { return file('playlist.json', JSON.stringify(playlist)).pipe(dest('./dist')); }; -const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, buildPlaylist, copyImageSources)); +const buildDist = series(clean, parallel(buildJs, buildWorkers, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, copyImageSources, buildPlaylist)); // upload_images could be in parallel with upload, but _images logs a lot and has little changes // by running upload last the majority of the changes will be at the bottom of the log for easy viewing diff --git a/index.mjs b/index.mjs index a09b706..471134a 100644 --- a/index.mjs +++ b/index.mjs @@ -71,11 +71,15 @@ const geoip = (req, res) => { // debugging if (process.env?.DIST === '1') { + // distribution + app.use('/scripts', express.static('./server/scripts')); + app.use('/geoip', geoip); app.use('/', express.static('./dist')); } else { // debugging app.get('/index.html', index); app.use('/geoip', geoip); + app.use('/resources', express.static('./server/scripts/modules')); app.get('/', index); app.get('*name', express.static('./server')); // cors pass-thru to api.weather.gov diff --git a/server/scripts/modules/navigation.mjs b/server/scripts/modules/navigation.mjs index d4e6f2f..f252b5d 100644 --- a/server/scripts/modules/navigation.mjs +++ b/server/scripts/modules/navigation.mjs @@ -92,7 +92,7 @@ const updateStatus = (value) => { if (displays[0].status === STATUS.loading) return; // calculate first enabled display - const firstDisplayIndex = displays.findIndex((display) => display.enabled && display.timing.totalScreens > 0); + const firstDisplayIndex = displays.findIndex((display) => display?.enabled && display?.timing?.totalScreens > 0); // value.id = 0 is hazards, if they fail to load hot-wire a new value.id to the current display to see if it needs to be loaded // typically this plays out as current conditions loads, then hazards fails. diff --git a/server/scripts/modules/progress.mjs b/server/scripts/modules/progress.mjs index a3dbff0..674dc5e 100644 --- a/server/scripts/modules/progress.mjs +++ b/server/scripts/modules/progress.mjs @@ -14,7 +14,7 @@ class Progress extends WeatherDisplay { // setup event listener for dom-required initialization document.addEventListener('DOMContentLoaded', () => { - this.version = document.querySelector('#version').innerHTML; + this.version = document.querySelector('#version').innerHTML.replace(/\s/g, ''); this.elem.querySelector('.container').addEventListener('click', this.lineClick.bind(this)); }); @@ -91,3 +91,10 @@ class Progress extends WeatherDisplay { // register our own display const progress = new Progress(-1, 'progress'); registerProgress(progress); + +const version = () => progress.version; + +export default progress; +export { + version, +}; diff --git a/server/scripts/modules/radar.mjs b/server/scripts/modules/radar.mjs index 7b6681b..311483c 100644 --- a/server/scripts/modules/radar.mjs +++ b/server/scripts/modules/radar.mjs @@ -5,6 +5,7 @@ import { text } from './utils/fetch.mjs'; import WeatherDisplay from './weatherdisplay.mjs'; import { registerDisplay, timeZone } from './navigation.mjs'; import * as utils from './radar-utils.mjs'; +import { version } from './progress.mjs'; // TEMPORARY fix to disable radar on ios safari. The same engine (webkit) is // used for all ios browers (chrome, brave, firefox, etc) so it's safe to skip @@ -196,7 +197,7 @@ class Radar extends WeatherDisplay { // create a radar worker with helper functions const radarWorker = () => { // create the worker - const worker = new Worker(new URL('./radar-worker.mjs', import.meta.url), { type: 'module' }); + const worker = new Worker(`/resources/radar-worker.mjs?_=${version()}`, { type: 'module' }); const processRadar = (url) => new Promise((resolve, reject) => { // prepare for done message