@@ -30,6 +30,7 @@ const babel = require('gulp-babel');
30
30
const fsc = require ( 'fs-cli' ) ;
31
31
const semver = require ( 'semver' ) ;
32
32
const inject = require ( 'gulp-inject-string' ) ;
33
+ const version = require ( './package.json' ) . version ;
33
34
34
35
/**
35
36
* @typedef {{argv: object} } yargs
@@ -70,7 +71,50 @@ function es6concat(type = 'all') {
70
71
. pipe ( concat ( 'gauge.es6.js' ) )
71
72
. pipe ( replace ( / ( ( v a r | c o n s t | l e t ) \s + .* ?= \s * ) ? r e q u i r e \( .* ?\) ; ? / g, '' ) )
72
73
. pipe ( replace ( / ( m o d u l e \. ) ? e x p o r t s ( .d e f a u l t ) ? \s + = \s * .* ?\r ? \n / g, '' ) )
73
- . pipe ( replace ( / e x p o r t \s + ( d e f a u l t \s + ) ? ( G e n e r i c O p t i o n s ; ) ? / g, '' ) ) ;
74
+ . pipe ( replace ( / e x p o r t \s + ( d e f a u l t \s + ) ? ( G e n e r i c O p t i o n s ; ) ? / g, '' ) )
75
+ . pipe ( replace ( / % V E R S I O N % / g, version ) ) ;
76
+ }
77
+
78
+ function es5transpile ( type = 'all' , withSourceMaps = true , resolve = ( ) => { } ) {
79
+ let stream = es6concat ( type )
80
+ . pipe ( rename ( 'gauge.es5.js' ) )
81
+ . pipe ( babel ( {
82
+ presets : [ 'es2015' ] ,
83
+ compact : false
84
+ } ) )
85
+ . on ( 'error' , function ( err ) {
86
+ gutil . log ( err ) ;
87
+ this . emit ( 'end' ) ;
88
+ resolve ( ) ;
89
+ } )
90
+ . pipe ( rename ( 'gauge.min.js' ) )
91
+ . pipe ( replace ( / ^ / , license ( ) + '(function(ns) {' ) )
92
+ . pipe ( replace ( / $ / ,
93
+ ';typeof module !== "undefined" && Object.assign(ns, {' +
94
+ 'Collection: Collection,' +
95
+ 'GenericOptions: GenericOptions,' +
96
+ 'Animation: Animation,' +
97
+ 'BaseGauge: BaseGauge,' +
98
+ 'drawings: drawings,' +
99
+ 'SmartCanvas: SmartCanvas,' +
100
+ 'vendorize: vendorize' +
101
+ '});' +
102
+ '}(typeof module !== "undefined" ? ' +
103
+ 'module.exports : window));' ) ) ;
104
+
105
+ if ( withSourceMaps ) {
106
+ stream = stream . pipe ( sourcemaps . init ( { loadMaps : true } ) ) ;
107
+ }
108
+
109
+ stream = stream . pipe ( uglify ( {
110
+ preserveComments : ( node , comment ) => comment . line === 1
111
+ } ) ) ;
112
+
113
+ if ( withSourceMaps ) {
114
+ stream = stream . pipe ( sourcemaps . write ( '.' ) ) ;
115
+ }
116
+
117
+ return stream ;
74
118
}
75
119
76
120
function license ( ) {
@@ -80,7 +124,8 @@ function license() {
80
124
81
125
src . pop ( ) ;
82
126
83
- return '/*!\n * ' + src . join ( '\n * ' ) + '\n */\n' ;
127
+ return '/*!\n * ' + src . join ( '\n * ' ) + '\n *\n * @version ' +
128
+ version + '\n */\n' ;
84
129
}
85
130
86
131
/**
@@ -99,34 +144,7 @@ gulp.task('build:prod', done => {
99
144
rimraf ( 'dist' , ( ) => {
100
145
Promise . all ( types . map ( type => {
101
146
return new Promise ( resolve => {
102
- es6concat ( type )
103
- . pipe ( rename ( 'gauge.es5.js' ) )
104
- . pipe ( babel ( {
105
- presets : [ 'es2015' ] ,
106
- compact : false
107
- } ) )
108
- . on ( 'error' , function ( err ) {
109
- gutil . log ( err ) ;
110
- this . emit ( 'end' ) ;
111
- resolve ( ) ;
112
- } )
113
- . pipe ( rename ( 'gauge.min.js' ) )
114
- . pipe ( replace ( / ^ / , license ( ) + '(function(ns) {' ) )
115
- . pipe ( replace ( / $ / ,
116
- ';typeof module !== "undefined" && Object.assign(ns, {' +
117
- 'Collection: Collection,' +
118
- 'GenericOptions: GenericOptions,' +
119
- 'Animation: Animation,' +
120
- 'BaseGauge: BaseGauge,' +
121
- 'drawings: drawings,' +
122
- 'SmartCanvas: SmartCanvas,' +
123
- 'vendorize: vendorize' +
124
- '});' +
125
- '}(typeof module !== "undefined" ? ' +
126
- 'module.exports : window));' ) )
127
- . pipe ( uglify ( {
128
- preserveComments : ( node , comment ) => comment . line === 1
129
- } ) )
147
+ es5transpile ( type , false , resolve )
130
148
. pipe ( gulp . dest ( 'dist/' + type ) )
131
149
. on ( 'end' , ( ) => {
132
150
let pkg = JSON . parse ( fs . readFileSync ( './package.json' ) ) ;
@@ -159,7 +177,6 @@ gulp.task('build:prod', done => {
159
177
} ) ;
160
178
} ) ;
161
179
} ) ) . then ( ( ) => {
162
- let version = require ( './package.json' ) . version ;
163
180
let cmd = '' ;
164
181
165
182
console . log ( chalk . bold . green ( 'Production packages are now ready!' ) ) ;
@@ -253,36 +270,8 @@ gulp.task('build:es6', ['clean'], () => {
253
270
* @task {build:es5}
254
271
* @arg {type} build type: 'radial' - Gauge object only, 'linear' - LinearGauge object only, 'all' - everything (default)
255
272
*/
256
- gulp . task ( 'build:es5' , [ 'clean' ] , ( ) => {
257
- es6concat ( yargs . argv . type || 'all' )
258
- . pipe ( rename ( 'gauge.es5.js' ) )
259
- . pipe ( babel ( {
260
- presets : [ 'es2015' ] ,
261
- compact : false
262
- } ) )
263
- . on ( 'error' , function ( err ) {
264
- gutil . log ( err ) ;
265
- this . emit ( 'end' ) ;
266
- } )
267
- //.pipe(gulp.dest('.'))
268
- . pipe ( rename ( 'gauge.min.js' ) )
269
- . pipe ( replace ( / ^ / , license ( ) + '(function(ns) {' ) )
270
- . pipe ( replace ( / $ / ,
271
- ';typeof module !== "undefined" && Object.assign(ns, {' +
272
- 'Collection: Collection,' +
273
- 'GenericOptions: GenericOptions,' +
274
- 'Animation: Animation,' +
275
- 'BaseGauge: BaseGauge,' +
276
- 'drawings: drawings,' +
277
- 'SmartCanvas: SmartCanvas,' +
278
- 'vendorize: vendorize' +
279
- '});' +
280
- '}(typeof module !== "undefined" ? module.exports : window));' ) )
281
- . pipe ( sourcemaps . init ( { loadMaps : true } ) )
282
- . pipe ( uglify ( {
283
- preserveComments : ( node , comment ) => comment . line === 1
284
- } ) )
285
- . pipe ( sourcemaps . write ( '.' ) )
273
+ gulp . task ( 'build:es5' , [ 'clean' ] , done => {
274
+ es5transpile ( yargs . argv . type || 'all' )
286
275
. pipe ( gulp . dest ( '.' ) )
287
276
. on ( 'end' , ( ) => {
288
277
if ( ! process . env . TRVIS ) {
@@ -297,6 +286,8 @@ gulp.task('build:es5', ['clean'], () => {
297
286
fs . readFileSync ( 'gauge.min.js.map' )
298
287
) ;
299
288
}
289
+
290
+ done ( ) ;
300
291
} ) ;
301
292
} ) ;
302
293
@@ -366,7 +357,6 @@ gulp.task('doc', ['clean:docs'], done => {
366
357
367
358
//move to pages
368
359
369
- let version = require ( './package.json' ) . version ;
370
360
let target = '../canvas-gauges-pages/docs/' + version ;
371
361
372
362
rimraf ( target , ( ) => fs . rename ( 'docs' , target , done ) ) ;
0 commit comments