mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
Merge upstream/main: integrate radar worker removal and improvements
- Remove radar-worker.mjs and integrate functionality into radar-processor.mjs - Update package.json and gulpfile.mjs with upstream changes
This commit is contained in:
@@ -26,7 +26,7 @@ const cloudfront = new CloudFrontClient({ region: 'us-east-1' });
|
||||
|
||||
const RESOURCES_PATH = './dist/resources';
|
||||
|
||||
// Data is now injected server-side, no need to bundle separate data files
|
||||
// Data is now served as JSON files to avoid redundancy
|
||||
|
||||
const webpackOptions = {
|
||||
mode: 'production',
|
||||
@@ -96,29 +96,6 @@ 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 = {
|
||||
chunkFilename: '[id].mjs',
|
||||
chunkFormat: 'module',
|
||||
filename: '[name].mjs',
|
||||
};
|
||||
const workerWebpackOptions = {
|
||||
...webpackOptions,
|
||||
output,
|
||||
entry: {
|
||||
'radar-worker': workerSources[0],
|
||||
},
|
||||
};
|
||||
return src(workerSources)
|
||||
.pipe(webpack(workerWebpackOptions))
|
||||
.pipe(dest(RESOURCES_PATH));
|
||||
};
|
||||
|
||||
const cssSources = [
|
||||
'server/styles/main.css',
|
||||
];
|
||||
@@ -172,9 +149,10 @@ const uploadSources = [
|
||||
'!dist/images/**/*',
|
||||
'!dist/fonts/**/*',
|
||||
];
|
||||
const upload = () => src(uploadSources, { base: './dist', encoding: false })
|
||||
|
||||
const uploadCreator = (bucket) => () => src(uploadSources, { base: './dist', encoding: false })
|
||||
.pipe(s3({
|
||||
Bucket: process.env.BUCKET,
|
||||
Bucket: bucket,
|
||||
StorageClass: 'STANDARD',
|
||||
maps: {
|
||||
CacheControl: (keyname) => {
|
||||
@@ -190,10 +168,14 @@ const imageSources = [
|
||||
'server/images/**',
|
||||
'!server/images/gimp/**',
|
||||
];
|
||||
const uploadImages = () => src(imageSources, { base: './server', encoding: false })
|
||||
|
||||
const upload = uploadCreator(process.env.BUCKET);
|
||||
const uploadPreview = uploadCreator(process.env.BUCKET_PREVIEW);
|
||||
|
||||
const uploadImagesCreator = (bucket) => () => src(imageSources, { base: './server', encoding: false })
|
||||
.pipe(
|
||||
s3({
|
||||
Bucket: process.env.BUCKET,
|
||||
Bucket: bucket,
|
||||
StorageClass: 'STANDARD',
|
||||
maps: {
|
||||
CacheControl: () => 'max-age=31536000',
|
||||
@@ -201,11 +183,14 @@ const uploadImages = () => src(imageSources, { base: './server', encoding: false
|
||||
}),
|
||||
);
|
||||
|
||||
const uploadImages = uploadImagesCreator(process.env.BUCKET);
|
||||
const uploadImagesPreview = uploadImagesCreator(process.env.BUCKET_PREVIEW);
|
||||
|
||||
const copyImageSources = () => src(imageSources, { base: './server', encoding: false })
|
||||
.pipe(dest('./dist'));
|
||||
|
||||
const invalidate = () => cloudfront.send(new CreateInvalidationCommand({
|
||||
DistributionId: process.env.DISTRIBUTION_ID,
|
||||
const invalidateCreator = (distributionId) => () => cloudfront.send(new CreateInvalidationCommand({
|
||||
DistributionId: distributionId,
|
||||
InvalidationBatch: {
|
||||
CallerReference: (new Date()).toLocaleString(),
|
||||
Paths: {
|
||||
@@ -215,21 +200,26 @@ const invalidate = () => cloudfront.send(new CreateInvalidationCommand({
|
||||
},
|
||||
}));
|
||||
|
||||
const invalidate = invalidateCreator(process.env.DISTRIBUTION_ID);
|
||||
const invalidatePreview = invalidateCreator(process.env.DISTRIBUTION_ID_PREVIEW);
|
||||
|
||||
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, buildWorkers, compressJsVendor, copyMetarVendor, copyCss, compressHtml, copyOtherFiles, copyDataFiles, copyImageSources, buildPlaylist));
|
||||
const buildDist = series(clean, parallel(buildJs, compressJsVendor, copyMetarVendor, copyCss, compressHtml, copyOtherFiles, copyDataFiles, 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
|
||||
const publishFrontend = series(buildDist, uploadImages, upload, invalidate);
|
||||
const stageFrontend = series(buildDist, uploadImagesPreview, uploadPreview, invalidatePreview);
|
||||
|
||||
export default publishFrontend;
|
||||
|
||||
export {
|
||||
buildDist,
|
||||
invalidate,
|
||||
stageFrontend,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user