From 913a9e85bd24a286c3399ab6e9a0c47fdfbeae0d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 25 Jul 2016 16:34:29 -0700 Subject: Inject inpage script synchronously Huge thanks to the Firefox team, for their help on the issue of our long-standing inpage script race condition. http://stackoverflow.com/questions/38577656/how-can-i-make-a-firefox-add-on-contentscript-inject-and-run-a-script-before-oth The problem is that we were injecting a `script` tag and assigning its `src` attribute, which triggers an asynchronous fetch request, and does not guarantee execution order! (That was news to me!) Instead, I'm now assigning the `script` tag a `textContent` value of the script to inject, and it seems to fix the problem! There is also a Firefox-only API that could solve this whole problem in an even more elegant way, so we might want to expose a code path for that solution later on: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction Allows you to expose an object from one scope to another. There was even talk of creating a polyfill for it that does virtually what we do, message passing between contexts. --- gulpfile.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 941155ff4..e10a4eb7d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,6 +8,7 @@ var watch = require('gulp-watch') var sourcemaps = require('gulp-sourcemaps') var assign = require('lodash.assign') var livereload = require('gulp-livereload') +var brfs = require('gulp-brfs') var del = require('del') var eslint = require('gulp-eslint') var fs = require('fs') @@ -144,6 +145,7 @@ function bundleTask(opts) { // log errors if they happen .on('error', gutil.log.bind(gutil, 'Browserify Error')) .pipe(source(opts.filename)) + .pipe(brfs()) // optional, remove if you don't need to buffer file contents .pipe(buffer()) // optional, remove if you dont want sourcemaps -- cgit v1.2.3 From 2368c2993d44375203e0b85158bac707489d1137 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 26 Jul 2016 15:15:40 -0700 Subject: Add platform specific builds and zip tasks (#486) * Add platform specific folders to dist folder * Remove gulp hacks * Add platform specific bundling dev and dist tasks now build into platform-specific folders within the `dist` folder. Added tasks `gulp zip` and `gulp dist`. `zip` builds the platform-specific folders into platform-specific bundles within the `dist` folder. `dist` builds and then zips all at once. * Fix chrome bundle zipping * Fix broken reference in eth warning * Fix but where web3.eth.accounts are not available in firefox. * Bump changelog --- gulpfile.js | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index e10a4eb7d..5dbdea04b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,6 +6,8 @@ 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 brfs = require('gulp-brfs') @@ -19,7 +21,7 @@ var path = require('path') gulp.task('dev:reload', function() { livereload.listen({ port: 35729, - // basePath: './dist/' + // basePath: './dist/firefox/' }) }) @@ -28,27 +30,41 @@ gulp.task('dev:reload', function() { gulp.task('copy:locales', copyTask({ source: './app/_locales/', - destination: './dist/_locales', + destination: './dist/firefox/_locales', })) gulp.task('copy:images', copyTask({ source: './app/images/', - destination: './dist/images', + destination: './dist/firefox/images', })) gulp.task('copy:fonts', copyTask({ source: './app/fonts/', - destination: './dist/fonts', + destination: './dist/firefox/fonts', })) gulp.task('copy:reload', copyTask({ source: './app/scripts/', - destination: './dist/scripts', + destination: './dist/firefox/scripts', pattern: '/chromereload.js', })) gulp.task('copy:root', copyTask({ source: './app/', - destination: './dist', + destination: './dist/firefox', pattern: '/*', })) -gulp.task('copy', gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root')) +gulp.task('manifest:cleanup', function() { + return gulp.src('./dist/firefox/manifest.json') + .pipe(jsoneditor(function(json) { + delete json.applications + return json + })) + .pipe(gulp.dest('./dist/chrome', { overwrite: false })) +}) +gulp.task('copy:chrome', gulp.series( +copyTask({ + source: './dist/firefox', + destination: './dist/chrome', + pattern: '**/[^manifest]*' +}), 'manifest:cleanup')) +gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'copy:chrome')) gulp.task('copy:watch', function(){ gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) }) @@ -56,8 +72,8 @@ gulp.task('copy:watch', function(){ // lint js gulp.task('lint', function () { - // Ignoring node_modules, dist, and docs folders: - return gulp.src(['app/**/*.js', 'ui/**/*.js', '!node_modules/**', '!dist/**', '!docs/**', '!app/scripts/chromereload.js']) + // Ignoring node_modules, dist/firefox, and docs folders: + return gulp.src(['app/**/*.js', 'ui/**/*.js', '!node_modules/**', '!dist/firefox/**', '!docs/**', '!app/scripts/chromereload.js']) .pipe(eslint(fs.readFileSync(path.join(__dirname, '.eslintrc')))) // eslint.format() outputs the lint results to the console. // Alternatively use eslint.formatEach() (see Docs). @@ -87,18 +103,31 @@ gulp.task('build:js:background', bundleTask({ watch: false, filename: 'backgroun gulp.task('build:js:popup', bundleTask({ watch: false, filename: 'popup.js' })) gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup')) -// clean dist +// clean dist/firefox gulp.task('clean', function clean() { - return del(['./dist']) + return del(['./dist/*']) }) +// zip tasks for distribution +gulp.task('zip:chrome', () => { + return gulp.src('dist/chrome/**') + .pipe(zip('chrome.zip')) + .pipe(gulp.dest('dist')); +}); +gulp.task('zip:firefox', () => { + return gulp.src('dist/firefox/**') + .pipe(zip('firefox.zip')) + .pipe(gulp.dest('dist')); +}); +gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox')) // high level tasks gulp.task('dev', gulp.series('dev:js', 'copy', gulp.parallel('copy:watch', 'dev:reload'))) gulp.task('build', gulp.series('clean', gulp.parallel('build:js', 'copy'))) +gulp.task('dist', gulp.series('build', 'zip')) // task generators @@ -152,7 +181,7 @@ function bundleTask(opts) { .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file // Add transformation tasks to the pipeline here. .pipe(sourcemaps.write('./')) // writes .map file - .pipe(gulp.dest('./dist/scripts')) + .pipe(gulp.dest('./dist/firefox/scripts')) .pipe(livereload()) ) -- cgit v1.2.3 From 5276897668674bb5e34923a473920564603ad292 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 26 Jul 2016 15:35:08 -0700 Subject: Store versioned builds in builds folder --- gulpfile.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 5dbdea04b..d63a95975 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -15,6 +15,7 @@ var del = require('del') var eslint = require('gulp-eslint') var fs = require('fs') var path = require('path') +var manifest = require('./app/manifest.json') // browser reload @@ -113,13 +114,13 @@ gulp.task('clean', function clean() { // zip tasks for distribution gulp.task('zip:chrome', () => { return gulp.src('dist/chrome/**') - .pipe(zip('chrome.zip')) - .pipe(gulp.dest('dist')); + .pipe(zip(`metamask-chrome-${manifest.version}.zip`)) + .pipe(gulp.dest('builds')); }); gulp.task('zip:firefox', () => { return gulp.src('dist/firefox/**') - .pipe(zip('firefox.zip')) - .pipe(gulp.dest('dist')); + .pipe(zip(`metamask-firefox-${manifest.version}.zip`)) + .pipe(gulp.dest('builds')); }); gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox')) -- cgit v1.2.3 From de5a2bf9bc8dd8f028fdb8acb7d8c763d455d07c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 26 Jul 2016 16:48:48 -0700 Subject: Fix chrome build --- gulpfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index d63a95975..976671055 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -57,13 +57,13 @@ gulp.task('manifest:cleanup', function() { delete json.applications return json })) - .pipe(gulp.dest('./dist/chrome', { overwrite: false })) + .pipe(gulp.dest('./dist/chrome', { overwrite: true })) }) gulp.task('copy:chrome', gulp.series( copyTask({ source: './dist/firefox', destination: './dist/chrome', - pattern: '**/[^manifest]*' + pattern: '**/*' }), 'manifest:cleanup')) gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'copy:chrome')) gulp.task('copy:watch', function(){ -- cgit v1.2.3 From 0b620026c27bf07080c830f325fe14ffa12130e9 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 26 Jul 2016 17:13:52 -0700 Subject: Fix copy task --- gulpfile.js | 1 - 1 file changed, 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 976671055..42554ca1a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -63,7 +63,6 @@ gulp.task('copy:chrome', gulp.series( copyTask({ source: './dist/firefox', destination: './dist/chrome', - pattern: '**/*' }), 'manifest:cleanup')) gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'copy:chrome')) gulp.task('copy:watch', function(){ -- cgit v1.2.3 From c759bc587166f4d1953653e3ef3bea359804256c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 26 Jul 2016 17:25:15 -0700 Subject: Correct typo comment --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 42554ca1a..c71ccb652 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -103,7 +103,7 @@ gulp.task('build:js:background', bundleTask({ watch: false, filename: 'backgroun gulp.task('build:js:popup', bundleTask({ watch: false, filename: 'popup.js' })) gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup')) -// clean dist/firefox +// clean dist gulp.task('clean', function clean() { -- cgit v1.2.3 From 7f00ee43ba542e6847a95a639969935201ff0c4f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 27 Jul 2016 16:58:00 -0700 Subject: Fix nondeterministic build We used to be able to copy static resources while we built js, but now part of the copy task is copying firefox built files into chrome, so they need to be done in order. This could probably be optimized a bit more, but for now it builds reliably again. --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index c71ccb652..0d31eeb5b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -126,7 +126,7 @@ gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox')) // high level tasks gulp.task('dev', gulp.series('dev:js', 'copy', gulp.parallel('copy:watch', 'dev:reload'))) -gulp.task('build', gulp.series('clean', gulp.parallel('build:js', 'copy'))) +gulp.task('build', gulp.series('clean', 'build:js', 'copy')) gulp.task('dist', gulp.series('build', 'zip')) // task generators -- cgit v1.2.3 From daaac17be20faf3f53f3a4b04d70504ebf894568 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 28 Jul 2016 10:50:14 -0700 Subject: Fix dev tasks for multi browser copying --- gulpfile.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 0d31eeb5b..96e5e11c7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -64,7 +64,7 @@ copyTask({ source: './dist/firefox', destination: './dist/chrome', }), 'manifest:cleanup')) -gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'copy:chrome')) +gulp.task('copy', gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root')) gulp.task('copy:watch', function(){ gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) }) @@ -91,16 +91,20 @@ gulp.task('default', ['lint'], function () { // build js -gulp.task('dev:js:inpage', bundleTask({ watch: true, filename: 'inpage.js' })) -gulp.task('dev:js:contentscript', bundleTask({ watch: true, filename: 'contentscript.js' })) -gulp.task('dev:js:background', bundleTask({ watch: true, filename: 'background.js' })) -gulp.task('dev:js:popup', bundleTask({ watch: true, filename: 'popup.js' })) -gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup')) +const jsFiles = [ + 'inpage', + 'contentscript', + 'background', + 'popup', +] + +jsFiles.forEach((jsFile) => { + gulp.task(`dev:js:${jsFile}`, bundleTask({ watch: true, filename: `${jsFile}.js` })) + gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` })) +}) + +gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup')) -gulp.task('build:js:inpage', bundleTask({ watch: false, filename: 'inpage.js' })) -gulp.task('build:js:contentscript', bundleTask({ watch: false, filename: 'contentscript.js' })) -gulp.task('build:js:background', bundleTask({ watch: false, filename: 'background.js' })) -gulp.task('build:js:popup', bundleTask({ watch: false, filename: 'popup.js' })) gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup')) // clean dist @@ -182,6 +186,7 @@ function bundleTask(opts) { // Add transformation tasks to the pipeline here. .pipe(sourcemaps.write('./')) // writes .map file .pipe(gulp.dest('./dist/firefox/scripts')) + .pipe(gulp.dest('./dist/chrome/scripts')) .pipe(livereload()) ) -- cgit v1.2.3 From bdd2752cc778760da798163cc94975b5a9cece3c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 28 Jul 2016 12:59:37 -0700 Subject: Fix some gulp task issues I know, I've been fixing up the gulp scripts all week. I keep fixing one thing then breaking another. In this commit, I fix some issues with some previous approaches. I no longer try to do the copying to `chrome` after `firefox`, I simply stream to both during copy and build tasks, and that logic is reused during dev and build tasks. The `copyTask` function now supports an array of `destinations`, that allows piping to multiple destinations, which is pretty cool. The `manifest:cleanup` task that chrome requires is now just part of the `copy` task, so we don't have to remember it everywhere we copy. So obvious it's like why only now. --- gulpfile.js | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 96e5e11c7..aeaf3e674 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -31,26 +31,42 @@ gulp.task('dev:reload', function() { gulp.task('copy:locales', copyTask({ source: './app/_locales/', - destination: './dist/firefox/_locales', + destinations: [ + './dist/firefox/_locales', + './dist/chrome/_locales', + ] })) gulp.task('copy:images', copyTask({ source: './app/images/', - destination: './dist/firefox/images', + destinations: [ + './dist/firefox/images', + './dist/chrome/images', + ], })) gulp.task('copy:fonts', copyTask({ source: './app/fonts/', - destination: './dist/firefox/fonts', + destinations: [ + './dist/firefox/fonts', + './dist/chrome/fonts', + ], })) gulp.task('copy:reload', copyTask({ source: './app/scripts/', - destination: './dist/firefox/scripts', + destinations: [ + './dist/firefox/scripts', + './dist/chrome/scripts', + ], pattern: '/chromereload.js', })) gulp.task('copy:root', copyTask({ source: './app/', - destination: './dist/firefox', + destinations: [ + './dist/firefox', + './dist/chrome', + ], pattern: '/*', })) + gulp.task('manifest:cleanup', function() { return gulp.src('./dist/firefox/manifest.json') .pipe(jsoneditor(function(json) { @@ -59,12 +75,8 @@ gulp.task('manifest:cleanup', function() { })) .pipe(gulp.dest('./dist/chrome', { overwrite: true })) }) -gulp.task('copy:chrome', gulp.series( -copyTask({ - source: './dist/firefox', - destination: './dist/chrome', -}), 'manifest:cleanup')) -gulp.task('copy', gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root')) + +gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'manifest:cleanup')) gulp.task('copy:watch', function(){ gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy')) }) @@ -130,7 +142,7 @@ gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox')) // high level tasks gulp.task('dev', gulp.series('dev:js', 'copy', gulp.parallel('copy:watch', 'dev:reload'))) -gulp.task('build', gulp.series('clean', 'build:js', 'copy')) +gulp.task('build', gulp.series('clean', gulp.parallel('build:js', 'copy'))) gulp.task('dist', gulp.series('build', 'zip')) // task generators @@ -138,18 +150,19 @@ gulp.task('dist', gulp.series('build', 'zip')) function copyTask(opts){ var source = opts.source var destination = opts.destination + var destinations = opts.destinations || [ destination ] var pattern = opts.pattern || '/**/*' return performCopy function performCopy(){ - return ( + let stream = gulp.src(source + pattern, { base: source }) + destinations.forEach(function(destination) { + stream = stream.pipe(gulp.dest(destination)) + }) + stream.pipe(livereload()) - gulp.src(source + pattern, { base: source }) - .pipe(gulp.dest(destination)) - .pipe(livereload()) - - ) + return stream } } -- cgit v1.2.3