aboutsummaryrefslogtreecommitdiffstats
path: root/tasks
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-04-24 00:47:41 +1000
committerSam Potts <sam@potts.es>2020-04-24 00:47:41 +1000
commite48b1d11ce37960bc5803056561ec2b3996258c3 (patch)
tree10cab37f09f710c22d338ac8a0d8f43df5817caf /tasks
parentba91f23c50a6c7efa7d39dfb7105c16c20671434 (diff)
downloadplyr-e48b1d11ce37960bc5803056561ec2b3996258c3.tar.lz
plyr-e48b1d11ce37960bc5803056561ec2b3996258c3.tar.xz
plyr-e48b1d11ce37960bc5803056561ec2b3996258c3.zip
Housekeeping
Diffstat (limited to 'tasks')
-rw-r--r--tasks/build.js270
-rw-r--r--tasks/deploy.js355
2 files changed, 313 insertions, 312 deletions
diff --git a/tasks/build.js b/tasks/build.js
index bd801e32..9f1efd4f 100644
--- a/tasks/build.js
+++ b/tasks/build.js
@@ -37,37 +37,37 @@ const minSuffix = '.min';
// Paths
const root = path.join(__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'),
- },
-
- // Output paths
- output: path.join(root, 'dist/'),
+ 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'),
},
- demo: {
- // Source paths
- src: {
- sass: path.join(root, 'demo/src/sass/**/*.scss'),
- js: path.join(root, 'demo/src/js/**/*.js'),
- },
-
- // Output paths
- output: path.join(root, 'demo/dist/'),
-
- // Demo
- root: path.join(root, 'demo/'),
+
+ // Output paths
+ output: path.join(root, 'dist/'),
+ },
+ demo: {
+ // Source paths
+ src: {
+ sass: path.join(root, 'demo/src/sass/**/*.scss'),
+ js: path.join(root, 'demo/src/js/**/*.js'),
},
+
+ // Output paths
+ output: path.join(root, 'demo/dist/'),
+
+ // Demo
+ root: path.join(root, 'demo/'),
+ },
};
// Task lists
const tasks = {
- css: [],
- js: [],
- sprite: [],
+ css: [],
+ js: [],
+ sprite: [],
};
// Size plugin
@@ -75,115 +75,115 @@ const sizeOptions = { showFiles: true, gzip: true };
// Clean out /dist
gulp.task('clean', done => {
- const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
+ const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
- // Don't delete the mp4
- dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
+ // Don't delete the mp4
+ dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
- del(dirs);
+ del(dirs);
- done();
+ done();
});
// JavaScript
Object.entries(build.js).forEach(([filename, entry]) => {
- const { dist, formats, namespace, polyfill, src } = entry;
-
- formats.forEach(format => {
- const name = `js:${filename}:${format}`;
- const extension = format === 'es' ? 'mjs' : 'js';
- tasks.js.push(name);
-
- gulp.task(name, () =>
- gulp
- .src(src)
- .pipe(plumber())
- .pipe(sourcemaps.init())
- .pipe(
- rollup(
- {
- plugins: [
- resolve(),
- commonjs(),
- babel({
- presets: [
- [
- '@babel/env',
- {
- // debug: true,
- useBuiltIns: polyfill ? 'usage' : false,
- corejs: polyfill ? 3 : undefined,
- bugfixes: true,
- },
- ],
- ],
- babelrc: false,
- exclude: [/\/core-js\//],
- }),
- ],
- },
- {
- name: namespace,
- format,
- },
- ),
- )
- .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
- .pipe(
- rename({
- extname: `.${extension}`,
- }),
- )
- .pipe(gulp.dest(dist))
- .pipe(filter(`**/*.${extension}`))
- .pipe(terser())
- .pipe(rename({ suffix: minSuffix }))
- .pipe(size(sizeOptions))
- .pipe(sourcemaps.write(''))
- .pipe(gulp.dest(dist)),
- );
- });
-});
+ const { dist, formats, namespace, polyfill, src } = entry;
-// CSS
-Object.entries(build.css).forEach(([filename, entry]) => {
- const { dist, src } = entry;
- const name = `css:${filename}`;
- tasks.css.push(name);
+ formats.forEach(format => {
+ const name = `js:${filename}:${format}`;
+ const extension = format === 'es' ? 'mjs' : 'js';
+ tasks.js.push(name);
gulp.task(name, () =>
- gulp
- .src(src)
- .pipe(plumber())
- .pipe(sass())
- .pipe(postcss([customprops(), autoprefixer(), clean()]))
- .pipe(size(sizeOptions))
- .pipe(gulp.dest(dist)),
+ gulp
+ .src(src)
+ .pipe(plumber())
+ .pipe(sourcemaps.init())
+ .pipe(
+ rollup(
+ {
+ plugins: [
+ resolve(),
+ commonjs(),
+ babel({
+ presets: [
+ [
+ '@babel/env',
+ {
+ // debug: true,
+ useBuiltIns: polyfill ? 'usage' : false,
+ corejs: polyfill ? 3 : undefined,
+ bugfixes: true,
+ },
+ ],
+ ],
+ babelrc: false,
+ exclude: [/\/core-js\//],
+ }),
+ ],
+ },
+ {
+ name: namespace,
+ format,
+ },
+ ),
+ )
+ .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
+ .pipe(
+ rename({
+ extname: `.${extension}`,
+ }),
+ )
+ .pipe(gulp.dest(dist))
+ .pipe(filter(`**/*.${extension}`))
+ .pipe(terser())
+ .pipe(rename({ suffix: minSuffix }))
+ .pipe(size(sizeOptions))
+ .pipe(sourcemaps.write(''))
+ .pipe(gulp.dest(dist)),
);
+ });
+});
+
+// CSS
+Object.entries(build.css).forEach(([filename, entry]) => {
+ const { dist, src } = entry;
+ const name = `css:${filename}`;
+ tasks.css.push(name);
+
+ gulp.task(name, () =>
+ gulp
+ .src(src)
+ .pipe(plumber())
+ .pipe(sass())
+ .pipe(postcss([customprops(), autoprefixer(), clean()]))
+ .pipe(size(sizeOptions))
+ .pipe(gulp.dest(dist)),
+ );
});
// SVG Sprites
Object.entries(build.sprite).forEach(([filename, entry]) => {
- const { dist, src } = entry;
- const name = `sprite:${filename}`;
- tasks.sprite.push(name);
-
- gulp.task(name, () =>
- gulp
- .src(src)
- .pipe(plumber())
- .pipe(
- imagemin([
- imagemin.svgo({
- plugins: [{ removeViewBox: false }],
- }),
- ]),
- )
- .pipe(svgstore())
- .pipe(rename({ basename: path.parse(filename).name }))
- .pipe(size(sizeOptions))
- .pipe(gulp.dest(dist)),
- );
+ const { dist, src } = entry;
+ const name = `sprite:${filename}`;
+ tasks.sprite.push(name);
+
+ gulp.task(name, () =>
+ gulp
+ .src(src)
+ .pipe(plumber())
+ .pipe(
+ imagemin([
+ imagemin.svgo({
+ plugins: [{ removeViewBox: false }],
+ }),
+ ]),
+ )
+ .pipe(svgstore())
+ .pipe(rename({ basename: path.parse(filename).name }))
+ .pipe(size(sizeOptions))
+ .pipe(gulp.dest(dist)),
+ );
});
// Build all tasks
@@ -193,26 +193,26 @@ gulp.task('sprites', gulp.parallel(...tasks.sprite));
// Watch for file changes
gulp.task('watch', () => {
- // Plyr core
- gulp.watch(paths.plyr.src.js, gulp.parallel('js'));
- gulp.watch(paths.plyr.src.sass, gulp.parallel('css'));
- gulp.watch(paths.plyr.src.sprite, gulp.parallel('sprites'));
-
- // Demo
- gulp.watch(paths.demo.src.js, gulp.parallel('js'));
- gulp.watch(paths.demo.src.sass, gulp.parallel('css'));
+ // Plyr core
+ gulp.watch(paths.plyr.src.js, gulp.parallel('js'));
+ gulp.watch(paths.plyr.src.sass, gulp.parallel('css'));
+ gulp.watch(paths.plyr.src.sprite, gulp.parallel('sprites'));
+
+ // Demo
+ gulp.watch(paths.demo.src.js, gulp.parallel('js'));
+ gulp.watch(paths.demo.src.sass, gulp.parallel('css'));
});
// Serve via browser sync
gulp.task('serve', () =>
- browserSync.init({
- server: {
- baseDir: paths.demo.root,
- },
- notify: false,
- watch: true,
- ghostMode: false,
- }),
+ browserSync.init({
+ server: {
+ baseDir: paths.demo.root,
+ },
+ notify: false,
+ watch: true,
+ ghostMode: false,
+ }),
);
// Build distribution
diff --git a/tasks/deploy.js b/tasks/deploy.js
index 4ff94680..22fdb444 100644
--- a/tasks/deploy.js
+++ b/tasks/deploy.js
@@ -28,244 +28,245 @@ 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' }),
- }),
- });
+ Object.assign(target, {
+ publisher: publish.create({
+ region: target.region,
+ params: {
+ Bucket: target.bucket,
+ },
+ credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }),
+ }),
+ });
});
// Paths
const root = path.join(__dirname, '..');
const paths = {
- 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(root, 'demo/dist/*.svg'),
- ],
+ 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(root, 'demo/dist/*.svg'),
+ ],
};
// Get credentials
let credentials = {};
try {
- credentials = require('../credentials.json'); //eslint-disable-line
+ credentials = require('../credentials.json'); //eslint-disable-line
} catch (e) {
- // Do nothing
+ // Do nothing
}
// Get branch info
const branch = {
- current: gitbranch.sync(),
- master: 'master',
- beta: 'beta',
+ current: gitbranch.sync(),
+ master: 'master',
+ beta: 'beta',
};
const maxAge = 31536000; // 1 year
const options = {
- cdn: {
- headers: {
- 'Cache-Control': `max-age=${maxAge}, immutable`,
- },
- },
- demo: {
- uploadPath: branch.current === branch.beta ? '/beta' : null,
- headers: {
- 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
- },
+ cdn: {
+ headers: {
+ 'Cache-Control': `max-age=${maxAge}, immutable`,
},
- 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',
- },
- };
+ },
+ demo: {
+ uploadPath: branch.current === branch.beta ? '/beta' : null,
+ headers: {
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
},
+ },
+ 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',
+ },
+ };
+ },
};
// Size plugin
const sizeOptions = { showFiles: true, gzip: true };
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 localPath = new RegExp('(../)?dist', 'gi');
const versionPath = `https://${deploy.cdn.domain}/${version}`;
const cdnpath = new RegExp(`${deploy.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
+ 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];
+ const allowed = [branch.master, branch.beta];
- if (!allowed.includes(branch.current)) {
- console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
+ if (!allowed.includes(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 => {
- if (!canDeploy()) {
- done();
- return null;
- }
-
- const { domain } = deploy.cdn;
-
- 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'];
-
- 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('./'));
+ if (!canDeploy()) {
+ done();
+ return null;
+ }
+
+ const { domain } = deploy.cdn;
+
+ 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'];
+
+ 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('./'));
});
// Publish version to CDN bucket
gulp.task('cdn', done => {
- if (!canDeploy()) {
- done();
- return null;
- }
-
- const { domain, publisher } = deploy.cdn;
-
- if (!publisher) {
- throw new Error('No publisher instance. Check AWS configuration.');
- }
-
- log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(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(sizeOptions))
- .pipe(replace(localPath, versionPath))
- .pipe(publisher.publish(options.cdn.headers))
- .pipe(publish.reporter())
- );
+ if (!canDeploy()) {
+ done();
+ return null;
+ }
+
+ const { domain, publisher } = deploy.cdn;
+
+ if (!publisher) {
+ throw new Error('No publisher instance. Check AWS configuration.');
+ }
+
+ log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(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(sizeOptions))
+ .pipe(replace(localPath, versionPath))
+ .pipe(publisher.publish(options.cdn.headers))
+ .pipe(publish.reporter())
+ );
});
// 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 => {
- log(`Purging ${ansi.cyan(url)}...`);
-
- purge.url(url, (error, result) => {
- if (error) {
- log.error(error);
- } else if (result) {
- log(result);
- }
- });
- });
+ 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 => {
+ log(`Purging ${ansi.cyan(url)}...`);
+
+ purge.url(url, (error, result) => {
+ if (error) {
+ log.error(error);
+ } else if (result) {
+ log(result);
+ }
});
+ });
+ });
});
// 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.');
- }
-
- log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(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];
-
- if (branch.current === branch.master) {
- pages.push(error);
- }
-
- return gulp
- .src(pages)
- .pipe(replace(localPath, versionPath))
- .pipe(
- rename(p => {
- if (options.demo.uploadPath) {
- // eslint-disable-next-line no-param-reassign
- p.dirname += options.demo.uploadPath;
- }
- }),
- )
- .pipe(publisher.publish(options.demo.headers))
- .pipe(publish.reporter());
+ if (!canDeploy()) {
+ done();
+ return null;
+ }
+
+ const { publisher } = deploy.demo;
+ const { domain } = deploy.cdn;
+
+ if (!publisher) {
+ throw new Error('No publisher instance. Check AWS configuration.');
+ }
+
+ log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(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];
+
+ if (branch.current === branch.master) {
+ pages.push(error);
+ }
+
+ return gulp
+ .src(pages)
+ .pipe(replace(localPath, versionPath))
+ .pipe(
+ rename(p => {
+ if (options.demo.uploadPath) {
+ // eslint-disable-next-line no-param-reassign
+ p.dirname += options.demo.uploadPath;
+ }
+ }),
+ )
+ .pipe(publisher.publish(options.demo.headers))
+ .pipe(publish.reporter());
});
// Open the demo site to check it's ok
gulp.task('open', () => {
- const { domain } = deploy.demo;
+ const { domain } = deploy.demo;
- return gulp.src(__filename).pipe(
- open({
- uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`,
- }),
- );
+ return gulp.src(__filename).pipe(
+ open({
+ uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`,
+ }),
+ );
});
// Do everything