2014-11-05 19:46:01 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-01-26 10:24:14 +01:00
|
|
|
var version = require('./lerna.json');
|
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');
|
2017-02-28 16:02:08 +01:00
|
|
|
// var closureCompiler = require('google-closure-compiler').gulp();
|
2014-11-06 22:51:37 +02:00
|
|
|
var rename = require('gulp-rename');
|
|
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var exorcist = require('exorcist');
|
2014-11-05 19:46:01 +02:00
|
|
|
var bower = require('bower');
|
2015-02-17 12:11:57 +01:00
|
|
|
var streamify = require('gulp-streamify');
|
2015-03-12 17:28:33 +01:00
|
|
|
var replace = require('gulp-replace');
|
2014-11-05 19:46:01 +02:00
|
|
|
|
2015-06-26 08:56:18 +02:00
|
|
|
var DEST = path.join(__dirname, 'dist/');
|
2017-02-28 16:02:08 +01:00
|
|
|
var packages = [{
|
|
|
|
fileName: 'web3',
|
|
|
|
expose: 'Web3',
|
|
|
|
src: './src/index.js'
|
|
|
|
},{
|
|
|
|
fileName: 'web3-utils',
|
|
|
|
expose: 'Utils',
|
|
|
|
src: './packages/web3-utils/src/index.js'
|
|
|
|
},{
|
|
|
|
fileName: 'web3-core-requestManager',
|
|
|
|
expose: 'RequestManager',
|
|
|
|
src: './packages/web3-core-requestManager/src/index.js'
|
|
|
|
},{
|
|
|
|
fileName: 'web3-providers-ipc',
|
|
|
|
expose: 'IpcProvider',
|
|
|
|
src: './packages/web3-providers-ipc/src/index.js'
|
|
|
|
},{
|
|
|
|
fileName: 'web3-providers-http',
|
|
|
|
expose: 'HttpProvider',
|
|
|
|
src: './packages/web3-providers-http/src/index.js',
|
|
|
|
ignore: ['xmlhttprequest']
|
|
|
|
},{
|
|
|
|
fileName: 'web3-providers-ws',
|
|
|
|
expose: 'WsProvider',
|
|
|
|
src: './packages/web3-providers-ws/src/index.js'
|
|
|
|
},{
|
|
|
|
fileName: 'web3-eth',
|
|
|
|
expose: 'Eth',
|
|
|
|
src: './packages/web3-eth/src/index.js'
|
|
|
|
}];
|
|
|
|
// ,{
|
|
|
|
// fileName: 'web3-eth',
|
|
|
|
// expose: 'Eth',
|
|
|
|
// src: './packages/web3-eth/src/index.js'
|
|
|
|
// },{
|
|
|
|
// fileName: 'web3-personal',
|
|
|
|
// expose: 'Personal',
|
|
|
|
// src: './packages/web3-personal/src/index.js'
|
|
|
|
// },{
|
|
|
|
// fileName: 'web3-shh',
|
|
|
|
// expose: 'Shh',
|
|
|
|
// src: './packages/web3-shh/src/index.js'
|
|
|
|
// },{
|
|
|
|
// fileName: 'web3-bzz',
|
|
|
|
// expose: 'Bzz',
|
|
|
|
// src: './packages/web3-bzz/src/index.js'
|
|
|
|
// },{
|
|
|
|
// fileName: 'web3-eth-iban',
|
|
|
|
// expose: 'Iban',
|
|
|
|
// src: './packages/web3-eth-iban/src/index.js'
|
|
|
|
// }];
|
2015-02-17 12:11:57 +01:00
|
|
|
|
|
|
|
var browserifyOptions = {
|
|
|
|
debug: true,
|
2017-02-28 16:02:08 +01:00
|
|
|
// standalone: 'Web3',
|
|
|
|
derequire: true,
|
|
|
|
insertGlobalVars: false, // jshint ignore:line
|
2015-02-17 12:11:57 +01:00
|
|
|
detectGlobals: false,
|
2015-03-16 08:14:13 +00:00
|
|
|
bundleExternal: true
|
2014-11-11 10:45:38 +01:00
|
|
|
};
|
|
|
|
|
2015-06-26 08:56:18 +02:00
|
|
|
gulp.task('version', function(){
|
2015-03-12 17:28:33 +01:00
|
|
|
gulp.src(['./package.json'])
|
2016-06-29 12:20:20 +02:00
|
|
|
.pipe(replace(/\"version\"\: \"([\.0-9\-a-z]*)\"/, '"version": "'+ version.version + '"'))
|
2015-03-27 14:48:56 +01:00
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
gulp.src(['./bower.json'])
|
2016-06-29 12:20:20 +02:00
|
|
|
.pipe(replace(/\"version\"\: \"([\.0-9\-a-z]*)\"/, '"version": "'+ version.version + '"'))
|
2015-03-12 17:28:33 +01:00
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
gulp.src(['./package.js'])
|
2016-06-29 12:20:20 +02:00
|
|
|
.pipe(replace(/version\: \'([\.0-9\-a-z]*)\'/, "version: '"+ version.version + "'"))
|
2015-03-12 17:28:33 +01:00
|
|
|
.pipe(gulp.dest('./'));
|
|
|
|
});
|
|
|
|
|
2015-06-26 08:56:18 +02:00
|
|
|
gulp.task('bower', ['version'], function(cb){
|
2015-02-17 12:11:57 +01:00
|
|
|
bower.commands.install().on('end', function (installed){
|
|
|
|
console.log(installed);
|
|
|
|
cb();
|
|
|
|
});
|
2014-11-11 10:45:38 +01:00
|
|
|
});
|
|
|
|
|
2015-10-05 09:25:25 +02:00
|
|
|
gulp.task('lint', [], function(){
|
2015-02-17 12:11:57 +01:00
|
|
|
return gulp.src(['./*.js', './lib/*.js'])
|
|
|
|
.pipe(jshint())
|
|
|
|
.pipe(jshint.reporter('default'));
|
2014-11-11 10:45:38 +01:00
|
|
|
});
|
|
|
|
|
2015-06-26 08:56:18 +02:00
|
|
|
gulp.task('clean', ['lint'], function(cb) {
|
2015-10-05 09:25:25 +02:00
|
|
|
del([ DEST ]).then(cb.bind(null, null));
|
2015-06-26 08:56:18 +02:00
|
|
|
});
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
packages.forEach(function(pckg, i){
|
|
|
|
var prevPckg = (!i) ? 'clean' : packages[i-1].fileName;
|
|
|
|
|
|
|
|
gulp.task(pckg.fileName, [prevPckg], function () {
|
|
|
|
browserifyOptions.standalone = pckg.expose;
|
|
|
|
|
|
|
|
var pipe = browserify(browserifyOptions)
|
|
|
|
.require(pckg.src, {expose: pckg.expose})
|
|
|
|
.require('bn.js', {expose: 'BN'}) // expose it to dapp developers
|
|
|
|
.add(pckg.src);
|
2015-03-23 17:29:50 +01:00
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
if(pckg.ignore) {
|
|
|
|
pckg.ignore.forEach(function (ignore) {
|
|
|
|
pipe.ignore(ignore);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipe.bundle()
|
|
|
|
.pipe(exorcist(path.join( DEST, pckg.fileName + '.js.map')))
|
|
|
|
.pipe(source(pckg.fileName + '.js'))
|
|
|
|
.pipe(gulp.dest( DEST ))
|
|
|
|
.pipe(streamify(uglify()))
|
|
|
|
.pipe(rename(pckg.fileName + '.min.js'))
|
|
|
|
// .pipe(streamify(closureCompiler({
|
|
|
|
// compilation_level: 'ADVANCED_OPTIMIZATIONS',
|
|
|
|
// warning_level: 'VERBOSE',
|
|
|
|
// jscomp_off: 'checkVars',
|
|
|
|
// language_in: 'ECMASCRIPT6_STRICT',
|
|
|
|
// language_out: 'ECMASCRIPT5_STRICT',
|
|
|
|
// output_wrapper: '(function(){\n%output%\n}).call(this)',
|
|
|
|
// js_output_file: pckg.fileName + '.min.js'
|
|
|
|
// })))
|
|
|
|
.pipe(gulp.dest( DEST ));
|
|
|
|
});
|
2014-11-05 19:46:01 +02:00
|
|
|
});
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
|
2014-11-05 19:46:01 +02:00
|
|
|
gulp.task('watch', function() {
|
2017-02-28 16:02:08 +01:00
|
|
|
gulp.watch(['./src/*.js'], ['lint', 'build']);
|
2014-11-05 19:46:01 +02:00
|
|
|
});
|
|
|
|
|
2017-02-28 16:02:08 +01:00
|
|
|
gulp.task('default', ['version', 'lint', 'clean', packages[packages.length-1].fileName]);
|
2015-03-12 17:28:33 +01:00
|
|
|
|