From 24e1f7c710880ec56440d13b22570035598309de Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 26 Aug 2020 21:57:01 +0200 Subject: [PATCH] #35 Creating dist for each browser including zipped version --- gulpfile.js | 112 ++++++++++++++++++++++++++++++++++++++++++--------- package.json | 1 + 2 files changed, 93 insertions(+), 20 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 0b94e6c..f163a62 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,7 @@ const browserify = require('browserify'); const babelify = require('babelify'); const source = require('vinyl-source-stream'); const buffer = require('vinyl-buffer'); +const merge = require('merge-stream'); const fs = require('fs'); const $ = gulpLoadPlugins() @@ -33,17 +34,30 @@ const tmp = { styles: '.tmp/stylesheets', scripts: '.tmp/javascript', images: '.tmp/images', - vendor: '.tmp/libs', } // Dist path const dist = { root: 'dist', - manifests: 'dist/manifests', - styles: 'dist/stylesheets', - scripts: 'dist/javascript', - images: 'dist/images', - vendor: 'dist/libs', + chrome: { + root: 'dist/chrome', + styles: 'dist/chrome/stylesheets', + scripts: 'dist/chrome/javascript', + images: 'dist/chrome/images', + }, + firefox: { + root: 'dist/firefox', + styles: 'dist/firefox/stylesheets', + scripts: 'dist/firefox/javascript', + images: 'dist/firefox/images', + }, + opera: { + root: 'dist/opera', + styles: 'dist/opera/stylesheets', + scripts: 'dist/opera/javascript', + images: 'dist/opera/images', + }, + zip: 'dist/zips', } // Build mode @@ -169,24 +183,82 @@ gulp.task('build', gulp.series('clean:build', 'manifests', 'images', 'scripts', DIST CLEAN ALL ============================================================================ */ -gulp.task('dist:copy', (done) => { - // copy vendor - gulp.src(`${tmp.vendor}/**/*`) - .pipe(gulp.dest(dist.vendor)) +gulp.task('dist:chrome', (done) => { + return merge( + // copy images + gulp.src(`${tmp.images}/**/*`) + .pipe(gulp.dest(dist.chrome.images)), - // copy images - gulp.src(`${tmp.images}/**/*`) - .pipe(gulp.dest(dist.images)) + // copy scripts + gulp.src(`${tmp.scripts}/**/*.{min.js,min.js.gz}`) + .pipe(gulp.dest(dist.chrome.scripts)), - // copy scripts - gulp.src(`${tmp.scripts}/**/*.{min.js,min.js.gz}`) - .pipe(gulp.dest(dist.scripts)) + // copy styles + gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) + .pipe(gulp.dest(dist.chrome.styles)), - // copy styles - gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) - .pipe(gulp.dest(dist.styles)) + gulp.src(`${tmp.manifests}/chrome*`) + .pipe($.rename('manifest.json')) + .pipe(gulp.dest(dist.chrome.root)) + ); +}) + +gulp.task('dist:firefox', (done) => { + return merge( + // copy images + gulp.src(`${tmp.images}/**/*`) + .pipe(gulp.dest(dist.firefox.images)), + + // copy scripts + gulp.src(`${tmp.scripts}/**/*.{min.js,min.js.gz}`) + .pipe(gulp.dest(dist.firefox.scripts)), + + // copy styles + gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) + .pipe(gulp.dest(dist.firefox.styles)), + + gulp.src(`${tmp.manifests}/firefox*`) + .pipe($.rename('manifest.json')) + .pipe(gulp.dest(dist.firefox.root)) + ); +}) + +gulp.task('dist:opera', (done) => { + return merge( + // copy images + gulp.src(`${tmp.images}/**/*`) + .pipe(gulp.dest(dist.opera.images)), + + // copy scripts + gulp.src(`${tmp.scripts}/**/*.{min.js,min.js.gz}`) + .pipe(gulp.dest(dist.opera.scripts)), + + // copy styles + gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`) + .pipe(gulp.dest(dist.opera.styles)), + + gulp.src(`${tmp.manifests}/opera*`) + .pipe($.rename('manifest.json')) + .pipe(gulp.dest(dist.opera.root)) + ); +}) + +gulp.task('dist:copy', gulp.series('dist:chrome', 'dist:firefox', 'dist:opera')); + +gulp.task('dist:zip', (done) => { + gulp.src(`${dist.chrome.root}/**/*`) + .pipe($.zip('chrome.zip')) + .pipe(gulp.dest(dist.root)); + + gulp.src(`${dist.firefox.root}/**/*`) + .pipe($.zip('firefox.zip')) + .pipe(gulp.dest(dist.root)); + + gulp.src(`${dist.opera.root}/**/*`) + .pipe($.zip('opera.zip')) + .pipe(gulp.dest(dist.root)); done(); }) -gulp.task('dist', gulp.series('clean', 'build', 'dist:copy')); \ No newline at end of file +gulp.task('dist', gulp.series('clean', 'build', 'dist:copy', 'dist:zip')); \ No newline at end of file diff --git a/package.json b/package.json index 64ba9a6..b8e6bc6 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "gulp-sourcemaps": "^2.6.5", "gulp-uglify-es": "^2.0.0", "gulp-zip": "^5.0.2", + "merge-stream": "^2.0.0", "sass": "^1.26.10", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0"