2
2
3
3
'use strict' ;
4
4
5
- var version = require ( './lerna.json' ) ;
5
+ var lernaJSON = require ( './lerna.json' ) ;
6
6
var path = require ( 'path' ) ;
7
7
8
8
var del = require ( 'del' ) ;
@@ -24,74 +24,74 @@ var packages = [{
24
24
fileName : 'web3' ,
25
25
expose : 'Web3' ,
26
26
src : './packages/web3/src/index.js' ,
27
- ignore : [ 'xmlhttprequest' , 'websocket' ]
28
- } , {
27
+ ignore : [ 'xmlhttprequest' , 'websocket' ]
28
+ } , {
29
29
fileName : 'web3-utils' ,
30
30
expose : 'Web3Utils' ,
31
31
src : './packages/web3-utils/src/index.js'
32
- } , {
32
+ } , {
33
33
fileName : 'web3-eth' ,
34
34
expose : 'Web3Eth' ,
35
35
src : './packages/web3-eth/src/index.js'
36
- } , {
36
+ } , {
37
37
fileName : 'web3-eth-accounts' ,
38
38
expose : 'Web3EthAccounts' ,
39
39
src : './packages/web3-eth-accounts/src/index.js'
40
- } , {
40
+ } , {
41
41
fileName : 'web3-eth-contract' ,
42
42
expose : 'Web3EthContract' ,
43
43
src : './packages/web3-eth-contract/src/index.js'
44
- } , {
44
+ } , {
45
45
fileName : 'web3-eth-personal' ,
46
46
expose : 'Web3EthPersonal' ,
47
47
src : './packages/web3-eth-personal/src/index.js'
48
- } , {
48
+ } , {
49
49
fileName : 'web3-eth-iban' ,
50
50
expose : 'Web3EthIban' ,
51
51
src : './packages/web3-eth-iban/src/index.js'
52
- } , {
52
+ } , {
53
53
fileName : 'web3-eth-abi' ,
54
54
expose : 'Web3EthAbi' ,
55
55
src : './packages/web3-eth-abi/src/index.js'
56
- } , {
56
+ } , {
57
57
fileName : 'web3-net' ,
58
58
expose : 'Web3Net' ,
59
59
src : './packages/web3-net/src/index.js'
60
- } , {
60
+ } , {
61
61
fileName : 'web3-shh' ,
62
62
expose : 'Web3Shh' ,
63
63
src : './packages/web3-shh/src/index.js'
64
- } , {
64
+ } , {
65
65
fileName : 'web3-bzz' ,
66
66
expose : 'Web3Bzz' ,
67
67
src : './packages/web3-bzz/src/index.js'
68
- } , {
68
+ } , {
69
69
fileName : 'web3-providers-ipc' ,
70
70
expose : 'Web3IpcProvider' ,
71
71
src : './packages/web3-providers-ipc/src/index.js'
72
- } , {
72
+ } , {
73
73
fileName : 'web3-providers-http' ,
74
74
expose : 'Web3HttpProvider' ,
75
75
src : './packages/web3-providers-http/src/index.js' ,
76
76
ignore : [ 'xmlhttprequest' ]
77
- } , {
77
+ } , {
78
78
fileName : 'web3-providers-ws' ,
79
79
expose : 'Web3WsProvider' ,
80
80
src : './packages/web3-providers-ws/src/index.js' ,
81
81
ignore : [ 'websocket' ]
82
- } , {
82
+ } , {
83
83
fileName : 'web3-core-subscriptions' ,
84
84
expose : 'Web3Subscriptions' ,
85
85
src : './packages/web3-core-subscriptions/src/index.js'
86
- } , {
86
+ } , {
87
87
fileName : 'web3-core-requestmanager' ,
88
88
expose : 'Web3RequestManager' ,
89
89
src : './packages/web3-core-requestmanager/src/index.js'
90
- } , {
90
+ } , {
91
91
fileName : 'web3-core-promievent' ,
92
92
expose : 'Web3PromiEvent' ,
93
93
src : './packages/web3-core-promievent/src/index.js'
94
- } , {
94
+ } , {
95
95
fileName : 'web3-core-method' ,
96
96
expose : 'Web3Method' ,
97
97
src : './packages/web3-core-method/src/index.js'
@@ -107,88 +107,93 @@ var browserifyOptions = {
107
107
} ;
108
108
109
109
var ugliyOptions = {
110
- compress :{
111
- dead_code : true , // jshint ignore:line
112
- drop_debugger : true , // jshint ignore:line
113
- global_defs : { // jshint ignore:line
110
+ compress : {
111
+ dead_code : true , // jshint ignore:line
112
+ drop_debugger : true , // jshint ignore:line
113
+ global_defs : { // jshint ignore:line
114
114
"DEBUG" : false // matters for some libraries
115
115
}
116
116
}
117
117
} ;
118
118
119
- gulp . task ( 'version' , function ( ) {
120
- if ( ! version . version ) return ;
121
-
122
- gulp . src ( [ './package.json' ] )
123
- . pipe ( replace ( / \" v e r s i o n \" \: \" ( [ \. 0 - 9 \- a - z ] * ) \" / , '"version": "' + version . version + '"' ) )
124
- . pipe ( gulp . dest ( './' ) ) ;
125
- gulp . src ( [ './bower.json' ] )
126
- . pipe ( replace ( / \" v e r s i o n \" \: \" ( [ \. 0 - 9 \- a - z ] * ) \" / , '"version": "' + version . version + '"' ) )
127
- . pipe ( gulp . dest ( './' ) ) ;
128
- gulp . src ( [ './package.js' ] )
129
- . pipe ( replace ( / v e r s i o n \: \' ( [ \. 0 - 9 \- a - z ] * ) \' / , "version: '" + version . version + "'" ) )
130
- . pipe ( gulp . dest ( './' ) ) ;
119
+ gulp . task ( 'version' , function ( ) {
120
+ if ( ! lernaJSON . version ) {
121
+ throw new Error ( "version property is missing from lerna.json" ) ;
122
+ }
123
+
124
+ var version = lernaJSON . version ;
125
+ var jsonPattern = / " v e r s i o n " : " [ . 0 - 9 \- a - z ] * " / ;
126
+ var jsPattern = / v e r s i o n : ' [ . 0 - 9 \- a - z ] * ' / ;
127
+ var glob = [
128
+ './package.json' ,
129
+ './bower.json' ,
130
+ './package.js'
131
+ ] ;
132
+
133
+ gulp . src ( glob , { base : './' } )
134
+ . pipe ( replace ( jsonPattern , '"version": "' + version + '"' ) )
135
+ . pipe ( replace ( jsPattern , "version: '" + version + "'" ) )
136
+ . pipe ( gulp . dest ( './' ) ) ;
131
137
} ) ;
132
138
133
- gulp . task ( 'bower' , [ 'version' ] , function ( cb ) {
134
- bower . commands . install ( ) . on ( 'end' , function ( installed ) {
139
+ gulp . task ( 'bower' , [ 'version' ] , function ( cb ) {
140
+ bower . commands . install ( ) . on ( 'end' , function ( installed ) {
135
141
console . log ( installed ) ;
136
142
cb ( ) ;
137
143
} ) ;
138
144
} ) ;
139
145
140
- gulp . task ( 'lint' , [ ] , function ( ) {
146
+ gulp . task ( 'lint' , [ ] , function ( ) {
141
147
return gulp . src ( [ './*.js' , './lib/*.js' ] )
142
148
. pipe ( jshint ( ) )
143
149
. pipe ( jshint . reporter ( 'default' ) ) ;
144
150
} ) ;
145
151
146
- gulp . task ( 'clean' , [ 'lint' ] , function ( cb ) {
147
- del ( [ DEST ] ) . then ( cb . bind ( null , null ) ) ;
152
+ gulp . task ( 'clean' , [ 'lint' ] , function ( cb ) {
153
+ del ( [ DEST ] ) . then ( cb . bind ( null , null ) ) ;
148
154
} ) ;
149
155
150
- packages . forEach ( function ( pckg , i ) {
151
- var prevPckg = ( ! i ) ? 'clean' : packages [ i - 1 ] . fileName ;
156
+ packages . forEach ( function ( pckg , i ) {
157
+ var prevPckg = ( ! i ) ? 'clean' : packages [ i - 1 ] . fileName ;
152
158
153
159
gulp . task ( pckg . fileName , [ prevPckg ] , function ( ) {
154
160
browserifyOptions . standalone = pckg . expose ;
155
161
156
162
var pipe = browserify ( browserifyOptions )
157
- . require ( pckg . src , { expose : pckg . expose } )
158
- . require ( 'bn.js' , { expose : 'BN' } ) // expose it to dapp developers
163
+ . require ( pckg . src , { expose : pckg . expose } )
164
+ . require ( 'bn.js' , { expose : 'BN' } ) // expose it to dapp developers
159
165
. add ( pckg . src ) ;
160
166
161
- if ( pckg . ignore ) {
167
+ if ( pckg . ignore ) {
162
168
pckg . ignore . forEach ( function ( ignore ) {
163
169
pipe . ignore ( ignore ) ;
164
170
} ) ;
165
171
}
166
172
167
173
return pipe . bundle ( )
168
- . pipe ( exorcist ( path . join ( DEST , pckg . fileName + '.js.map' ) ) )
174
+ . pipe ( exorcist ( path . join ( DEST , pckg . fileName + '.js.map' ) ) )
169
175
. pipe ( source ( pckg . fileName + '.js' ) )
170
176
. pipe ( streamify ( babel ( {
171
177
compact : false ,
172
178
presets : [ 'env' ]
173
179
} ) ) )
174
- . pipe ( gulp . dest ( DEST ) )
180
+ . pipe ( gulp . dest ( DEST ) )
175
181
. pipe ( streamify ( babel ( {
176
182
compact : true ,
177
183
presets : [ 'env' ]
178
184
} ) ) )
179
185
. pipe ( streamify ( uglify ( ugliyOptions ) ) )
180
186
. on ( 'error' , function ( err ) { console . error ( err ) ; } )
181
187
. pipe ( rename ( pckg . fileName + '.min.js' ) )
182
- . pipe ( gulp . dest ( DEST ) ) ;
188
+ . pipe ( gulp . dest ( DEST ) ) ;
183
189
} ) ;
184
190
} ) ;
185
191
186
-
187
- gulp . task ( 'watch' , function ( ) {
192
+ gulp . task ( 'watch' , function ( ) {
188
193
gulp . watch ( [ './packages/web3/src/*.js' ] , [ 'lint' , 'build' ] ) ;
189
194
} ) ;
190
195
191
- gulp . task ( 'all' , [ 'version' , 'lint' , 'clean' , packages [ packages . length - 1 ] . fileName ] ) ;
196
+ gulp . task ( 'all' , [ 'version' , 'lint' , 'clean' , packages [ packages . length - 1 ] . fileName ] ) ;
192
197
193
198
gulp . task ( 'default' , [ 'version' , 'lint' , 'clean' , packages [ 0 ] . fileName ] ) ;
194
199
0 commit comments