-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
62 lines (50 loc) · 1.69 KB
/
gulpfile.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
const gulp = require('gulp');
const __browserify = require('browserify')
const source = require( 'vinyl-source-stream' )
// Contains all plugins the project depends on
const plugins = require('gulp-load-plugins')();
// Generate the peg from the grammar
function generatePeg() {
return gulp.src('src/tidal.pegjs')
.pipe(gulp.dest('dist')) // Add the tidal.pegjs file to dist to do everything in the same directory
.pipe(plugins.pegjs({format: 'commonjs', cache:true }))
.pipe(gulp.dest('dist'));
}
// Concatenate the flatten.js file with the generated peg
function flatten(){
return gulp.src(['dist/tidal.js', './src/queryArc.js', './src/pattern.js' ])
.pipe(plugins.concat('peg-parse-query.js'))
.pipe(gulp.dest('dist'));
}
function browserify() {
return __browserify({
entries:'./src/pattern.js',
standalone:'Pattern'
})
.bundle()
.pipe( source('pattern.js' ) )
.pipe( gulp.dest( 'dist' ) )
}
// Run tests
function runTests(){
return gulp.src('test/*.js', {read:false})
.pipe(plugins.mocha({ reporter:'nyan'}));
}
// Watch for changes in the peg, any js file or any test file and run tests
function watchFiles(){
gulp.watch('./src/*', gulp.series('test'));
gulp.watch('./test/*', gulp.series('test'));
}
// Clean everything that was made with gulp
function clean(){
return gulp.src('dist/*', {read: false})
.pipe(plugins.clean())
}
// Task definitions
gulp.task('build', generatePeg);
gulp.task('flatten', gulp.series('build', flatten));
gulp.task('test', gulp.series('flatten', runTests));
gulp.task('watch', watchFiles);
gulp.task('clean', clean);
gulp.task('default', gulp.series('build'));
gulp.task('browserify', gulp.series( 'build', browserify ) );