unique version numbers for staging uploads

This commit is contained in:
Matt Walsh
2025-09-04 21:57:12 -05:00
parent 517c560ef6
commit 093b6ac239

View File

@@ -97,11 +97,16 @@ const copyCss = () => src(cssSources)
const htmlSources = [ const htmlSources = [
'views/*.ejs', 'views/*.ejs',
]; ];
const compressHtml = async () => { const packageJson = await readFile('package.json');
const packageJson = await readFile('package.json'); let { version } = JSON.parse(packageJson);
const { version } = JSON.parse(packageJson); const previewVersion = async () => {
// generate a relatively unique timestamp for cache invalidation of the preview site
const now = new Date();
const msNow = now.getTime() % 1_000_000;
version = msNow.toString();
};
return src(htmlSources) const compressHtml = async () => src(htmlSources)
.pipe(ejs({ .pipe(ejs({
production: version, production: version,
serverAvailable: false, serverAvailable: false,
@@ -112,7 +117,6 @@ const compressHtml = async () => {
.pipe(rename({ extname: '.html' })) .pipe(rename({ extname: '.html' }))
.pipe(htmlmin({ collapseWhitespace: true })) .pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('./dist')); .pipe(dest('./dist'));
};
const otherFiles = [ const otherFiles = [
'server/robots.txt', 'server/robots.txt',
@@ -205,7 +209,7 @@ const buildDist = series(clean, parallel(buildJs, compressJsVendor, copyCss, com
// upload_images could be in parallel with upload, but _images logs a lot and has little changes // 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 // 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 publishFrontend = series(buildDist, uploadImages, upload, invalidate);
const stageFrontend = series(buildDist, uploadImagesPreview, uploadPreview, invalidatePreview); const stageFrontend = series(previewVersion, buildDist, uploadImagesPreview, uploadPreview, invalidatePreview);
export default publishFrontend; export default publishFrontend;