aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2018-01-09 19:35:17 +1100
committerSam Potts <me@sampotts.me>2018-01-09 19:35:17 +1100
commit1df79cf7f8d9d41aa2c26ce6fe879ad58ce658fc (patch)
tree8f1db257ef4c420800f34adc9c5a0deea03dcf89 /gulpfile.js
parente6badacf0d83b62e97606c8d718317999139e2d0 (diff)
downloadplyr-1df79cf7f8d9d41aa2c26ce6fe879ad58ce658fc.tar.lz
plyr-1df79cf7f8d9d41aa2c26ce6fe879ad58ce658fc.tar.xz
plyr-1df79cf7f8d9d41aa2c26ce6fe879ad58ce658fc.zip
Publishing to /beta
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js56
1 files changed, 39 insertions, 17 deletions
diff --git a/gulpfile.js b/gulpfile.js
index a8ea7d9a..88d9cd15 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -13,6 +13,7 @@ const sass = require('gulp-sass');
const cleancss = require('gulp-clean-css');
const run = require('run-sequence');
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');
@@ -32,7 +33,7 @@ const bundles = require('./bundles.json');
const pkg = require('./package.json');
// Get AWS config
-let aws;
+let aws = {};
try {
aws = require('./aws.json'); //eslint-disable-line
} catch (e) {
@@ -137,12 +138,12 @@ const build = {
uglify({}, minify),
],
},
- options
- )
+ options,
+ ),
)
.pipe(size(sizeOptions))
.pipe(sourcemaps.write(''))
- .pipe(gulp.dest(paths[bundle].output))
+ .pipe(gulp.dest(paths[bundle].output)),
);
});
},
@@ -160,7 +161,7 @@ const build = {
.pipe(prefix(browsers, { cascade: false }))
.pipe(cleancss())
.pipe(size(sizeOptions))
- .pipe(gulp.dest(paths[bundle].output))
+ .pipe(gulp.dest(paths[bundle].output)),
);
});
},
@@ -177,12 +178,12 @@ const build = {
plugins: [{
removeDesc: true,
}],
- })
+ }),
)
.pipe(svgstore())
.pipe(rename({ basename: bundle }))
.pipe(size(sizeOptions))
- .pipe(gulp.dest(paths[bundle].output))
+ .pipe(gulp.dest(paths[bundle].output)),
);
},
};
@@ -247,16 +248,32 @@ const options = {
};
// If aws is setup
-if (aws && 'cdn' in aws) {
+if (Object.keys(aws).includes('cdn') && Object.keys(aws).includes('demo')) {
+ const branch = {
+ current: gitbranch.sync(),
+ master: 'master',
+ beta: 'beta',
+ };
+ const allowed = [
+ branch.master,
+ branch.beta,
+ ];
+
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 cdnpath = new RegExp(`${aws.cdn.domain}/${regex}`, 'gi');
+ const folder = branch.current === branch.beta ? '/beta' : '';
+ const cdnpath = new RegExp(`${aws.cdn.domain}${folder}/${regex}`, 'gi');
const semver = new RegExp(`v${regex}`, 'gi');
const localPath = new RegExp('(../)?dist', 'gi');
- const versionPath = `https://${aws.cdn.domain}/${version}`;
+ const versionPath = `https://${aws.cdn.domain}${folder}/${version}`;
// Publish version to CDN bucket
gulp.task('cdn', () => {
- console.log(`Uploading ${version} to ${aws.cdn.domain}...`);
+ if (!allowed.includes(branch.current)) {
+ console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
+ return null;
+ }
+
+ console.log(`Uploading '${version}' to ${aws.cdn.domain}${folder}...`);
// Upload to CDN
return gulp
@@ -265,13 +282,13 @@ if (aws && 'cdn' in aws) {
size({
showFiles: true,
gzip: true,
- })
+ }),
)
.pipe(
rename(p => {
// eslint-disable-next-line
p.dirname = p.dirname.replace('.', version);
- })
+ }),
)
.pipe(replace(localPath, versionPath))
.pipe(s3(aws.cdn, options.cdn));
@@ -279,19 +296,24 @@ if (aws && 'cdn' in aws) {
// Publish to demo bucket
gulp.task('demo', () => {
- console.log(`Uploading ${version} demo to ${aws.demo.domain}...`);
+ if (!allowed.includes(branch.current)) {
+ console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
+ return null;
+ }
+
+ console.log(`Uploading '${version}' demo to ${aws.demo.domain}${folder}...`);
// Replace versioned files in readme.md
gulp
.src([`${root}/readme.md`])
- .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}`))
+ .pipe(replace(cdnpath, `${aws.cdn.domain}${folder}/${version}`))
.pipe(gulp.dest(root));
// Replace versioned files in plyr.js
gulp
.src(path.join(root, 'src/js/plyr.js'))
.pipe(replace(semver, `v${version}`))
- .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}`))
+ .pipe(replace(cdnpath, `${aws.cdn.domain}${folder}/${version}`))
.pipe(gulp.dest(path.join(root, 'src/js/')));
// Replace local file paths with remote paths in demo HTML
@@ -341,7 +363,7 @@ if (aws && 'cdn' in aws) {
return gulp.src([`${paths.demo.root}index.html`]).pipe(
open('', {
url: `http://${aws.demo.domain}`,
- })
+ }),
);
});