Browse Source

Update build process

Sam Potts 6 months ago
parent
commit
54110f8358

+ 46
- 0
build.json View File

@@ -0,0 +1,46 @@
1
+{
2
+    "js": {
3
+        "plyr.js": {
4
+            "src": "./src/js/plyr.js",
5
+            "dist": "./dist/",
6
+            "formats": ["es", "umd"],
7
+            "namespace": "Plyr"
8
+        },
9
+        "plyr.polyfilled.js": {
10
+            "src": "./src/js/plyr.polyfilled.js",
11
+            "dist": "./dist/",
12
+            "formats": ["es", "umd"],
13
+            "namespace": "Plyr"
14
+        },
15
+        "demo.js": {
16
+            "src": "./demo/src/js/demo.js",
17
+            "dist": "./demo/dist/",
18
+            "formats": ["iife"],
19
+            "namespace": "Demo"
20
+        }
21
+    },
22
+    "css": {
23
+        "plyr.css": {
24
+            "src": "./src/sass/plyr.scss",
25
+            "dist": "./dist/"
26
+        },
27
+        "demo.css": {
28
+            "src": "./demo/src/sass/bundles/demo.scss",
29
+            "dist": "./demo/dist/"
30
+        },
31
+        "error.css": {
32
+            "src": "./demo/src/sass/bundles/error.scss",
33
+            "dist": "./demo/dist/"
34
+        }
35
+    },
36
+    "sprite": {
37
+        "plyr.svg": {
38
+            "src": "./src/sprite/*.svg",
39
+            "dist": "./dist"
40
+        },
41
+        "demo.svg": {
42
+            "src": "./src/sprite/*.svg",
43
+            "dist": "./demo/dist"
44
+        }
45
+    }
46
+}

+ 0
- 20
bundles.json View File

@@ -1,20 +0,0 @@
1
-{
2
-    "plyr": {
3
-        "sass": {
4
-            "plyr.css": "src/sass/plyr.scss"
5
-        },
6
-        "js": {
7
-            "plyr.js": "src/js/plyr.js",
8
-            "plyr.polyfilled.js": "src/js/plyr.polyfilled.js"
9
-        }
10
-    },
11
-    "demo": {
12
-        "sass": {
13
-            "demo.css": "demo/src/sass/bundles/demo.scss",
14
-            "error.css": "demo/src/sass/bundles/error.scss"
15
-        },
16
-        "js": {
17
-            "demo.js": "demo/src/js/demo.js"
18
-        }
19
-    }
20
-}

+ 5
- 11
demo/dist/demo.js View File

@@ -5911,7 +5911,7 @@ typeof navigator === "object" && (function () {
5911 5911
 	      min: 0,
5912 5912
 	      max: 100,
5913 5913
 	      value: 0,
5914
-	      role: 'presentation',
5914
+	      role: 'progressbar',
5915 5915
 	      'aria-hidden': true
5916 5916
 	    }, attributes)); // Create the label inside
5917 5917
 
@@ -13004,17 +13004,12 @@ typeof navigator === "object" && (function () {
13004 13004
 
13005 13005
 	          focused.classList.add(tabClassName);
13006 13006
 	        }, 10);
13007
-	      });
13008
-	      var userType = 'annon';
13009
-	      var contentType = 'on-demand';
13010
-	      var cmsid = 2490180;
13011
-	      var vid = 3788;
13012
-	      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
13007
+	      }); // Setup the player
13013 13008
 
13014 13009
 	      var player = new Plyr(selector, {
13015 13010
 	        debug: true,
13016 13011
 	        title: 'View From A Blue Moon',
13017
-	        iconUrl: 'dist/plyr.svg',
13012
+	        iconUrl: 'dist/demo.svg',
13018 13013
 	        keyboard: {
13019 13014
 	          global: true
13020 13015
 	        },
@@ -13028,9 +13023,8 @@ typeof navigator === "object" && (function () {
13028 13023
 	          google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c'
13029 13024
 	        },
13030 13025
 	        ads: {
13031
-	          enabled: true,
13032
-	          // env.prod || env.dev,
13033
-	          tagUrl: tagUrl
13026
+	          enabled: env.prod || env.dev,
13027
+	          publisherId: '918848828995742'
13034 13028
 	        },
13035 13029
 	        previewThumbnails: {
13036 13030
 	          enabled: true,

+ 1
- 1
demo/dist/demo.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
demo/dist/demo.min.js.map
File diff suppressed because it is too large
View File


demo/dist/demo.svg
File diff suppressed because it is too large
View File


+ 3
- 10
demo/src/js/demo.js View File

@@ -58,18 +58,11 @@ import Plyr from '../../../src/js/plyr';
58 58
                 }, 10);
59 59
             });
60 60
 
61
-            const userType = 'annon';
62
-            const contentType = 'on-demand';
63
-            const cmsid = 2490180;
64
-            const vid = 3788;
65
-
66
-            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}`;
67
-
68 61
             // Setup the player
69 62
             const player = new Plyr(selector, {
70 63
                 debug: true,
71 64
                 title: 'View From A Blue Moon',
72
-                iconUrl: 'dist/plyr.svg',
65
+                iconUrl: 'dist/demo.svg',
73 66
                 keyboard: {
74 67
                     global: true,
75 68
                 },
@@ -83,8 +76,8 @@ import Plyr from '../../../src/js/plyr';
83 76
                     google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c',
84 77
                 },
85 78
                 ads: {
86
-                    enabled: true, // env.prod || env.dev,
87
-                    tagUrl,
79
+                    enabled: env.prod || env.dev,
80
+                    publisherId: '918848828995742',
88 81
                 },
89 82
                 previewThumbnails: {
90 83
                     enabled: true,

+ 12
- 0
deploy.json View File

@@ -0,0 +1,12 @@
1
+{
2
+    "cdn": {
3
+        "bucket": "plyr",
4
+        "domain": "cdn.plyr.io",
5
+        "region": "us-east-1"
6
+    },
7
+    "demo": {
8
+        "bucket": "plyr.io",
9
+        "domain": "plyr.io",
10
+        "region": "us-west-1"
11
+    }
12
+}

+ 1
- 1
dist/plyr.js View File

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

+ 1
- 1
dist/plyr.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.min.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.min.mjs
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.min.mjs.map
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.mjs View File

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

+ 2
- 2
dist/plyr.polyfilled.js View File

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

+ 1
- 1
dist/plyr.polyfilled.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.polyfilled.min.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.polyfilled.min.mjs
File diff suppressed because it is too large
View File


+ 1
- 1
dist/plyr.polyfilled.min.mjs.map
File diff suppressed because it is too large
View File


+ 2
- 2
dist/plyr.polyfilled.mjs View File

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

+ 1
- 1
dist/plyr.svg
File diff suppressed because it is too large
View File


+ 330
- 311
gulpfile.js View File

@@ -4,38 +4,65 @@
4 4
 /* global require, __dirname */
5 5
 /* eslint no-console: "off" */
6 6
 
7
-const del = require('del');
8 7
 const path = require('path');
9 8
 const gulp = require('gulp');
10
-const gutil = require('gulp-util');
11
-const concat = require('gulp-concat');
12
-const filter = require('gulp-filter');
9
+
10
+// JavaScript
11
+const terser = require('gulp-terser');
12
+const rollup = require('gulp-better-rollup');
13
+const babel = require('rollup-plugin-babel');
14
+const commonjs = require('rollup-plugin-commonjs');
15
+const resolve = require('rollup-plugin-node-resolve');
16
+
17
+// CSS
13 18
 const sass = require('gulp-sass');
14
-const cleancss = require('gulp-clean-css');
15
-const header = require('gulp-header');
19
+const clean = require('gulp-clean-css');
16 20
 const prefix = require('gulp-autoprefixer');
17
-const gitbranch = require('git-branch');
21
+
22
+// Images
18 23
 const svgstore = require('gulp-svgstore');
19
-const svgmin = require('gulp-svgmin');
24
+const imagemin = require('gulp-imagemin');
25
+
26
+// Utils
27
+const del = require('del');
28
+const filter = require('gulp-filter');
29
+const header = require('gulp-header');
30
+const gitbranch = require('git-branch');
20 31
 const rename = require('gulp-rename');
21
-const s3 = require('gulp-s3');
22 32
 const replace = require('gulp-replace');
33
+const log = require('fancy-log');
23 34
 const open = require('gulp-open');
35
+const plumber = require('gulp-plumber');
24 36
 const size = require('gulp-size');
25
-const rollup = require('gulp-better-rollup');
26
-const babel = require('rollup-plugin-babel');
27 37
 const sourcemaps = require('gulp-sourcemaps');
28
-const uglify = require('gulp-uglify-es').default;
29
-const commonjs = require('rollup-plugin-commonjs');
30
-const resolve = require('rollup-plugin-node-resolve');
31
-const FastlyPurge = require('fastly-purge');
32 38
 const through = require('through2');
33 39
 
34
-const bundles = require('./bundles.json');
40
+// Deployment
41
+const aws = require('aws-sdk');
42
+const publish = require('gulp-awspublish');
43
+const FastlyPurge = require('fastly-purge');
44
+
35 45
 const pkg = require('./package.json');
46
+const build = require('./build.json');
47
+const deploy = require('./deploy.json');
48
+
49
+const { browserslist: browsers, version } = pkg;
36 50
 
37 51
 const minSuffix = '.min';
38 52
 
53
+// Get AWS config
54
+Object.values(deploy).forEach(target => {
55
+    Object.assign(target, {
56
+        publisher: publish.create({
57
+            region: target.region,
58
+            params: {
59
+                Bucket: target.bucket,
60
+            },
61
+            credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }),
62
+        }),
63
+    });
64
+});
65
+
39 66
 // Paths
40 67
 const paths = {
41 68
     plyr: {
@@ -73,7 +100,7 @@ const paths = {
73 100
 
74 101
 // Task arrays
75 102
 const tasks = {
76
-    sass: [],
103
+    css: [],
77 104
     js: [],
78 105
     sprite: [],
79 106
     clean: ['clean'],
@@ -82,9 +109,6 @@ const tasks = {
82 109
 // Size plugin
83 110
 const sizeOptions = { showFiles: true, gzip: true };
84 111
 
85
-// Browserlist
86
-const browsers = ['> 1%'];
87
-
88 112
 // Babel config
89 113
 const babelrc = (polyfill = false) => ({
90 114
     presets: [
@@ -115,95 +139,91 @@ gulp.task('clean', done => {
115 139
     done();
116 140
 });
117 141
 
118
-const build = {
119
-    js(files, bundle, options) {
120
-        Object.keys(files).forEach(key => {
121
-            const { format } = options;
122
-            const name = `js:${key}:${format}`;
123
-            tasks.js.push(name);
124
-            const { output } = paths[bundle];
125
-            const polyfill = name.includes('polyfilled');
126
-            const extension = format === 'es' ? '.mjs' : '.js';
127
-
128
-            return gulp.task(name, () =>
129
-                gulp
130
-                    .src(bundles[bundle].js[key])
131
-                    .pipe(sourcemaps.init())
132
-                    .pipe(concat(key))
133
-                    .pipe(
134
-                        rollup(
135
-                            {
136
-                                plugins: [resolve(), commonjs(), babel(babelrc(polyfill))],
137
-                            },
138
-                            options,
139
-                        ),
140
-                    )
141
-                    .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
142
-                    .pipe(rename({ extname: extension }))
143
-                    .pipe(gulp.dest(output))
144
-                    .pipe(filter(`**/*${extension}`))
145
-                    .pipe(uglify())
146
-                    .pipe(size(sizeOptions))
147
-                    .pipe(rename({ suffix: minSuffix }))
148
-                    .pipe(sourcemaps.write(''))
149
-                    .pipe(gulp.dest(output)),
150
-            );
151
-        });
152
-    },
153
-    sass(files, bundle) {
154
-        Object.keys(files).forEach(key => {
155
-            const name = `sass:${key}`;
156
-            tasks.sass.push(name);
157
-
158
-            return gulp.task(name, () =>
159
-                gulp
160
-                    .src(bundles[bundle].sass[key])
161
-                    .pipe(sass())
162
-                    .on('error', gutil.log)
163
-                    .pipe(concat(key))
164
-                    .pipe(prefix(browsers, { cascade: false }))
165
-                    .pipe(cleancss())
166
-                    .pipe(size(sizeOptions))
167
-                    .pipe(gulp.dest(paths[bundle].output)),
168
-            );
169
-        });
170
-    },
171
-    sprite(bundle) {
172
-        const name = `svg:sprite:${bundle}`;
173
-        tasks.sprite.push(name);
174
-
175
-        // Process Icons
176
-        return gulp.task(name, () =>
177
-            gulp
178
-                .src(paths[bundle].src.sprite)
142
+// JAvaScript
143
+
144
+const namespace = 'Plyr';
145
+
146
+Object.entries(build.js).forEach(([filename, entry]) => {
147
+    entry.formats.forEach(format => {
148
+        const name = `js:${filename}:${format}`;
149
+        tasks.js.push(name);
150
+        const polyfill = filename.includes('polyfilled');
151
+        const extension = format === 'es' ? 'mjs' : 'js';
152
+
153
+        gulp.task(name, () => {
154
+            return gulp
155
+                .src(entry.src)
156
+                .pipe(plumber())
157
+                .pipe(sourcemaps.init())
179 158
                 .pipe(
180
-                    svgmin({
181
-                        plugins: [
182
-                            {
183
-                                removeDesc: true,
184
-                            },
185
-                        ],
159
+                    rollup(
160
+                        {
161
+                            plugins: [resolve(), commonjs(), babel(babelrc(polyfill))],
162
+                        },
163
+                        {
164
+                            name: namespace,
165
+                            // exports: 'named',
166
+                            format,
167
+                        },
168
+                    ),
169
+                )
170
+                .pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
171
+                .pipe(
172
+                    rename({
173
+                        extname: `.${extension}`,
186 174
                     }),
187 175
                 )
188
-                .pipe(svgstore())
189
-                .pipe(rename({ basename: bundle }))
190 176
                 .pipe(size(sizeOptions))
191
-                .pipe(gulp.dest(paths[bundle].output))
192
-                .pipe(gulp.dest(paths.demo.output)),
193
-        );
194
-    },
195
-};
177
+                .pipe(gulp.dest(entry.dist))
178
+                .pipe(filter(`**/*${extension}`))
179
+                .pipe(terser())
180
+                .pipe(rename({ suffix: minSuffix }))
181
+                .pipe(size(sizeOptions))
182
+                .pipe(sourcemaps.write(''))
183
+                .pipe(gulp.dest(entry.dist));
184
+        });
185
+    });
186
+});
196 187
 
197
-// Plyr core files
198
-const namespace = 'Plyr';
199
-build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'umd' });
200
-build.js(bundles.plyr.js, 'plyr', { name: namespace, format: 'es' });
201
-build.sass(bundles.plyr.sass, 'plyr');
202
-build.sprite('plyr');
188
+// CSS
189
+Object.entries(build.css).forEach(([filename, entry]) => {
190
+    const name = `css:${filename}`;
191
+    tasks.css.push(name);
192
+
193
+    gulp.task(name, () => {
194
+        return gulp
195
+            .src(entry.src)
196
+            .pipe(plumber())
197
+            .pipe(sass())
198
+            .pipe(
199
+                prefix(browsers, {
200
+                    cascade: false,
201
+                }),
202
+            )
203
+            .pipe(clean())
204
+            .pipe(size(sizeOptions))
205
+            .pipe(gulp.dest(entry.dist));
206
+    });
207
+});
208
+
209
+// SVG Sprites
210
+Object.entries(build.sprite).forEach(([filename, entry]) => {
211
+    const name = `sprite:${filename}`;
212
+    tasks.sprite.push(name);
203 213
 
204
-// Demo files
205
-build.sass(bundles.demo.sass, 'demo');
206
-build.js(bundles.demo.js, 'demo', { format: 'iife' });
214
+    log(path.basename(filename));
215
+
216
+    gulp.task(name, () => {
217
+        return gulp
218
+            .src(entry.src)
219
+            .pipe(plumber())
220
+            .pipe(imagemin())
221
+            .pipe(svgstore())
222
+            .pipe(rename({ basename: path.parse(filename).name }))
223
+            .pipe(size(sizeOptions))
224
+            .pipe(gulp.dest(entry.dist));
225
+    });
226
+});
207 227
 
208 228
 // Build all JS
209 229
 gulp.task('js', () => gulp.parallel(...tasks.js));
@@ -212,16 +232,16 @@ gulp.task('js', () => gulp.parallel(...tasks.js));
212 232
 gulp.task('watch', () => {
213 233
     // Plyr core
214 234
     gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js));
215
-    gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.sass));
235
+    gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.css));
216 236
     gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite));
217 237
 
218 238
     // Demo
219 239
     gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js));
220
-    gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.sass));
240
+    gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.css));
221 241
 });
222 242
 
223 243
 // Build distribution
224
-gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite)));
244
+gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite)));
225 245
 
226 246
 // Default gulp task
227 247
 gulp.task('default', gulp.series('build', 'watch'));
@@ -236,234 +256,233 @@ try {
236 256
     // Do nothing
237 257
 }
238 258
 
239
-// If deployment is setup
240
-// TODO: Use gulp-awspublish and use AWS CLI credentials
241
-if (Object.keys(credentials).includes('aws') && Object.keys(credentials).includes('fastly')) {
242
-    const { version } = pkg;
243
-    const { aws, fastly } = credentials;
244
-
245
-    // Get branch info
246
-    const branch = {
247
-        current: gitbranch.sync(),
248
-        master: 'master',
249
-        beta: 'beta',
250
-    };
251
-
252
-    const maxAge = 31536000; // 1 year
253
-    const options = {
254
-        cdn: {
255
-            headers: {
256
-                'Cache-Control': `max-age=${maxAge}`,
257
-                Vary: 'Accept-Encoding',
258
-            },
259
+// Get branch info
260
+const branch = {
261
+    current: gitbranch.sync(),
262
+    master: 'master',
263
+    beta: 'beta',
264
+};
265
+
266
+const maxAge = 31536000; // 1 year
267
+const options = {
268
+    cdn: {
269
+        headers: {
270
+            'Cache-Control': `max-age=${maxAge}`,
271
+            Vary: 'Accept-Encoding',
272
+        },
273
+    },
274
+    demo: {
275
+        uploadPath: branch.current === branch.beta ? 'beta' : null,
276
+        headers: {
277
+            'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
278
+            Vary: 'Accept-Encoding',
259 279
         },
260
-        demo: {
261
-            uploadPath: branch.current === branch.beta ? 'beta' : null,
280
+    },
281
+    symlinks(ver, filename) {
282
+        return {
262 283
             headers: {
284
+                // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
285
+                'x-amz-website-redirect-location': `/${ver}/${filename}`,
263 286
                 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
264
-                Vary: 'Accept-Encoding',
265 287
             },
266
-        },
267
-        symlinks(ver, filename) {
268
-            return {
269
-                headers: {
270
-                    // http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
271
-                    'x-amz-website-redirect-location': `/${ver}/${filename}`,
272
-                    'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
273
-                },
274
-            };
275
-        },
276
-    };
277
-
278
-    const regex =
279
-        '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
280
-    const semver = new RegExp(`v${regex}`, 'gi');
281
-    const localPath = new RegExp('(../)?dist', 'gi');
282
-    const versionPath = `https://${aws.cdn.domain}/${version}`;
283
-    const cdnpath = new RegExp(`${aws.cdn.domain}/${regex}/`, 'gi');
284
-
285
-    const renameFile = rename(p => {
286
-        p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
287
-        p.dirname = p.dirname.replace('.', version); // eslint-disable-line
288
-    });
289
-
290
-    // Check we're on the correct branch to deploy
291
-    const canDeploy = () => {
292
-        const allowed = [branch.master, branch.beta];
288
+        };
289
+    },
290
+};
293 291
 
294
-        if (!allowed.includes(branch.current)) {
295
-            console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
292
+const regex =
293
+    '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
294
+const semver = new RegExp(`v${regex}`, 'gi');
295
+const localPath = new RegExp('(../)?dist', 'gi');
296
+const versionPath = `https://${deploy.cdn.domain}/${version}`;
297
+const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}/`, 'gi');
296 298
 
297
-            return false;
298
-        }
299
+const renameFile = rename(p => {
300
+    p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
301
+    p.dirname = p.dirname.replace('.', version); // eslint-disable-line
302
+});
299 303
 
300
-        return true;
301
-    };
304
+// Check we're on the correct branch to deploy
305
+const canDeploy = () => {
306
+    const allowed = [branch.master, branch.beta];
302 307
 
303
-    gulp.task('version', done => {
304
-        if (!canDeploy()) {
305
-            done();
306
-            return null;
307
-        }
308
+    if (!allowed.includes(branch.current)) {
309
+        console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
308 310
 
309
-        console.log(`Updating versions to '${version}'...`);
311
+        return false;
312
+    }
310 313
 
311
-        // Replace versioned URLs in source
312
-        const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
314
+    return true;
315
+};
313 316
 
314
-        return gulp
315
-            .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' })
316
-            .pipe(replace(semver, `v${version}`))
317
-            .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
318
-            .pipe(gulp.dest('./'));
319
-    });
317
+gulp.task('version', done => {
318
+    if (!canDeploy()) {
319
+        done();
320
+        return null;
321
+    }
320 322
 
321
-    // Publish version to CDN bucket
322
-    gulp.task('cdn', done => {
323
-        if (!canDeploy()) {
324
-            done();
325
-            return null;
326
-        }
327
-
328
-        console.log(`Uploading '${version}' to ${aws.cdn.domain}...`);
329
-
330
-        // Upload to CDN
331
-        return (
332
-            gulp
333
-                .src(paths.upload)
334
-                .pipe(renameFile)
335
-                // Remove min suffix from source map URL
336
-                .pipe(
337
-                    replace(
338
-                        /sourceMappingURL=([\w-?.]+)/,
339
-                        (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
340
-                    ),
341
-                )
342
-                .pipe(
343
-                    size({
344
-                        showFiles: true,
345
-                        gzip: true,
346
-                    }),
347
-                )
348
-                .pipe(replace(localPath, versionPath))
349
-                .pipe(s3(aws.cdn, options.cdn))
350
-        );
351
-    });
323
+    const { domain } = deploy.cdn;
352 324
 
353
-    // Purge the fastly cache incase any 403/404 are cached
354
-    gulp.task('purge', () => {
355
-        const list = [];
325
+    console.log(`Updating versions to '${version}'...`);
356 326
 
357
-        return gulp
358
-            .src(paths.upload)
359
-            .pipe(
360
-                through.obj((file, enc, cb) => {
361
-                    const filename = file.path.split('/').pop();
362
-                    list.push(`${versionPath}/${filename.replace(minSuffix, '')}`);
363
-                    cb(null);
364
-                }),
365
-            )
366
-            .on('end', () => {
367
-                const purge = new FastlyPurge(fastly.token);
368
-
369
-                list.forEach(url => {
370
-                    console.log(`Purging ${url}...`);
371
-
372
-                    purge.url(url, (error, result) => {
373
-                        if (error) {
374
-                            console.log(error);
375
-                        } else if (result) {
376
-                            console.log(result);
377
-                        }
378
-                    });
379
-                });
380
-            });
381
-    });
327
+    // Replace versioned URLs in source
328
+    const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
382 329
 
383
-    // Publish to demo bucket
384
-    gulp.task('demo', done => {
385
-        if (!canDeploy()) {
386
-            done();
387
-            return null;
388
-        }
330
+    return gulp
331
+        .src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' })
332
+        .pipe(replace(semver, `v${version}`))
333
+        .pipe(replace(cdnpath, `${domain}/${version}/`))
334
+        .pipe(gulp.dest('./'));
335
+});
389 336
 
390
-        console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`);
337
+// Publish version to CDN bucket
338
+gulp.task('cdn', done => {
339
+    if (!canDeploy()) {
340
+        done();
341
+        return null;
342
+    }
391 343
 
392
-        // Replace versioned files in readme.md
393
-        gulp.src([`${__dirname}/readme.md`])
394
-            .pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
395
-            .pipe(gulp.dest(__dirname));
344
+    const { domain, publisher } = deploy.cdn;
396 345
 
397
-        // Replace local file paths with remote paths in demo HTML
398
-        // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
399
-        const index = `${paths.demo.root}index.html`;
400
-        const error = `${paths.demo.root}error.html`;
401
-        const pages = [index];
346
+    if (!publisher) {
347
+        throw new Error('No publisher instance. Check AWS configuration.');
348
+    }
402 349
 
403
-        if (branch.current === branch.master) {
404
-            pages.push(error);
405
-        }
350
+    console.log(`Uploading '${version}' to ${domain}...`);
406 351
 
407
-        gulp.src(pages)
352
+    // Upload to CDN
353
+    return (
354
+        gulp
355
+            .src(paths.upload)
356
+            .pipe(renameFile)
357
+            // Remove min suffix from source map URL
358
+            .pipe(
359
+                replace(
360
+                    /sourceMappingURL=([\w-?.]+)/,
361
+                    (match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
362
+                ),
363
+            )
364
+            .pipe(size(sizeOptions))
408 365
             .pipe(replace(localPath, versionPath))
409
-            .pipe(s3(aws.demo, options.demo));
366
+            .pipe(publisher.publish(options.cdn.headers))
367
+            .pipe(publish.reporter())
368
+    );
369
+});
410 370
 
411
-        // Only update CDN for master (prod)
412
-        if (branch.current !== branch.master) {
413
-            done();
414
-            return null;
415
-        }
371
+// Purge the fastly cache incase any 403/404 are cached
372
+gulp.task('purge', () => {
373
+    if (!Object.keys(credentials).includes('fastly')) {
374
+        throw new Error('Fastly credentials required to purge cache.');
375
+    }
376
+
377
+    const { fastly } = credentials;
378
+    const list = [];
379
+
380
+    return gulp
381
+        .src(paths.upload)
382
+        .pipe(
383
+            through.obj((file, enc, cb) => {
384
+                const filename = file.path.split('/').pop();
385
+                list.push(`${versionPath}/${filename.replace(minSuffix, '')}`);
386
+                cb(null);
387
+            }),
388
+        )
389
+        .on('end', () => {
390
+            const purge = new FastlyPurge(fastly.token);
391
+
392
+            list.forEach(url => {
393
+                console.log(`Purging ${url}...`);
394
+
395
+                purge.url(url, (error, result) => {
396
+                    if (error) {
397
+                        console.log(error);
398
+                    } else if (result) {
399
+                        console.log(result);
400
+                    }
401
+                });
402
+            });
403
+        });
404
+});
416 405
 
417
-        // Upload error.html to cdn (as well as demo site)
418
-        return gulp
419
-            .src([error])
420
-            .pipe(replace(localPath, versionPath))
421
-            .pipe(s3(aws.cdn, options.demo));
422
-    });
406
+// Publish to demo bucket
407
+gulp.task('demo', done => {
408
+    if (!canDeploy()) {
409
+        done();
410
+        return null;
411
+    }
412
+
413
+    const { publisher } = deploy.demo;
414
+    const { domain } = deploy.cdn;
415
+
416
+    if (!publisher) {
417
+        throw new Error('No publisher instance. Check AWS configuration.');
418
+    }
419
+
420
+    console.log(`Uploading '${version}' demo to ${deploy.demo.domain}...`);
421
+
422
+    // Replace versioned files in readme.md
423
+    gulp.src([`${__dirname}/readme.md`])
424
+        .pipe(replace(cdnpath, `${domain}/${version}/`))
425
+        .pipe(gulp.dest(__dirname));
426
+
427
+    // Replace local file paths with remote paths in demo HTML
428
+    // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
429
+    const index = `${paths.demo.root}index.html`;
430
+    const error = `${paths.demo.root}error.html`;
431
+    const pages = [index, error];
432
+
433
+    if (branch.current === branch.master) {
434
+        pages.push(error);
435
+    }
436
+
437
+    return gulp
438
+        .src(pages)
439
+        .pipe(replace(localPath, versionPath))
440
+        .pipe(publisher.publish(options.demo.headers))
441
+        .pipe(publish.reporter());
442
+});
423 443
 
424
-    // Update symlinks for latest
425
-    /* gulp.task("symlinks", function () {
426
-        console.log("Updating symlinks...");
427
-
428
-        return gulp.src(paths.upload)
429
-            .pipe(through.obj(function (chunk, enc, callback) {
430
-                if (chunk.stat.isFile()) {
431
-                    // Get the filename
432
-                    var filename = chunk.path.split("/").reverse()[0];
433
-
434
-                    // Create the 0 byte redirect files to upload
435
-                    createFile(filename, "")
436
-                        .pipe(rename(function (path) {
437
-                            path.dirname = path.dirname.replace(".", "latest");
438
-                        }))
439
-                        // Upload to S3 with correct headers
440
-                        .pipe(s3(aws.cdn, options.symlinks(version, filename)));
441
-                }
442
-
443
-                callback(null, chunk);
444
-            }));
445
-    }); */
446
-
447
-    // Open the demo site to check it's ok
448
-    gulp.task('open', () => {
449
-        return gulp.src(__filename).pipe(
450
-            open({
451
-                uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`,
452
-            }),
453
-        );
454
-    });
444
+gulp.task('error', done => {
445
+    // Only update CDN for master (prod)
446
+    if (!canDeploy() || branch.current !== branch.master) {
447
+        done();
448
+        return null;
449
+    }
450
+
451
+    const { publisher } = deploy.cdn;
452
+
453
+    if (!publisher) {
454
+        throw new Error('No publisher instance. Check AWS configuration.');
455
+    }
456
+
457
+    // Replace local file paths with remote paths in demo HTML
458
+    // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
459
+    // Upload error.html to cdn
460
+    return gulp
461
+        .src(`${paths.demo.root}error.html`)
462
+        .pipe(replace(localPath, versionPath))
463
+        .pipe(publisher.publish(options.demo.headers))
464
+        .pipe(publish.reporter());
465
+});
455 466
 
456
-    // Do everything
457
-    gulp.task(
458
-        'deploy',
459
-        gulp.series(
460
-            'version',
461
-            tasks.clean,
462
-            gulp.parallel(...tasks.js, ...tasks.sass, ...tasks.sprite),
463
-            'cdn',
464
-            'demo',
465
-            'purge',
466
-            'open',
467
-        ),
467
+// Open the demo site to check it's ok
468
+gulp.task('open', () => {
469
+    return gulp.src(__filename).pipe(
470
+        open({
471
+            uri: `https://${aws.demo.domain}/${branch.current === branch.beta ? 'beta' : ''}`,
472
+        }),
468 473
     );
469
-}
474
+});
475
+
476
+// Do everything
477
+gulp.task(
478
+    'deploy',
479
+    gulp.series(
480
+        'version',
481
+        tasks.clean,
482
+        gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite),
483
+        'cdn',
484
+        'demo',
485
+        'purge',
486
+        'open',
487
+    ),
488
+);

+ 15
- 12
package.json View File

@@ -27,45 +27,48 @@
27 27
     "bugs": {
28 28
         "url": "https://github.com/sampotts/plyr/issues"
29 29
     },
30
-    "directories": {
31
-        "doc": "readme.md"
32
-    },
30
+    "browserslist": [
31
+        "> 1%",
32
+        "not dead"
33
+    ],
33 34
     "scripts": {
34 35
         "build": "gulp build",
35 36
         "lint": "eslint src/js && npm run-script remark",
36 37
         "remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'",
37
-        "test": "echo \"Error: no test specified\" && exit 1"
38
+        "deploy": "yarn lint && gulp deploy"
38 39
     },
39 40
     "devDependencies": {
40
-        "@babel/core": "^7.2.2",
41
-        "babel-eslint": "^10.0.1",
41
+        "aws-sdk": "^2.404.0",
42
+        "@babel/core": "^7.3.3",
42 43
         "@babel/preset-env": "^7.3.1",
44
+        "babel-eslint": "^10.0.1",
45
+        "babel-preset-minify": "^0.5.0",
43 46
         "del": "^3.0.0",
44
-        "eslint": "^5.13.0",
47
+        "eslint": "^5.14.0",
45 48
         "eslint-config-airbnb-base": "^13.1.0",
46 49
         "eslint-config-prettier": "^4.0.0",
47 50
         "eslint-plugin-import": "^2.16.0",
51
+        "fancy-log": "^1.3.3",
48 52
         "fastly-purge": "^1.0.1",
49 53
         "git-branch": "^2.0.1",
50 54
         "gulp": "^4.0.0",
51 55
         "gulp-autoprefixer": "^6.0.0",
56
+        "gulp-awspublish": "^4.0.0",
52 57
         "gulp-better-rollup": "^3.4.0",
53 58
         "gulp-clean-css": "^4.0.0",
54
-        "gulp-concat": "^2.6.1",
55 59
         "gulp-filter": "^5.1.0",
56 60
         "gulp-header": "^2.0.7",
61
+        "gulp-imagemin": "^5.0.3",
57 62
         "gulp-open": "^3.0.1",
63
+        "gulp-plumber": "^1.2.1",
58 64
         "gulp-postcss": "^8.0.0",
59 65
         "gulp-rename": "^1.4.0",
60 66
         "gulp-replace": "^1.0.0",
61
-        "gulp-s3": "^0.11.0",
62 67
         "gulp-sass": "^4.0.2",
63 68
         "gulp-size": "^3.0.0",
64 69
         "gulp-sourcemaps": "^2.6.4",
65
-        "gulp-svgmin": "^2.1.0",
66 70
         "gulp-svgstore": "^7.0.1",
67
-        "gulp-uglify-es": "^1.0.4",
68
-        "gulp-util": "^3.0.8",
71
+        "gulp-terser": "^1.1.7",
69 72
         "postcss-custom-properties": "^8.0.9",
70 73
         "prettier-eslint": "^8.8.2",
71 74
         "prettier-stylelint": "^0.4.2",

+ 1507
- 581
yarn.lock
File diff suppressed because it is too large
View File