2018-03-29 05:13:47 +02:00
|
|
|
const watchify = require('watchify')
|
|
|
|
const browserify = require('browserify')
|
2018-04-03 18:51:33 +02:00
|
|
|
const envify = require('envify/custom')
|
2018-03-29 05:13:47 +02:00
|
|
|
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 fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const manifest = require('./app/manifest.json')
|
|
|
|
const mkdirp = require('mkdirp')
|
|
|
|
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
|
2018-03-30 07:19:15 +02:00
|
|
|
const pify = require('pify')
|
2018-03-31 07:19:02 +02:00
|
|
|
const gulpMultiProcess = require('gulp-multi-process')
|
2018-03-30 07:19:15 +02:00
|
|
|
const endOfStream = pify(require('end-of-stream'))
|
2018-03-29 05:13:47 +02:00
|
|
|
|
2018-03-31 07:19:02 +02:00
|
|
|
function gulpParallel (...args) {
|
2018-07-03 00:49:33 +02:00
|
|
|
return function spawnGulpChildProcess (cb) {
|
2018-03-31 07:19:02 +02:00
|
|
|
return gulpMultiProcess(args, cb, true)
|
|
|
|
}
|
|
|
|
}
|
2016-09-02 00:19:31 +02:00
|
|
|
|
2018-03-29 04:56:44 +02:00
|
|
|
const browserPlatforms = [
|
2018-03-28 23:07:32 +02:00
|
|
|
'firefox',
|
|
|
|
'chrome',
|
|
|
|
'edge',
|
|
|
|
'opera',
|
2018-03-29 04:56:44 +02:00
|
|
|
]
|
|
|
|
const commonPlatforms = [
|
2018-03-28 23:07:32 +02:00
|
|
|
// browser webapp
|
|
|
|
'mascara',
|
2018-03-29 04:56:44 +02:00
|
|
|
// browser extensions
|
2018-07-03 00:49:33 +02:00
|
|
|
...browserPlatforms,
|
2018-03-28 23:07:32 +02:00
|
|
|
]
|
2017-08-14 10:03:16 +02:00
|
|
|
|
2016-03-03 08:06:43 +01:00
|
|
|
// browser reload
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
gulp.task('dev:reload', function () {
|
2016-03-03 08:06:43 +01:00
|
|
|
livereload.listen({
|
|
|
|
port: 35729,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-03-29 04:56:44 +02:00
|
|
|
// copy universal
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2018-03-29 08:11:07 +02:00
|
|
|
const copyTaskNames = []
|
|
|
|
const copyDevTaskNames = []
|
|
|
|
|
|
|
|
createCopyTasks('locales', {
|
2016-03-03 08:06:43 +01:00
|
|
|
source: './app/_locales/',
|
2018-03-28 23:07:32 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}/_locales`),
|
2018-03-29 08:11:07 +02:00
|
|
|
})
|
|
|
|
createCopyTasks('images', {
|
2016-03-03 08:06:43 +01:00
|
|
|
source: './app/images/',
|
2018-03-28 23:07:32 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}/images`),
|
2018-03-29 08:11:07 +02:00
|
|
|
})
|
|
|
|
createCopyTasks('contractImages', {
|
2018-03-30 07:34:59 +02:00
|
|
|
source: './node_modules/eth-contract-metadata/images/',
|
2018-03-28 23:07:32 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}/images/contract`),
|
2018-03-29 08:11:07 +02:00
|
|
|
})
|
|
|
|
createCopyTasks('fonts', {
|
2016-05-11 01:51:49 +02:00
|
|
|
source: './app/fonts/',
|
2018-03-28 23:07:32 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`),
|
2018-03-29 08:11:07 +02:00
|
|
|
})
|
|
|
|
createCopyTasks('reload', {
|
|
|
|
devOnly: true,
|
2016-04-14 00:28:44 +02:00
|
|
|
source: './app/scripts/',
|
2016-03-03 08:06:43 +01:00
|
|
|
pattern: '/chromereload.js',
|
2018-03-29 05:54:59 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}`),
|
2018-03-29 08:11:07 +02:00
|
|
|
})
|
|
|
|
createCopyTasks('html', {
|
|
|
|
source: './app/',
|
2018-03-29 05:54:59 +02:00
|
|
|
pattern: '/*.html',
|
2018-03-29 08:11:07 +02:00
|
|
|
destinations: commonPlatforms.map(platform => `./dist/${platform}`),
|
|
|
|
})
|
2018-03-29 04:56:44 +02:00
|
|
|
|
|
|
|
// copy extension
|
|
|
|
|
2018-03-29 08:11:07 +02:00
|
|
|
createCopyTasks('manifest', {
|
2018-03-29 04:56:44 +02:00
|
|
|
source: './app/',
|
|
|
|
pattern: '/*.json',
|
2018-03-29 08:11:07 +02:00
|
|
|
destinations: browserPlatforms.map(platform => `./dist/${platform}`),
|
|
|
|
})
|
2018-03-29 05:54:59 +02:00
|
|
|
|
|
|
|
// copy mascara
|
|
|
|
|
2018-03-29 08:11:07 +02:00
|
|
|
createCopyTasks('html:mascara', {
|
2018-03-29 05:54:59 +02:00
|
|
|
source: './mascara/',
|
|
|
|
pattern: 'proxy/index.html',
|
2018-03-29 08:11:07 +02:00
|
|
|
destinations: [`./dist/mascara/`],
|
|
|
|
})
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function createCopyTasks (label, opts) {
|
2018-03-29 08:11:07 +02:00
|
|
|
if (!opts.devOnly) {
|
|
|
|
const copyTaskName = `copy:${label}`
|
|
|
|
copyTask(copyTaskName, opts)
|
|
|
|
copyTaskNames.push(copyTaskName)
|
|
|
|
}
|
2018-03-30 06:28:35 +02:00
|
|
|
const copyDevTaskName = `dev:copy:${label}`
|
2018-03-29 08:11:07 +02:00
|
|
|
copyTask(copyDevTaskName, Object.assign({ devMode: true }, opts))
|
|
|
|
copyDevTaskNames.push(copyDevTaskName)
|
|
|
|
}
|
2016-07-28 21:59:37 +02:00
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function copyTask (taskName, opts) {
|
2018-03-30 06:53:38 +02:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function performCopy () {
|
2018-03-30 06:53:38 +02:00
|
|
|
// stream from source
|
|
|
|
let stream = gulp.src(source + pattern, { base: source })
|
|
|
|
|
|
|
|
// copy to destinations
|
2018-07-03 00:49:33 +02:00
|
|
|
destinations.forEach(function (destination) {
|
2018-03-30 06:53:38 +02:00
|
|
|
stream = stream.pipe(gulp.dest(destination))
|
|
|
|
})
|
|
|
|
|
|
|
|
return stream
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 04:56:44 +02:00
|
|
|
// manifest tinkering
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
gulp.task('manifest:chrome', function () {
|
2016-09-02 00:01:45 +02:00
|
|
|
return gulp.src('./dist/chrome/manifest.json')
|
2018-07-03 00:49:33 +02:00
|
|
|
.pipe(jsoneditor(function (json) {
|
2016-07-27 00:15:40 +02:00
|
|
|
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
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
gulp.task('manifest:opera', function () {
|
2017-01-03 20:23:27 +01:00
|
|
|
return gulp.src('./dist/opera/manifest.json')
|
2018-07-03 00:49:33 +02:00
|
|
|
.pipe(jsoneditor(function (json) {
|
2017-01-03 20:23:27 +01:00
|
|
|
json.permissions = [
|
2018-07-03 00:49:33 +02:00
|
|
|
'storage',
|
|
|
|
'tabs',
|
|
|
|
'clipboardWrite',
|
|
|
|
'clipboardRead',
|
|
|
|
'http://localhost:8545/',
|
2017-01-03 20:23:27 +01:00
|
|
|
]
|
|
|
|
return json
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./dist/opera', { overwrite: true }))
|
|
|
|
})
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
gulp.task('manifest:production', function () {
|
2016-09-02 00:19:31 +02:00
|
|
|
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',
|
2018-07-03 00:49:33 +02:00
|
|
|
], {base: './dist/'})
|
2017-11-22 00:19:10 +01:00
|
|
|
|
|
|
|
// Exclude chromereload script in production:
|
2018-07-03 00:49:33 +02:00
|
|
|
.pipe(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
|
2018-03-31 00:09:25 +02:00
|
|
|
}))
|
2017-11-22 00:19:10 +01:00
|
|
|
|
2016-09-02 00:19:31 +02:00
|
|
|
.pipe(gulp.dest('./dist/', { overwrite: true }))
|
|
|
|
})
|
|
|
|
|
2018-03-29 04:56:44 +02:00
|
|
|
gulp.task('copy',
|
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(...copyTaskNames),
|
|
|
|
'manifest:production',
|
|
|
|
'manifest:chrome',
|
|
|
|
'manifest:opera'
|
|
|
|
)
|
|
|
|
)
|
2018-03-29 08:11:07 +02:00
|
|
|
|
2018-03-30 06:28:35 +02:00
|
|
|
gulp.task('dev:copy',
|
2018-03-29 08:11:07 +02:00
|
|
|
gulp.series(
|
|
|
|
gulp.parallel(...copyDevTaskNames),
|
|
|
|
'manifest:chrome',
|
|
|
|
'manifest:opera'
|
|
|
|
)
|
|
|
|
)
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2017-08-06 21:29:26 +02:00
|
|
|
// scss compilation and autoprefixing tasks
|
2016-07-28 19:50:14 +02:00
|
|
|
|
2018-03-30 06:28:35 +02:00
|
|
|
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,
|
2018-04-22 09:14:40 +02:00
|
|
|
pattern: 'ui/app/**/*.scss',
|
2018-03-30 06:28:35 +02:00
|
|
|
}))
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function createScssBuildTask ({ src, dest, devMode, pattern }) {
|
2018-03-30 06:28:35 +02:00
|
|
|
return function () {
|
|
|
|
if (devMode) {
|
2018-03-30 07:19:15 +02:00
|
|
|
watch(pattern, async (event) => {
|
|
|
|
const stream = buildScss()
|
|
|
|
await endOfStream(stream)
|
|
|
|
livereload.changed(event.path)
|
|
|
|
})
|
2018-09-26 02:40:55 +02:00
|
|
|
return buildScssWithSourceMaps()
|
2018-03-30 06:28:35 +02:00
|
|
|
}
|
|
|
|
return buildScss()
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:40:55 +02:00
|
|
|
function buildScssWithSourceMaps () {
|
2018-03-30 06:28:35 +02:00
|
|
|
return gulp.src(src)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(sass().on('error', sass.logError))
|
|
|
|
.pipe(sourcemaps.write())
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
}
|
2018-09-26 02:40:55 +02:00
|
|
|
|
|
|
|
function buildScss () {
|
|
|
|
return gulp.src(src)
|
|
|
|
.pipe(sass().on('error', sass.logError))
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
}
|
2018-03-30 06:28:35 +02:00
|
|
|
}
|
2017-08-06 21:09:17 +02:00
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
gulp.task('lint-scss', function () {
|
2017-08-14 10:03:16 +02:00
|
|
|
return gulp
|
|
|
|
.src('ui/app/css/itcss/**/*.scss')
|
|
|
|
.pipe(gulpStylelint({
|
|
|
|
reporters: [
|
2018-07-03 00:49:33 +02:00
|
|
|
{ formatter: 'string', console: true },
|
2017-08-29 17:39:47 +02:00
|
|
|
],
|
|
|
|
fix: true,
|
2018-07-03 00:49:33 +02:00
|
|
|
}))
|
|
|
|
})
|
2017-08-14 10:03:16 +02:00
|
|
|
|
|
|
|
gulp.task('fmt-scss', function () {
|
|
|
|
return gulp.src('ui/app/css/itcss/**/*.scss')
|
|
|
|
.pipe(stylefmt())
|
2018-07-03 00:49:33 +02:00
|
|
|
.pipe(gulp.dest('ui/app/css/itcss'))
|
|
|
|
})
|
2017-08-14 10:03:16 +02:00
|
|
|
|
2018-03-29 05:41:56 +02:00
|
|
|
// build js
|
|
|
|
|
|
|
|
const buildJsFiles = [
|
|
|
|
'inpage',
|
|
|
|
'contentscript',
|
|
|
|
'background',
|
|
|
|
'ui',
|
|
|
|
]
|
|
|
|
|
2017-01-10 22:46:15 +01:00
|
|
|
// bundle tasks
|
2018-03-30 07:34:59 +02:00
|
|
|
createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'dev:extension:js', devMode: true })
|
2018-07-03 00:49:33 +02:00
|
|
|
createTasksForBuildJsExtension({ buildJsFiles, taskPrefix: 'build:extension:js' })
|
2018-03-30 07:34:59 +02:00
|
|
|
createTasksForBuildJsMascara({ taskPrefix: 'build:mascara:js' })
|
|
|
|
createTasksForBuildJsMascara({ taskPrefix: 'dev:mascara:js', devMode: true })
|
2018-03-28 23:07:32 +02:00
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function createTasksForBuildJsExtension ({ buildJsFiles, taskPrefix, devMode, bundleTaskOpts = {} }) {
|
2018-03-28 23:07:32 +02:00
|
|
|
// inpage must be built before all other scripts:
|
|
|
|
const rootDir = './app/scripts'
|
2018-03-29 05:41:56 +02:00
|
|
|
const nonInpageFiles = buildJsFiles.filter(file => file !== 'inpage')
|
2018-03-28 23:07:32 +02:00
|
|
|
const buildPhase1 = ['inpage']
|
|
|
|
const buildPhase2 = nonInpageFiles
|
2018-03-29 06:29:57 +02:00
|
|
|
const destinations = browserPlatforms.map(platform => `./dist/${platform}`)
|
2018-03-29 05:41:56 +02:00
|
|
|
bundleTaskOpts = Object.assign({
|
|
|
|
buildSourceMaps: true,
|
2018-03-29 06:29:57 +02:00
|
|
|
sourceMapDir: devMode ? './' : '../sourcemaps',
|
2018-03-29 05:41:56 +02:00
|
|
|
minifyBuild: !devMode,
|
|
|
|
buildWithFullPaths: devMode,
|
2018-03-30 02:34:30 +02:00
|
|
|
watch: devMode,
|
2018-03-31 00:09:25 +02:00
|
|
|
devMode,
|
2018-03-29 05:41:56 +02:00
|
|
|
}, bundleTaskOpts)
|
|
|
|
createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1, buildPhase2 })
|
2018-03-28 23:07:32 +02:00
|
|
|
}
|
2017-01-10 22:46:15 +01:00
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function createTasksForBuildJsMascara ({ taskPrefix, devMode, bundleTaskOpts = {} }) {
|
2018-03-28 23:07:32 +02:00
|
|
|
// inpage must be built before all other scripts:
|
|
|
|
const rootDir = './mascara/src/'
|
2018-03-30 08:06:01 +02:00
|
|
|
const buildPhase1 = ['ui', 'proxy', 'background', 'metamascara']
|
2018-03-29 04:56:44 +02:00
|
|
|
const destinations = ['./dist/mascara']
|
2018-03-29 05:41:56 +02:00
|
|
|
bundleTaskOpts = Object.assign({
|
|
|
|
buildSourceMaps: true,
|
|
|
|
sourceMapDir: './',
|
|
|
|
minifyBuild: !devMode,
|
|
|
|
buildWithFullPaths: devMode,
|
2018-03-30 02:34:30 +02:00
|
|
|
watch: devMode,
|
2018-03-31 00:09:25 +02:00
|
|
|
devMode,
|
2018-03-29 05:41:56 +02:00
|
|
|
}, bundleTaskOpts)
|
|
|
|
createTasksForBuildJs({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1 })
|
2018-03-28 23:07:32 +02:00
|
|
|
}
|
2016-07-28 19:50:14 +02:00
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function createTasksForBuildJs ({ rootDir, taskPrefix, bundleTaskOpts, destinations, buildPhase1 = [], buildPhase2 = [] }) {
|
2018-03-28 23:07:32 +02:00
|
|
|
// bundle task for each file
|
2018-03-29 05:41:56 +02:00
|
|
|
const jsFiles = [].concat(buildPhase1, buildPhase2)
|
2018-03-28 23:07:32 +02:00
|
|
|
jsFiles.forEach((jsFile) => {
|
|
|
|
gulp.task(`${taskPrefix}:${jsFile}`, bundleTask(Object.assign({
|
|
|
|
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}`)))
|
2017-10-12 20:03:42 +02:00
|
|
|
|
2018-03-30 02:37:49 +02:00
|
|
|
gulp.task(taskPrefix, gulp.series(subtasks))
|
2018-03-28 23:07:32 +02:00
|
|
|
}
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2017-01-10 22:46:15 +01:00
|
|
|
// disc bundle analyzer tasks
|
|
|
|
|
2018-03-29 05:41:56 +02:00
|
|
|
buildJsFiles.forEach((jsFile) => {
|
|
|
|
gulp.task(`disc:${jsFile}`, discTask({ label: jsFile, filename: `${jsFile}.js` }))
|
2017-01-10 22:46:15 +01:00
|
|
|
})
|
|
|
|
|
2018-03-29 05:41:56 +02:00
|
|
|
gulp.task('disc', gulp.parallel(buildJsFiles.map(jsFile => `disc:${jsFile}`)))
|
2017-01-10 22:46:15 +01:00
|
|
|
|
2016-07-27 02:25:15 +02:00
|
|
|
// clean dist
|
2016-03-03 08:06:43 +01:00
|
|
|
|
2018-07-03 00:49:33 +02: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
|
|
|
|
|
|
|
// high level tasks
|
|
|
|
|
2018-03-28 23:07:32 +02:00
|
|
|
gulp.task('dev',
|
|
|
|
gulp.series(
|
2018-03-30 06:28:35 +02:00
|
|
|
'clean',
|
|
|
|
'dev:scss',
|
2018-03-28 23:07:32 +02:00
|
|
|
gulp.parallel(
|
2018-03-30 07:34:59 +02:00
|
|
|
'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',
|
2018-03-30 06:28:35 +02:00
|
|
|
'dev:copy',
|
2018-03-28 23:07:32 +02:00
|
|
|
'dev:reload'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
gulp.task('build',
|
|
|
|
gulp.series(
|
|
|
|
'clean',
|
|
|
|
'build:scss',
|
2018-03-31 07:19:02 +02:00
|
|
|
gulpParallel(
|
2018-03-30 07:34:59 +02:00
|
|
|
'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',
|
2018-03-28 23:07:32 +02:00
|
|
|
'copy'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2016-09-02 23:00:36 +02:00
|
|
|
|
2018-03-28 23:07:32 +02:00
|
|
|
gulp.task('dist',
|
|
|
|
gulp.series(
|
|
|
|
'build',
|
|
|
|
'zip'
|
|
|
|
)
|
|
|
|
)
|
2016-03-03 08:06:43 +01:00
|
|
|
|
|
|
|
// task generators
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function zipTask (target) {
|
2017-01-10 22:08:13 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function generateBundler (opts, performBundle) {
|
2017-08-09 02:53:34 +02:00
|
|
|
const browserifyOpts = assign({}, watchify.args, {
|
2018-03-28 23:07:32 +02:00
|
|
|
entries: [opts.filepath],
|
2016-04-20 22:22:41 +02:00
|
|
|
plugin: 'browserify-derequire',
|
2018-03-29 05:41:56 +02:00
|
|
|
debug: opts.buildSourceMaps,
|
|
|
|
fullPaths: opts.buildWithFullPaths,
|
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
|
|
|
|
2018-04-03 18:51:33 +02:00
|
|
|
// inject variables into bundle
|
|
|
|
bundler.transform(envify({
|
|
|
|
METAMASK_DEBUG: opts.devMode,
|
|
|
|
NODE_ENV: opts.devMode ? 'development' : 'production',
|
|
|
|
}))
|
|
|
|
|
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
|
2018-03-30 07:19:15 +02:00
|
|
|
bundler.on('update', async (ids) => {
|
|
|
|
const stream = performBundle()
|
|
|
|
await endOfStream(stream)
|
|
|
|
livereload.changed(`${ids}`)
|
|
|
|
})
|
2017-01-10 22:46:15 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 02:53:34 +02:00
|
|
|
return bundler
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function discTask (opts) {
|
2018-03-29 05:41:56 +02:00
|
|
|
opts = Object.assign({
|
|
|
|
buildWithFullPaths: true,
|
|
|
|
}, 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)
|
2017-01-10 22:46:15 +01:00
|
|
|
|
|
|
|
return performBundle
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function performBundle () {
|
2017-01-10 22:46:15 +01:00
|
|
|
// start "disc" build
|
2018-03-29 05:41:56 +02:00
|
|
|
const discDir = path.join(__dirname, 'disc')
|
2017-01-10 22:46:15 +01:00
|
|
|
mkdirp.sync(discDir)
|
2018-03-29 05:41:56 +02:00
|
|
|
const discPath = path.join(discDir, `${opts.label}.html`)
|
2017-01-10 22:46:15 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
bundler.bundle()
|
|
|
|
.pipe(disc())
|
|
|
|
.pipe(fs.createWriteStream(discPath))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
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
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function performBundle () {
|
2018-03-28 23:07:32 +02:00
|
|
|
let buildStream = bundler.bundle()
|
|
|
|
|
|
|
|
// handle errors
|
|
|
|
buildStream.on('error', (err) => {
|
|
|
|
beep()
|
|
|
|
if (opts.watch) {
|
|
|
|
console.warn(err.stack)
|
|
|
|
} else {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
})
|
2017-08-09 02:46:31 +02:00
|
|
|
|
2018-03-28 23:07:32 +02:00
|
|
|
// process bundles
|
|
|
|
buildStream = buildStream
|
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
|
|
|
// buffer file contents (?)
|
2016-03-03 08:06:43 +01:00
|
|
|
.pipe(buffer())
|
2018-03-29 05:41:56 +02:00
|
|
|
|
|
|
|
// Initialize Source Maps
|
|
|
|
if (opts.buildSourceMaps) {
|
|
|
|
buildStream = buildStream
|
|
|
|
// loads map from browserify file
|
|
|
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
|
|
|
}
|
|
|
|
|
2018-04-28 03:15:50 +02:00
|
|
|
// Minification
|
|
|
|
if (opts.minifyBuild) {
|
|
|
|
buildStream = buildStream
|
|
|
|
.pipe(uglify({
|
|
|
|
mangle: {
|
2018-07-03 00:49:33 +02:00
|
|
|
reserved: [ 'MetamaskInpageProvider' ],
|
2018-04-28 03:15:50 +02:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:41:56 +02:00
|
|
|
// Finalize Source Maps (writes .map file)
|
|
|
|
if (opts.buildSourceMaps) {
|
|
|
|
buildStream = buildStream
|
|
|
|
.pipe(sourcemaps.write(opts.sourceMapDir))
|
|
|
|
}
|
2018-03-28 23:07:32 +02:00
|
|
|
|
|
|
|
// write completed bundles
|
|
|
|
opts.destinations.forEach((dest) => {
|
|
|
|
buildStream = buildStream.pipe(gulp.dest(dest))
|
|
|
|
})
|
|
|
|
|
|
|
|
return buildStream
|
|
|
|
|
2016-03-03 08:06:43 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-09 02:46:31 +02:00
|
|
|
|
|
|
|
function beep () {
|
|
|
|
process.stdout.write('\x07')
|
|
|
|
}
|