Update build process

This commit is contained in:
Sam Potts 2019-02-19 01:05:59 +11:00
parent 522135adaf
commit 54110f8358
24 changed files with 1918 additions and 945 deletions

46
build.json Normal file
View File

@ -0,0 +1,46 @@
{
"js": {
"plyr.js": {
"src": "./src/js/plyr.js",
"dist": "./dist/",
"formats": ["es", "umd"],
"namespace": "Plyr"
},
"plyr.polyfilled.js": {
"src": "./src/js/plyr.polyfilled.js",
"dist": "./dist/",
"formats": ["es", "umd"],
"namespace": "Plyr"
},
"demo.js": {
"src": "./demo/src/js/demo.js",
"dist": "./demo/dist/",
"formats": ["iife"],
"namespace": "Demo"
}
},
"css": {
"plyr.css": {
"src": "./src/sass/plyr.scss",
"dist": "./dist/"
},
"demo.css": {
"src": "./demo/src/sass/bundles/demo.scss",
"dist": "./demo/dist/"
},
"error.css": {
"src": "./demo/src/sass/bundles/error.scss",
"dist": "./demo/dist/"
}
},
"sprite": {
"plyr.svg": {
"src": "./src/sprite/*.svg",
"dist": "./dist"
},
"demo.svg": {
"src": "./src/sprite/*.svg",
"dist": "./demo/dist"
}
}
}

View File

@ -1,20 +0,0 @@
{
"plyr": {
"sass": {
"plyr.css": "src/sass/plyr.scss"
},
"js": {
"plyr.js": "src/js/plyr.js",
"plyr.polyfilled.js": "src/js/plyr.polyfilled.js"
}
},
"demo": {
"sass": {
"demo.css": "demo/src/sass/bundles/demo.scss",
"error.css": "demo/src/sass/bundles/error.scss"
},
"js": {
"demo.js": "demo/src/js/demo.js"
}
}
}

16
demo/dist/demo.js vendored
View File

@ -5911,7 +5911,7 @@ typeof navigator === "object" && (function () {
min: 0, min: 0,
max: 100, max: 100,
value: 0, value: 0,
role: 'presentation', role: 'progressbar',
'aria-hidden': true 'aria-hidden': true
}, attributes)); // Create the label inside }, attributes)); // Create the label inside
@ -13004,17 +13004,12 @@ typeof navigator === "object" && (function () {
focused.classList.add(tabClassName); focused.classList.add(tabClassName);
}, 10); }, 10);
}); }); // Setup the player
var userType = 'annon';
var contentType = 'on-demand';
var cmsid = 2490180;
var vid = 3788;
var tagUrl = "https://pubads.g.doubleclick.net/gampad/live/ads?sz=640x360&iu=/21736521837/ovo/web&impl=s&gdfp_req=1&env=vp&output=vast&cust_params=usergroup%3D".concat(userType, "%26content-type%3D").concat(contentType, "&cmsid=").concat(cmsid, "&vid=").concat(vid); // Setup the player
var player = new Plyr(selector, { var player = new Plyr(selector, {
debug: true, debug: true,
title: 'View From A Blue Moon', title: 'View From A Blue Moon',
iconUrl: 'dist/plyr.svg', iconUrl: 'dist/demo.svg',
keyboard: { keyboard: {
global: true global: true
}, },
@ -13028,9 +13023,8 @@ typeof navigator === "object" && (function () {
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c' google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c'
}, },
ads: { ads: {
enabled: true, enabled: env.prod || env.dev,
// env.prod || env.dev, publisherId: '918848828995742'
tagUrl: tagUrl
}, },
previewThumbnails: { previewThumbnails: {
enabled: true, enabled: true,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -58,18 +58,11 @@ import Plyr from '../../../src/js/plyr';
}, 10); }, 10);
}); });
const userType = 'annon';
const contentType = 'on-demand';
const cmsid = 2490180;
const vid = 3788;
const tagUrl = `https://pubads.g.doubleclick.net/gampad/live/ads?sz=640x360&iu=/21736521837/ovo/web&impl=s&gdfp_req=1&env=vp&output=vast&cust_params=usergroup%3D${userType}%26content-type%3D${contentType}&cmsid=${cmsid}&vid=${vid}`;
// Setup the player // Setup the player
const player = new Plyr(selector, { const player = new Plyr(selector, {
debug: true, debug: true,
title: 'View From A Blue Moon', title: 'View From A Blue Moon',
iconUrl: 'dist/plyr.svg', iconUrl: 'dist/demo.svg',
keyboard: { keyboard: {
global: true, global: true,
}, },
@ -83,8 +76,8 @@ import Plyr from '../../../src/js/plyr';
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c', google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c',
}, },
ads: { ads: {
enabled: true, // env.prod || env.dev, enabled: env.prod || env.dev,
tagUrl, publisherId: '918848828995742',
}, },
previewThumbnails: { previewThumbnails: {
enabled: true, enabled: true,

12
deploy.json Normal file
View File

@ -0,0 +1,12 @@
{
"cdn": {
"bucket": "plyr",
"domain": "cdn.plyr.io",
"region": "us-east-1"
},
"demo": {
"bucket": "plyr.io",
"domain": "plyr.io",
"region": "us-west-1"
}
}

2
dist/plyr.js vendored
View File

@ -1826,7 +1826,7 @@ typeof navigator === "object" && (function (global, factory) {
min: 0, min: 0,
max: 100, max: 100,
value: 0, value: 0,
role: 'presentation', role: 'progressbar',
'aria-hidden': true 'aria-hidden': true
}, attributes)); // Create the label inside }, attributes)); // Create the label inside

2
dist/plyr.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/plyr.min.mjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/plyr.mjs vendored
View File

@ -1820,7 +1820,7 @@ var controls = {
min: 0, min: 0,
max: 100, max: 100,
value: 0, value: 0,
role: 'presentation', role: 'progressbar',
'aria-hidden': true 'aria-hidden': true
}, attributes)); // Create the label inside }, attributes)); // Create the label inside

View File

@ -574,7 +574,7 @@ typeof navigator === "object" && (function (global, factory) {
}); });
var _core = createCommonjsModule(function (module) { var _core = createCommonjsModule(function (module) {
var core = module.exports = { version: '2.6.4' }; var core = module.exports = { version: '2.6.5' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
}); });
var _core_1 = _core.version; var _core_1 = _core.version;
@ -4892,7 +4892,7 @@ typeof navigator === "object" && (function (global, factory) {
min: 0, min: 0,
max: 100, max: 100,
value: 0, value: 0,
role: 'presentation', role: 'progressbar',
'aria-hidden': true 'aria-hidden': true
}, attributes)); // Create the label inside }, attributes)); // Create the label inside

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -568,7 +568,7 @@ if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
}); });
var _core = createCommonjsModule(function (module) { var _core = createCommonjsModule(function (module) {
var core = module.exports = { version: '2.6.4' }; var core = module.exports = { version: '2.6.5' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
}); });
var _core_1 = _core.version; var _core_1 = _core.version;
@ -4886,7 +4886,7 @@ var controls = {
min: 0, min: 0,
max: 100, max: 100,
value: 0, value: 0,
role: 'presentation', role: 'progressbar',
'aria-hidden': true 'aria-hidden': true
}, attributes)); // Create the label inside }, attributes)); // Create the label inside

2
dist/plyr.svg vendored

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -4,38 +4,65 @@
/* global require, __dirname */ /* global require, __dirname */
/* eslint no-console: "off" */ /* eslint no-console: "off" */
const del = require('del');
const path = require('path'); const path = require('path');
const gulp = require('gulp'); const gulp = require('gulp');
const gutil = require('gulp-util');
const concat = require('gulp-concat'); // JavaScript
const filter = require('gulp-filter'); const terser = require('gulp-terser');
const sass = require('gulp-sass');
const cleancss = require('gulp-clean-css');
const header = require('gulp-header');
const prefix = require('gulp-autoprefixer');
const gitbranch = require('git-branch');
const svgstore = require('gulp-svgstore');
const svgmin = require('gulp-svgmin');
const rename = require('gulp-rename');
const s3 = require('gulp-s3');
const replace = require('gulp-replace');
const open = require('gulp-open');
const size = require('gulp-size');
const rollup = require('gulp-better-rollup'); const rollup = require('gulp-better-rollup');
const babel = require('rollup-plugin-babel'); 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 commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve'); const resolve = require('rollup-plugin-node-resolve');
const FastlyPurge = require('fastly-purge');
// CSS
const sass = require('gulp-sass');
const clean = require('gulp-clean-css');
const prefix = require('gulp-autoprefixer');
// Images
const svgstore = require('gulp-svgstore');
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 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 sourcemaps = require('gulp-sourcemaps');
const through = require('through2'); 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 pkg = require('./package.json');
const build = require('./build.json');
const deploy = require('./deploy.json');
const { browserslist: browsers, version } = pkg;
const minSuffix = '.min'; 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 // Paths
const paths = { const paths = {
plyr: { plyr: {
@ -73,7 +100,7 @@ const paths = {
// Task arrays // Task arrays
const tasks = { const tasks = {
sass: [], css: [],
js: [], js: [],
sprite: [], sprite: [],
clean: ['clean'], clean: ['clean'],
@ -82,9 +109,6 @@ const tasks = {
// Size plugin // Size plugin
const sizeOptions = { showFiles: true, gzip: true }; const sizeOptions = { showFiles: true, gzip: true };
// Browserlist
const browsers = ['> 1%'];
// Babel config // Babel config
const babelrc = (polyfill = false) => ({ const babelrc = (polyfill = false) => ({
presets: [ presets: [
@ -115,95 +139,91 @@ gulp.task('clean', done => {
done(); done();
}); });
const build = { // JAvaScript
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, () => const namespace = 'Plyr';
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, () => Object.entries(build.js).forEach(([filename, entry]) => {
gulp entry.formats.forEach(format => {
.src(bundles[bundle].sass[key]) const name = `js:${filename}:${format}`;
.pipe(sass()) tasks.js.push(name);
.on('error', gutil.log) const polyfill = filename.includes('polyfilled');
.pipe(concat(key)) const extension = format === 'es' ? 'mjs' : 'js';
.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 gulp.task(name, () => {
return gulp.task(name, () => return gulp
gulp .src(entry.src)
.src(paths[bundle].src.sprite) .pipe(plumber())
.pipe(sourcemaps.init())
.pipe( .pipe(
svgmin({ rollup(
plugins: [ {
{ plugins: [resolve(), commonjs(), babel(babelrc(polyfill))],
removeDesc: true, },
}, {
], 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(size(sizeOptions))
.pipe(gulp.dest(paths[bundle].output)) .pipe(gulp.dest(entry.dist))
.pipe(gulp.dest(paths.demo.output)), .pipe(filter(`**/*${extension}`))
); .pipe(terser())
}, .pipe(rename({ suffix: minSuffix }))
}; .pipe(size(sizeOptions))
.pipe(sourcemaps.write(''))
.pipe(gulp.dest(entry.dist));
});
});
});
// Plyr core files // CSS
const namespace = 'Plyr'; Object.entries(build.css).forEach(([filename, entry]) => {
build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'umd' }); const name = `css:${filename}`;
build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'es' }); tasks.css.push(name);
build.sass(bundles.plyr.sass, 'plyr');
build.sprite('plyr');
// Demo files gulp.task(name, () => {
build.sass(bundles.demo.sass, 'demo'); return gulp
build.js(bundles.demo.js, 'demo', { format: 'iife' }); .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);
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 // Build all JS
gulp.task('js', () => gulp.parallel(...tasks.js)); gulp.task('js', () => gulp.parallel(...tasks.js));
@ -212,16 +232,16 @@ gulp.task('js', () => gulp.parallel(...tasks.js));
gulp.task('watch', () => { gulp.task('watch', () => {
// Plyr core // Plyr core
gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js)); 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)); gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite));
// Demo // Demo
gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js)); 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 // 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 // Default gulp task
gulp.task('default', gulp.series('build', 'watch')); gulp.task('default', gulp.series('build', 'watch'));
@ -236,234 +256,233 @@ try {
// Do nothing // Do nothing
} }
// If deployment is setup // Get branch info
// TODO: Use gulp-awspublish and use AWS CLI credentials const branch = {
if (Object.keys(credentials).includes('aws') && Object.keys(credentials).includes('fastly')) { current: gitbranch.sync(),
const { version } = pkg; master: 'master',
const { aws, fastly } = credentials; beta: 'beta',
};
// Get branch info const maxAge = 31536000; // 1 year
const branch = { const options = {
current: gitbranch.sync(), cdn: {
master: 'master', headers: {
beta: 'beta', 'Cache-Control': `max-age=${maxAge}`,
}; Vary: 'Accept-Encoding',
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, 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) {
return {
headers: { 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', '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 = 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\\-]+)*)?'; '(?: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 semver = new RegExp(`v${regex}`, 'gi');
const localPath = new RegExp('(../)?dist', 'gi'); const localPath = new RegExp('(../)?dist', 'gi');
const versionPath = `https://${aws.cdn.domain}/${version}`; const versionPath = `https://${deploy.cdn.domain}/${version}`;
const cdnpath = new RegExp(`${aws.cdn.domain}/${regex}/`, 'gi'); const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}/`, 'gi');
const renameFile = rename(p => { const renameFile = rename(p => {
p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
p.dirname = p.dirname.replace('.', version); // eslint-disable-line p.dirname = p.dirname.replace('.', version); // eslint-disable-line
}); });
// Check we're on the correct branch to deploy // Check we're on the correct branch to deploy
const canDeploy = () => { const canDeploy = () => {
const allowed = [branch.master, branch.beta]; const allowed = [branch.master, branch.beta];
if (!allowed.includes(branch.current)) { if (!allowed.includes(branch.current)) {
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`); console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
return false; return false;
} }
return true; return true;
}; };
gulp.task('version', done => { gulp.task('version', done => {
if (!canDeploy()) { if (!canDeploy()) {
done(); done();
return null; return null;
} }
console.log(`Updating versions to '${version}'...`); const { domain } = deploy.cdn;
// Replace versioned URLs in source console.log(`Updating versions to '${version}'...`);
const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
return gulp // Replace versioned URLs in source
.src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' }) const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
.pipe(replace(semver, `v${version}`))
.pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
.pipe(gulp.dest('./'));
});
// Publish version to CDN bucket return gulp
gulp.task('cdn', done => { .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' })
if (!canDeploy()) { .pipe(replace(semver, `v${version}`))
done(); .pipe(replace(cdnpath, `${domain}/${version}/`))
return null; .pipe(gulp.dest('./'));
} });
console.log(`Uploading '${version}' to ${aws.cdn.domain}...`); // Publish version to CDN bucket
gulp.task('cdn', done => {
if (!canDeploy()) {
done();
return null;
}
// Upload to CDN const { domain, publisher } = deploy.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))
);
});
// Purge the fastly cache incase any 403/404 are cached if (!publisher) {
gulp.task('purge', () => { throw new Error('No publisher instance. Check AWS configuration.');
const list = []; }
return gulp console.log(`Uploading '${version}' to ${domain}...`);
// Upload to CDN
return (
gulp
.src(paths.upload) .src(paths.upload)
.pipe(renameFile)
// Remove min suffix from source map URL
.pipe( .pipe(
through.obj((file, enc, cb) => { replace(
const filename = file.path.split('/').pop(); /sourceMappingURL=([\w-?.]+)/,
list.push(`${versionPath}/${filename.replace(minSuffix, '')}`); (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
cb(null); ),
}),
) )
.on('end', () => { .pipe(size(sizeOptions))
const purge = new FastlyPurge(fastly.token); .pipe(replace(localPath, versionPath))
.pipe(publisher.publish(options.cdn.headers))
.pipe(publish.reporter())
);
});
list.forEach(url => { // Purge the fastly cache incase any 403/404 are cached
console.log(`Purging ${url}...`); gulp.task('purge', () => {
if (!Object.keys(credentials).includes('fastly')) {
throw new Error('Fastly credentials required to purge cache.');
}
purge.url(url, (error, result) => { const { fastly } = credentials;
if (error) { const list = [];
console.log(error);
} else if (result) { return gulp
console.log(result); .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);
}
}); });
}); });
}); });
});
// Publish to demo bucket // Publish to demo bucket
gulp.task('demo', done => { gulp.task('demo', done => {
if (!canDeploy()) { if (!canDeploy()) {
done(); done();
return null; return null;
} }
console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`); const { publisher } = deploy.demo;
const { domain } = deploy.cdn;
// Replace versioned files in readme.md if (!publisher) {
gulp.src([`${__dirname}/readme.md`]) throw new Error('No publisher instance. Check AWS configuration.');
.pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`)) }
.pipe(gulp.dest(__dirname));
// Replace local file paths with remote paths in demo HTML console.log(`Uploading '${version}' demo to ${deploy.demo.domain}...`);
// 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 (branch.current === branch.master) { // Replace versioned files in readme.md
pages.push(error); gulp.src([`${__dirname}/readme.md`])
} .pipe(replace(cdnpath, `${domain}/${version}/`))
.pipe(gulp.dest(__dirname));
gulp.src(pages) // Replace local file paths with remote paths in demo HTML
.pipe(replace(localPath, versionPath)) // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
.pipe(s3(aws.demo, options.demo)); const index = `${paths.demo.root}index.html`;
const error = `${paths.demo.root}error.html`;
const pages = [index, error];
// Only update CDN for master (prod) if (branch.current === branch.master) {
if (branch.current !== branch.master) { pages.push(error);
done(); }
return null;
}
// Upload error.html to cdn (as well as demo site) return gulp
return gulp .src(pages)
.src([error]) .pipe(replace(localPath, versionPath))
.pipe(replace(localPath, versionPath)) .pipe(publisher.publish(options.demo.headers))
.pipe(s3(aws.cdn, options.demo)); .pipe(publish.reporter());
}); });
// Update symlinks for latest gulp.task('error', done => {
/* gulp.task("symlinks", function () { // Only update CDN for master (prod)
console.log("Updating symlinks..."); if (!canDeploy() || branch.current !== branch.master) {
done();
return null;
}
return gulp.src(paths.upload) const { publisher } = deploy.cdn;
.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 if (!publisher) {
createFile(filename, "") throw new Error('No publisher instance. Check AWS configuration.');
.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); // 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());
});
// Open the demo site to check it's ok // Open the demo site to check it's ok
gulp.task('open', () => { gulp.task('open', () => {
return gulp.src(__filename).pipe( return gulp.src(__filename).pipe(
open({ open({
uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`, 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.sass, ...tasks.sprite),
'cdn',
'demo',
'purge',
'open',
),
); );
} });
// Do everything
gulp.task(
'deploy',
gulp.series(
'version',
tasks.clean,
gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite),
'cdn',
'demo',
'purge',
'open',
),
);

View File

@ -27,45 +27,48 @@
"bugs": { "bugs": {
"url": "https://github.com/sampotts/plyr/issues" "url": "https://github.com/sampotts/plyr/issues"
}, },
"directories": { "browserslist": [
"doc": "readme.md" "> 1%",
}, "not dead"
],
"scripts": { "scripts": {
"build": "gulp build", "build": "gulp build",
"lint": "eslint src/js && npm run-script remark", "lint": "eslint src/js && npm run-script remark",
"remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'", "remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'",
"test": "echo \"Error: no test specified\" && exit 1" "deploy": "yarn lint && gulp deploy"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.2.2", "aws-sdk": "^2.404.0",
"babel-eslint": "^10.0.1", "@babel/core": "^7.3.3",
"@babel/preset-env": "^7.3.1", "@babel/preset-env": "^7.3.1",
"babel-eslint": "^10.0.1",
"babel-preset-minify": "^0.5.0",
"del": "^3.0.0", "del": "^3.0.0",
"eslint": "^5.13.0", "eslint": "^5.14.0",
"eslint-config-airbnb-base": "^13.1.0", "eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.0.0", "eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.16.0", "eslint-plugin-import": "^2.16.0",
"fancy-log": "^1.3.3",
"fastly-purge": "^1.0.1", "fastly-purge": "^1.0.1",
"git-branch": "^2.0.1", "git-branch": "^2.0.1",
"gulp": "^4.0.0", "gulp": "^4.0.0",
"gulp-autoprefixer": "^6.0.0", "gulp-autoprefixer": "^6.0.0",
"gulp-awspublish": "^4.0.0",
"gulp-better-rollup": "^3.4.0", "gulp-better-rollup": "^3.4.0",
"gulp-clean-css": "^4.0.0", "gulp-clean-css": "^4.0.0",
"gulp-concat": "^2.6.1",
"gulp-filter": "^5.1.0", "gulp-filter": "^5.1.0",
"gulp-header": "^2.0.7", "gulp-header": "^2.0.7",
"gulp-imagemin": "^5.0.3",
"gulp-open": "^3.0.1", "gulp-open": "^3.0.1",
"gulp-plumber": "^1.2.1",
"gulp-postcss": "^8.0.0", "gulp-postcss": "^8.0.0",
"gulp-rename": "^1.4.0", "gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0", "gulp-replace": "^1.0.0",
"gulp-s3": "^0.11.0",
"gulp-sass": "^4.0.2", "gulp-sass": "^4.0.2",
"gulp-size": "^3.0.0", "gulp-size": "^3.0.0",
"gulp-sourcemaps": "^2.6.4", "gulp-sourcemaps": "^2.6.4",
"gulp-svgmin": "^2.1.0",
"gulp-svgstore": "^7.0.1", "gulp-svgstore": "^7.0.1",
"gulp-uglify-es": "^1.0.4", "gulp-terser": "^1.1.7",
"gulp-util": "^3.0.8",
"postcss-custom-properties": "^8.0.9", "postcss-custom-properties": "^8.0.9",
"prettier-eslint": "^8.8.2", "prettier-eslint": "^8.8.2",
"prettier-stylelint": "^0.4.2", "prettier-stylelint": "^0.4.2",

2080
yarn.lock

File diff suppressed because it is too large Load Diff