aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js364
1 files changed, 190 insertions, 174 deletions
diff --git a/gulpfile.js b/gulpfile.js
index 26b97238..7f33abcc 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -4,72 +4,69 @@
/*global require, __dirname,Buffer*/
/*jshint -W079 */
-var fs = require("fs"),
- path = require("path"),
- gulp = require("gulp"),
- gutil = require("gulp-util"),
- concat = require("gulp-concat"),
- uglify = require("gulp-uglify"),
- less = require("gulp-less"),
- sass = require("gulp-sass"),
- cleanCSS = require("gulp-clean-css"),
- run = require("run-sequence"),
- prefix = require("gulp-autoprefixer"),
- svgstore = require("gulp-svgstore"),
- svgmin = require("gulp-svgmin"),
- rename = require("gulp-rename"),
- s3 = require("gulp-s3"),
- replace = require("gulp-replace"),
- open = require("gulp-open"),
- size = require("gulp-size"),
- through = require("through2");
+var fs = require('fs'),
+ path = require('path'),
+ gulp = require('gulp'),
+ gutil = require('gulp-util'),
+ concat = require('gulp-concat'),
+ uglify = require('gulp-uglify'),
+ less = require('gulp-less'),
+ sass = require('gulp-sass'),
+ cleanCSS = require('gulp-clean-css'),
+ run = require('run-sequence'),
+ prefix = require('gulp-autoprefixer'),
+ svgstore = require('gulp-svgstore'),
+ svgmin = require('gulp-svgmin'),
+ rename = require('gulp-rename'),
+ s3 = require('gulp-s3'),
+ replace = require('gulp-replace'),
+ open = require('gulp-open'),
+ size = require('gulp-size'),
+ through = require('through2');
var root = __dirname,
-paths = {
- plyr: {
- // Source paths
- src: {
- less: path.join(root, "src/less/**/*"),
- scss: path.join(root, "src/scss/**/*"),
- js: path.join(root, "src/js/**/*"),
- sprite: path.join(root, "src/sprite/*.svg")
+ paths = {
+ plyr: {
+ // Source paths
+ src: {
+ less: path.join(root, 'src/less/**/*'),
+ scss: path.join(root, 'src/scss/**/*'),
+ js: path.join(root, 'src/js/**/*'),
+ sprite: path.join(root, 'src/sprite/*.svg'),
+ },
+ // Output paths
+ output: path.join(root, 'dist/'),
},
- // Output paths
- output: path.join(root, "dist/")
- },
- demo: {
- // Source paths
- src: {
- less: path.join(root, "demo/src/less/**/*"),
- js: path.join(root, "demo/src/js/**/*"),
- sprite: path.join(root, "demo/src/sprite/**/*")
+ demo: {
+ // Source paths
+ src: {
+ less: path.join(root, 'demo/src/less/**/*'),
+ js: path.join(root, 'demo/src/js/**/*'),
+ sprite: path.join(root, 'demo/src/sprite/**/*'),
+ },
+ // Output paths
+ output: path.join(root, 'demo/dist/'),
+ // Demo
+ root: path.join(root, 'demo/'),
},
- // Output paths
- output: path.join(root, "demo/dist/"),
- // Demo
- root: path.join(root, "demo/")
+ upload: [path.join(root, 'dist/**'), path.join(root, 'demo/dist/**')],
},
- upload: [path.join(root, "dist/**"), path.join(root, "demo/dist/**")]
-},
-
-// Task arrays
-tasks = {
- less: [],
- scss: [],
- js: [],
- sprite: []
-},
-
-// Fetch bundles from JSON
-bundles = loadJSON(path.join(root, "bundles.json")),
-package = loadJSON(path.join(root, "package.json"));
+ // Task arrays
+ tasks = {
+ less: [],
+ scss: [],
+ js: [],
+ sprite: [],
+ },
+ // Fetch bundles from JSON
+ bundles = loadJSON(path.join(root, 'bundles.json')),
+ package = loadJSON(path.join(root, 'package.json'));
// Load json
function loadJSON(path) {
try {
return JSON.parse(fs.readFileSync(path));
- }
- catch(err) {
+ } catch (err) {
return {};
}
}
@@ -78,37 +75,39 @@ function loadJSON(path) {
// 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
+ 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
- }
- }));
+ 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
+ };
+ return src;
}
var build = {
- js: function (files, bundle) {
+ js: function(files, bundle) {
for (var key in files) {
(function(key) {
- var name = "js-" + key;
+ var name = 'js-' + key;
tasks.js.push(name);
- gulp.task(name, function () {
+ gulp.task(name, function() {
return gulp
.src(bundles[bundle].js[key])
.pipe(concat(key))
- .pipe(uglify())
+ .pipe(uglify().on('error', gutil.log))
.pipe(gulp.dest(paths[bundle].output));
});
})(key);
@@ -116,17 +115,17 @@ var build = {
},
less: function(files, bundle) {
for (var key in files) {
- (function (key) {
- var name = "less-" + key;
+ (function(key) {
+ var name = 'less-' + key;
tasks.less.push(name);
- gulp.task(name, function () {
+ gulp.task(name, function() {
return gulp
.src(bundles[bundle].less[key])
.pipe(less())
- .on("error", gutil.log)
+ .on('error', gutil.log)
.pipe(concat(key))
- .pipe(prefix(["last 2 versions"], { cascade: true }))
+ .pipe(prefix(['last 2 versions'], { cascade: true }))
.pipe(cleanCSS())
.pipe(gulp.dest(paths[bundle].output));
});
@@ -135,17 +134,17 @@ var build = {
},
scss: function(files, bundle) {
for (var key in files) {
- (function (key) {
- var name = "scss-" + key;
+ (function(key) {
+ var name = 'scss-' + key;
tasks.scss.push(name);
- gulp.task(name, function () {
+ gulp.task(name, function() {
return gulp
.src(bundles[bundle].scss[key])
.pipe(sass())
- .on("error", gutil.log)
+ .on('error', gutil.log)
.pipe(concat(key))
- .pipe(prefix(["last 2 versions"], { cascade: true }))
+ .pipe(prefix(['last 2 versions'], { cascade: true }))
.pipe(cleanCSS())
.pipe(gulp.dest(paths[bundle].output));
});
@@ -153,48 +152,52 @@ var build = {
}
},
sprite: function(bundle) {
- var name = "sprite-" + bundle;
+ var name = 'sprite-' + bundle;
tasks.sprite.push(name);
// Process Icons
- gulp.task(name, function () {
+ gulp.task(name, function() {
return gulp
.src(paths[bundle].src.sprite)
- .pipe(svgmin({
- plugins: [{
- removeDesc: true
- }]
- }))
+ .pipe(
+ svgmin({
+ plugins: [
+ {
+ removeDesc: true,
+ },
+ ],
+ }),
+ )
.pipe(svgstore())
.pipe(rename({ basename: bundle }))
.pipe(gulp.dest(paths[bundle].output));
});
- }
+ },
};
// Plyr core files
-build.js(bundles.plyr.js, "plyr");
-build.less(bundles.plyr.less, "plyr");
-build.scss(bundles.plyr.scss, "plyr");
-build.sprite("plyr");
+build.js(bundles.plyr.js, 'plyr');
+build.less(bundles.plyr.less, 'plyr');
+build.scss(bundles.plyr.scss, 'plyr');
+build.sprite('plyr');
// Demo files
-build.less(bundles.demo.less, "demo");
-build.js(bundles.demo.js, "demo");
-build.sprite("demo");
+build.less(bundles.demo.less, 'demo');
+build.js(bundles.demo.js, 'demo');
+build.sprite('demo');
// Build all JS
-gulp.task("js", function(){
+gulp.task('js', function() {
run(tasks.js);
});
// Build SCSS (for testing, default is LESS)
-gulp.task("scss", function(){
+gulp.task('scss', function() {
run(tasks.scss);
});
// Watch for file changes
-gulp.task("watch", function () {
+gulp.task('watch', function() {
// Plyr core
gulp.watch(paths.plyr.src.js, tasks.js);
gulp.watch(paths.plyr.src.less, tasks.less);
@@ -207,131 +210,144 @@ gulp.task("watch", function () {
});
// Default gulp task
-gulp.task("default", function(){
- run(tasks.js, tasks.less, tasks.sprite, "watch");
+gulp.task('default', function() {
+ run(tasks.js, tasks.less, tasks.sprite, 'watch');
});
// Publish a version to CDN and demo
// --------------------------------------------
// Some options
-var aws = loadJSON(path.join(root, "aws.json")),
-version = package.version,
-maxAge = 31536000, // seconds 1 year
-options = {
- cdn: {
- headers: {
- "Cache-Control": "max-age=" + maxAge,
- "Vary": "Accept-Encoding"
- }
- },
- demo: {
- headers: {
- "Cache-Control": "no-cache, no-store, must-revalidate, max-age=0",
- "Vary": "Accept-Encoding"
- }
- },
- symlinks: function(version, filename) {
- return {
+var aws = loadJSON(path.join(root, 'aws.json')),
+ version = package.version,
+ maxAge = 31536000, // seconds 1 year
+ options = {
+ cdn: {
headers: {
- // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
- "x-amz-website-redirect-location": "/" + version + "/" + filename,
- "Cache-Control": "no-cache, no-store, must-revalidate, max-age=0"
- }
- }
- }
-};
+ 'Cache-Control': 'max-age=' + maxAge,
+ Vary: 'Accept-Encoding',
+ },
+ },
+ demo: {
+ headers: {
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
+ Vary: 'Accept-Encoding',
+ },
+ },
+ symlinks: function(version, filename) {
+ return {
+ headers: {
+ // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
+ 'x-amz-website-redirect-location': '/' + version + '/' + filename,
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
+ },
+ };
+ },
+ };
// If aws is setup
-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.domain + "\/" + regex, "gi"),
- semver = new RegExp("v" + regex, "gi"),
- localPath = new RegExp("(\.\.\/)?dist", "gi"),
- versionPath = "https://" + aws.cdn.domain + "/" + version;
+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.domain + '/' + regex, 'gi'),
+ semver = new RegExp('v' + regex, 'gi'),
+ localPath = new RegExp('(../)?dist', 'gi'),
+ versionPath = 'https://' + aws.cdn.domain + '/' + version;
}
// Publish version to CDN bucket
-gulp.task("cdn", function () {
- console.log("Uploading " + version + " to " + aws.cdn.domain + "...");
+gulp.task('cdn', function() {
+ console.log('Uploading ' + version + ' to ' + aws.cdn.domain + '...');
// Upload to CDN
- return gulp.src(paths.upload)
- .pipe(size({
- showFiles: true,
- gzip: true
- }))
- .pipe(rename(function (path) {
- path.dirname = path.dirname.replace(".", version);
- }))
+ return gulp
+ .src(paths.upload)
+ .pipe(
+ size({
+ showFiles: true,
+ gzip: true,
+ }),
+ )
+ .pipe(
+ rename(function(path) {
+ path.dirname = path.dirname.replace('.', version);
+ }),
+ )
.pipe(replace(localPath, versionPath))
.pipe(s3(aws.cdn, options.cdn));
});
// Publish to demo bucket
-gulp.task("demo", function () {
- console.log("Uploading " + version + " demo to " + aws.demo.domain + "...");
+gulp.task('demo', function() {
+ console.log('Uploading ' + version + ' demo to ' + aws.demo.domain + '...');
// Replace versioned files in readme.md
- gulp.src([root + "/readme.md"])
- .pipe(replace(cdnpath, aws.cdn.domain + "/" + version))
+ gulp
+ .src([root + '/readme.md'])
+ .pipe(replace(cdnpath, aws.cdn.domain + '/' + 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(gulp.dest(path.join(root, "src/js/")));
+ gulp
+ .src(path.join(root, 'src/js/plyr.js'))
+ .pipe(replace(semver, 'v' + version))
+ .pipe(replace(cdnpath, aws.cdn.domain + '/' + version))
+ .pipe(gulp.dest(path.join(root, 'src/js/')));
// 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"
- gulp.src([paths.demo.root + "*.html"])
+ gulp
+ .src([paths.demo.root + '*.html'])
.pipe(replace(localPath, versionPath))
.pipe(s3(aws.demo, options.demo));
// Upload error.html to cdn (as well as demo site)
- return gulp.src([paths.demo.root + "error.html"])
+ return gulp
+ .src([paths.demo.root + 'error.html'])
.pipe(replace(localPath, versionPath))
.pipe(s3(aws.cdn, options.demo));
});
// Open the demo site to check it's sweet
-gulp.task("symlinks", function () {
- console.log("Updating symlinks...");
+gulp.task('symlinks', function() {
+ console.log('Updating symlinks...');
- return gulp.src(paths.upload)
- .pipe(through.obj(function (chunk, enc, callback) {
+ 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];
+ 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");
- }))
+ 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 sweet
-gulp.task("open", function () {
- console.log("Opening " + aws.demo.domain + "...");
+gulp.task('open', function() {
+ console.log('Opening ' + aws.demo.domain + '...');
// 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...
- return gulp.src([paths.demo.root + "index.html"])
- .pipe(open("", {
- url: "http://" + aws.demo.domain
- }));
+ return gulp.src([paths.demo.root + 'index.html']).pipe(
+ open('', {
+ url: 'http://' + aws.demo.domain,
+ }),
+ );
});
// Do everything
-gulp.task("publish", function () {
- run(tasks.js, tasks.less, tasks.sprite, "cdn", "demo", "symlinks");
+gulp.task('publish', function() {
+ run(tasks.js, tasks.less, tasks.sprite, 'cdn', 'demo', 'symlinks');
});