2021-01-04 17:58:58 +00:00
|
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
|
|
const fs = require('fs');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
|
|
|
const gulp = require('gulp');
|
|
|
|
const concat = require('gulp-concat');
|
|
|
|
const terser = require('gulp-terser');
|
|
|
|
const cleanCSS = require('gulp-clean-css');
|
|
|
|
const ejs = require('gulp-ejs');
|
|
|
|
const rename = require('gulp-rename');
|
|
|
|
const htmlmin = require('gulp-htmlmin');
|
|
|
|
const del = require('del');
|
|
|
|
const s3Upload = require('gulp-s3-upload');
|
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
const clean = () => del(['./dist**']);
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
// get cloudfront
|
|
|
|
const AWS = require('aws-sdk');
|
|
|
|
|
|
|
|
AWS.config.update({ region: 'us-east-1' });
|
|
|
|
const cloudfront = new AWS.CloudFront({ apiVersion: '2020-01-01' });
|
|
|
|
|
|
|
|
const jsSourcesData = [
|
2020-09-08 15:05:46 +00:00
|
|
|
'server/scripts/data/travelcities.js',
|
|
|
|
'server/scripts/data/regionalcities.js',
|
|
|
|
'server/scripts/data/stations.js',
|
2020-09-17 19:37:54 +00:00
|
|
|
'server/scripts/data/states.js',
|
2020-09-08 15:05:46 +00:00
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('compress_js_data', () => gulp.src(jsSourcesData)
|
|
|
|
.pipe(concat('data.min.js'))
|
|
|
|
.pipe(terser())
|
|
|
|
.pipe(gulp.dest('./dist/resources')));
|
2020-09-08 15:05:46 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
const jsSources = [
|
2020-09-25 02:29:03 +00:00
|
|
|
'server/scripts/vendor/auto/jquery.js',
|
2020-09-17 19:37:54 +00:00
|
|
|
'server/scripts/vendor/jquery.autocomplete.min.js',
|
2020-09-25 02:29:03 +00:00
|
|
|
'server/scripts/vendor/auto/nosleep.js',
|
2020-10-16 20:52:56 +00:00
|
|
|
'server/scripts/vendor/auto/swiped-events.js',
|
2020-09-17 19:37:54 +00:00
|
|
|
'server/scripts/index.js',
|
2020-09-25 02:29:03 +00:00
|
|
|
'server/scripts/libgif.js',
|
|
|
|
'server/scripts/vendor/auto/luxon.js',
|
|
|
|
'server/scripts/vendor/auto/suncalc.js',
|
2020-09-04 18:02:20 +00:00
|
|
|
'server/scripts/modules/draw.js',
|
|
|
|
'server/scripts/modules/weatherdisplay.js',
|
|
|
|
'server/scripts/modules/icons.js',
|
|
|
|
'server/scripts/modules/utilities.js',
|
|
|
|
'server/scripts/modules/currentweather.js',
|
2020-09-25 03:44:51 +00:00
|
|
|
'server/scripts/modules/currentweatherscroll.js',
|
2020-09-04 18:02:20 +00:00
|
|
|
'server/scripts/modules/latestobservations.js',
|
|
|
|
'server/scripts/modules/travelforecast.js',
|
|
|
|
'server/scripts/modules/regionalforecast.js',
|
|
|
|
'server/scripts/modules/localforecast.js',
|
|
|
|
'server/scripts/modules/extendedforecast.js',
|
|
|
|
'server/scripts/modules/almanac.js',
|
2020-09-04 22:03:03 +00:00
|
|
|
'server/scripts/modules/radar.js',
|
2020-10-20 21:37:11 +00:00
|
|
|
'server/scripts/modules/hourly.js',
|
2020-09-08 19:39:17 +00:00
|
|
|
'server/scripts/modules/progress.js',
|
2020-09-04 18:02:20 +00:00
|
|
|
'server/scripts/modules/navigation.js',
|
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('compress_js', () => gulp.src(jsSources)
|
|
|
|
.pipe(concat('ws.min.js'))
|
|
|
|
.pipe(terser())
|
|
|
|
.pipe(gulp.dest('./dist/resources')));
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
const cssSources = [
|
2020-09-08 15:05:46 +00:00
|
|
|
'server/styles/index.css',
|
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('compress_css', () => gulp.src(cssSources)
|
|
|
|
.pipe(concat('ws.min.css'))
|
|
|
|
.pipe(cleanCSS())
|
|
|
|
.pipe(gulp.dest('./dist/resources')));
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
const htmlSources = [
|
2020-09-04 18:02:20 +00:00
|
|
|
'views/*.ejs',
|
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('compress_html', () => {
|
|
|
|
const { version } = JSON.parse(fs.readFileSync('./package.json'));
|
|
|
|
return gulp.src(htmlSources)
|
2020-09-04 18:02:20 +00:00
|
|
|
.pipe(ejs({
|
|
|
|
production: version,
|
2020-09-08 19:39:17 +00:00
|
|
|
version,
|
2020-09-04 18:02:20 +00:00
|
|
|
}))
|
2021-01-04 17:58:58 +00:00
|
|
|
.pipe(rename({ extname: '.html' }))
|
|
|
|
.pipe(htmlmin({ collapseWhitespace: true }))
|
|
|
|
.pipe(gulp.dest('./dist'));
|
|
|
|
});
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
const otherFiles = [
|
2020-09-04 18:02:20 +00:00
|
|
|
'server/robots.txt',
|
|
|
|
'server/manifest.json',
|
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('copy_other_files', () => gulp.src(otherFiles, { base: 'server/' })
|
|
|
|
.pipe(gulp.dest('./dist')));
|
2020-09-04 18:02:20 +00:00
|
|
|
|
|
|
|
const s3 = s3Upload({
|
|
|
|
useIAM: true,
|
2021-01-04 17:58:58 +00:00
|
|
|
}, {
|
2020-09-04 18:02:20 +00:00
|
|
|
region: 'us-east-1',
|
|
|
|
});
|
2021-01-04 17:58:58 +00:00
|
|
|
const uploadSources = [
|
2020-09-04 18:02:20 +00:00
|
|
|
'dist/**',
|
|
|
|
];
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('upload', () => gulp.src(uploadSources, { base: './dist' })
|
|
|
|
.pipe(s3({
|
|
|
|
Bucket: 'weatherstar',
|
|
|
|
StorageClass: 'STANDARD',
|
|
|
|
maps: {
|
|
|
|
CacheControl: (keyname) => {
|
|
|
|
if (keyname.indexOf('index.html') > -1) return 'max-age=300'; // 10 minutes
|
|
|
|
return 'max-age=2592000'; // 1 month
|
2020-09-04 18:02:20 +00:00
|
|
|
},
|
2021-01-04 17:58:58 +00:00
|
|
|
},
|
|
|
|
})));
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
gulp.task('invalidate', async () => cloudfront.createInvalidation({
|
|
|
|
DistributionId: 'E9171A4KV8KCW',
|
|
|
|
InvalidationBatch: {
|
|
|
|
CallerReference: (new Date()).toLocaleString(),
|
|
|
|
Paths: {
|
|
|
|
Quantity: 1,
|
|
|
|
Items: ['/*'],
|
2020-09-04 18:02:20 +00:00
|
|
|
},
|
2021-01-04 17:58:58 +00:00
|
|
|
},
|
|
|
|
}).promise());
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2021-01-04 17:58:58 +00:00
|
|
|
module.exports = gulp.series(clean, gulp.parallel('compress_js', 'compress_js_data', 'compress_css', 'compress_html', 'copy_other_files'), 'upload', 'invalidate');
|