From 4f915cf2d817cf4dadea581c90a98841b81c156d Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 14:07:32 -0700 Subject: build - refactor build task generators + add mascara to standard build phase --- gulpfile.js | 202 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 116 insertions(+), 86 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index f57ea6206..2c000f576 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -32,6 +32,15 @@ var babel = require('gulp-babel') var disableDebugTools = gutil.env.disableDebugTools var debug = gutil.env.debug +const commonPlatforms = [ + // browser extensions + 'firefox', + 'chrome', + 'edge', + 'opera', + // browser webapp + 'mascara', +] // browser reload @@ -46,58 +55,28 @@ gulp.task('dev:reload', function() { gulp.task('copy:locales', copyTask({ source: './app/_locales/', - destinations: [ - './dist/firefox/_locales', - './dist/chrome/_locales', - './dist/edge/_locales', - './dist/opera/_locales', - ] + destinations: commonPlatforms.map(platform => `./dist/${platform}/_locales`), })) gulp.task('copy:images', copyTask({ source: './app/images/', - destinations: [ - './dist/firefox/images', - './dist/chrome/images', - './dist/edge/images', - './dist/opera/images', - ], + destinations: commonPlatforms.map(platform => `./dist/${platform}/images`), })) gulp.task('copy:contractImages', copyTask({ source: './node_modules/eth-contract-metadata/images/', - destinations: [ - './dist/firefox/images/contract', - './dist/chrome/images/contract', - './dist/edge/images/contract', - './dist/opera/images/contract', - ], + destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contract`), })) gulp.task('copy:fonts', copyTask({ source: './app/fonts/', - destinations: [ - './dist/firefox/fonts', - './dist/chrome/fonts', - './dist/edge/fonts', - './dist/opera/fonts', - ], + destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`), })) gulp.task('copy:reload', copyTask({ source: './app/scripts/', - destinations: [ - './dist/firefox/scripts', - './dist/chrome/scripts', - './dist/edge/scripts', - './dist/opera/scripts', - ], + destinations: commonPlatforms.map(platform => `./dist/${platform}/scripts`), pattern: '/chromereload.js', })) gulp.task('copy:root', copyTask({ source: './app/', - destinations: [ - './dist/firefox', - './dist/chrome', - './dist/edge', - './dist/opera', - ], + destinations: commonPlatforms.map(platform => `./dist/${platform}`), pattern: '/*', })) @@ -208,7 +187,7 @@ const jsFiles = [ 'inpage', 'contentscript', 'background', - 'popup', + 'ui', ] // scss compilation and autoprefixing tasks @@ -230,7 +209,7 @@ gulp.task('lint-scss', function() { .src('ui/app/css/itcss/**/*.scss') .pipe(gulpStylelint({ reporters: [ - {formatter: 'string', console: true} + { formatter: 'string', console: true } ], fix: true, })); @@ -243,32 +222,51 @@ gulp.task('fmt-scss', function () { }); // bundle tasks +createTasksForBuildJsExtension({ jsFiles, taskPrefix: 'dev:js', bundleTaskOpts: { isBuild: false } }) +createTasksForBuildJsExtension({ jsFiles, taskPrefix: 'build:js:extension', bundleTaskOpts: { isBuild: true } }) +createTasksForBuildJsMascara({ taskPrefix: 'build:js:mascara' }) + +function createTasksForBuildJsExtension({ jsFiles, taskPrefix, bundleTaskOpts }) { + // inpage must be built before all other scripts: + const rootDir = './app/scripts' + const nonInpageFiles = jsFiles.filter(file => file !== 'inpage') + const buildPhase1 = ['inpage'] + const buildPhase2 = nonInpageFiles + const destinations = [ + './dist/firefox/scripts', + './dist/chrome/scripts', + './dist/edge/scripts', + './dist/opera/scripts', + ] + createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1, buildPhase2 }) +} -var jsDevStrings = jsFiles.map(jsFile => `dev:js:${jsFile}`) -var jsBuildStrings = jsFiles.map(jsFile => `build:js:${jsFile}`) - -jsFiles.forEach((jsFile) => { - gulp.task(`dev:js:${jsFile}`, bundleTask({ - watch: true, - label: jsFile, - filename: `${jsFile}.js`, - isBuild: false - })) - gulp.task(`build:js:${jsFile}`, bundleTask({ - watch: false, - label: jsFile, - filename: `${jsFile}.js`, - isBuild: true - })) -}) +function createTasksForBuildJsMascara({ taskPrefix, bundleTaskOpts }) { + // inpage must be built before all other scripts: + const rootDir = './mascara/src/' + const jsFiles = ['ui', 'proxy', 'background'] + const destinations = ['./dist/mascara/scripts'] + createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1: jsFiles }) +} -// inpage must be built before all other scripts: -const firstDevString = jsDevStrings.shift() -gulp.task('dev:js', gulp.series(firstDevString, gulp.parallel(...jsDevStrings))) +function createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1 = [], buildPhase2 = [] }) { + // bundle task for each file + jsFiles.forEach((jsFile) => { + gulp.task(`${taskPrefix}:${jsFile}`, bundleTask(Object.assign({ + watch: false, + label: jsFile, + filename: `${jsFile}.js`, + filepath: `${rootDir}/${jsFile}.js`, + destinations, + }, bundleTaskOpts))) + }) + // compose into larger task + const subtasks = [] + subtasks.push(gulp.parallel(buildPhase1.map(file => `${taskPrefix}:${file}`))) + if (buildPhase2.length) subtasks.push(gulp.parallel(buildPhase2.map(file => `${taskPrefix}:${file}`))) -// inpage must be built before all other scripts: -const firstBuildString = jsBuildStrings.shift() -gulp.task('build:js', gulp.series(firstBuildString, gulp.parallel(...jsBuildStrings))) + gulp.task(taskPrefix, gulp.series(subtasks)) +} // disc bundle analyzer tasks @@ -278,7 +276,6 @@ jsFiles.forEach((jsFile) => { gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`))) - // clean dist @@ -295,16 +292,44 @@ gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:ope // set env var for production gulp.task('apply-prod-environment', function(done) { - process.env.NODE_ENV = 'production' - done() + process.env.NODE_ENV = 'production' + done() }); // high level tasks -gulp.task('dev', gulp.series('build:scss', 'dev:js', 'copy', gulp.parallel('watch:scss', 'copy:watch', 'dev:reload'))) +gulp.task('dev', + gulp.series( + 'build:scss', + 'dev:js', + 'copy', + gulp.parallel( + 'watch:scss', + 'copy:watch', + 'dev:reload' + ) + ) +) + +gulp.task('build', + gulp.series( + 'clean', + 'build:scss', + gulp.parallel( + 'build:js:extension', + 'build:js:mascara', + 'copy' + ) + ) +) -gulp.task('build', gulp.series('clean', 'build:scss', gulp.parallel('build:js', 'copy'))) -gulp.task('dist', gulp.series('apply-prod-environment', 'build', 'zip')) +gulp.task('dist', + gulp.series( + 'apply-prod-environment', + 'build', + 'zip' + ) +) // task generators @@ -337,7 +362,7 @@ function zipTask(target) { function generateBundler(opts, performBundle) { const browserifyOpts = assign({}, watchify.args, { - entries: ['./app/scripts/'+opts.filename], + entries: [opts.filepath], plugin: 'browserify-derequire', debug: true, fullPaths: debug, @@ -384,19 +409,21 @@ function bundleTask(opts) { return performBundle function performBundle(){ - return ( - bundler.bundle() + let buildStream = bundler.bundle() + + // handle errors + buildStream.on('error', (err) => { + beep() + if (opts.watch) { + console.warn(err.stack) + } else { + throw err + } + }) - // handle errors - .on('error', (err) => { - beep() - if (opts.watch) { - console.warn(err.stack) - } else { - throw err - } - }) + // process bundles + buildStream = buildStream // convert bundle stream to gulp vinyl stream .pipe(source(opts.filename)) // inject variables into bundle @@ -412,15 +439,18 @@ function bundleTask(opts) { }))) // writes .map file .pipe(sourcemaps.write(debug ? './' : '../../sourcemaps')) - // write completed bundles - .pipe(gulp.dest('./dist/firefox/scripts')) - .pipe(gulp.dest('./dist/chrome/scripts')) - .pipe(gulp.dest('./dist/edge/scripts')) - .pipe(gulp.dest('./dist/opera/scripts')) - // finally, trigger live reload + + // write completed bundles + opts.destinations.forEach((dest) => { + buildStream = buildStream.pipe(gulp.dest(dest)) + }) + + // finally, trigger live reload + buildStream = buildStream .pipe(gulpif(debug, livereload())) - ) + return buildStream + } } -- cgit v1.2.3 From 98f240064902f69b063b022eada56deacc9f1b35 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 19:56:44 -0700 Subject: build - refactor copy tasks --- gulpfile.js | 72 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 2c000f576..2b8627f14 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,19 +27,23 @@ var gulpStylelint = require('gulp-stylelint') var stylefmt = require('gulp-stylefmt') var uglify = require('gulp-uglify-es').default var babel = require('gulp-babel') +var debug = require('gulp-debug') var disableDebugTools = gutil.env.disableDebugTools -var debug = gutil.env.debug +var debugMode = gutil.env.debug -const commonPlatforms = [ - // browser extensions +const browserPlatforms = [ 'firefox', 'chrome', 'edge', 'opera', +] +const commonPlatforms = [ // browser webapp 'mascara', + // browser extensions + ...browserPlatforms ] // browser reload @@ -51,7 +55,7 @@ gulp.task('dev:reload', function() { }) -// copy static +// copy universal gulp.task('copy:locales', copyTask({ source: './app/_locales/', @@ -74,12 +78,22 @@ gulp.task('copy:reload', copyTask({ destinations: commonPlatforms.map(platform => `./dist/${platform}/scripts`), pattern: '/chromereload.js', })) -gulp.task('copy:root', copyTask({ + +// copy extension + +gulp.task('copy:manifest', copyTask({ + source: './app/', + destinations: browserPlatforms.map(platform => `./dist/${platform}`), + pattern: '/*.json', +})) +gulp.task('copy:html', copyTask({ source: './app/', - destinations: commonPlatforms.map(platform => `./dist/${platform}`), - pattern: '/*', + destinations: browserPlatforms.map(platform => `./dist/${platform}`), + pattern: '/*.html', })) +// manifest tinkering + gulp.task('manifest:chrome', function() { return gulp.src('./dist/chrome/manifest.json') .pipe(jsoneditor(function(json) { @@ -113,7 +127,7 @@ gulp.task('manifest:production', function() { ],{base: './dist/'}) // Exclude chromereload script in production: - .pipe(gulpif(!debug,jsoneditor(function(json) { + .pipe(gulpif(!debugMode,jsoneditor(function(json) { json.background.scripts = json.background.scripts.filter((script) => { return !script.includes('chromereload') }) @@ -123,21 +137,27 @@ gulp.task('manifest:production', function() { .pipe(gulp.dest('./dist/', { overwrite: true })) }) -const staticFiles = [ - 'locales', - 'images', - 'fonts', - 'root' +const copyTaskNames = [ + 'copy:locales', + 'copy:images', + 'copy:fonts', + 'copy:manifest', + 'copy:html', + 'copy:contractImages', ] -var copyStrings = staticFiles.map(staticFile => `copy:${staticFile}`) -copyStrings.push('copy:contractImages') - -if (debug) { - copyStrings.push('copy:reload') +if (debugMode) { + copyTaskNames.push('copy:reload') } -gulp.task('copy', gulp.series(gulp.parallel(...copyStrings), 'manifest:production', 'manifest:chrome', 'manifest:opera')) +gulp.task('copy', + gulp.series( + gulp.parallel(...copyTaskNames), + 'manifest:production', + 'manifest:chrome', + 'manifest:opera' + ) +) gulp.task('copy:watch', function(){ gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) }) @@ -245,7 +265,7 @@ function createTasksForBuildJsMascara({ taskPrefix, bundleTaskOpts }) { // inpage must be built before all other scripts: const rootDir = './mascara/src/' const jsFiles = ['ui', 'proxy', 'background'] - const destinations = ['./dist/mascara/scripts'] + const destinations = ['./dist/mascara'] createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1: jsFiles }) } @@ -342,11 +362,11 @@ function copyTask(opts){ return performCopy function performCopy(){ - let stream = gulp.src(source + pattern, { base: source }) + let stream = gulp.src(source + pattern, { base: source }).pipe(debug({ title: source })) destinations.forEach(function(destination) { stream = stream.pipe(gulp.dest(destination)) }) - stream.pipe(gulpif(debug,livereload())) + stream.pipe(gulpif(debugMode,livereload())) return stream } @@ -365,7 +385,7 @@ function generateBundler(opts, performBundle) { entries: [opts.filepath], plugin: 'browserify-derequire', debug: true, - fullPaths: debug, + fullPaths: debugMode, }) let bundler = browserify(browserifyOpts) @@ -427,7 +447,7 @@ function bundleTask(opts) { // convert bundle stream to gulp vinyl stream .pipe(source(opts.filename)) // inject variables into bundle - .pipe(replace('\'GULP_METAMASK_DEBUG\'', debug)) + .pipe(replace('\'GULP_METAMASK_DEBUG\'', debugMode)) // buffer file contents (?) .pipe(buffer()) // sourcemaps @@ -438,7 +458,7 @@ function bundleTask(opts) { mangle: { reserved: [ 'MetamaskInpageProvider' ] }, }))) // writes .map file - .pipe(sourcemaps.write(debug ? './' : '../../sourcemaps')) + .pipe(sourcemaps.write(debugMode ? './' : '../../sourcemaps')) // write completed bundles opts.destinations.forEach((dest) => { @@ -447,7 +467,7 @@ function bundleTask(opts) { // finally, trigger live reload buildStream = buildStream - .pipe(gulpif(debug, livereload())) + .pipe(gulpif(debugMode, livereload())) return buildStream -- cgit v1.2.3 From 91e8ea205e1902dbefecaf2d764e7bb40847e5b5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 19:58:06 -0700 Subject: build - remove deprecated deps task --- gulpfile.js | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 2b8627f14..a094356ac 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -162,18 +162,6 @@ gulp.task('copy:watch', function(){ gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) }) -// record deps - -gulp.task('deps', function (cb) { - exec('npm ls', (err, stdoutOutput, stderrOutput) => { - if (err) return cb(err) - const browsers = ['firefox','chrome','edge','opera'] - asyncEach(browsers, (target, done) => { - fs.writeFile(`./dist/${target}/deps.txt`, stdoutOutput, done) - }, cb) - }) -}) - // lint js gulp.task('lint', function () { -- cgit v1.2.3 From 909cbca7a63d2f328121c55d5eb032f4c0778605 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 19:59:24 -0700 Subject: build - remove copy debug --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index a094356ac..739da162e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -350,7 +350,7 @@ function copyTask(opts){ return performCopy function performCopy(){ - let stream = gulp.src(source + pattern, { base: source }).pipe(debug({ title: source })) + let stream = gulp.src(source + pattern, { base: source }) destinations.forEach(function(destination) { stream = stream.pipe(gulp.dest(destination)) }) -- cgit v1.2.3 From e5c6c93c29f1747fa20d7d9fbace97c634442185 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 20:13:47 -0700 Subject: build - fix mascara sourcemaps dest --- gulpfile.js | 95 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 49 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 739da162e..719a5c339 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,37 +1,37 @@ -var watchify = require('watchify') -var browserify = require('browserify') -var disc = require('disc') -var gulp = require('gulp') -var source = require('vinyl-source-stream') -var buffer = require('vinyl-buffer') -var gutil = require('gulp-util') -var watch = require('gulp-watch') -var sourcemaps = require('gulp-sourcemaps') -var jsoneditor = require('gulp-json-editor') -var zip = require('gulp-zip') -var assign = require('lodash.assign') -var livereload = require('gulp-livereload') -var del = require('del') -var eslint = require('gulp-eslint') -var fs = require('fs') -var path = require('path') -var manifest = require('./app/manifest.json') -var gulpif = require('gulp-if') -var replace = require('gulp-replace') -var mkdirp = require('mkdirp') -var asyncEach = require('async/each') -var exec = require('child_process').exec -var sass = require('gulp-sass') -var autoprefixer = require('gulp-autoprefixer') -var gulpStylelint = require('gulp-stylelint') -var stylefmt = require('gulp-stylefmt') -var uglify = require('gulp-uglify-es').default -var babel = require('gulp-babel') -var debug = require('gulp-debug') - - -var disableDebugTools = gutil.env.disableDebugTools -var debugMode = gutil.env.debug +const watchify = require('watchify') +const browserify = require('browserify') +const disc = require('disc') +const gulp = require('gulp') +const source = require('vinyl-source-stream') +const buffer = require('vinyl-buffer') +const gutil = require('gulp-util') +const watch = require('gulp-watch') +const sourcemaps = require('gulp-sourcemaps') +const jsoneditor = require('gulp-json-editor') +const zip = require('gulp-zip') +const assign = require('lodash.assign') +const livereload = require('gulp-livereload') +const del = require('del') +const eslint = require('gulp-eslint') +const fs = require('fs') +const path = require('path') +const manifest = require('./app/manifest.json') +const gulpif = require('gulp-if') +const replace = require('gulp-replace') +const mkdirp = require('mkdirp') +const asyncEach = require('async/each') +const exec = require('child_process').exec +const sass = require('gulp-sass') +const autoprefixer = require('gulp-autoprefixer') +const gulpStylelint = require('gulp-stylelint') +const stylefmt = require('gulp-stylefmt') +const uglify = require('gulp-uglify-es').default +const babel = require('gulp-babel') +const debug = require('gulp-debug') + + +const disableDebugTools = gutil.env.disableDebugTools +const debugMode = gutil.env.debug const browserPlatforms = [ 'firefox', @@ -240,13 +240,9 @@ function createTasksForBuildJsExtension({ jsFiles, taskPrefix, bundleTaskOpts }) const nonInpageFiles = jsFiles.filter(file => file !== 'inpage') const buildPhase1 = ['inpage'] const buildPhase2 = nonInpageFiles - const destinations = [ - './dist/firefox/scripts', - './dist/chrome/scripts', - './dist/edge/scripts', - './dist/opera/scripts', - ] - createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1, buildPhase2 }) + const destinations = browserPlatforms.map(platform => `./dist/${platform}/scripts`) + bundleTaskOpts.sourceMapDir = bundleTaskOpts.sourceMapDir || (debugMode ? './' : '../../sourcemaps') + createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1, buildPhase2 }) } function createTasksForBuildJsMascara({ taskPrefix, bundleTaskOpts }) { @@ -254,10 +250,11 @@ function createTasksForBuildJsMascara({ taskPrefix, bundleTaskOpts }) { const rootDir = './mascara/src/' const jsFiles = ['ui', 'proxy', 'background'] const destinations = ['./dist/mascara'] - createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1: jsFiles }) + bundleTaskOpts.sourceMapDir = bundleTaskOpts.sourceMapDir || (debugMode ? './' : '../sourcemaps') + createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1: jsFiles }) } -function createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, buildPhase1 = [], buildPhase2 = [] }) { +function createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1 = [], buildPhase2 = [] }) { // bundle task for each file jsFiles.forEach((jsFile) => { gulp.task(`${taskPrefix}:${jsFile}`, bundleTask(Object.assign({ @@ -298,7 +295,7 @@ gulp.task('zip:edge', zipTask('edge')) gulp.task('zip:opera', zipTask('opera')) gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:opera')) -// set env var for production +// set env for production gulp.task('apply-prod-environment', function(done) { process.env.NODE_ENV = 'production' done() @@ -342,10 +339,10 @@ gulp.task('dist', // task generators function copyTask(opts){ - var source = opts.source - var destination = opts.destination - var destinations = opts.destinations || [ destination ] - var pattern = opts.pattern || '/**/*' + const source = opts.source + const destination = opts.destination + const destinations = opts.destinations || [ destination ] + const pattern = opts.pattern || '/**/*' return performCopy @@ -446,7 +443,7 @@ function bundleTask(opts) { mangle: { reserved: [ 'MetamaskInpageProvider' ] }, }))) // writes .map file - .pipe(sourcemaps.write(debugMode ? './' : '../../sourcemaps')) + .pipe(sourcemaps.write(opts.sourceMapDir)) // write completed bundles opts.destinations.forEach((dest) => { -- cgit v1.2.3 From 18acdfe6b3fecf5e681d584898ef8399c62b0fa5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 20:41:56 -0700 Subject: build - refactor js build process --- gulpfile.js | 109 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 43 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 719a5c339..740b1a296 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -183,21 +183,6 @@ gulp.task('lint:fix', function () { .pipe(eslint.failAfterError()) }); -/* -gulp.task('default', ['lint'], function () { - // This will only run if the lint task is successful... -}); -*/ - -// build js - -const jsFiles = [ - 'inpage', - 'contentscript', - 'background', - 'ui', -] - // scss compilation and autoprefixing tasks gulp.task('build:scss', function () { @@ -229,33 +214,53 @@ gulp.task('fmt-scss', function () { .pipe(gulp.dest('ui/app/css/itcss')); }); +// build js + +const buildJsFiles = [ + 'inpage', + 'contentscript', + 'background', + 'ui', +] + // bundle tasks -createTasksForBuildJsExtension({ jsFiles, taskPrefix: 'dev:js', bundleTaskOpts: { isBuild: false } }) -createTasksForBuildJsExtension({ jsFiles, taskPrefix: 'build:js:extension', bundleTaskOpts: { isBuild: true } }) +createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'dev:js', devMode: true }) +createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'build:js:extension' }) createTasksForBuildJsMascara({ taskPrefix: 'build:js:mascara' }) -function createTasksForBuildJsExtension({ jsFiles, taskPrefix, bundleTaskOpts }) { +function createTasksForBuildJsExtension({ buildJsFiles, taskPrefix, devMode, bundleTaskOpts = {} }) { // inpage must be built before all other scripts: const rootDir = './app/scripts' - const nonInpageFiles = jsFiles.filter(file => file !== 'inpage') + const nonInpageFiles = buildJsFiles.filter(file => file !== 'inpage') const buildPhase1 = ['inpage'] const buildPhase2 = nonInpageFiles const destinations = browserPlatforms.map(platform => `./dist/${platform}/scripts`) - bundleTaskOpts.sourceMapDir = bundleTaskOpts.sourceMapDir || (debugMode ? './' : '../../sourcemaps') - createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1, buildPhase2 }) + bundleTaskOpts = Object.assign({ + buildSourceMaps: true, + sourceMapDir: devMode ? './' : '../../sourcemaps', + minifyBuild: !devMode, + buildWithFullPaths: devMode, + }, bundleTaskOpts) + createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1, buildPhase2 }) } -function createTasksForBuildJsMascara({ taskPrefix, bundleTaskOpts }) { +function createTasksForBuildJsMascara({ taskPrefix, devMode, bundleTaskOpts = {} }) { // inpage must be built before all other scripts: const rootDir = './mascara/src/' - const jsFiles = ['ui', 'proxy', 'background'] + const buildPhase1 = ['ui', 'proxy', 'background'] const destinations = ['./dist/mascara'] - bundleTaskOpts.sourceMapDir = bundleTaskOpts.sourceMapDir || (debugMode ? './' : '../sourcemaps') - createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1: jsFiles }) + bundleTaskOpts = Object.assign({ + buildSourceMaps: true, + sourceMapDir: './', + minifyBuild: !devMode, + buildWithFullPaths: devMode, + }, bundleTaskOpts) + createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1 }) } -function createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, destinations, sourceMapDir, buildPhase1 = [], buildPhase2 = [] }) { +function createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1 = [], buildPhase2 = [] }) { // bundle task for each file + const jsFiles = [].concat(buildPhase1, buildPhase2) jsFiles.forEach((jsFile) => { gulp.task(`${taskPrefix}:${jsFile}`, bundleTask(Object.assign({ watch: false, @@ -275,15 +280,14 @@ function createTasksForBuildJs({ rootDir, jsFiles, taskPrefix, bundleTaskOpts, d // disc bundle analyzer tasks -jsFiles.forEach((jsFile) => { - gulp.task(`disc:${jsFile}`, discTask({ label: jsFile, filename: `${jsFile}.js` })) +buildJsFiles.forEach((jsFile) => { + gulp.task(`disc:${jsFile}`, discTask({ label: jsFile, filename: `${jsFile}.js` })) }) -gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`))) +gulp.task('disc', gulp.parallel(buildJsFiles.map(jsFile => `disc:${jsFile}`))) // clean dist - gulp.task('clean', function clean() { return del(['./dist/*']) }) @@ -369,8 +373,8 @@ function generateBundler(opts, performBundle) { const browserifyOpts = assign({}, watchify.args, { entries: [opts.filepath], plugin: 'browserify-derequire', - debug: true, - fullPaths: debugMode, + debug: opts.buildSourceMaps, + fullPaths: opts.buildWithFullPaths, }) let bundler = browserify(browserifyOpts) @@ -385,6 +389,10 @@ function generateBundler(opts, performBundle) { } function discTask(opts) { + opts = Object.assign({ + buildWithFullPaths: true, + }, opts) + const bundler = generateBundler(opts, performBundle) // output build logs to terminal bundler.on('log', gutil.log) @@ -393,9 +401,9 @@ function discTask(opts) { function performBundle(){ // start "disc" build - let discDir = path.join(__dirname, 'disc') + const discDir = path.join(__dirname, 'disc') mkdirp.sync(discDir) - let discPath = path.join(discDir, `${opts.label}.html`) + const discPath = path.join(discDir, `${opts.label}.html`) return ( bundler.bundle() @@ -435,15 +443,30 @@ function bundleTask(opts) { .pipe(replace('\'GULP_METAMASK_DEBUG\'', debugMode)) // buffer file contents (?) .pipe(buffer()) - // sourcemaps - // loads map from browserify file - .pipe(sourcemaps.init({ loadMaps: true })) - // Minification - .pipe(gulpif(opts.isBuild, uglify({ - mangle: { reserved: [ 'MetamaskInpageProvider' ] }, - }))) - // writes .map file - .pipe(sourcemaps.write(opts.sourceMapDir)) + + + // Initialize Source Maps + if (opts.buildSourceMaps) { + buildStream = buildStream + // loads map from browserify file + .pipe(sourcemaps.init({ loadMaps: true })) + } + + // Minification + if (opts.minifyBuild) { + buildStream = buildStream + .pipe(uglify({ + mangle: { + reserved: [ 'MetamaskInpageProvider' ] + }, + })) + } + + // Finalize Source Maps (writes .map file) + if (opts.buildSourceMaps) { + buildStream = buildStream + .pipe(sourcemaps.write(opts.sourceMapDir)) + } // write completed bundles opts.destinations.forEach((dest) => { -- cgit v1.2.3 From b88119c23851144448771e8a6de97e48fb96b2b0 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 20:54:59 -0700 Subject: build - mascara - copy proxy html --- gulpfile.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 740b1a296..68618dfb4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -78,6 +78,11 @@ gulp.task('copy:reload', copyTask({ destinations: commonPlatforms.map(platform => `./dist/${platform}/scripts`), pattern: '/chromereload.js', })) +gulp.task('copy:html', copyTask({ + source: './app/', + destinations: commonPlatforms.map(platform => `./dist/${platform}`), + pattern: '/*.html', +})) // copy extension @@ -86,10 +91,13 @@ gulp.task('copy:manifest', copyTask({ destinations: browserPlatforms.map(platform => `./dist/${platform}`), pattern: '/*.json', })) -gulp.task('copy:html', copyTask({ - source: './app/', - destinations: browserPlatforms.map(platform => `./dist/${platform}`), - pattern: '/*.html', + +// copy mascara + +gulp.task('copy:html:mascara', copyTask({ + source: './mascara/', + destinations: [`./dist/mascara/`], + pattern: 'proxy/index.html', })) // manifest tinkering @@ -143,6 +151,7 @@ const copyTaskNames = [ 'copy:fonts', 'copy:manifest', 'copy:html', + 'copy:html:mascara', 'copy:contractImages', ] -- cgit v1.2.3 From 253abd60fca5a6efb1a2e0ecbe305989a852ec32 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 21:29:57 -0700 Subject: build - extension - move js files to toplevel --- gulpfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 68618dfb4..cd523a107 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -75,7 +75,7 @@ gulp.task('copy:fonts', copyTask({ })) gulp.task('copy:reload', copyTask({ source: './app/scripts/', - destinations: commonPlatforms.map(platform => `./dist/${platform}/scripts`), + destinations: commonPlatforms.map(platform => `./dist/${platform}`), pattern: '/chromereload.js', })) gulp.task('copy:html', copyTask({ @@ -243,10 +243,10 @@ function createTasksForBuildJsExtension({ buildJsFiles, taskPrefix, devMode, bun const nonInpageFiles = buildJsFiles.filter(file => file !== 'inpage') const buildPhase1 = ['inpage'] const buildPhase2 = nonInpageFiles - const destinations = browserPlatforms.map(platform => `./dist/${platform}/scripts`) + const destinations = browserPlatforms.map(platform => `./dist/${platform}`) bundleTaskOpts = Object.assign({ buildSourceMaps: true, - sourceMapDir: devMode ? './' : '../../sourcemaps', + sourceMapDir: devMode ? './' : '../sourcemaps', minifyBuild: !devMode, buildWithFullPaths: devMode, }, bundleTaskOpts) -- cgit v1.2.3 From 86c7c6746d64e8c9a32010520d49fc34c5e2edba Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 28 Mar 2018 23:11:07 -0700 Subject: build - refactor copy and copy:watch (renamed to copy:dev) --- gulpfile.js | 106 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 44 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index cd523a107..d6892cc7e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -54,51 +54,65 @@ gulp.task('dev:reload', function() { }) }) - // copy universal -gulp.task('copy:locales', copyTask({ +const copyTaskNames = [] +const copyDevTaskNames = [] + +createCopyTasks('locales', { source: './app/_locales/', destinations: commonPlatforms.map(platform => `./dist/${platform}/_locales`), -})) -gulp.task('copy:images', copyTask({ +}) +createCopyTasks('images', { source: './app/images/', destinations: commonPlatforms.map(platform => `./dist/${platform}/images`), -})) -gulp.task('copy:contractImages', copyTask({ - source: './node_modules/eth-contract-metadata/images/', +}) +createCopyTasks('contractImages', { + source: `${require.resolve('eth-contract-metadata')}/images/`, destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contract`), -})) -gulp.task('copy:fonts', copyTask({ +}) +createCopyTasks('fonts', { source: './app/fonts/', destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`), -})) -gulp.task('copy:reload', copyTask({ +}) +createCopyTasks('reload', { + devOnly: true, source: './app/scripts/', - destinations: commonPlatforms.map(platform => `./dist/${platform}`), pattern: '/chromereload.js', -})) -gulp.task('copy:html', copyTask({ - source: './app/', destinations: commonPlatforms.map(platform => `./dist/${platform}`), +}) +createCopyTasks('html', { + source: './app/', pattern: '/*.html', -})) + destinations: commonPlatforms.map(platform => `./dist/${platform}`), +}) // copy extension -gulp.task('copy:manifest', copyTask({ +createCopyTasks('manifest', { source: './app/', - destinations: browserPlatforms.map(platform => `./dist/${platform}`), pattern: '/*.json', -})) + destinations: browserPlatforms.map(platform => `./dist/${platform}`), +}) // copy mascara -gulp.task('copy:html:mascara', copyTask({ +createCopyTasks('html:mascara', { source: './mascara/', - destinations: [`./dist/mascara/`], pattern: 'proxy/index.html', -})) + destinations: [`./dist/mascara/`], +}) + +function createCopyTasks(label, opts) { + if (!opts.devOnly) { + const copyTaskName = `copy:${label}` + copyTask(copyTaskName, opts) + copyTaskNames.push(copyTaskName) + } + const copyDevTaskName = `copy:dev:${label}` + copyTask(copyDevTaskName, Object.assign({ devMode: true }, opts)) + copyDevTaskNames.push(copyDevTaskName) +} // manifest tinkering @@ -145,20 +159,6 @@ gulp.task('manifest:production', function() { .pipe(gulp.dest('./dist/', { overwrite: true })) }) -const copyTaskNames = [ - 'copy:locales', - 'copy:images', - 'copy:fonts', - 'copy:manifest', - 'copy:html', - 'copy:html:mascara', - 'copy:contractImages', -] - -if (debugMode) { - copyTaskNames.push('copy:reload') -} - gulp.task('copy', gulp.series( gulp.parallel(...copyTaskNames), @@ -167,9 +167,14 @@ gulp.task('copy', 'manifest:opera' ) ) -gulp.task('copy:watch', function(){ - gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) -}) + +gulp.task('copy:dev', + gulp.series( + gulp.parallel(...copyDevTaskNames), + 'manifest:chrome', + 'manifest:opera' + ) +) // lint js @@ -323,7 +328,7 @@ gulp.task('dev', 'copy', gulp.parallel( 'watch:scss', - 'copy:watch', + 'copy:dev', 'dev:reload' ) ) @@ -351,20 +356,33 @@ gulp.task('dist', // task generators -function copyTask(opts){ +function copyTask(taskName, opts){ const source = opts.source const destination = opts.destination const destinations = opts.destinations || [ destination ] const pattern = opts.pattern || '/**/*' + const devMode = opts.devMode - return performCopy + return gulp.task(taskName, performCopy) function performCopy(){ - let stream = gulp.src(source + pattern, { base: source }) + // stream from source + let stream + if (devMode) { + stream = watch(source + pattern, { base: source }) + } else { + stream = gulp.src(source + pattern, { base: source }) + } + + // copy to destinations destinations.forEach(function(destination) { stream = stream.pipe(gulp.dest(destination)) }) - stream.pipe(gulpif(debugMode,livereload())) + + // trigger reload + if (devMode) { + stream.pipe(livereload()) + } return stream } -- cgit v1.2.3 From 7067f636274cc00254661bb28ae371c975664e3d Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 17:34:30 -0700 Subject: build - dev - run js tasks in parallel and set watch flag --- gulpfile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index d6892cc7e..de3d5be11 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -254,6 +254,7 @@ function createTasksForBuildJsExtension({ buildJsFiles, taskPrefix, devMode, bun sourceMapDir: devMode ? './' : '../sourcemaps', minifyBuild: !devMode, buildWithFullPaths: devMode, + watch: devMode, }, bundleTaskOpts) createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1, buildPhase2 }) } @@ -268,6 +269,7 @@ function createTasksForBuildJsMascara({ taskPrefix, devMode, bundleTaskOpts = {} sourceMapDir: './', minifyBuild: !devMode, buildWithFullPaths: devMode, + watch: devMode, }, bundleTaskOpts) createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1 }) } @@ -277,7 +279,6 @@ function createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinatio const jsFiles = [].concat(buildPhase1, buildPhase2) jsFiles.forEach((jsFile) => { gulp.task(`${taskPrefix}:${jsFile}`, bundleTask(Object.assign({ - watch: false, label: jsFile, filename: `${jsFile}.js`, filepath: `${rootDir}/${jsFile}.js`, @@ -289,7 +290,7 @@ function createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinatio subtasks.push(gulp.parallel(buildPhase1.map(file => `${taskPrefix}:${file}`))) if (buildPhase2.length) subtasks.push(gulp.parallel(buildPhase2.map(file => `${taskPrefix}:${file}`))) - gulp.task(taskPrefix, gulp.series(subtasks)) + gulp.task(taskPrefix, gulp.parallel(subtasks)) } // disc bundle analyzer tasks @@ -324,9 +325,9 @@ gulp.task('apply-prod-environment', function(done) { gulp.task('dev', gulp.series( 'build:scss', - 'dev:js', 'copy', gulp.parallel( + 'dev:js', 'watch:scss', 'copy:dev', 'dev:reload' -- cgit v1.2.3 From 77d4a9a2bbd28c633cb6731cdbce47d3f79972a7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 17:37:49 -0700 Subject: build - dev - fix js build order --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index de3d5be11..0c16eb18e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -290,7 +290,7 @@ function createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinatio subtasks.push(gulp.parallel(buildPhase1.map(file => `${taskPrefix}:${file}`))) if (buildPhase2.length) subtasks.push(gulp.parallel(buildPhase2.map(file => `${taskPrefix}:${file}`))) - gulp.task(taskPrefix, gulp.parallel(subtasks)) + gulp.task(taskPrefix, gulp.series(subtasks)) } // disc bundle analyzer tasks -- cgit v1.2.3 From 4606a23c3fbfbbbd93ea59f3ca3e2e06766d3a04 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 21:28:35 -0700 Subject: build - refactor scss compilation into single config --- gulpfile.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 18 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 0c16eb18e..4a4ab8ee0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -109,7 +109,7 @@ function createCopyTasks(label, opts) { copyTask(copyTaskName, opts) copyTaskNames.push(copyTaskName) } - const copyDevTaskName = `copy:dev:${label}` + const copyDevTaskName = `dev:copy:${label}` copyTask(copyDevTaskName, Object.assign({ devMode: true }, opts)) copyDevTaskNames.push(copyDevTaskName) } @@ -168,7 +168,7 @@ gulp.task('copy', ) ) -gulp.task('copy:dev', +gulp.task('dev:copy', gulp.series( gulp.parallel(...copyDevTaskNames), 'manifest:chrome', @@ -199,17 +199,50 @@ gulp.task('lint:fix', function () { // scss compilation and autoprefixing tasks -gulp.task('build:scss', function () { - return gulp.src('ui/app/css/index.scss') - .pipe(sourcemaps.init()) - .pipe(sass().on('error', sass.logError)) - .pipe(sourcemaps.write()) - .pipe(autoprefixer()) - .pipe(gulp.dest('ui/app/css/output')) -}) -gulp.task('watch:scss', function() { - gulp.watch(['ui/app/css/**/*.scss'], gulp.series(['build:scss'])) -}) +// gulp.task('build:scss', function () { +// return gulp.src('ui/app/css/index.scss') +// .pipe(sourcemaps.init()) +// .pipe(sass().on('error', sass.logError)) +// .pipe(sourcemaps.write()) +// .pipe(autoprefixer()) +// .pipe(gulp.dest('ui/app/css/output')) +// }) +// gulp.task('dev:scss', function() { +// gulp.watch(['ui/app/css/**/*.scss'], gulp.parallel(['build:scss'])) +// }) + + + +gulp.task('build:scss', createScssBuildTask({ + src: 'ui/app/css/index.scss', + dest: 'ui/app/css/output', + devMode: false, +})) + +gulp.task('dev:scss', createScssBuildTask({ + src: 'ui/app/css/index.scss', + dest: 'ui/app/css/output', + devMode: true, + pattern: 'ui/app/css/**/*.scss', +})) + +function createScssBuildTask({ src, dest, devMode, pattern }) { + return function () { + if (devMode) { + watch(pattern, buildScss) + } + return buildScss() + } + + function buildScss() { + return gulp.src(src) + .pipe(sourcemaps.init()) + .pipe(sass().on('error', sass.logError)) + .pipe(sourcemaps.write()) + .pipe(autoprefixer()) + .pipe(gulp.dest(dest)) + } +} gulp.task('lint-scss', function() { return gulp @@ -321,15 +354,27 @@ gulp.task('apply-prod-environment', function(done) { }); // high level tasks +// +// gulp.task('dev', +// gulp.series( +// 'build:scss', +// 'copy', +// gulp.parallel( +// 'dev:js', +// 'dev:scss', +// 'dev:copy', +// 'dev:reload' +// ) +// ) +// ) gulp.task('dev', gulp.series( - 'build:scss', - 'copy', + 'clean', + 'dev:scss', gulp.parallel( 'dev:js', - 'watch:scss', - 'copy:dev', + 'dev:copy', 'dev:reload' ) ) @@ -341,7 +386,7 @@ gulp.task('build', 'build:scss', gulp.parallel( 'build:js:extension', - 'build:js:mascara', + // 'build:js:mascara', 'copy' ) ) -- cgit v1.2.3 From b2d0e9871c5004458ef9be4a83d08df8a39e6e48 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 21:53:38 -0700 Subject: build - fix copy devMode --- gulpfile.js | 63 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 4a4ab8ee0..c2e18395c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -114,6 +114,37 @@ function createCopyTasks(label, opts) { copyDevTaskNames.push(copyDevTaskName) } +function copyTask(taskName, opts){ + const source = opts.source + const destination = opts.destination + const destinations = opts.destinations || [destination] + const pattern = opts.pattern || '/**/*' + const devMode = opts.devMode + + return gulp.task(taskName, function () { + if (devMode) { + watch(source + pattern, (event) => { + livereload.changed(event.path) + performCopy() + }) + } + + return performCopy() + }) + + function performCopy() { + // stream from source + let stream = gulp.src(source + pattern, { base: source }) + + // copy to destinations + destinations.forEach(function(destination) { + stream = stream.pipe(gulp.dest(destination)) + }) + + return stream + } +} + // manifest tinkering gulp.task('manifest:chrome', function() { @@ -402,38 +433,6 @@ gulp.task('dist', // task generators -function copyTask(taskName, opts){ - const source = opts.source - const destination = opts.destination - const destinations = opts.destinations || [ destination ] - const pattern = opts.pattern || '/**/*' - const devMode = opts.devMode - - return gulp.task(taskName, performCopy) - - function performCopy(){ - // stream from source - let stream - if (devMode) { - stream = watch(source + pattern, { base: source }) - } else { - stream = gulp.src(source + pattern, { base: source }) - } - - // copy to destinations - destinations.forEach(function(destination) { - stream = stream.pipe(gulp.dest(destination)) - }) - - // trigger reload - if (devMode) { - stream.pipe(livereload()) - } - - return stream - } -} - function zipTask(target) { return () => { return gulp.src(`dist/${target}/**`) -- cgit v1.2.3 From 7b9b890aa94557c4665be00da8c0f2e24ba4ea1a Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 22:19:15 -0700 Subject: build - fix scss + js reload --- gulpfile.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index c2e18395c..5e7b5dc03 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -28,7 +28,8 @@ const stylefmt = require('gulp-stylefmt') const uglify = require('gulp-uglify-es').default const babel = require('gulp-babel') const debug = require('gulp-debug') - +const pify = require('pify') +const endOfStream = pify(require('end-of-stream')) const disableDebugTools = gutil.env.disableDebugTools const debugMode = gutil.env.debug @@ -260,7 +261,11 @@ gulp.task('dev:scss', createScssBuildTask({ function createScssBuildTask({ src, dest, devMode, pattern }) { return function () { if (devMode) { - watch(pattern, buildScss) + watch(pattern, async (event) => { + const stream = buildScss() + await endOfStream(stream) + livereload.changed(event.path) + }) } return buildScss() } @@ -454,7 +459,11 @@ function generateBundler(opts, performBundle) { if (opts.watch) { bundler = watchify(bundler) // on any file update, re-runs the bundler - bundler.on('update', performBundle) + bundler.on('update', async (ids) => { + const stream = performBundle() + await endOfStream(stream) + livereload.changed(`${ids}`) + }) } return bundler @@ -494,7 +503,6 @@ function bundleTask(opts) { return performBundle function performBundle(){ - let buildStream = bundler.bundle() // handle errors @@ -545,10 +553,6 @@ function bundleTask(opts) { buildStream = buildStream.pipe(gulp.dest(dest)) }) - // finally, trigger live reload - buildStream = buildStream - .pipe(gulpif(debugMode, livereload())) - return buildStream } -- cgit v1.2.3 From edd70bd13e514013073f75ff005bddf6f6a568a9 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 22:20:24 -0700 Subject: build - cleanup commented code --- gulpfile.js | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 5e7b5dc03..910441e4d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -231,20 +231,6 @@ gulp.task('lint:fix', function () { // scss compilation and autoprefixing tasks -// gulp.task('build:scss', function () { -// return gulp.src('ui/app/css/index.scss') -// .pipe(sourcemaps.init()) -// .pipe(sass().on('error', sass.logError)) -// .pipe(sourcemaps.write()) -// .pipe(autoprefixer()) -// .pipe(gulp.dest('ui/app/css/output')) -// }) -// gulp.task('dev:scss', function() { -// gulp.watch(['ui/app/css/**/*.scss'], gulp.parallel(['build:scss'])) -// }) - - - gulp.task('build:scss', createScssBuildTask({ src: 'ui/app/css/index.scss', dest: 'ui/app/css/output', @@ -390,19 +376,6 @@ gulp.task('apply-prod-environment', function(done) { }); // high level tasks -// -// gulp.task('dev', -// gulp.series( -// 'build:scss', -// 'copy', -// gulp.parallel( -// 'dev:js', -// 'dev:scss', -// 'dev:copy', -// 'dev:reload' -// ) -// ) -// ) gulp.task('dev', gulp.series( -- cgit v1.2.3 From 433bb0f01ae3631774191f8ed802eb7f2f04a552 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 22:34:59 -0700 Subject: build - split primary tasks into metamask + extension * dev + build --- gulpfile.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 910441e4d..647abb6d2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -69,7 +69,7 @@ createCopyTasks('images', { destinations: commonPlatforms.map(platform => `./dist/${platform}/images`), }) createCopyTasks('contractImages', { - source: `${require.resolve('eth-contract-metadata')}/images/`, + source: './node_modules/eth-contract-metadata/images/', destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contract`), }) createCopyTasks('fonts', { @@ -293,9 +293,10 @@ const buildJsFiles = [ ] // bundle tasks -createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'dev:js', devMode: true }) -createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'build:js:extension' }) -createTasksForBuildJsMascara({ taskPrefix: 'build:js:mascara' }) +createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'dev:extension:js', devMode: true }) +createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'build:extension:js' }) +createTasksForBuildJsMascara({ taskPrefix: 'build:mascara:js' }) +createTasksForBuildJsMascara({ taskPrefix: 'dev:mascara:js', devMode: true }) function createTasksForBuildJsExtension({ buildJsFiles, taskPrefix, devMode, bundleTaskOpts = {} }) { // inpage must be built before all other scripts: @@ -382,7 +383,32 @@ gulp.task('dev', 'clean', 'dev:scss', gulp.parallel( - 'dev:js', + 'dev:extension:js', + 'dev:mascara:js', + 'dev:copy', + 'dev:reload' + ) + ) +) + +gulp.task('dev:extension', + gulp.series( + 'clean', + 'dev:scss', + gulp.parallel( + 'dev:extension:js', + 'dev:copy', + 'dev:reload' + ) + ) +) + +gulp.task('dev:mascara', + gulp.series( + 'clean', + 'dev:scss', + gulp.parallel( + 'dev:mascara:js', 'dev:copy', 'dev:reload' ) @@ -394,8 +420,30 @@ gulp.task('build', 'clean', 'build:scss', gulp.parallel( - 'build:js:extension', - // 'build:js:mascara', + 'build:extension:js', + 'build:mascara:js', + 'copy' + ) + ) +) + +gulp.task('build:extension', + gulp.series( + 'clean', + 'build:scss', + gulp.parallel( + 'build:extension:js', + 'copy' + ) + ) +) + +gulp.task('build:mascara', + gulp.series( + 'clean', + 'build:scss', + gulp.parallel( + 'build:mascara:js', 'copy' ) ) -- cgit v1.2.3 From 99e618d3f2fed0504e9dcc4647b8492440617162 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 29 Mar 2018 23:06:01 -0700 Subject: mascara - server - serve bundles from dist --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 647abb6d2..3ca0c65de 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -318,7 +318,7 @@ function createTasksForBuildJsExtension({ buildJsFiles, taskPrefix, devMode, bun function createTasksForBuildJsMascara({ taskPrefix, devMode, bundleTaskOpts = {} }) { // inpage must be built before all other scripts: const rootDir = './mascara/src/' - const buildPhase1 = ['ui', 'proxy', 'background'] + const buildPhase1 = ['ui', 'proxy', 'background', 'metamascara'] const destinations = ['./dist/mascara'] bundleTaskOpts = Object.assign({ buildSourceMaps: true, -- cgit v1.2.3