2014-11-05 17:46:01 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-15 22:02:22 +00:00
|
|
|
var version = require('./lib/version.json');
|
2014-11-06 20:51:37 +00:00
|
|
|
var path = require('path');
|
|
|
|
|
2014-11-05 17:46:01 +00:00
|
|
|
var del = require('del');
|
|
|
|
var gulp = require('gulp');
|
2014-11-06 20:51:37 +00:00
|
|
|
var browserify = require('browserify');
|
2014-11-05 17:46:01 +00:00
|
|
|
var jshint = require('gulp-jshint');
|
2014-11-06 20:51:37 +00:00
|
|
|
var uglify = require('gulp-uglify');
|
|
|
|
var rename = require('gulp-rename');
|
|
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var exorcist = require('exorcist');
|
2014-11-05 17:46:01 +00:00
|
|
|
var bower = require('bower');
|
2015-02-17 11:11:57 +00:00
|
|
|
var streamify = require('gulp-streamify');
|
2015-03-12 16:28:33 +00:00
|
|
|
var replace = require('gulp-replace');
|
2014-11-05 17:46:01 +00:00
|
|
|
|
|
|
|
var DEST = './dist/';
|
2015-02-17 11:11:57 +00:00
|
|
|
var src = 'index';
|
2015-04-07 02:39:47 +00:00
|
|
|
var dst = 'web3';
|
|
|
|
var lightDst = 'web3-light';
|
2015-02-17 11:11:57 +00:00
|
|
|
|
|
|
|
var browserifyOptions = {
|
|
|
|
debug: true,
|
2015-02-25 14:53:28 +00:00
|
|
|
insert_global_vars: false, // jshint ignore:line
|
2015-02-17 11:11:57 +00:00
|
|
|
detectGlobals: false,
|
2015-03-16 08:14:13 +00:00
|
|
|
bundleExternal: true
|
2014-11-11 09:45:38 +00:00
|
|
|
};
|
|
|
|
|
2015-03-12 16:28:33 +00:00
|
|
|
gulp.task('versionReplace', function(){
|
|
|
|
gulp.src(['./package.json'])
|
|
|
|
.pipe(replace(/\"version\"\: \"(.{5})\"/, '"version": "'+ version.version + '"'))
|
2015-03-27 13:48:56 +00:00
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
gulp.src(['./bower.json'])
|
|
|
|
.pipe(replace(/\"version\"\: \"(.{5})\"/, '"version": "'+ version.version + '"'))
|
2015-03-12 16:28:33 +00:00
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
gulp.src(['./package.js'])
|
|
|
|
.pipe(replace(/version\: \'(.{5})\'/, "version: '"+ version.version + "'"))
|
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
});
|
|
|
|
|
2014-11-11 09:45:38 +00:00
|
|
|
gulp.task('bower', function(cb){
|
2015-02-17 11:11:57 +00:00
|
|
|
bower.commands.install().on('end', function (installed){
|
|
|
|
console.log(installed);
|
|
|
|
cb();
|
|
|
|
});
|
2014-11-11 09:45:38 +00:00
|
|
|
});
|
|
|
|
|
2015-01-07 13:13:29 +00:00
|
|
|
gulp.task('clean', ['lint'], function(cb) {
|
2015-02-17 11:11:57 +00:00
|
|
|
del([ DEST ], cb);
|
2015-01-07 13:13:29 +00:00
|
|
|
});
|
|
|
|
|
2014-11-11 09:45:38 +00:00
|
|
|
gulp.task('lint', function(){
|
2015-02-17 11:11:57 +00:00
|
|
|
return gulp.src(['./*.js', './lib/*.js'])
|
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('default'));
|
2014-11-11 09:45:38 +00:00
|
|
|
});
|
|
|
|
|
2015-03-23 16:47:53 +00:00
|
|
|
gulp.task('buildLight', ['clean'], function () {
|
2015-03-23 16:29:50 +00:00
|
|
|
return browserify(browserifyOptions)
|
2015-04-07 02:39:47 +00:00
|
|
|
.require('./' + src + '.js', {expose: 'web3'})
|
2015-03-23 16:29:50 +00:00
|
|
|
.ignore('bignumber.js')
|
|
|
|
.require('./lib/utils/browser-bn.js', {expose: 'bignumber.js'}) // fake bignumber.js
|
|
|
|
.add('./' + src + '.js')
|
|
|
|
.bundle()
|
2015-03-23 16:47:53 +00:00
|
|
|
.pipe(exorcist(path.join( DEST, lightDst + '.js.map')))
|
|
|
|
.pipe(source(lightDst + '.js'))
|
|
|
|
.pipe(gulp.dest( DEST ))
|
2015-03-23 16:29:50 +00:00
|
|
|
.pipe(streamify(uglify()))
|
2015-03-23 16:47:53 +00:00
|
|
|
.pipe(rename(lightDst + '.min.js'))
|
|
|
|
.pipe(gulp.dest( DEST ));
|
2015-03-23 16:29:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('buildStandalone', ['clean'], function () {
|
2015-02-17 11:11:57 +00:00
|
|
|
return browserify(browserifyOptions)
|
2015-04-07 02:39:47 +00:00
|
|
|
.require('./' + src + '.js', {expose: 'web3'})
|
2015-03-16 09:46:37 +00:00
|
|
|
.require('bignumber.js') // expose it to dapp users
|
2015-02-17 11:11:57 +00:00
|
|
|
.add('./' + src + '.js')
|
2015-03-16 08:14:13 +00:00
|
|
|
.ignore('crypto')
|
2015-02-17 11:11:57 +00:00
|
|
|
.bundle()
|
|
|
|
.pipe(exorcist(path.join( DEST, dst + '.js.map')))
|
|
|
|
.pipe(source(dst + '.js'))
|
|
|
|
.pipe(gulp.dest( DEST ))
|
|
|
|
.pipe(streamify(uglify()))
|
|
|
|
.pipe(rename(dst + '.min.js'))
|
|
|
|
.pipe(gulp.dest( DEST ));
|
2014-11-05 17:46:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function() {
|
2015-02-17 11:11:57 +00:00
|
|
|
gulp.watch(['./lib/*.js'], ['lint', 'build']);
|
2014-11-05 17:46:01 +00:00
|
|
|
});
|
|
|
|
|
2015-03-23 16:47:53 +00:00
|
|
|
gulp.task('light', ['versionReplace','bower', 'lint', 'buildLight']);
|
2015-03-23 16:29:50 +00:00
|
|
|
gulp.task('standalone', ['versionReplace','bower', 'lint', 'buildStandalone']);
|
2015-03-23 16:47:53 +00:00
|
|
|
gulp.task('default', ['light', 'standalone']);
|
2014-11-11 14:47:58 +00:00
|
|
|
|
2015-03-12 16:28:33 +00:00
|
|
|
|
|
|
|
gulp.task('version', ['versionReplace']);
|
|
|
|
|