When running the gulp default task, one of the build tasks does not complete. And it seems to depend on the order in which they are called. Here's the script.
var gulp = require('gulp');
var del = require('del');
var ts = require('gulp-typescript');
var concat = require('gulp-concat');
var tsProject = ts.createProject('tsconfig.json');
gulp.task('clean', function () {
return del(['dist']);
});
gulp.task('buildCommon', function () {
return gulp.src('src/common/**/*.ts')
.pipe(ts(tsProject))
.pipe(concat('common.min.js'))
.pipe(gulp.dest('dist/server'))
.pipe(gulp.dest('dist/client'));
});
gulp.task('buildServer', function () {
return gulp.src('src/server/**/*.ts')
.pipe(ts(tsProject))
.pipe(concat('server.min.js'))
.pipe(gulp.dest('dist/server'));
});
gulp.task('build', ['clean'], function () {
gulp.start('buildCommon');
gulp.start('buildServer');
});
Running results in the following.
c:\development\git\fsts>gulp build
[06:31:19] Using gulpfile c:\development\git\fsts\gulpfile.js
[06:31:19] Starting 'clean'...
[06:31:19] Finished 'clean' after 10 ms
[06:31:19] Starting 'build'...
[06:31:19] Starting 'buildCommon'...
[06:31:19] Starting 'buildServer'...
[06:31:19] Finished 'build' after 15 ms
[06:31:20] Finished 'buildServer' after 1.18 s
You should notice that buildCommon does not complete.
If I run, buildCommon or buildServer tasks individually, they work.
c:\development\git\fsts>gulp buildServer
[06:34:00] Using gulpfile c:\development\git\fsts\gulpfile.js
[06:34:00] Starting 'buildServer'...
[06:34:01] Finished 'buildServer' after 783 ms
c:\development\git\fsts>gulp buildCommon
[06:34:31] Using gulpfile c:\development\git\fsts\gulpfile.js
[06:34:31] Starting 'buildCommon'...
[06:34:31] Finished 'buildCommon' after 761 ms
Here's the other weird part. If I change the order of the start calls, then the buildServer doesn't complete.
gulp.task('build', ['clean'], function () {
gulp.start('buildServer');
gulp.start('buildCommon');
});
c:\development\git\fsts>gulp build
[06:39:20] Using gulpfile c:\development\git\fsts\gulpfile.js
[06:39:20] Starting 'clean'...
[06:39:20] Finished 'clean' after 9.86 ms
[06:39:20] Starting 'build'...
[06:39:20] Starting 'buildServer'...
[06:39:20] Starting 'buildCommon'...
[06:39:20] Finished 'build' after 16 ms
[06:39:21] Finished 'buildCommon' after 1.18 s
Any ideas why the two separate tasks with their own streams won't let one of them finish?
Update: tried to use merge-stream and a single task and it still has the same behavior.
Update! My next move was to try and merge the streams and just use one task but I am getting a similar result.
var gulp = require('gulp');
var del = require('del');
var ts = require('gulp-typescript');
var concat = require('gulp-concat');
var merge = require('merge-stream');
var tsProject = ts.createProject('tsconfig.json');
gulp.task('clean', function () {
return del(['dist']);
});
gulp.task('build', ['clean'], function () {
var serverStream = gulp.src('src/server/**/*.ts')
.pipe(ts(tsProject))
.pipe(concat('server.js'))
.pipe(gulp.dest('dist/server'));
var commonStream = gulp.src('src/common/**/*.ts')
.pipe(ts(tsProject))
.pipe(concat('common.js'))
.pipe(gulp.dest('dist/server'))
.pipe(gulp.dest('dist/client'));
var merged = merge(commonStream, serverStream);
return merged;
});
gulp.task('default', ['build']);
With the result looking like the build task doesn't complete.
c:\development\git\fsts>gulp
[06:58:00] Using gulpfile c:\development\git\fsts\gulpfile.js
[06:58:00] Starting 'clean'...
[06:58:00] Finished 'clean' after 9.9 ms
[06:58:00] Starting 'build'...