2016-03-03 08:06:43 +01:00
|
|
|
var watchify = require('watchify')
|
|
|
|
var browserify = require('browserify')
|
2017-01-10 22:46:15 +01:00
|
|
|
var disc = require('disc')
|
2016-03-03 08:06:43 +01:00
|
|
|
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')
|
2016-07-27 00:15:40 +02:00
|
|
|
var jsoneditor = require('gulp-json-editor')
|
|
|
|
var zip = require('gulp-zip')
|
2016-03-03 08:06:43 +01:00
|
|
|
var assign = require('lodash.assign')
|
|
|
|
var livereload = require('gulp-livereload')
|
|
|
|
var del = require('del')
|
2016-06-21 21:07:13 +02:00
|
|
|
var eslint = require('gulp-eslint')
|
2016-06-21 21:40:09 +02:00
|
|
|
var fs = require('fs')
|
|
|
|
var path = require('path')
|
2016-07-27 00:35:08 +02:00
|
|
|
var manifest = require('./app/manifest.json')
|
2016-09-02 00:01:45 +02:00
|
|
|
var gulpif = require('gulp-if')
|
|
|
|
var replace = require('gulp-replace')
|
2017-01-10 22:46:15 +01:00
|
|
|
var mkdirp = require('mkdirp')
|
2018-01-10 22:54:29 +01:00
|
|
|
var asyncEach = require('async/each')
|
|
|
|
var exec = require('child_process').exec
|
2017-08-06 21:09:17 +02:00
|
|
|
var sass = require('gulp-sass')
|
|
|
|
var autoprefixer = require('gulp-autoprefixer')
|
2017-08-14 10:03:16 +02:00
|
|
|
var gulpStylelint = require('gulp-stylelint')
|
|
|
|
var stylefmt = require('gulp-stylefmt')
|
2018-01-16 04:00:07 +01:00
|
|
|
var uglify = require('gulp-uglify-es').default
|
2018-01-12 03:15:22 +01:00
|
|
|
var babel = require('gulp-babel')
|
2017-08-14 10:03:16 +02:00
|
|
|
|
2016-10-11 23:32:03 +02:00
|
|
|
|
2017-06-26 20:37:12 +02:00
|
|
|
var disableDebugTools = gutil.env.disableDebugTools
|
2016-10-11 23:32:03 +02:00
|
|
|
var debug = gutil.env.debug
|
2016-09-02 00:19:31 +02:00
|
|
|
|
2017-08-14 10:03:16 +02:00
|
|
|
|
2016-03-03 08:06:43 +01:00
|
|
|
// browser reload
|
|
|
|
|
|
|
|
gulp.task('dev:reload', function() {
|
|
|
|
livereload.listen({
|
|
|
|
port: 35729,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// copy static
|
|
|
|
|
|
|
|
gulp.task('copy:locales', copyTask({
|
|
|
|
source: './app/_locales/',
|
2016-07-28 21:59:37 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox/_locales',
|
|
|
|
'./dist/chrome/_locales',
|
2016-08-07 22:36:02 +02:00
|
|
|
'./dist/edge/_locales',
|
2017-01-03 20:23:27 +01:00
|
|
|
'./dist/opera/_locales',
|
2016-07-28 21:59:37 +02:00
|
|
|
]
|
2016-03-03 08:06:43 +01:00
|
|
|
}))
|
|
|
|
gulp.task('copy:images', copyTask({
|
|
|
|
source: './app/images/',
|
2016-07-28 21:59:37 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox/images',
|
|
|
|
'./dist/chrome/images',
|
2016-08-07 22:36:02 +02:00
|
|
|
'./dist/edge/images',
|
2017-01-03 20:23:27 +01:00
|
|
|
'./dist/opera/images',
|
2016-07-28 21:59:37 +02:00
|
|
|
],
|
2016-03-03 08:06:43 +01:00
|
|
|
}))
|
2017-05-26 09:19:24 +02:00
|
|
|
gulp.task('copy:contractImages', copyTask({
|
2017-06-14 02:46:47 +02:00
|
|
|
source: './node_modules/eth-contract-metadata/images/',
|
2017-05-26 09:19:24 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox/images/contract',
|
|
|
|
'./dist/chrome/images/contract',
|
|
|
|
'./dist/edge/images/contract',
|
|
|
|
'./dist/opera/images/contract',
|
|
|
|
],
|
|
|
|
}))
|
2016-05-11 01:51:49 +02:00
|
|
|
gulp.task('copy:fonts', copyTask({
|
|
|
|
source: './app/fonts/',
|
2016-07-28 21:59:37 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox/fonts',
|
|
|
|
'./dist/chrome/fonts',
|
2016-08-07 22:36:02 +02:00
|
|
|
'./dist/edge/fonts',
|
2017-01-03 20:23:27 +01:00
|
|
|
'./dist/opera/fonts',
|
2016-07-28 21:59:37 +02:00
|
|
|
],
|
2016-05-11 01:51:49 +02:00
|
|
|
}))
|
2016-03-03 08:06:43 +01:00
|
|
|
gulp.task('copy:reload', copyTask({
|
2016-04-14 00:28:44 +02:00
|
|
|
source: './app/scripts/',
|
2016-07-28 21:59:37 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox/scripts',
|
|
|
|
'./dist/chrome/scripts',
|
2016-08-07 22:36:02 +02:00
|
|
|
'./dist/edge/scripts',
|
2017-01-03 20:23:27 +01:00
|
|
|
'./dist/opera/scripts',
|
2016-07-28 21:59:37 +02:00
|
|
|
],
|
2016-03-03 08:06:43 +01:00
|
|
|
pattern: '/chromereload.js',
|
|
|
|
}))
|
|
|
|
gulp.task('copy:root', copyTask({
|
|
|
|
source: './app/',
|
2016-07-28 21:59:37 +02:00
|
|
|
destinations: [
|
|
|
|
'./dist/firefox',
|
|
|
|
'./dist/chrome',
|
2016-08-07 22:36:02 +02:00
|
|
|
'./dist/edge',
|
2017-01-03 20:23:27 +01:00
|
|
|
'./dist/opera',
|
2016-07-28 21:59:37 +02:00
|
|
|
],
|
2016-03-03 08:06:43 +01:00
|
|
|
pattern: '/*',
|
|
|
|
}))
|
2016-07-28 21:59:37 +02:00
|
|
|
|
2016-09-02 00:01:45 +02:00
|
|
|
gulp.task('manifest:chrome', function() {
|
|
|
|
return gulp.src('./dist/chrome/manifest.json')
|
2016-07-27 00:15:40 +02:00
|
|
|
.pipe(jsoneditor(function(json) {
|
|
|
|
delete json.applications
|
|
|
|
return json
|
|
|
|
}))
|
2016-07-27 01:48:48 +02:00
|
|
|
.pipe(gulp.dest('./dist/chrome', { overwrite: true }))
|
2016-07-27 00:15:40 +02:00
|
|
|
})
|
2016-07-28 21:59:37 +02:00
|
|
|
|
2017-01-03 20:23:27 +01:00
|
|
|
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 }))
|
|
|
|
})
|
|
|
|
|
2016-09-02 00:19:31 +02:00
|
|
|
gulp.task('manifest:production', function() {
|
|
|
|
return gulp.src([
|
|
|
|
'./dist/firefox/manifest.json',
|
|
|
|
'./dist/chrome/manifest.json',
|
|
|
|
'./dist/edge/manifest.json',
|
2017-11-22 00:19:10 +01:00
|
|
|
'./dist/opera/manifest.json',
|
2016-09-02 00:19:31 +02:00
|
|
|
],{base: './dist/'})
|
2017-11-22 00:19:10 +01:00
|
|
|
|
|
|
|
// Exclude chromereload script in production:
|
2017-06-26 20:37:12 +02:00
|
|
|
.pipe(gulpif(!debug,jsoneditor(function(json) {
|
2017-11-22 00:19:10 +01:00
|
|
|
json.background.scripts = json.background.scripts.filter((script) => {
|
|
|
|
return !script.includes('chromereload')
|
|
|
|
})
|
2016-09-02 00:19:31 +02:00
|
|
|
return json
|
|
|
|
})))
|
2017-11-22 00:19:10 +01:00
|
|
|
|
2016-09-02 00:19:31 +02:00
|
|
|
.pipe(gulp.dest('./dist/', { overwrite: true }))
|
|
|
|
})
|
|
|
|
|
2016-09-02 23:00:36 +02:00
|
|
|
const staticFiles = [
|
|
|
|
'locales',
|
|
|
|
'images',
|
|
|
|
'fonts',
|
|
|
|
'root'
|
|
|
|
]
|
|
|
|
|
|
|
|
var copyStrings = staticFiles.map(staticFile => `copy:${staticFile}`)
|
2017-05-26 09:19:24 +02:00
|
|
|
copyStrings.push('copy:contractImages')
|
2016-09-02 23:00:36 +02:00
|
|
|
|
2017-06-26 20:37:12 +02:00
|
|
|
if (debug) {
|
2016-09-02 23:15:00 +02:00
|
|
|
copyStrings.push('copy:reload')
|
2016-09-02 23:00:36 +02:00
|
|
|
}
|
|
|
|
|
2017-01-03 20:23:27 +01:00
|
|
|
gulp.task('copy', gulp.series(gulp.parallel(...copyStrings), 'manifest:production', 'manifest:chrome', 'manifest:opera'))
|
2016-03-03 08:06:43 +01:00
|
|
|
gulp.task('copy:watch', function(){
|
2016-06-14 21:43:55 +02:00
|
|
|
gulp.watch(['./app/{_locales,images}/*', './app/scripts/chromereload.js', './app/*.{html,json}'], gulp.series('copy'))
|
2016-03-03 08:06:43 +01:00
|
|
|
})
|
|
|
|
|
2018-01-10 22:54:29 +01:00
|
|
|
// 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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-06-21 21:07:13 +02:00
|
|
|
// lint js
|
|
|
|
|
|
|
|
gulp.task('lint', function () {
|
2016-07-27 00:15:40 +02:00
|
|
|
// Ignoring node_modules, dist/firefox, and docs folders:
|
2018-01-18 00:45:36 +01:00
|
|
|
return gulp.src(['app/**/*.js', '!app/scripts/vendor/**/*.js', 'ui/**/*.js', 'mascara/src/*.js', 'mascara/server/*.js', '!node_modules/**', '!dist/firefox/**', '!docs/**', '!app/scripts/chromereload.js', '!mascara/test/jquery-3.1.0.min.js'])
|
2016-06-21 21:40:09 +02:00
|
|
|
.pipe(eslint(fs.readFileSync(path.join(__dirname, '.eslintrc'))))
|
2016-06-21 21:07:13 +02:00
|
|
|
// eslint.format() outputs the lint results to the console.
|
|
|
|
// Alternatively use eslint.formatEach() (see Docs).
|
|
|
|
.pipe(eslint.format())
|
|
|
|
// To have the process exit with an error code (1) on
|
|
|
|
// lint error, return the stream and pipe to failAfterError last.
|
|
|
|
.pipe(eslint.failAfterError())
|
|
|
|
});
|
|
|
|
|
2017-10-21 21:04:24 +02:00
|
|
|
gulp.task('lint:fix', function () {
|
|
|
|
return gulp.src(['app/**/*.js', 'ui/**/*.js', 'mascara/src/*.js', 'mascara/server/*.js', '!node_modules/**', '!dist/firefox/**', '!docs/**', '!app/scripts/chromereload.js', '!mascara/test/jquery-3.1.0.min.js'])
|
|
|
|
.pipe(eslint(Object.assign(fs.readFileSync(path.join(__dirname, '.eslintrc')), {fix: true})))
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError())
|
|
|
|
});
|
|
|
|
|
2016-06-21 21:07:13 +02:00
|
|
|
/*
|
|
|
|
gulp.task('default', ['lint'], function () {
|
|
|
|
// This will only run if the lint task is successful...
|
|
|
|
});
|
|
|
|
*/
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
// build js
|
|
|
|
|
2016-07-28 19:50:14 +02:00
|
|
|
const jsFiles = [
|
|
|
|
'inpage',
|
|
|
|
'contentscript',
|
|
|
|
'background',
|
|
|
|
'popup',
|
|
|
|
]
|
|
|
|
|
2017-08-06 21:29:26 +02:00
|
|
|
// scss compilation and autoprefixing tasks
|
2016-07-28 19:50:14 +02:00
|
|
|
|
2017-08-06 21:09:17 +02:00
|
|
|
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())
|
2017-08-06 21:29:26 +02:00
|
|
|
.pipe(gulp.dest('ui/app/css/output'))
|
2017-08-06 22:44:50 +02:00
|
|
|
})
|
2017-08-14 10:03:16 +02:00
|
|
|
gulp.task('watch:scss', function() {
|
2017-08-06 22:44:50 +02:00
|
|
|
gulp.watch(['ui/app/css/**/*.scss'], gulp.series(['build:scss']))
|
|
|
|
})
|
2017-08-06 21:09:17 +02:00
|
|
|
|
2017-08-14 10:03:16 +02:00
|
|
|
gulp.task('lint-scss', function() {
|
|
|
|
return gulp
|
|
|
|
.src('ui/app/css/itcss/**/*.scss')
|
|
|
|
.pipe(gulpStylelint({
|
|
|
|
reporters: [
|
|
|
|
{formatter: 'string', console: true}
|
2017-08-29 17:39:47 +02:00
|
|
|
],
|
|
|
|
fix: true,
|
2017-08-14 10:03:16 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('fmt-scss', function () {
|
|
|
|
return gulp.src('ui/app/css/itcss/**/*.scss')
|
|
|
|
.pipe(stylefmt())
|
|
|
|
.pipe(gulp.dest('ui/app/css/itcss'));
|
|
|
|
});
|
|
|
|
|
2017-01-10 22:46:15 +01:00
|
|
|
// bundle tasks
|
|
|
|
|
2016-09-02 23:00:36 +02:00
|
|
|
var jsDevStrings = jsFiles.map(jsFile => `dev:js:${jsFile}`)
|
|
|
|
var jsBuildStrings = jsFiles.map(jsFile => `build:js:${jsFile}`)
|
|
|
|
|
2016-07-28 19:50:14 +02:00
|
|
|
jsFiles.forEach((jsFile) => {
|
2018-01-16 04:00:07 +01:00
|
|
|
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
|
|
|
|
}))
|
2016-07-28 19:50:14 +02:00
|
|
|
})
|
|
|
|
|
2017-10-12 20:03:42 +02:00
|
|
|
// inpage must be built before all other scripts:
|
|
|
|
const firstDevString = jsDevStrings.shift()
|
|
|
|
gulp.task('dev:js', gulp.series(firstDevString, gulp.parallel(...jsDevStrings)))
|
|
|
|
|
|
|
|
// inpage must be built before all other scripts:
|
|
|
|
const firstBuildString = jsBuildStrings.shift()
|
|
|
|
gulp.task('build:js', gulp.series(firstBuildString, gulp.parallel(...jsBuildStrings)))
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2017-01-10 22:46:15 +01:00
|
|
|
// disc bundle analyzer tasks
|
|
|
|
|
|
|
|
jsFiles.forEach((jsFile) => {
|
2017-05-08 21:30:47 +02:00
|
|
|
gulp.task(`disc:${jsFile}`, discTask({ label: jsFile, filename: `${jsFile}.js` }))
|
2017-01-10 22:46:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`)))
|
|
|
|
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2016-07-27 02:25:15 +02:00
|
|
|
// clean dist
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
gulp.task('clean', function clean() {
|
2016-07-27 00:15:40 +02:00
|
|
|
return del(['./dist/*'])
|
2016-03-03 08:06:43 +01:00
|
|
|
})
|
|
|
|
|
2016-07-27 00:15:40 +02:00
|
|
|
// zip tasks for distribution
|
2017-01-10 22:08:13 +01:00
|
|
|
gulp.task('zip:chrome', zipTask('chrome'))
|
|
|
|
gulp.task('zip:firefox', zipTask('firefox'))
|
|
|
|
gulp.task('zip:edge', zipTask('edge'))
|
|
|
|
gulp.task('zip:opera', zipTask('opera'))
|
2017-01-03 20:23:27 +01:00
|
|
|
gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge', 'zip:opera'))
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2018-01-16 04:00:07 +01:00
|
|
|
// set env var for production
|
|
|
|
gulp.task('apply-prod-environment', function(done) {
|
|
|
|
process.env.NODE_ENV = 'production'
|
|
|
|
done()
|
|
|
|
});
|
|
|
|
|
2016-03-03 08:06:43 +01:00
|
|
|
// high level tasks
|
|
|
|
|
2017-08-06 22:44:50 +02:00
|
|
|
gulp.task('dev', gulp.series('build:scss', 'dev:js', 'copy', gulp.parallel('watch:scss', 'copy:watch', 'dev:reload')))
|
2016-09-02 23:00:36 +02:00
|
|
|
|
2018-02-07 21:02:47 +01:00
|
|
|
gulp.task('build', gulp.series('clean', 'build:scss', gulp.parallel('build:js', 'copy')))
|
2018-01-16 04:00:07 +01:00
|
|
|
gulp.task('dist', gulp.series('apply-prod-environment', 'build', 'zip'))
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
// task generators
|
|
|
|
|
|
|
|
function copyTask(opts){
|
|
|
|
var source = opts.source
|
|
|
|
var destination = opts.destination
|
2016-07-28 21:59:37 +02:00
|
|
|
var destinations = opts.destinations || [ destination ]
|
2016-03-03 08:06:43 +01:00
|
|
|
var pattern = opts.pattern || '/**/*'
|
|
|
|
|
|
|
|
return performCopy
|
|
|
|
|
|
|
|
function performCopy(){
|
2016-07-28 21:59:37 +02:00
|
|
|
let stream = gulp.src(source + pattern, { base: source })
|
|
|
|
destinations.forEach(function(destination) {
|
|
|
|
stream = stream.pipe(gulp.dest(destination))
|
|
|
|
})
|
2017-06-26 20:37:12 +02:00
|
|
|
stream.pipe(gulpif(debug,livereload()))
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2016-07-28 21:59:37 +02:00
|
|
|
return stream
|
2016-03-03 08:06:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-10 22:08:13 +01:00
|
|
|
function zipTask(target) {
|
|
|
|
return () => {
|
|
|
|
return gulp.src(`dist/${target}/**`)
|
|
|
|
.pipe(zip(`metamask-${target}-${manifest.version}.zip`))
|
2017-08-06 22:44:50 +02:00
|
|
|
.pipe(gulp.dest('builds'))
|
2017-01-10 22:08:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 02:53:34 +02:00
|
|
|
function generateBundler(opts, performBundle) {
|
|
|
|
const browserifyOpts = assign({}, watchify.args, {
|
2016-03-03 08:06:43 +01:00
|
|
|
entries: ['./app/scripts/'+opts.filename],
|
2016-04-20 22:22:41 +02:00
|
|
|
plugin: 'browserify-derequire',
|
2017-01-10 22:08:13 +01:00
|
|
|
debug: debug,
|
|
|
|
fullPaths: debug,
|
2016-03-03 08:06:43 +01:00
|
|
|
})
|
|
|
|
|
2017-08-09 02:53:34 +02:00
|
|
|
let bundler = browserify(browserifyOpts)
|
2017-01-10 22:46:15 +01:00
|
|
|
|
|
|
|
if (opts.watch) {
|
|
|
|
bundler = watchify(bundler)
|
2017-08-09 02:53:34 +02:00
|
|
|
// on any file update, re-runs the bundler
|
2017-01-10 22:56:31 +01:00
|
|
|
bundler.on('update', performBundle)
|
2017-01-10 22:46:15 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 02:53:34 +02:00
|
|
|
return bundler
|
|
|
|
}
|
|
|
|
|
|
|
|
function discTask(opts) {
|
|
|
|
const bundler = generateBundler(opts, performBundle)
|
2017-01-10 22:56:31 +01:00
|
|
|
// output build logs to terminal
|
|
|
|
bundler.on('log', gutil.log)
|
2017-01-10 22:46:15 +01:00
|
|
|
|
|
|
|
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) {
|
2017-08-09 02:53:34 +02:00
|
|
|
const bundler = generateBundler(opts, performBundle)
|
2017-01-10 22:56:31 +01:00
|
|
|
// output build logs to terminal
|
|
|
|
bundler.on('log', gutil.log)
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
return performBundle
|
|
|
|
|
|
|
|
function performBundle(){
|
|
|
|
return (
|
|
|
|
|
|
|
|
bundler.bundle()
|
2017-08-09 02:46:31 +02:00
|
|
|
|
|
|
|
// handle errors
|
|
|
|
.on('error', (err) => {
|
|
|
|
beep()
|
|
|
|
if (opts.watch) {
|
|
|
|
console.warn(err.stack)
|
|
|
|
} else {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
})
|
2017-01-10 22:56:31 +01:00
|
|
|
// convert bundle stream to gulp vinyl stream
|
2016-03-03 08:06:43 +01:00
|
|
|
.pipe(source(opts.filename))
|
2017-01-10 22:56:31 +01:00
|
|
|
// inject variables into bundle
|
2016-10-11 23:32:03 +02:00
|
|
|
.pipe(replace('\'GULP_METAMASK_DEBUG\'', debug))
|
2017-01-10 22:56:31 +01:00
|
|
|
// buffer file contents (?)
|
2016-03-03 08:06:43 +01:00
|
|
|
.pipe(buffer())
|
2017-01-10 22:56:31 +01:00
|
|
|
// sourcemaps
|
|
|
|
// loads map from browserify file
|
2017-08-09 02:46:31 +02:00
|
|
|
.pipe(gulpif(debug, sourcemaps.init({ loadMaps: true })))
|
2018-01-12 03:15:22 +01:00
|
|
|
// Minification
|
2018-03-02 19:32:53 +01:00
|
|
|
.pipe(gulpif(opts.isBuild, uglify({
|
|
|
|
mangle: { reserved: [ 'MetamaskInpageProvider' ] },
|
|
|
|
})))
|
2017-01-10 22:56:31 +01:00
|
|
|
// writes .map file
|
2017-06-26 20:37:12 +02:00
|
|
|
.pipe(gulpif(debug, sourcemaps.write('./')))
|
2017-01-10 22:56:31 +01:00
|
|
|
// write completed bundles
|
2016-07-27 00:15:40 +02:00
|
|
|
.pipe(gulp.dest('./dist/firefox/scripts'))
|
2016-07-28 19:50:14 +02:00
|
|
|
.pipe(gulp.dest('./dist/chrome/scripts'))
|
2016-08-07 22:36:02 +02:00
|
|
|
.pipe(gulp.dest('./dist/edge/scripts'))
|
2017-01-03 20:23:27 +01:00
|
|
|
.pipe(gulp.dest('./dist/opera/scripts'))
|
2017-01-10 22:56:31 +01:00
|
|
|
// finally, trigger live reload
|
2017-06-26 20:37:12 +02:00
|
|
|
.pipe(gulpif(debug, livereload()))
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-08-09 02:46:31 +02:00
|
|
|
|
|
|
|
function beep () {
|
|
|
|
process.stdout.write('\x07')
|
|
|
|
}
|