|
|
|
@ -1,6 +1,8 @@ |
|
|
|
|
const fs = require('fs') |
|
|
|
|
const gulp = require('gulp') |
|
|
|
|
const watch = require('gulp-watch') |
|
|
|
|
const pify = require('pify') |
|
|
|
|
const pump = pify(require('pump')) |
|
|
|
|
const source = require('vinyl-source-stream') |
|
|
|
|
const buffer = require('vinyl-buffer') |
|
|
|
|
const log = require('fancy-log') |
|
|
|
@ -11,8 +13,6 @@ const envify = require('envify/custom') |
|
|
|
|
const sourcemaps = require('gulp-sourcemaps') |
|
|
|
|
const sesify = require('sesify') |
|
|
|
|
const terser = require('gulp-terser-js') |
|
|
|
|
const pify = require('pify') |
|
|
|
|
const endOfStream = pify(require('end-of-stream')) |
|
|
|
|
const { makeStringTransform } = require('browserify-transform-tools') |
|
|
|
|
|
|
|
|
|
const conf = require('rc')('metamask', { |
|
|
|
@ -200,33 +200,19 @@ function createScriptTasks({ browserPlatforms, livereload }) { |
|
|
|
|
bundler.on('log', log) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let buildStream = bundler.bundle() |
|
|
|
|
|
|
|
|
|
// handle errors
|
|
|
|
|
buildStream.on('error', (err) => { |
|
|
|
|
beep() |
|
|
|
|
if (opts.devMode) { |
|
|
|
|
console.warn(err.stack) |
|
|
|
|
} else { |
|
|
|
|
throw err |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// process bundles
|
|
|
|
|
buildStream = buildStream |
|
|
|
|
const buildPipeline = [ |
|
|
|
|
bundler.bundle(), |
|
|
|
|
// convert bundle stream to gulp vinyl stream
|
|
|
|
|
.pipe(source(opts.filename)) |
|
|
|
|
// buffer file contents (?)
|
|
|
|
|
.pipe(buffer()) |
|
|
|
|
|
|
|
|
|
// Initialize Source Maps
|
|
|
|
|
buildStream = buildStream |
|
|
|
|
source(opts.filename), |
|
|
|
|
// Initialize Source Maps
|
|
|
|
|
buffer(), |
|
|
|
|
// loads map from browserify file
|
|
|
|
|
.pipe(sourcemaps.init({ loadMaps: true })) |
|
|
|
|
sourcemaps.init({ loadMaps: true }), |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
// Minification
|
|
|
|
|
if (!opts.devMode) { |
|
|
|
|
buildStream = buildStream.pipe( |
|
|
|
|
buildPipeline.push( |
|
|
|
|
terser({ |
|
|
|
|
mangle: { |
|
|
|
|
reserved: ['MetamaskInpageProvider'], |
|
|
|
@ -242,18 +228,28 @@ function createScriptTasks({ browserPlatforms, livereload }) { |
|
|
|
|
if (opts.devMode) { |
|
|
|
|
// Use inline source maps for development due to Chrome DevTools bug
|
|
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=931675
|
|
|
|
|
buildStream = buildStream.pipe(sourcemaps.write()) |
|
|
|
|
// note: sourcemaps call arity is important
|
|
|
|
|
buildPipeline.push(sourcemaps.write()) |
|
|
|
|
} else { |
|
|
|
|
buildStream = buildStream.pipe(sourcemaps.write('../sourcemaps')) |
|
|
|
|
buildPipeline.push(sourcemaps.write('../sourcemaps')) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// write completed bundles
|
|
|
|
|
browserPlatforms.forEach((platform) => { |
|
|
|
|
const dest = `./dist/${platform}` |
|
|
|
|
buildStream = buildStream.pipe(gulp.dest(dest)) |
|
|
|
|
buildPipeline.push(gulp.dest(dest)) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
await endOfStream(buildStream) |
|
|
|
|
// process bundles
|
|
|
|
|
if (opts.devMode) { |
|
|
|
|
try { |
|
|
|
|
await pump(buildPipeline) |
|
|
|
|
} catch (err) { |
|
|
|
|
gracefulError(err) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
await pump(buildPipeline) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -406,10 +402,6 @@ function createScriptTasks({ browserPlatforms, livereload }) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function beep() { |
|
|
|
|
process.stdout.write('\x07') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getEnvironment({ devMode, test }) { |
|
|
|
|
// get environment slug
|
|
|
|
|
if (devMode) { |
|
|
|
@ -429,3 +421,12 @@ function getEnvironment({ devMode, test }) { |
|
|
|
|
} |
|
|
|
|
return 'other' |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function beep() { |
|
|
|
|
process.stdout.write('\x07') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function gracefulError(err) { |
|
|
|
|
console.warn(err) |
|
|
|
|
beep() |
|
|
|
|
} |
|
|
|
|