1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

gulp - add disc bundle analysis task

This commit is contained in:
kumavis 2017-01-10 13:46:15 -08:00
parent 464b7d5814
commit 8e3661555d
3 changed files with 55 additions and 5 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ test/bower_components
package
.DS_Store
builds/
disc/
notes.txt
app/.DS_Store
development/bundle.js

View File

@ -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')
@ -21,6 +22,7 @@ var replace = require('gulp-replace')
var disclaimer = fs.readFileSync(path.join(__dirname, 'USER_AGREEMENT.md')).toString()
var crypto = require('crypto')
var hash = crypto.createHash('sha256')
var mkdirp = require('mkdirp')
hash.update(disclaimer)
var tosHash = hash.digest('hex')
@ -172,18 +174,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, filename: `${jsFile}.js` }))
gulp.task(`build:js:${jsFile}`, bundleTask({ watch: false, filename: `${jsFile}.js` }))
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(`disc:${jsFile}`, bundleTask({ label: jsFile, filename: `${jsFile}.js` }))
})
gulp.task('disc', gulp.parallel(jsFiles.map(jsFile => `disc:${jsFile}`)))
// clean dist
@ -235,7 +246,7 @@ function zipTask(target) {
}
}
function bundleTask(opts) {
function generateBundler(opts) {
var browserifyOpts = assign({}, watchify.args, {
entries: ['./app/scripts/'+opts.filename],
plugin: 'browserify-derequire',
@ -243,7 +254,42 @@ function bundleTask(opts) {
fullPaths: debug,
})
var bundler = browserify(browserifyOpts)
return browserify(browserifyOpts)
}
function discTask(opts) {
let bundler = generateBundler(opts)
if (opts.watch) {
bundler = watchify(bundler)
bundler.on('update', performBundle) // on any dep update, runs the bundler
}
bundler.on('log', gutil.log) // output build logs to terminal
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))
// .once('close', function() {
// console.log(`disc: ${opts.label} build completed.`)
// })
)
}
}
function bundleTask(opts) {
let bundler = generateBundler(opts)
if (opts.watch) {
bundler = watchify(bundler)
bundler.on('update', performBundle) // on any dep update, runs the bundler

View File

@ -8,6 +8,7 @@
"lint": "gulp lint",
"buildCiUnits": "node test/integration/index.js",
"dev": "gulp dev --debug",
"disc": "gulp disc --debug",
"dist": "gulp dist --disableLiveReload",
"test": "npm run fastTest && npm run ci && npm run lint",
"fastTest": "METAMASK_ENV=test mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"",
@ -42,6 +43,7 @@
"copy-to-clipboard": "^2.0.0",
"debounce": "^1.0.0",
"denodeify": "^1.2.1",
"disc": "^1.3.2",
"dnode": "^1.2.2",
"end-of-stream": "^1.1.0",
"ensnare": "^1.0.0",
@ -64,6 +66,7 @@
"menu-droppo": "^1.1.0",
"metamask-logo": "^2.1.2",
"mississippi": "^1.2.0",
"mkdirp": "^0.5.1",
"multiplex": "^6.7.0",
"once": "^1.3.3",
"ping-pong-stream": "^1.0.0",