-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
115 lines (99 loc) · 3.52 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env node
'use strict';
var version = require('./lib/version.json');
var path = require('path');
var del = require('del');
var gulp = require('gulp');
var browserify = require('browserify');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var exorcist = require('exorcist');
var bower = require('bower');
var streamify = require('gulp-streamify');
var replace = require('gulp-replace');
var DEST = path.join(__dirname, 'dist/');
var src = 'index';
var dst = 'chain3';
var lightDst = 'chain3-light';
var browserifyOptions = {
debug: true,
insert_global_vars: false, // jshint ignore:line
detectGlobals: false,
bundleExternal: true
};
gulp.task('version', function(){
gulp.src(['./package.json'])
.pipe(replace(/\"version\"\: \"([\.0-9]*)\"/, '"version": "'+ version.version + '"'))
.pipe(gulp.dest('./'));
gulp.src(['./bower.json'])
.pipe(replace(/\"version\"\: \"([\.0-9]*)\"/, '"version": "'+ version.version + '"'))
.pipe(gulp.dest('./'));
gulp.src(['./package.js'])
.pipe(replace(/version\: \'([\.0-9]*)\'/, "version: '"+ version.version + "'"))
.pipe(gulp.dest('./'));
});
gulp.task('bower', ['version'], function(cb){
bower.commands.install().on('end', function (installed){
console.log(installed);
cb();
});
});
gulp.task('lint', [], function(){
return gulp.src(['./*.js', './lib/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('clean', ['lint'], function(cb) {
del([ DEST ]).then(cb.bind(null, null));
});
//build the light version of the chain3 library used for browser
gulp.task('light', ['clean'], function () {
return browserify(browserifyOptions)
.require('./' + src + '.js', {expose: 'chain3'})
.ignore('bignumber.js')
.require('./lib/utils/browser-bn.js', {expose: 'bignumber.js'}) // fake bignumber.js
.add('./' + src + '.js')
.bundle()
.pipe(exorcist(path.join( DEST, lightDst + '.js.map')))
.pipe(source(lightDst + '.js'))
.pipe(gulp.dest( DEST ))
.pipe(streamify(uglify()))
.pipe(rename(lightDst + '.min.js'))
.pipe(gulp.dest( DEST ));
});
/*build the chain3.js under dist using files listed in the [lint] option*/
gulp.task('standalone', ['clean'], function () {
return browserify(browserifyOptions)
.require('./' + src + '.js', {expose: 'chain3'})
.require('bignumber.js') // expose it to dapp users
.add('./' + src + '.js')
.ignore('crypto')
.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 ));
});
gulp.task('chain3', ['clean'], function () {
return browserify(browserifyOptions)
.require('./' + src + '.js', {expose: 'chain3'})
.require('bignumber.js') // expose it to dapp users
.add('./' + src + '.js')
.ignore('crypto')
.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 ));
});
gulp.task('watch', function() {
gulp.watch(['./lib/*.js'], ['lint', 'build']);
});
/*Default build process*/
gulp.task('default', ['version', 'lint', 'clean', 'light', 'standalone']);