Merge branch 'main' into remove-jquery

This commit is contained in:
Matt Walsh
2025-05-12 13:35:01 -05:00
84 changed files with 31678 additions and 49296 deletions

View File

@@ -12,11 +12,13 @@ import s3Upload from 'gulp-s3-upload';
import webpack from 'webpack-stream';
import TerserPlugin from 'terser-webpack-plugin';
import { readFile } from 'fs/promises';
import file from 'gulp-file';
// get cloudfront
import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront';
import reader from '../src/playlist-reader.mjs';
const clean = () => deleteAsync(['./dist**']);
const clean = () => deleteAsync(['./dist/**/*', '!./dist/readme.txt']);
const cloudfront = new CloudFrontClient({ region: 'us-east-1' });
@@ -85,6 +87,7 @@ const mjsSources = [
'server/scripts/modules/regionalforecast.mjs',
'server/scripts/modules/travelforecast.mjs',
'server/scripts/modules/progress.mjs',
'server/scripts/modules/media.mjs',
'server/scripts/index.mjs',
];
@@ -119,8 +122,9 @@ const compressHtml = async () => {
const otherFiles = [
'server/robots.txt',
'server/manifest.json',
'server/music/**/*.mp3',
];
const copyOtherFiles = () => src(otherFiles, { base: 'server/' })
const copyOtherFiles = () => src(otherFiles, { base: 'server/', encoding: false })
.pipe(dest('./dist'));
const s3 = s3Upload({
@@ -132,13 +136,14 @@ const uploadSources = [
'dist/**',
'!dist/**/*.map',
];
const upload = () => src(uploadSources, { base: './dist' })
const upload = () => src(uploadSources, { base: './dist', encoding: false })
.pipe(s3({
Bucket: 'weatherstar',
StorageClass: 'STANDARD',
maps: {
CacheControl: (keyname) => {
if (keyname.indexOf('index.html') > -1) return 'max-age=300'; // 10 minutes
if (keyname.indexOf('.mp3') > -1) return 'max-age=31536000'; // 1 year for mp3 files
return 'max-age=2592000'; // 1 month
},
},
@@ -167,10 +172,20 @@ const invalidate = () => cloudfront.send(new CreateInvalidationCommand({
},
}));
const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles));
const buildPlaylist = async () => {
const availableFiles = await reader();
const playlist = { availableFiles };
return file('playlist.json', JSON.stringify(playlist)).pipe(dest('./dist'));
};
const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, 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
const publishFrontend = series(buildDist, uploadImages, upload, invalidate);
export default publishFrontend;
export {
buildDist,
};