aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js183
1 files changed, 149 insertions, 34 deletions
diff --git a/gulpfile.js b/gulpfile.js
index aeaf3e674..fe223adf1 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -1,5 +1,6 @@
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')
@@ -10,19 +11,23 @@ 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')
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 disableLiveReload = gutil.env.disableLiveReload
+var debug = gutil.env.debug
// browser reload
gulp.task('dev:reload', function() {
livereload.listen({
port: 35729,
- // basePath: './dist/firefox/'
})
})
@@ -34,6 +39,8 @@ gulp.task('copy:locales', copyTask({
destinations: [
'./dist/firefox/_locales',
'./dist/chrome/_locales',
+ './dist/edge/_locales',
+ './dist/opera/_locales',
]
}))
gulp.task('copy:images', copyTask({
@@ -41,6 +48,8 @@ gulp.task('copy:images', copyTask({
destinations: [
'./dist/firefox/images',
'./dist/chrome/images',
+ './dist/edge/images',
+ './dist/opera/images',
],
}))
gulp.task('copy:fonts', copyTask({
@@ -48,6 +57,8 @@ gulp.task('copy:fonts', copyTask({
destinations: [
'./dist/firefox/fonts',
'./dist/chrome/fonts',
+ './dist/edge/fonts',
+ './dist/opera/fonts',
],
}))
gulp.task('copy:reload', copyTask({
@@ -55,6 +66,8 @@ gulp.task('copy:reload', copyTask({
destinations: [
'./dist/firefox/scripts',
'./dist/chrome/scripts',
+ './dist/edge/scripts',
+ './dist/opera/scripts',
],
pattern: '/chromereload.js',
}))
@@ -63,12 +76,14 @@ gulp.task('copy:root', copyTask({
destinations: [
'./dist/firefox',
'./dist/chrome',
+ './dist/edge',
+ './dist/opera',
],
pattern: '/*',
}))
-gulp.task('manifest:cleanup', function() {
- return gulp.src('./dist/firefox/manifest.json')
+gulp.task('manifest:chrome', function() {
+ return gulp.src('./dist/chrome/manifest.json')
.pipe(jsoneditor(function(json) {
delete json.applications
return json
@@ -76,7 +91,48 @@ gulp.task('manifest:cleanup', function() {
.pipe(gulp.dest('./dist/chrome', { overwrite: true }))
})
-gulp.task('copy', gulp.series(gulp.parallel('copy:locales','copy:images','copy:fonts','copy:reload','copy:root'), 'manifest:cleanup'))
+gulp.task('manifest:opera', function() {
+ return gulp.src('./dist/opera/manifest.json')
+ .pipe(jsoneditor(function(json) {
+ json.permissions = [
+ "storage",
+ "tabs",
+ "clipboardWrite",
+ "clipboardRead",
+ "http://localhost:8545/"
+ ]
+ return json
+ }))
+ .pipe(gulp.dest('./dist/opera', { overwrite: true }))
+})
+
+gulp.task('manifest:production', function() {
+ return gulp.src([
+ './dist/firefox/manifest.json',
+ './dist/chrome/manifest.json',
+ './dist/edge/manifest.json',
+ ],{base: './dist/'})
+ .pipe(gulpif(disableLiveReload,jsoneditor(function(json) {
+ json.background.scripts = ["scripts/background.js"]
+ return json
+ })))
+ .pipe(gulp.dest('./dist/', { overwrite: true }))
+})
+
+const staticFiles = [
+ 'locales',
+ 'images',
+ 'fonts',
+ 'root'
+]
+
+var copyStrings = staticFiles.map(staticFile => `copy:${staticFile}`)
+
+if (!disableLiveReload) {
+ copyStrings.push('copy:reload')
+}
+
+gulp.task('copy', gulp.series(gulp.parallel(...copyStrings), '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'))
})
@@ -110,14 +166,27 @@ const jsFiles = [
'popup',
]
+// bundle tasks
+
+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` }))
+ gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, label: jsFile, filename: `${jsFile}.js` }))
+})
+
+gulp.task('dev:js', gulp.parallel(...jsDevStrings))
+gulp.task('build:js', gulp.parallel(...jsBuildStrings))
+
+// disc bundle analyzer tasks
+
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(`disc:${jsFile}`, bundleTask({ label: jsFile, filename: `${jsFile}.js` }))
})
-gulp.task('dev:js', gulp.parallel('dev:js:inpage','dev:js:contentscript','dev:js:background','dev:js:popup'))
+gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`)))
-gulp.task('build:js', gulp.parallel('build:js:inpage','build:js:contentscript','build:js:background','build:js:popup'))
// clean dist
@@ -127,21 +196,16 @@ gulp.task('clean', function clean() {
})
// zip tasks for distribution
-gulp.task('zip:chrome', () => {
- return gulp.src('dist/chrome/**')
- .pipe(zip(`metamask-chrome-${manifest.version}.zip`))
- .pipe(gulp.dest('builds'));
-});
-gulp.task('zip:firefox', () => {
- return gulp.src('dist/firefox/**')
- .pipe(zip(`metamask-firefox-${manifest.version}.zip`))
- .pipe(gulp.dest('builds'));
-});
-gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox'))
+gulp.task('zip:chrome', zipTask('chrome'))
+gulp.task('zip:firefox', zipTask('firefox'))
+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'))
// 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'))
@@ -160,27 +224,71 @@ function copyTask(opts){
destinations.forEach(function(destination) {
stream = stream.pipe(gulp.dest(destination))
})
- stream.pipe(livereload())
+ stream.pipe(gulpif(!disableLiveReload,livereload()))
return stream
}
}
-function bundleTask(opts) {
+function zipTask(target) {
+ return () => {
+ return gulp.src(`dist/${target}/**`)
+ .pipe(zip(`metamask-${target}-${manifest.version}.zip`))
+ .pipe(gulp.dest('builds'));
+ }
+}
+
+function generateBundler(opts) {
var browserifyOpts = assign({}, watchify.args, {
entries: ['./app/scripts/'+opts.filename],
- debug: true,
plugin: 'browserify-derequire',
+ debug: debug,
+ fullPaths: debug,
})
- var bundler = browserify(browserifyOpts)
- bundler.transform('brfs')
+ return browserify(browserifyOpts)
+}
+
+function discTask(opts) {
+ let bundler = generateBundler(opts)
+
+ if (opts.watch) {
+ bundler = watchify(bundler)
+ // on any dep update, runs the bundler
+ bundler.on('update', performBundle)
+ }
+
+ // output build logs to terminal
+ bundler.on('log', gutil.log)
+
+ return performBundle
+
+ function performBundle(){
+ // start "disc" build
+ let discDir = path.join(__dirname, 'disc')
+ mkdirp.sync(discDir)
+ let discPath = path.join(discDir, `${opts.label}.html`)
+
+ return (
+ bundler.bundle()
+ .pipe(disc())
+ .pipe(fs.createWriteStream(discPath))
+ )
+ }
+}
+
+
+function bundleTask(opts) {
+ let bundler = generateBundler(opts)
+
if (opts.watch) {
bundler = watchify(bundler)
- bundler.on('update', performBundle) // on any dep update, runs the bundler
+ // on any file update, re-runs the bundler
+ bundler.on('update', performBundle)
}
- bundler.on('log', gutil.log) // output build logs to terminal
+ // output build logs to terminal
+ bundler.on('log', gutil.log)
return performBundle
@@ -190,17 +298,24 @@ function bundleTask(opts) {
bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
+ // convert bundle stream to gulp vinyl stream
.pipe(source(opts.filename))
- .pipe(brfs())
- // optional, remove if you don't need to buffer file contents
+ // inject variables into bundle
+ .pipe(replace('\'GULP_METAMASK_DEBUG\'', debug))
+ // buffer file contents (?)
.pipe(buffer())
- // optional, remove if you dont want sourcemaps
- .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
- // Add transformation tasks to the pipeline here.
- .pipe(sourcemaps.write('./')) // writes .map file
+ // sourcemaps
+ // loads map from browserify file
+ .pipe(sourcemaps.init({loadMaps: true}))
+ // writes .map file
+ .pipe(sourcemaps.write('./'))
+ // write completed bundles
.pipe(gulp.dest('./dist/firefox/scripts'))
.pipe(gulp.dest('./dist/chrome/scripts'))
- .pipe(livereload())
+ .pipe(gulp.dest('./dist/edge/scripts'))
+ .pipe(gulp.dest('./dist/opera/scripts'))
+ // finally, trigger live reload
+ .pipe(gulpif(!disableLiveReload, livereload()))
)
}