@@ -2,59 +2,83 @@ import gulp from 'gulp';
22import babel from 'gulp-babel' ;
33import sass from 'gulp-sass' ;
44import cleanCSS from 'gulp-clean-css' ;
5+ import cleanDir from 'gulp-clean' ;
56import rename from 'gulp-rename' ;
6- import rimraf from 'rimraf' ;
7- import * as path from 'path' ;
8-
9- gulp . task ( 'default' , [ 'prod' ] ) ;
10-
11- gulp . task ( 'clean' , ( ) => {
12- [
13- path . join ( __dirname , 'packages/react-bootstrap-table2/lib' ) ,
14- path . join ( __dirname , 'packages/react-bootstrap-table2-editor/lib' ) ,
15- path . join ( __dirname , 'packages/react-bootstrap-table2-filter/lib' ) ,
16- path . join ( __dirname , 'packages/react-bootstrap-table2-overlay/lib' ) ,
17- path . join ( __dirname , 'packages/react-bootstrap-table2-paginator/lib' )
18- ] . forEach ( ( dir ) => {
19- rimraf . sync ( dir ) ;
20- } ) ;
21- } ) ;
22-
23- gulp . task ( 'build-js' , ( ) => {
24- [
25- 'react-bootstrap-table2' ,
26- 'react-bootstrap-table2-editor' ,
27- 'react-bootstrap-table2-filter' ,
28- 'react-bootstrap-table2-overlay' ,
29- 'react-bootstrap-table2-paginator'
30- ] . forEach ( ( pkg ) => {
31- gulp . src ( [
32- `./packages/${ pkg } /**/*.js` ,
33- `!packages/${ pkg } /+(test|dist|node_modules)/**/*.js`
7+ import shell from 'gulp-shell' ;
8+
9+ const LIB = 'lib' ;
10+ const DIST = 'dist' ;
11+ const TEST = 'test' ;
12+ const PKG_PATH = './packages' ;
13+ const NODE_MODULES = 'node_modules' ;
14+
15+ const JS_PKGS = [
16+ 'react-bootstrap-table2' ,
17+ 'react-bootstrap-table2-editor' ,
18+ 'react-bootstrap-table2-filter' ,
19+ 'react-bootstrap-table2-overlay' ,
20+ 'react-bootstrap-table2-paginator'
21+ ] . reduce ( ( pkg , curr ) => `${ curr } |${ pkg } ` , '' ) ;
22+
23+ const JS_SKIPS = `+(${ TEST } |${ LIB } |${ DIST } |${ NODE_MODULES } )` ;
24+
25+ const STYLE_PKGS = [
26+ 'react-bootstrap-table2' ,
27+ 'react-bootstrap-table2-paginator'
28+ ] . reduce ( ( pkg , curr ) => `${ curr } |${ pkg } ` , '' ) ;
29+
30+ const STYLE_SKIPS = `+(${ NODE_MODULES } )` ;
31+
32+
33+ function clean ( ) {
34+ return gulp
35+ . src ( `./packages/+(${ JS_PKGS } )/+(${ LIB } |${ DIST } )` , { allowEmpty : true } )
36+ . pipe ( cleanDir ( ) ) ;
37+ }
38+
39+ function scripts ( ) {
40+ return gulp
41+ . src ( [
42+ `./packages/+(${ JS_PKGS } )/**/*.js` ,
43+ `!packages/+(${ JS_PKGS } )/${ JS_SKIPS } /**/*.js`
44+ ] )
45+ . pipe ( babel ( ) )
46+ . pipe ( rename ( ( path ) => {
47+ if ( path . dirname . indexOf ( 'src' ) > - 1 ) {
48+ path . dirname = path . dirname . replace ( 'src' , `${ LIB } /src` ) ;
49+ } else {
50+ path . dirname += `/${ LIB } ` ;
51+ }
52+ } ) )
53+ . pipe ( gulp . dest ( PKG_PATH ) ) ;
54+ }
55+
56+ function styles ( ) {
57+ return gulp
58+ . src ( [
59+ `./packages/+(${ STYLE_PKGS } )/style/**/*.scss` ,
60+ `!packages/+(${ STYLE_PKGS } )/${ STYLE_SKIPS } /**/*.scss`
3461 ] )
35- . pipe ( babel ( ) )
36- . pipe ( gulp . dest ( `./packages/${ pkg } /lib` ) ) ;
37- } ) ;
38- } ) ;
39-
40- gulp . task ( 'build-sass' , ( ) => {
41- [
42- 'react-bootstrap-table2' ,
43- 'react-bootstrap-table2-paginator'
44- ] . forEach ( ( pkg ) => {
45- gulp
46- . src ( [
47- `./packages/${ pkg } /style/**/*.scss` ,
48- `!packages/${ pkg } /+(dist|node_modules)/**/*.scss`
49- ] )
50- . pipe ( sass ( ) . on ( 'error' , sass . logError ) )
51- . pipe ( gulp . dest ( `./packages/${ pkg } /dist` ) )
52- . pipe ( cleanCSS ( { compatibility : 'ie8' } ) )
53- . pipe ( rename ( ( path ) => {
54- path . extname = '.min.css' ;
55- } ) )
56- . pipe ( gulp . dest ( `./packages/${ pkg } /dist` ) ) ;
57- } ) ;
58- } ) ;
59-
60- gulp . task ( 'prod' , [ 'clean' , 'build-js' , 'build-sass' ] ) ;
62+ . pipe ( sass ( ) . on ( 'error' , sass . logError ) )
63+ . pipe ( rename ( ( path ) => {
64+ path . dirname = path . dirname . replace ( 'style' , DIST ) ;
65+ } ) )
66+ . pipe ( gulp . dest ( PKG_PATH ) )
67+ . pipe ( cleanCSS ( { compatibility : 'ie8' } ) )
68+ . pipe ( rename ( ( path ) => {
69+ path . extname = '.min.css' ;
70+ } ) )
71+ . pipe ( gulp . dest ( PKG_PATH ) ) ;
72+ }
73+
74+ function umd ( ) {
75+ return gulp . src ( './webpack.prod.config.babel.js' )
76+ . pipe ( shell ( [ 'webpack --config <%= file.path %>' ] ) ) ;
77+ }
78+
79+ const buildJS = gulp . parallel ( umd , scripts ) ;
80+ const buildCSS = styles ;
81+ const build = gulp . series ( clean , gulp . parallel ( buildJS , buildCSS ) ) ;
82+
83+ gulp . task ( 'prod' , build ) ;
84+ gulp . task ( 'default' , build ) ;
0 commit comments