aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2016-05-15 18:57:21 +1000
committerSam Potts <me@sampotts.me>2016-05-15 18:57:21 +1000
commit21c22763595c9deb4e6dea2a25778defdfca8c85 (patch)
tree85620a9c3574336bb523529739083ad06d29fe39 /gulpfile.js
parent602944ea4f41b3afa117b2645e7d5ceefe6e5ca7 (diff)
downloadplyr-21c22763595c9deb4e6dea2a25778defdfca8c85.tar.lz
plyr-21c22763595c9deb4e6dea2a25778defdfca8c85.tar.xz
plyr-21c22763595c9deb4e6dea2a25778defdfca8c85.zip
Build changes, sprite.svg => plyr.svg
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js92
1 files changed, 71 insertions, 21 deletions
diff --git a/gulpfile.js b/gulpfile.js
index 59c95571..228f2345 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,7 +1,7 @@
// ==========================================================================
// Gulp build script
// ==========================================================================
-/*global require, __dirname*/
+/*global require, __dirname,Buffer*/
/*jshint -W079 */
var fs = require("fs"),
@@ -19,10 +19,10 @@ var fs = require("fs"),
svgmin = require("gulp-svgmin"),
rename = require("gulp-rename"),
s3 = require("gulp-s3"),
- gzip = require("gulp-gzip"),
replace = require("gulp-replace"),
open = require("gulp-open"),
- size = require("gulp-size");
+ size = require("gulp-size"),
+ through = require("through2");
var root = __dirname,
paths = {
@@ -74,6 +74,29 @@ function loadJSON(path) {
}
}
+// Create a file from a string
+// http://stackoverflow.com/questions/23230569/how-do-you-create-a-file-from-a-string-in-gulp
+function createFile(filename, string) {
+ var src = require('stream').Readable({
+ objectMode: true
+ });
+ src._read = function () {
+ this.push(new gutil.File({
+ cwd: "",
+ base: "",
+ path: filename,
+ contents: new Buffer(string),
+ // stats also required for some functions
+ // https://nodejs.org/api/fs.html#fs_class_fs_stats
+ stat: {
+ size: string.length
+ }
+ }));
+ this.push(null);
+ }
+ return src
+}
+
var build = {
js: function (files, bundle) {
for (var key in files) {
@@ -143,7 +166,7 @@ var build = {
}]
}))
.pipe(svgstore())
- .pipe(rename({ basename: (bundle == "plyr" ? "sprite" : bundle) }))
+ .pipe(rename({ basename: bundle }))
.pipe(gulp.dest(paths[bundle].output));
});
}
@@ -200,15 +223,21 @@ options = {
headers: {
"Cache-Control": "max-age=" + maxAge,
"Vary": "Accept-Encoding"
- },
- gzippedOnly: true
+ }
},
docs: {
headers: {
- "Cache-Control": "public, must-revalidate, proxy-revalidate, max-age=0",
+ "Cache-Control": "no-cache, no-store, must-revalidate, max-age=0",
"Vary": "Accept-Encoding"
- },
- gzippedOnly: true
+ }
+ },
+ symlinks: function(version, filename) {
+ return {
+ headers: {
+ "X-Amz-Website-Redirect-Location": "/" + version + "/" + filename,
+ "Cache-Control": "no-cache, no-store, must-revalidate, max-age=0"
+ }
+ }
}
};
@@ -217,15 +246,16 @@ if("cdn" in aws) {
var regex = "(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:\.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:\.[\\da-z\\-]+)*)?",
cdnpath = new RegExp(aws.cdn.bucket + "\/" + regex, "gi"),
semver = new RegExp("v" + regex, "gi"),
- localpath = new RegExp("(\.\.\/)?dist", "gi");
+ localpath = new RegExp("(\.\.\/)?dist", "gi"),
+ latest = "https://" + aws.cdn.bucket + "/latest";
}
// Publish version to CDN bucket
gulp.task("cdn", function () {
- console.log("Uploading " + version + " to " + aws.cdn.bucket);
+ console.log("Uploading " + version + " to " + aws.cdn.bucket + "...");
// Upload to CDN
- gulp.src(paths.upload)
+ return gulp.src(paths.upload)
.pipe(size({
showFiles: true,
gzip: true
@@ -233,13 +263,12 @@ gulp.task("cdn", function () {
.pipe(rename(function (path) {
path.dirname = path.dirname.replace(".", version);
}))
- .pipe(gzip())
.pipe(s3(aws.cdn, options.cdn));
});
// Publish to Docs bucket
gulp.task("docs", function () {
- console.log("Uploading " + version + " docs to " + aws.docs.bucket);
+ console.log("Uploading " + version + " docs to " + aws.docs.bucket + "...");
// Replace versioned files in readme.md
gulp.src([root + "/readme.md"])
@@ -254,25 +283,46 @@ gulp.task("docs", function () {
// Replace local file paths with remote paths in docs
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
gulp.src([paths.docs.root + "*.html"])
- .pipe(replace(localpath, "https://" + aws.cdn.bucket + "/" + version))
- .pipe(gzip())
+ .pipe(replace(localpath, latest))
.pipe(s3(aws.docs, options.docs));
// Upload error.html to cdn (as well as docs site)
- gulp.src([paths.docs.root + "error.html"])
- .pipe(replace(localpath, "https://" + aws.cdn.bucket + "/" + version))
- .pipe(gzip())
+ return gulp.src([paths.docs.root + "error.html"])
+ .pipe(replace(localpath, latest))
.pipe(s3(aws.cdn, options.docs));
});
// Open the docs site to check it's sweet
+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 docs site to check it's sweet
gulp.task("open", function () {
console.log("Opening " + aws.docs.bucket + "...");
// A file must be specified or gulp will skip the task
// Doesn't matter which file since we set the URL above
// Weird, I know...
- gulp.src([paths.docs.root + "index.html"])
+ return gulp.src([paths.docs.root + "index.html"])
.pipe(open("", {
url: "http://" + aws.docs.bucket
}));
@@ -280,5 +330,5 @@ gulp.task("open", function () {
// Do everything
gulp.task("publish", function () {
- run(tasks.js, tasks.less, tasks.sprite, "cdn", "docs");
+ run(tasks.js, tasks.less, tasks.sprite, "cdn", "docs", "symlinks");
});