2014-11-05 19:46:01 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-11-06 22:51:37 +02:00
|
|
|
var path = require('path');
|
|
|
|
|
2014-11-05 19:46:01 +02:00
|
|
|
var del = require('del');
|
|
|
|
var gulp = require('gulp');
|
2014-11-06 22:51:37 +02:00
|
|
|
var browserify = require('browserify');
|
2014-11-05 19:46:01 +02:00
|
|
|
var jshint = require('gulp-jshint');
|
2014-11-06 22:51:37 +02:00
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
var rename = require('gulp-rename');
|
|
|
|
var envify = require('envify/custom');
|
|
|
|
var unreach = require('unreachable-branch-transform');
|
|
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var exorcist = require('exorcist');
|
2014-11-05 19:46:01 +02:00
|
|
|
var bower = require('bower');
|
|
|
|
|
|
|
|
var DEST = './dist/';
|
|
|
|
|
2015-01-07 15:13:29 +02:00
|
|
|
var build = function(src, dst, ugly) {
|
|
|
|
var result = browserify({
|
2014-11-06 22:51:37 +02:00
|
|
|
debug: true,
|
|
|
|
insert_global_vars: false,
|
|
|
|
detectGlobals: false,
|
|
|
|
bundleExternal: false
|
|
|
|
})
|
2014-11-11 11:45:38 +02:00
|
|
|
.require('./' + src + '.js', {expose: 'web3'})
|
2014-11-11 16:47:58 +02:00
|
|
|
.add('./' + src + '.js')
|
2014-11-06 22:51:37 +02:00
|
|
|
.transform('envify', {
|
|
|
|
NODE_ENV: 'build'
|
|
|
|
})
|
2015-01-07 15:13:29 +02:00
|
|
|
.transform('unreachable-branch-transform');
|
|
|
|
|
|
|
|
if (ugly) {
|
|
|
|
result = result.transform('uglifyify', {
|
|
|
|
mangle: false,
|
|
|
|
compress: {
|
|
|
|
dead_code: false,
|
|
|
|
conditionals: true,
|
|
|
|
unused: false,
|
|
|
|
hoist_funs: true,
|
|
|
|
hoist_vars: true,
|
|
|
|
negate_iife: false
|
|
|
|
},
|
|
|
|
beautify: true,
|
|
|
|
warnings: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.bundle()
|
2014-11-11 16:47:58 +02:00
|
|
|
.pipe(exorcist(path.join( DEST, dst + '.js.map')))
|
|
|
|
.pipe(source(dst + '.js'))
|
|
|
|
.pipe(gulp.dest( DEST ));
|
|
|
|
};
|
|
|
|
|
2014-11-11 11:45:38 +02:00
|
|
|
var uglifyFile = function(file) {
|
|
|
|
return gulp.src( DEST + file + '.js')
|
2014-11-05 19:46:01 +02:00
|
|
|
.pipe(uglify())
|
2014-11-11 11:45:38 +02:00
|
|
|
.pipe(rename(file + '.min.js'))
|
2014-11-05 19:46:01 +02:00
|
|
|
.pipe(gulp.dest( DEST ));
|
2014-11-11 11:45:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('bower', function(cb){
|
|
|
|
bower.commands.install().on('end', function (installed){
|
|
|
|
console.log(installed);
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-01-07 15:13:29 +02:00
|
|
|
gulp.task('clean', ['lint'], function(cb) {
|
|
|
|
del([ DEST ], cb);
|
|
|
|
});
|
|
|
|
|
2014-11-11 11:45:38 +02:00
|
|
|
gulp.task('lint', function(){
|
|
|
|
return gulp.src(['./*.js', './lib/*.js'])
|
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('default'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build', ['clean'], function () {
|
2015-01-07 15:13:29 +02:00
|
|
|
return build('index', 'ethereum', true);
|
2014-11-11 16:47:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('buildDev', ['clean'], function () {
|
2015-01-07 15:13:29 +02:00
|
|
|
return build('index', 'ethereum', false);
|
2014-11-11 11:45:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('uglify', ['build'], function(){
|
|
|
|
return uglifyFile('ethereum');
|
|
|
|
});
|
|
|
|
|
2015-01-16 11:47:43 +02:00
|
|
|
gulp.task('uglifyDev', ['buildDev'], function(){
|
2014-11-11 16:47:58 +02:00
|
|
|
return uglifyFile('ethereum');
|
2014-11-05 19:46:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
2014-11-10 14:53:35 +02:00
|
|
|
gulp.watch(['./lib/*.js'], ['lint', 'prepare', 'build']);
|
2014-11-05 19:46:01 +02:00
|
|
|
});
|
|
|
|
|
2015-01-07 15:13:29 +02:00
|
|
|
gulp.task('release', ['bower', 'lint', 'build', 'uglify']);
|
2015-01-16 11:47:43 +02:00
|
|
|
gulp.task('dev', ['bower', 'lint', 'buildDev', 'uglifyDev']);
|
2015-01-07 15:13:29 +02:00
|
|
|
gulp.task('default', ['dev']);
|
2014-11-11 16:47:58 +02:00
|
|
|
|