Repository navigation
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
70 lines (53 loc) · 1.78 KB
/
Copy pathgulpfile.babel.js
File metadata and controls
70 lines (53 loc) · 1.78 KB
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
import path from 'path';
import gulp from 'gulp';
import del from 'del';
import sourcemaps from 'gulp-sourcemaps';
import babel from 'gulp-babel';
import through from 'through2';
import moment from 'moment';
const packageInfo = require( './package.json' );
const OUT_TIME_FMT = 'HH.mm.ss.SSS';
const cfg = {
src: {
root: '.',
files: [ 'index.js', path.join( '.', 'lib', '**', '*.js' ) ]
},
prod: {
root: 'dist',
'es2015-node': `${ path.join( 'dist', 'es2015-node' ) }`
}
}
function _formatFiles( filePaths ) {
return '\t' + filePaths
.join( '\n\t' );
}
gulp.task( 'prod.clean', ( ) => {
return del( [ path.join( cfg.prod[ 'es2015-node' ], '**', '*' ), cfg.prod[ 'es2015-node' ], cfg.prod.root ] )
.then( ( paths ) => {
console.log( `[${ moment().format( OUT_TIME_FMT ) }] [LOG] Deleted files [${ paths.length }]: \n${ _formatFiles( paths ) }` )
} );
} );
gulp.task( 'prod', [ 'prod.clean' ], ( ) => {
const inFiles = cfg.src.files;
const es2015Dest = cfg.prod[ 'es2015-node' ];
const es2015NodeFiles = [ ];
const es2015NodeStream = gulp.src( inFiles )
.pipe( sourcemaps.init( ) )
.pipe( babel( ) )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( ( file ) => {
return path.join( '.', es2015Dest, path.relative( process.cwd( ), file.base ) );
} ) )
.pipe( through.obj( function ( file, enc, callback ) {
if ( file && file.path ) {
es2015NodeFiles.push( file.path )
}
this.push( file );
callback( );
} ) )
.on( 'end', ( ) => {
console.log( `[${ moment().format( OUT_TIME_FMT ) }] [LOG] Generated ${ 'ES2015 NodeJS' } files [${ es2015NodeFiles.length }]: \n${ _formatFiles( es2015NodeFiles ) }` );
} );
return es2015NodeStream;
} );
gulp.task( 'default', [ 'prod' ] );