1
+ /* eslint-disable no-use-before-define */
1
2
const gulp = require ( 'gulp' ) ;
2
3
const eslint = require ( 'gulp-eslint' ) ;
3
4
const file = require ( 'gulp-file' ) ;
@@ -13,14 +14,14 @@ const yargs = require('yargs');
13
14
const path = require ( 'path' ) ;
14
15
const htmllint = require ( 'gulp-htmllint' ) ;
15
16
const typescript = require ( 'gulp-typescript' ) ;
16
- const typedoc = require ( " gulp-typedoc" ) ;
17
+ const typedoc = require ( ' gulp-typedoc' ) ;
17
18
18
19
const pkg = require ( './package.json' ) ;
19
20
const tsProject = typescript . createProject ( './tsconfig.json' ) ;
20
21
21
22
const argv = yargs
22
- . option ( 'verbose' , { default : false } )
23
- . argv ;
23
+ . option ( 'verbose' , { default : false } )
24
+ . argv ;
24
25
25
26
const srcDir = './src/' ;
26
27
const outDir = './dist/' ;
@@ -40,156 +41,156 @@ gulp.task('module-sizes', moduleSizesTask);
40
41
gulp . task ( 'size' , gulp . parallel ( 'library-size' , 'module-sizes' ) ) ;
41
42
gulp . task ( 'default' , gulp . parallel ( 'build' ) ) ;
42
43
43
- function run ( bin , args , done ) {
44
- return new Promise ( function ( resolve , reject ) {
45
- const exe = '"' + process . execPath + '"' ;
46
- const src = require . resolve ( bin ) ;
47
- const cmd = [ exe , src ] . concat ( args || [ ] ) . join ( ' ' ) ;
48
- const ps = exec ( cmd ) ;
49
-
50
- ps . stdout . pipe ( process . stdout ) ;
51
- ps . stderr . pipe ( process . stderr ) ;
52
- ps . on ( 'close' , function ( error ) {
53
- if ( error ) {
54
- reject ( error ) ;
55
- } else {
56
- resolve ( ) ;
57
- }
58
- } ) ;
59
- } ) ;
44
+ function run ( bin , args ) {
45
+ return new Promise ( function ( resolve , reject ) {
46
+ const exe = '"' + process . execPath + '"' ;
47
+ const src = require . resolve ( bin ) ;
48
+ const cmd = [ exe , src ] . concat ( args || [ ] ) . join ( ' ' ) ;
49
+ const ps = exec ( cmd ) ;
50
+
51
+ ps . stdout . pipe ( process . stdout ) ;
52
+ ps . stderr . pipe ( process . stderr ) ;
53
+ ps . on ( 'close' , function ( error ) {
54
+ if ( error ) {
55
+ reject ( error ) ;
56
+ } else {
57
+ resolve ( ) ;
58
+ }
59
+ } ) ;
60
+ } ) ;
60
61
}
61
62
62
63
/**
63
64
* Generates the bower.json manifest file which will be pushed along release tags.
64
65
* Specs: https://github.com/bower/spec/blob/master/json.md
65
66
*/
66
67
function bowerTask ( ) {
67
- const json = JSON . stringify ( {
68
- name : pkg . name ,
69
- description : pkg . description ,
70
- homepage : pkg . homepage ,
71
- license : pkg . license ,
72
- version : pkg . version ,
73
- main : outDir + 'Chart.js' ,
74
- ignore : [
75
- '.github' ,
76
- '.codeclimate.yml' ,
77
- '.gitignore' ,
78
- '.npmignore' ,
79
- '.travis.yml' ,
80
- 'scripts'
81
- ]
82
- } , null , 2 ) ;
83
-
84
- return file ( 'bower.json' , json , { src : true } )
85
- . pipe ( gulp . dest ( './' ) ) ;
68
+ const json = JSON . stringify ( {
69
+ name : pkg . name ,
70
+ description : pkg . description ,
71
+ homepage : pkg . homepage ,
72
+ license : pkg . license ,
73
+ version : pkg . version ,
74
+ main : outDir + 'Chart.js' ,
75
+ ignore : [
76
+ '.github' ,
77
+ '.codeclimate.yml' ,
78
+ '.gitignore' ,
79
+ '.npmignore' ,
80
+ '.travis.yml' ,
81
+ 'scripts'
82
+ ]
83
+ } , null , 2 ) ;
84
+
85
+ return file ( 'bower.json' , json , { src : true } )
86
+ . pipe ( gulp . dest ( './' ) ) ;
86
87
}
87
88
88
89
function buildTask ( ) {
89
- return run ( 'rollup/dist/bin/rollup' , [ '-c' , argv . watch ? '--watch' : '' ] ) ;
90
+ return run ( 'rollup/dist/bin/rollup' , [ '-c' , argv . watch ? '--watch' : '' ] ) ;
90
91
}
91
92
92
93
function packageTask ( ) {
93
- return merge (
94
- // gather "regular" files landing in the package root
95
- gulp . src ( [ outDir + '*.js' , outDir + '*.css' , 'LICENSE.md' ] ) ,
96
-
97
- // since we moved the dist files one folder up (package root), we need to rewrite
98
- // samples src="../dist/ to src="../ and then copy them in the /samples directory.
99
- gulp . src ( './samples/**/*' , { base : '.' } )
100
- . pipe ( streamify ( replace ( / s r c = " ( (?: \. \. \/ ) + ) d i s t \/ / g, 'src="$1' ) ) )
101
- )
102
- // finally, create the zip archive
103
- . pipe ( zip ( 'Chart.js.zip' ) )
104
- . pipe ( gulp . dest ( outDir ) ) ;
94
+ return merge (
95
+ // gather "regular" files landing in the package root
96
+ gulp . src ( [ outDir + '*.js' , outDir + '*.css' , 'LICENSE.md' ] ) ,
97
+
98
+ // since we moved the dist files one folder up (package root), we need to rewrite
99
+ // samples src="../dist/ to src="../ and then copy them in the /samples directory.
100
+ gulp . src ( './samples/**/*' , { base : '.' } )
101
+ . pipe ( streamify ( replace ( / s r c = " ( (?: \. \. \/ ) + ) d i s t \/ / g, 'src="$1' ) ) )
102
+ )
103
+ // finally, create the zip archive
104
+ . pipe ( zip ( 'Chart.js.zip' ) )
105
+ . pipe ( gulp . dest ( outDir ) ) ;
105
106
}
106
107
107
108
function lintJsTask ( ) {
108
- const files = [
109
- 'samples/**/*.html' ,
110
- 'samples/**/*.js' ,
111
- 'src/**/*.js' ,
112
- 'test/**/*.js'
113
- ] ;
114
-
115
- // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
116
- // compare to what the current codebase can support, and since it's not straightforward
117
- // to fix, let's turn them as warnings and rewrite code later progressively.
118
- const options = {
119
- rules : {
120
- ' complexity' : [ 1 , 10 ] ,
121
- 'max-statements' : [ 1 , 30 ]
122
- }
123
- } ;
124
-
125
- return gulp . src ( files )
126
- . pipe ( eslint ( options ) )
127
- . pipe ( eslint . format ( ) )
128
- . pipe ( eslint . failAfterError ( ) ) ;
109
+ const files = [
110
+ 'samples/**/*.html' ,
111
+ 'samples/**/*.js' ,
112
+ 'src/**/*.js' ,
113
+ 'test/**/*.js'
114
+ ] ;
115
+
116
+ // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
117
+ // compare to what the current codebase can support, and since it's not straightforward
118
+ // to fix, let's turn them as warnings and rewrite code later progressively.
119
+ const options = {
120
+ rules : {
121
+ complexity : [ 1 , 10 ] ,
122
+ 'max-statements' : [ 1 , 30 ]
123
+ }
124
+ } ;
125
+
126
+ return gulp . src ( files )
127
+ . pipe ( eslint ( options ) )
128
+ . pipe ( eslint . format ( ) )
129
+ . pipe ( eslint . failAfterError ( ) ) ;
129
130
}
130
131
131
132
function typescriptTask ( ) {
132
- return tsProject . src ( )
133
- . pipe ( tsProject ( ) )
134
- . js . pipe ( gulp . dest ( 'dist' ) ) ;
133
+ return tsProject . src ( )
134
+ . pipe ( tsProject ( ) )
135
+ . js . pipe ( gulp . dest ( 'dist' ) ) ;
135
136
}
136
137
137
138
function lintHtmlTask ( ) {
138
- return gulp . src ( 'samples/**/*.html' )
139
- . pipe ( htmllint ( {
140
- failOnError : true ,
141
- } ) ) ;
139
+ return gulp . src ( 'samples/**/*.html' )
140
+ . pipe ( htmllint ( {
141
+ failOnError : true ,
142
+ } ) ) ;
142
143
}
143
144
144
145
function docsTask ( done ) {
145
- const bin = require . resolve ( 'gitbook-cli/bin/gitbook.js' ) ;
146
- const cmd = argv . watch ? 'serve' : 'build' ;
147
-
148
- return run ( bin , [ 'install' , './' ] )
149
- . then ( ( ) => run ( bin , [ cmd , './' , './dist/docs' ] ) )
150
- . then ( ( ) => {
151
- const config = {
152
- moduleResolution : " Node" ,
153
- target : " ES6" ,
154
- out : " ./dist/docs/typedoc"
155
- } ;
156
- gulp . src ( [ './src/**/*.js' ] , { read : false } )
157
- . pipe ( typedoc ( config , done ) ) ;
158
- } ) . catch ( ( err ) => {
159
- done ( new Error ( err . stdout || err ) ) ;
160
- } ) ;
146
+ const bin = require . resolve ( 'gitbook-cli/bin/gitbook.js' ) ;
147
+ const cmd = argv . watch ? 'serve' : 'build' ;
148
+
149
+ return run ( bin , [ 'install' , './' ] )
150
+ . then ( ( ) => run ( bin , [ cmd , './' , './dist/docs' ] ) )
151
+ . then ( ( ) => {
152
+ const config = {
153
+ moduleResolution : ' Node' ,
154
+ target : ' ES6' ,
155
+ out : ' ./dist/docs/typedoc'
156
+ } ;
157
+ gulp . src ( [ './src/**/*.js' ] , { read : false } )
158
+ . pipe ( typedoc ( config , done ) ) ;
159
+ } ) . catch ( ( err ) => {
160
+ done ( new Error ( err . stdout || err ) ) ;
161
+ } ) ;
161
162
}
162
163
163
164
function unittestTask ( done ) {
164
- new karma . Server ( {
165
- configFile : path . join ( __dirname , 'karma.conf.js' ) ,
166
- singleRun : ! argv . watch ,
167
- args : {
168
- coverage : ! ! argv . coverage ,
169
- inputs : argv . inputs ,
170
- browsers : argv . browsers ,
171
- watch : argv . watch
172
- }
173
- } ,
174
- // https://github.com/karma-runner/gulp-karma/issues/18
175
- function ( error ) {
176
- error = error ? new Error ( 'Karma returned with the error code: ' + error ) : undefined ;
177
- done ( error ) ;
178
- } ) . start ( ) ;
165
+ new karma . Server ( {
166
+ configFile : path . join ( __dirname , 'karma.conf.js' ) ,
167
+ singleRun : ! argv . watch ,
168
+ args : {
169
+ coverage : ! ! argv . coverage ,
170
+ inputs : argv . inputs ,
171
+ browsers : argv . browsers ,
172
+ watch : argv . watch
173
+ }
174
+ } ,
175
+ // https://github.com/karma-runner/gulp-karma/issues/18
176
+ function ( error ) {
177
+ error = error ? new Error ( 'Karma returned with the error code: ' + error ) : undefined ;
178
+ done ( error ) ;
179
+ } ) . start ( ) ;
179
180
}
180
181
181
182
function librarySizeTask ( ) {
182
- return gulp . src ( 'dist/Chart.bundle.min.js' )
183
- . pipe ( size ( {
184
- gzip : true
185
- } ) ) ;
183
+ return gulp . src ( 'dist/Chart.bundle.min.js' )
184
+ . pipe ( size ( {
185
+ gzip : true
186
+ } ) ) ;
186
187
}
187
188
188
189
function moduleSizesTask ( ) {
189
- return gulp . src ( srcDir + '**/*.js' )
190
- . pipe ( terser ( ) )
191
- . pipe ( size ( {
192
- showFiles : true ,
193
- gzip : true
194
- } ) ) ;
190
+ return gulp . src ( srcDir + '**/*.js' )
191
+ . pipe ( terser ( ) )
192
+ . pipe ( size ( {
193
+ showFiles : true ,
194
+ gzip : true
195
+ } ) ) ;
195
196
}
0 commit comments