This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
84 lines (71 loc) · 2.06 KB
/
gulpfile.babel.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import gulp from 'gulp';
import sourceMaps from 'gulp-sourcemaps';
import run from 'gulp-run-command';
import babel from 'gulp-babel';
import path from 'path';
import del from 'del';
import fs from 'fs';
import concat from 'gulp-concat';
import gulpJsdoc2md from 'gulp-jsdoc-to-markdown';
const paths = {
es6Path: './src/**/*.*',
es6: [ './src/**/*.js', '!./src/**/*.json' ],
es5: './dist',
docs: './jsdoc2md',
unitTest: './test/unit/**/*.spec.js',
integrationTest: './test/integration/**/*.spec.js',
// Must be absolute or relative to source map
sourceRoot: path.join( __dirname, 'src' )
};
gulp.task( 'clean:dist', () => {
return del( [
'./dist/**/*'
] );
} );
gulp.task( 'build', [ 'clean:dist', 'copy:nonJs' ], () => {
return gulp.src( paths.es6 )
.pipe( sourceMaps.init() )
.pipe( babel( {
presets: [ 'env' ]
} ) )
.pipe( sourceMaps.write( '.', { sourceRoot: paths.sourceRoot } ) )
.pipe( gulp.dest( paths.es5 ) );
} );
// Copy all the non JavaScript files to the ./dist folder
gulp.task( 'copy:nonJs', () => {
return gulp.src( [ paths.es6Path, '!' + paths.es6 ] )
.pipe( gulp.dest( paths.es5 ) )
} );
gulp.task( 'watch', [ 'build' ], () => {
gulp.watch( paths.es6, [ 'build' ] );
} );
gulp.task( 'test:unit',
run(`mocha '${paths.unitTest}' --require './test/mocha.conf.js'`,
{ignoreErrors: true}
)
);
gulp.task( 'test:integration',
run(`mocha '${paths.integrationTest}' --require './test/mocha.conf.js'`,
{ignoreErrors: true}
)
);
gulp.task( 'test:unit:watch', () => {
gulp.watch( [paths.unitTest, paths.es6], [ 'test:unit' ] );
} );
gulp.task('docs', () => {
return gulp.src(paths.es6)
.pipe(concat('README.md'))
.pipe(gulpJsdoc2md({
template: fs.readFileSync(`${paths.docs}/README.hbs`, 'utf8'),
partial: [
`${paths.docs}/contribute.hbs`,
`${paths.docs}/badges.hbs`,
`${paths.docs}/intro.hbs`
]
}))
.on('error', (err) => {
console.log('jsdoc2md failed:', err.message)
})
.pipe(gulp.dest('./'))
});
gulp.task( 'default', [ 'watch' ] );