From 2475b2a82b5c25603a92492bdb53030283a81e92 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 14 Jan 2019 00:34:07 +1100 Subject: Gulp fixes --- gulpfile.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 5a3c2478..d57f0a67 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -37,38 +37,37 @@ const pkg = require('./package.json'); const minSuffix = '.min'; // Paths -const root = __dirname; const paths = { plyr: { // Source paths src: { - sass: path.join(root, 'src/sass/**/*.scss'), - js: path.join(root, 'src/js/**/*.js'), - sprite: path.join(root, 'src/sprite/*.svg'), + sass: path.join(__dirname, 'src/sass/**/*.scss'), + js: path.join(__dirname, 'src/js/**/*.js'), + sprite: path.join(__dirname, 'src/sprite/*.svg'), }, // Output paths - output: path.join(root, 'dist/'), + output: path.join(__dirname, 'dist/'), }, demo: { // Source paths src: { - sass: path.join(root, 'demo/src/sass/**/*.scss'), - js: path.join(root, 'demo/src/js/**/*.js'), + sass: path.join(__dirname, 'demo/src/sass/**/*.scss'), + js: path.join(__dirname, 'demo/src/js/**/*.js'), }, // Output paths - output: path.join(root, 'demo/dist/'), + output: path.join(__dirname, 'demo/dist/'), // Demo - root: path.join(root, 'demo/'), + root: path.join(__dirname, 'demo/'), }, upload: [ - path.join(root, `dist/*${minSuffix}.*`), - path.join(root, 'dist/*.css'), - path.join(root, 'dist/*.svg'), - path.join(root, `demo/dist/*${minSuffix}.*`), - path.join(root, 'demo/dist/*.css'), + path.join(__dirname, `dist/*${minSuffix}.*`), + path.join(__dirname, 'dist/*.css'), + path.join(__dirname, 'dist/*.svg'), + path.join(__dirname, `demo/dist/*${minSuffix}.*`), + path.join(__dirname, 'demo/dist/*.css'), ], }; @@ -202,22 +201,22 @@ build.sass(bundles.demo.sass, 'demo'); build.js(bundles.demo.js, 'demo', { format: 'iife' }); // Build all JS -gulp.task('js', () => gulp.parallel(tasks.js)); +gulp.task('js', () => gulp.parallel(...tasks.js)); // Watch for file changes gulp.task('watch', () => { // Plyr core - gulp.watch(paths.plyr.src.js, gulp.parallel(tasks.js)); - gulp.watch(paths.plyr.src.sass, gulp.parallel(tasks.sass)); - gulp.watch(paths.plyr.src.sprite, gulp.parallel(tasks.sprite)); + gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js)); + gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.sass)); + gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite)); // Demo - gulp.watch(paths.demo.src.js, gulp.parallel(tasks.js)); - gulp.watch(paths.demo.src.sass, gulp.parallel(tasks.sass)); + gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js)); + gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.sass)); }); // Build distribution -gulp.task('build', gulp.series(tasks.clean, gulp.parallel(tasks.js, tasks.sass, tasks.sprite))); +gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite))); // Default gulp task gulp.task('default', gulp.series('build', 'watch')); @@ -306,7 +305,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js']; return gulp - .src(files.map(file => path.join(root, `src/js/${file}`)), { base: '.' }) + .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' }) .pipe(replace(semver, `v${version}`)) .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) .pipe(gulp.dest('./')); @@ -382,9 +381,9 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`); // Replace versioned files in readme.md - gulp.src([`${root}/readme.md`]) + gulp.src([`${__dirname}/readme.md`]) .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) - .pipe(gulp.dest(root)); + .pipe(gulp.dest(__dirname)); // Replace local file paths with remote paths in demo HTML // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" @@ -452,7 +451,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include gulp.series( 'version', tasks.clean, - gulp.parallel(tasks.js, tasks.sass, tasks.sprite), + gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite), 'cdn', 'demo', 'purge', -- cgit v1.2.3 From c125c1a2c019adc9077a7eb875d7daf0b89ad0a2 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sun, 27 Jan 2019 01:08:39 +1100 Subject: Added ES builds --- gulpfile.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index d57f0a67..56a6e7a3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -118,16 +118,19 @@ gulp.task('clean', done => { const build = { js(files, bundle, options) { Object.keys(files).forEach(key => { - const name = `js:${key}`; + const { format } = options; + const name = `js:${key}:${format}`; tasks.js.push(name); const { output } = paths[bundle]; const polyfill = name.includes('polyfilled'); + const extension = format === 'es' ? '.mjs' : '.js'; return gulp.task(name, () => gulp .src(bundles[bundle].js[key]) .pipe(sourcemaps.init()) .pipe(concat(key)) + .pipe( rollup( { @@ -137,9 +140,9 @@ const build = { ), ) .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935) - .pipe(sourcemaps.write('')) + .pipe(rename({ extname: extension })) .pipe(gulp.dest(output)) - .pipe(filter('**/*.js')) + .pipe(filter(`**/*${extension}`)) .pipe(uglify()) .pipe(size(sizeOptions)) .pipe(rename({ suffix: minSuffix })) @@ -192,7 +195,9 @@ const build = { }; // Plyr core files -build.js(bundles.plyr.js, 'plyr', { name: 'Plyr', format: 'umd' }); +const namespace = 'Plyr'; +build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'umd' }); +build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'es' }); build.sass(bundles.plyr.sass, 'plyr'); build.sprite('plyr'); -- cgit v1.2.3 From 6bf6c3f0f482f59cb1a40c90cf5f859a5b0d11b8 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sun, 27 Jan 2019 01:15:54 +1100 Subject: Paths --- gulpfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 56a6e7a3..b536662b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -189,7 +189,8 @@ const build = { .pipe(svgstore()) .pipe(rename({ basename: bundle })) .pipe(size(sizeOptions)) - .pipe(gulp.dest(paths[bundle].output)), + .pipe(gulp.dest(paths[bundle].output)) + .pipe(gulp.dest(paths.demo.output)), ); }, }; -- cgit v1.2.3 From d9daf2c618dd6f8ad267b7e4ad347b949e55c741 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Tue, 29 Jan 2019 21:36:47 +1100 Subject: Fix gulp --- gulpfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index b536662b..50eeb028 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -246,7 +246,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include const branch = { current: gitbranch.sync(), master: 'master', - develop: 'develop', + beta: 'beta', }; const maxAge = 31536000; // 1 year @@ -258,7 +258,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include }, }, demo: { - uploadPath: branch.current === branch.develop ? 'beta/' : null, + uploadPath: branch.current === branch.beta ? 'beta/' : null, headers: { 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', Vary: 'Accept-Encoding', @@ -289,7 +289,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include // Check we're on the correct branch to deploy const canDeploy = () => { - const allowed = [branch.master, branch.develop]; + const allowed = [branch.master, branch.beta]; if (!allowed.includes(branch.current)) { console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`); -- cgit v1.2.3 From eb628c8e4f109bb6aa4dc9196ee8f075092b225e Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Fri, 1 Feb 2019 00:24:48 +1100 Subject: Ads bug fixes --- gulpfile.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 50eeb028..2a3124f4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -238,6 +238,7 @@ try { } // If deployment is setup +// TODO: Use gulp-awspublish and use AWS CLI credentials if (Object.keys(credentials).includes('aws') && Object.keys(credentials).includes('fastly')) { const { version } = pkg; const { aws, fastly } = credentials; @@ -258,7 +259,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include }, }, demo: { - uploadPath: branch.current === branch.beta ? 'beta/' : null, + uploadPath: branch.current === branch.beta ? 'beta' : null, headers: { 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', Vary: 'Accept-Encoding', @@ -300,8 +301,9 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include return true; }; - gulp.task('version', () => { + gulp.task('version', done => { if (!canDeploy()) { + done(); return null; } @@ -318,8 +320,9 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include }); // Publish version to CDN bucket - gulp.task('cdn', () => { + gulp.task('cdn', done => { if (!canDeploy()) { + done(); return null; } @@ -379,8 +382,9 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include }); // Publish to demo bucket - gulp.task('demo', () => { + gulp.task('demo', done => { if (!canDeploy()) { + done(); return null; } @@ -407,6 +411,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include // Only update CDN for master (prod) if (branch.current !== branch.master) { + done(); return null; } @@ -441,14 +446,12 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include }); */ // Open the demo site to check it's ok - gulp.task('open', callback => { - gulp.src(__filename).pipe( + gulp.task('open', () => { + return gulp.src(__filename).pipe( open({ - uri: `https://${aws.demo.domain}`, + uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`, }), ); - - callback(); }); // Do everything -- cgit v1.2.3 From 0189e90fce151a94a47d0f3f7bbbc8290c6ad4cd Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Tue, 12 Feb 2019 13:55:45 +1100 Subject: Fix deployment --- gulpfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 2a3124f4..75d14c61 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -337,7 +337,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include .pipe( replace( /sourceMappingURL=([\w-?.]+)/, - (match, p1) => `sourceMappingURL=${p1.replace(minSuffix, '')}`, + (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`, ), ) .pipe( @@ -360,7 +360,7 @@ if (Object.keys(credentials).includes('aws') && Object.keys(credentials).include .pipe( through.obj((file, enc, cb) => { const filename = file.path.split('/').pop(); - list.push(`${versionPath}/${filename}`); + list.push(`${versionPath}/${filename.replace(minSuffix, '')}`); cb(null); }), ) -- cgit v1.2.3 From 153b8dc6bb96fdba8340a523c8828a72a832fcdf Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Tue, 19 Feb 2019 00:19:25 +1100 Subject: Added RangeTouch, updated Shr lib in demo --- gulpfile.js | 1 - 1 file changed, 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 75d14c61..6570330e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -130,7 +130,6 @@ const build = { .src(bundles[bundle].js[key]) .pipe(sourcemaps.init()) .pipe(concat(key)) - .pipe( rollup( { -- cgit v1.2.3 From 54110f83582e3c6d12ee7ba3f09e4b116be87ffd Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Tue, 19 Feb 2019 01:05:59 +1100 Subject: Update build process --- gulpfile.js | 641 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 330 insertions(+), 311 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 6570330e..cb005514 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,38 +4,65 @@ /* global require, __dirname */ /* eslint no-console: "off" */ -const del = require('del'); const path = require('path'); const gulp = require('gulp'); -const gutil = require('gulp-util'); -const concat = require('gulp-concat'); -const filter = require('gulp-filter'); + +// JavaScript +const terser = require('gulp-terser'); +const rollup = require('gulp-better-rollup'); +const babel = require('rollup-plugin-babel'); +const commonjs = require('rollup-plugin-commonjs'); +const resolve = require('rollup-plugin-node-resolve'); + +// CSS const sass = require('gulp-sass'); -const cleancss = require('gulp-clean-css'); -const header = require('gulp-header'); +const clean = require('gulp-clean-css'); const prefix = require('gulp-autoprefixer'); -const gitbranch = require('git-branch'); + +// Images const svgstore = require('gulp-svgstore'); -const svgmin = require('gulp-svgmin'); +const imagemin = require('gulp-imagemin'); + +// Utils +const del = require('del'); +const filter = require('gulp-filter'); +const header = require('gulp-header'); +const gitbranch = require('git-branch'); const rename = require('gulp-rename'); -const s3 = require('gulp-s3'); const replace = require('gulp-replace'); +const log = require('fancy-log'); const open = require('gulp-open'); +const plumber = require('gulp-plumber'); const size = require('gulp-size'); -const rollup = require('gulp-better-rollup'); -const babel = require('rollup-plugin-babel'); const sourcemaps = require('gulp-sourcemaps'); -const uglify = require('gulp-uglify-es').default; -const commonjs = require('rollup-plugin-commonjs'); -const resolve = require('rollup-plugin-node-resolve'); -const FastlyPurge = require('fastly-purge'); const through = require('through2'); -const bundles = require('./bundles.json'); +// Deployment +const aws = require('aws-sdk'); +const publish = require('gulp-awspublish'); +const FastlyPurge = require('fastly-purge'); + const pkg = require('./package.json'); +const build = require('./build.json'); +const deploy = require('./deploy.json'); + +const { browserslist: browsers, version } = pkg; const minSuffix = '.min'; +// Get AWS config +Object.values(deploy).forEach(target => { + Object.assign(target, { + publisher: publish.create({ + region: target.region, + params: { + Bucket: target.bucket, + }, + credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }), + }), + }); +}); + // Paths const paths = { plyr: { @@ -73,7 +100,7 @@ const paths = { // Task arrays const tasks = { - sass: [], + css: [], js: [], sprite: [], clean: ['clean'], @@ -82,9 +109,6 @@ const tasks = { // Size plugin const sizeOptions = { showFiles: true, gzip: true }; -// Browserlist -const browsers = ['> 1%']; - // Babel config const babelrc = (polyfill = false) => ({ presets: [ @@ -115,95 +139,91 @@ gulp.task('clean', done => { done(); }); -const build = { - js(files, bundle, options) { - Object.keys(files).forEach(key => { - const { format } = options; - const name = `js:${key}:${format}`; - tasks.js.push(name); - const { output } = paths[bundle]; - const polyfill = name.includes('polyfilled'); - const extension = format === 'es' ? '.mjs' : '.js'; - - return gulp.task(name, () => - gulp - .src(bundles[bundle].js[key]) - .pipe(sourcemaps.init()) - .pipe(concat(key)) - .pipe( - rollup( - { - plugins: [resolve(), commonjs(), babel(babelrc(polyfill))], - }, - options, - ), - ) - .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935) - .pipe(rename({ extname: extension })) - .pipe(gulp.dest(output)) - .pipe(filter(`**/*${extension}`)) - .pipe(uglify()) - .pipe(size(sizeOptions)) - .pipe(rename({ suffix: minSuffix })) - .pipe(sourcemaps.write('')) - .pipe(gulp.dest(output)), - ); - }); - }, - sass(files, bundle) { - Object.keys(files).forEach(key => { - const name = `sass:${key}`; - tasks.sass.push(name); - - return gulp.task(name, () => - gulp - .src(bundles[bundle].sass[key]) - .pipe(sass()) - .on('error', gutil.log) - .pipe(concat(key)) - .pipe(prefix(browsers, { cascade: false })) - .pipe(cleancss()) - .pipe(size(sizeOptions)) - .pipe(gulp.dest(paths[bundle].output)), - ); - }); - }, - sprite(bundle) { - const name = `svg:sprite:${bundle}`; - tasks.sprite.push(name); - - // Process Icons - return gulp.task(name, () => - gulp - .src(paths[bundle].src.sprite) +// JAvaScript + +const namespace = 'Plyr'; + +Object.entries(build.js).forEach(([filename, entry]) => { + entry.formats.forEach(format => { + const name = `js:${filename}:${format}`; + tasks.js.push(name); + const polyfill = filename.includes('polyfilled'); + const extension = format === 'es' ? 'mjs' : 'js'; + + gulp.task(name, () => { + return gulp + .src(entry.src) + .pipe(plumber()) + .pipe(sourcemaps.init()) .pipe( - svgmin({ - plugins: [ - { - removeDesc: true, - }, - ], + rollup( + { + plugins: [resolve(), commonjs(), babel(babelrc(polyfill))], + }, + { + name: namespace, + // exports: 'named', + format, + }, + ), + ) + .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935) + .pipe( + rename({ + extname: `.${extension}`, }), ) - .pipe(svgstore()) - .pipe(rename({ basename: bundle })) .pipe(size(sizeOptions)) - .pipe(gulp.dest(paths[bundle].output)) - .pipe(gulp.dest(paths.demo.output)), - ); - }, -}; + .pipe(gulp.dest(entry.dist)) + .pipe(filter(`**/*${extension}`)) + .pipe(terser()) + .pipe(rename({ suffix: minSuffix })) + .pipe(size(sizeOptions)) + .pipe(sourcemaps.write('')) + .pipe(gulp.dest(entry.dist)); + }); + }); +}); -// Plyr core files -const namespace = 'Plyr'; -build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'umd' }); -build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'es' }); -build.sass(bundles.plyr.sass, 'plyr'); -build.sprite('plyr'); +// CSS +Object.entries(build.css).forEach(([filename, entry]) => { + const name = `css:${filename}`; + tasks.css.push(name); + + gulp.task(name, () => { + return gulp + .src(entry.src) + .pipe(plumber()) + .pipe(sass()) + .pipe( + prefix(browsers, { + cascade: false, + }), + ) + .pipe(clean()) + .pipe(size(sizeOptions)) + .pipe(gulp.dest(entry.dist)); + }); +}); + +// SVG Sprites +Object.entries(build.sprite).forEach(([filename, entry]) => { + const name = `sprite:${filename}`; + tasks.sprite.push(name); -// Demo files -build.sass(bundles.demo.sass, 'demo'); -build.js(bundles.demo.js, 'demo', { format: 'iife' }); + log(path.basename(filename)); + + gulp.task(name, () => { + return gulp + .src(entry.src) + .pipe(plumber()) + .pipe(imagemin()) + .pipe(svgstore()) + .pipe(rename({ basename: path.parse(filename).name })) + .pipe(size(sizeOptions)) + .pipe(gulp.dest(entry.dist)); + }); +}); // Build all JS gulp.task('js', () => gulp.parallel(...tasks.js)); @@ -212,16 +232,16 @@ gulp.task('js', () => gulp.parallel(...tasks.js)); gulp.task('watch', () => { // Plyr core gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js)); - gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.sass)); + gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.css)); gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite)); // Demo gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js)); - gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.sass)); + gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.css)); }); // Build distribution -gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite))); +gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite))); // Default gulp task gulp.task('default', gulp.series('build', 'watch')); @@ -236,234 +256,233 @@ try { // Do nothing } -// If deployment is setup -// TODO: Use gulp-awspublish and use AWS CLI credentials -if (Object.keys(credentials).includes('aws') && Object.keys(credentials).includes('fastly')) { - const { version } = pkg; - const { aws, fastly } = credentials; - - // Get branch info - const branch = { - current: gitbranch.sync(), - master: 'master', - beta: 'beta', - }; - - const maxAge = 31536000; // 1 year - const options = { - cdn: { - headers: { - 'Cache-Control': `max-age=${maxAge}`, - Vary: 'Accept-Encoding', - }, +// Get branch info +const branch = { + current: gitbranch.sync(), + master: 'master', + beta: 'beta', +}; + +const maxAge = 31536000; // 1 year +const options = { + cdn: { + headers: { + 'Cache-Control': `max-age=${maxAge}`, + Vary: 'Accept-Encoding', + }, + }, + demo: { + uploadPath: branch.current === branch.beta ? 'beta' : null, + headers: { + 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', + Vary: 'Accept-Encoding', }, - demo: { - uploadPath: branch.current === branch.beta ? 'beta' : null, + }, + symlinks(ver, filename) { + return { headers: { + // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect + 'x-amz-website-redirect-location': `/${ver}/${filename}`, 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', - Vary: 'Accept-Encoding', }, - }, - symlinks(ver, filename) { - return { - headers: { - // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect - 'x-amz-website-redirect-location': `/${ver}/${filename}`, - 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', - }, - }; - }, - }; - - const regex = - '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?'; - const semver = new RegExp(`v${regex}`, 'gi'); - const localPath = new RegExp('(../)?dist', 'gi'); - const versionPath = `https://${aws.cdn.domain}/${version}`; - const cdnpath = new RegExp(`${aws.cdn.domain}/${regex}/`, 'gi'); - - const renameFile = rename(p => { - p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line - p.dirname = p.dirname.replace('.', version); // eslint-disable-line - }); - - // Check we're on the correct branch to deploy - const canDeploy = () => { - const allowed = [branch.master, branch.beta]; + }; + }, +}; - if (!allowed.includes(branch.current)) { - console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`); +const regex = + '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?'; +const semver = new RegExp(`v${regex}`, 'gi'); +const localPath = new RegExp('(../)?dist', 'gi'); +const versionPath = `https://${deploy.cdn.domain}/${version}`; +const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}/`, 'gi'); - return false; - } +const renameFile = rename(p => { + p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line + p.dirname = p.dirname.replace('.', version); // eslint-disable-line +}); - return true; - }; +// Check we're on the correct branch to deploy +const canDeploy = () => { + const allowed = [branch.master, branch.beta]; - gulp.task('version', done => { - if (!canDeploy()) { - done(); - return null; - } + if (!allowed.includes(branch.current)) { + console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`); - console.log(`Updating versions to '${version}'...`); + return false; + } - // Replace versioned URLs in source - const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js']; + return true; +}; - return gulp - .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' }) - .pipe(replace(semver, `v${version}`)) - .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) - .pipe(gulp.dest('./')); - }); +gulp.task('version', done => { + if (!canDeploy()) { + done(); + return null; + } - // Publish version to CDN bucket - gulp.task('cdn', done => { - if (!canDeploy()) { - done(); - return null; - } - - console.log(`Uploading '${version}' to ${aws.cdn.domain}...`); - - // Upload to CDN - return ( - gulp - .src(paths.upload) - .pipe(renameFile) - // Remove min suffix from source map URL - .pipe( - replace( - /sourceMappingURL=([\w-?.]+)/, - (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`, - ), - ) - .pipe( - size({ - showFiles: true, - gzip: true, - }), - ) - .pipe(replace(localPath, versionPath)) - .pipe(s3(aws.cdn, options.cdn)) - ); - }); + const { domain } = deploy.cdn; - // Purge the fastly cache incase any 403/404 are cached - gulp.task('purge', () => { - const list = []; + console.log(`Updating versions to '${version}'...`); - return gulp - .src(paths.upload) - .pipe( - through.obj((file, enc, cb) => { - const filename = file.path.split('/').pop(); - list.push(`${versionPath}/${filename.replace(minSuffix, '')}`); - cb(null); - }), - ) - .on('end', () => { - const purge = new FastlyPurge(fastly.token); - - list.forEach(url => { - console.log(`Purging ${url}...`); - - purge.url(url, (error, result) => { - if (error) { - console.log(error); - } else if (result) { - console.log(result); - } - }); - }); - }); - }); + // Replace versioned URLs in source + const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js']; - // Publish to demo bucket - gulp.task('demo', done => { - if (!canDeploy()) { - done(); - return null; - } + return gulp + .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' }) + .pipe(replace(semver, `v${version}`)) + .pipe(replace(cdnpath, `${domain}/${version}/`)) + .pipe(gulp.dest('./')); +}); - console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`); +// Publish version to CDN bucket +gulp.task('cdn', done => { + if (!canDeploy()) { + done(); + return null; + } - // Replace versioned files in readme.md - gulp.src([`${__dirname}/readme.md`]) - .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) - .pipe(gulp.dest(__dirname)); + const { domain, publisher } = deploy.cdn; - // Replace local file paths with remote paths in demo HTML - // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" - const index = `${paths.demo.root}index.html`; - const error = `${paths.demo.root}error.html`; - const pages = [index]; + if (!publisher) { + throw new Error('No publisher instance. Check AWS configuration.'); + } - if (branch.current === branch.master) { - pages.push(error); - } + console.log(`Uploading '${version}' to ${domain}...`); - gulp.src(pages) + // Upload to CDN + return ( + gulp + .src(paths.upload) + .pipe(renameFile) + // Remove min suffix from source map URL + .pipe( + replace( + /sourceMappingURL=([\w-?.]+)/, + (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`, + ), + ) + .pipe(size(sizeOptions)) .pipe(replace(localPath, versionPath)) - .pipe(s3(aws.demo, options.demo)); + .pipe(publisher.publish(options.cdn.headers)) + .pipe(publish.reporter()) + ); +}); - // Only update CDN for master (prod) - if (branch.current !== branch.master) { - done(); - return null; - } +// Purge the fastly cache incase any 403/404 are cached +gulp.task('purge', () => { + if (!Object.keys(credentials).includes('fastly')) { + throw new Error('Fastly credentials required to purge cache.'); + } + + const { fastly } = credentials; + const list = []; + + return gulp + .src(paths.upload) + .pipe( + through.obj((file, enc, cb) => { + const filename = file.path.split('/').pop(); + list.push(`${versionPath}/${filename.replace(minSuffix, '')}`); + cb(null); + }), + ) + .on('end', () => { + const purge = new FastlyPurge(fastly.token); + + list.forEach(url => { + console.log(`Purging ${url}...`); + + purge.url(url, (error, result) => { + if (error) { + console.log(error); + } else if (result) { + console.log(result); + } + }); + }); + }); +}); - // Upload error.html to cdn (as well as demo site) - return gulp - .src([error]) - .pipe(replace(localPath, versionPath)) - .pipe(s3(aws.cdn, options.demo)); - }); +// Publish to demo bucket +gulp.task('demo', done => { + if (!canDeploy()) { + done(); + return null; + } + + const { publisher } = deploy.demo; + const { domain } = deploy.cdn; + + if (!publisher) { + throw new Error('No publisher instance. Check AWS configuration.'); + } + + console.log(`Uploading '${version}' demo to ${deploy.demo.domain}...`); + + // Replace versioned files in readme.md + gulp.src([`${__dirname}/readme.md`]) + .pipe(replace(cdnpath, `${domain}/${version}/`)) + .pipe(gulp.dest(__dirname)); + + // Replace local file paths with remote paths in demo HTML + // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" + const index = `${paths.demo.root}index.html`; + const error = `${paths.demo.root}error.html`; + const pages = [index, error]; + + if (branch.current === branch.master) { + pages.push(error); + } + + return gulp + .src(pages) + .pipe(replace(localPath, versionPath)) + .pipe(publisher.publish(options.demo.headers)) + .pipe(publish.reporter()); +}); - // Update symlinks for latest - /* gulp.task("symlinks", function () { - console.log("Updating symlinks..."); - - return gulp.src(paths.upload) - .pipe(through.obj(function (chunk, enc, callback) { - if (chunk.stat.isFile()) { - // Get the filename - var filename = chunk.path.split("/").reverse()[0]; - - // Create the 0 byte redirect files to upload - createFile(filename, "") - .pipe(rename(function (path) { - path.dirname = path.dirname.replace(".", "latest"); - })) - // Upload to S3 with correct headers - .pipe(s3(aws.cdn, options.symlinks(version, filename))); - } - - callback(null, chunk); - })); - }); */ - - // Open the demo site to check it's ok - gulp.task('open', () => { - return gulp.src(__filename).pipe( - open({ - uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`, - }), - ); - }); +gulp.task('error', done => { + // Only update CDN for master (prod) + if (!canDeploy() || branch.current !== branch.master) { + done(); + return null; + } + + const { publisher } = deploy.cdn; + + if (!publisher) { + throw new Error('No publisher instance. Check AWS configuration.'); + } + + // Replace local file paths with remote paths in demo HTML + // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" + // Upload error.html to cdn + return gulp + .src(`${paths.demo.root}error.html`) + .pipe(replace(localPath, versionPath)) + .pipe(publisher.publish(options.demo.headers)) + .pipe(publish.reporter()); +}); - // Do everything - gulp.task( - 'deploy', - gulp.series( - 'version', - tasks.clean, - gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite), - 'cdn', - 'demo', - 'purge', - 'open', - ), +// Open the demo site to check it's ok +gulp.task('open', () => { + return gulp.src(__filename).pipe( + open({ + uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`, + }), ); -} +}); + +// Do everything +gulp.task( + 'deploy', + gulp.series( + 'version', + tasks.clean, + gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite), + 'cdn', + 'demo', + 'purge', + 'open', + ), +); -- cgit v1.2.3 From 825fd292aeb7f3aa06646e73ab28c65ca42b3ae2 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 23 Feb 2019 13:07:17 +1100 Subject: Fix build --- gulpfile.js | 99 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 46 insertions(+), 53 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index cb005514..b04a38ea 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -30,6 +30,7 @@ const header = require('gulp-header'); const gitbranch = require('git-branch'); const rename = require('gulp-rename'); const replace = require('gulp-replace'); +const ansi = require('ansi-colors'); const log = require('fancy-log'); const open = require('gulp-open'); const plumber = require('gulp-plumber'); @@ -95,6 +96,7 @@ const paths = { path.join(__dirname, 'dist/*.svg'), path.join(__dirname, `demo/dist/*${minSuffix}.*`), path.join(__dirname, 'demo/dist/*.css'), + path.join(__dirname, 'demo/dist/*.svg'), ], }; @@ -103,32 +105,14 @@ const tasks = { css: [], js: [], sprite: [], - clean: ['clean'], + clean: 'clean', }; // Size plugin const sizeOptions = { showFiles: true, gzip: true }; -// Babel config -const babelrc = (polyfill = false) => ({ - presets: [ - [ - '@babel/preset-env', - { - targets: { - browsers, - }, - useBuiltIns: polyfill ? 'usage' : false, - modules: false, - }, - ], - ], - babelrc: false, - exclude: 'node_modules/**', -}); - // Clean out /dist -gulp.task('clean', done => { +gulp.task(tasks.clean, done => { const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*')); // Don't delete the mp4 @@ -139,10 +123,7 @@ gulp.task('clean', done => { done(); }); -// JAvaScript - -const namespace = 'Plyr'; - +// JavaScript Object.entries(build.js).forEach(([filename, entry]) => { entry.formats.forEach(format => { const name = `js:${filename}:${format}`; @@ -150,19 +131,34 @@ Object.entries(build.js).forEach(([filename, entry]) => { const polyfill = filename.includes('polyfilled'); const extension = format === 'es' ? 'mjs' : 'js'; - gulp.task(name, () => { - return gulp + gulp.task(name, () => + gulp .src(entry.src) .pipe(plumber()) .pipe(sourcemaps.init()) .pipe( rollup( { - plugins: [resolve(), commonjs(), babel(babelrc(polyfill))], + plugins: [ + resolve(), + commonjs(), + babel({ + presets: [ + [ + '@babel/env', + { + // debug: true, + useBuiltIns: polyfill ? 'usage' : false, + }, + ], + ], + babelrc: false, + exclude: [/\/core-js\//], + }), + ], }, { - name: namespace, - // exports: 'named', + name: entry.namespace, format, }, ), @@ -173,15 +169,14 @@ Object.entries(build.js).forEach(([filename, entry]) => { extname: `.${extension}`, }), ) - .pipe(size(sizeOptions)) .pipe(gulp.dest(entry.dist)) - .pipe(filter(`**/*${extension}`)) + .pipe(filter(`**/*.${extension}`)) .pipe(terser()) .pipe(rename({ suffix: minSuffix })) .pipe(size(sizeOptions)) .pipe(sourcemaps.write('')) - .pipe(gulp.dest(entry.dist)); - }); + .pipe(gulp.dest(entry.dist)), + ); }); }); @@ -190,8 +185,8 @@ Object.entries(build.css).forEach(([filename, entry]) => { const name = `css:${filename}`; tasks.css.push(name); - gulp.task(name, () => { - return gulp + gulp.task(name, () => + gulp .src(entry.src) .pipe(plumber()) .pipe(sass()) @@ -202,8 +197,8 @@ Object.entries(build.css).forEach(([filename, entry]) => { ) .pipe(clean()) .pipe(size(sizeOptions)) - .pipe(gulp.dest(entry.dist)); - }); + .pipe(gulp.dest(entry.dist)), + ); }); // SVG Sprites @@ -211,18 +206,16 @@ Object.entries(build.sprite).forEach(([filename, entry]) => { const name = `sprite:${filename}`; tasks.sprite.push(name); - log(path.basename(filename)); - - gulp.task(name, () => { - return gulp + gulp.task(name, () => + gulp .src(entry.src) .pipe(plumber()) .pipe(imagemin()) .pipe(svgstore()) .pipe(rename({ basename: path.parse(filename).name })) .pipe(size(sizeOptions)) - .pipe(gulp.dest(entry.dist)); - }); + .pipe(gulp.dest(entry.dist)), + ); }); // Build all JS @@ -268,14 +261,12 @@ const options = { cdn: { headers: { 'Cache-Control': `max-age=${maxAge}`, - Vary: 'Accept-Encoding', }, }, demo: { uploadPath: branch.current === branch.beta ? 'beta' : null, headers: { 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', - Vary: 'Accept-Encoding', }, }, symlinks(ver, filename) { @@ -322,7 +313,7 @@ gulp.task('version', done => { const { domain } = deploy.cdn; - console.log(`Updating versions to '${version}'...`); + log(`Uploading ${ansi.green.bold(version)} to ${ansi.cyan(domain)}...`); // Replace versioned URLs in source const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js']; @@ -347,7 +338,7 @@ gulp.task('cdn', done => { throw new Error('No publisher instance. Check AWS configuration.'); } - console.log(`Uploading '${version}' to ${domain}...`); + log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`); // Upload to CDN return ( @@ -390,13 +381,13 @@ gulp.task('purge', () => { const purge = new FastlyPurge(fastly.token); list.forEach(url => { - console.log(`Purging ${url}...`); + log(`Purging ${ansi.cyan(url)}...`); purge.url(url, (error, result) => { if (error) { - console.log(error); + log.error(error); } else if (result) { - console.log(result); + log(result); } }); }); @@ -417,7 +408,7 @@ gulp.task('demo', done => { throw new Error('No publisher instance. Check AWS configuration.'); } - console.log(`Uploading '${version}' demo to ${deploy.demo.domain}...`); + log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`); // Replace versioned files in readme.md gulp.src([`${__dirname}/readme.md`]) @@ -428,7 +419,7 @@ gulp.task('demo', done => { // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" const index = `${paths.demo.root}index.html`; const error = `${paths.demo.root}error.html`; - const pages = [index, error]; + const pages = [index]; if (branch.current === branch.master) { pages.push(error); @@ -466,9 +457,11 @@ gulp.task('error', done => { // Open the demo site to check it's ok gulp.task('open', () => { + const { domain } = deploy.demo; + return gulp.src(__filename).pipe( open({ - uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`, + uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`, }), ); }); -- cgit v1.2.3