gulpgulp-injectrun-sequence

Gulp inject task doesn't work when calling with run-sequence


Required steps

  1. clean build directory.
  2. compile typescript files then put compiled files in to build directory.
  3. inject compiled files as script to index.html then put it to build directory.

Project structure

-- build
-- src
   --app
     --app.ts
     ..
-- index.html

index.html

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <!-- inject:js -->
    <!-- endinject -->
</body>
</html>

Gulp tasks

"devDependencies": {
   "del": "^2.2.0",
   "gulp": "^3.9.0",
   "gulp-inject": "^3.0.0",
   "gulp-typescript": "^2.10.0",
   "run-sequence": "^1.1.5"
}

gulp.task('clean', function() {
   return del('build');
});

gulp.task('ts', funtion() {
   var tsProject = ts.createProject('tsconfig.json');
   return tsProject.src('src/**/*.ts')
        .pipe(ts(tsProject))
        .js.pipe(gulp.dest('build'));
});

gulp.task('inject', funtion() {
   return gulp.src('index.html')
        .pipe(inject(gulp.src('build/**/*.js', {read: false}), {ignorePath: 'build', relative: true}))
        .pipe(gulp.dest('build'));
});

gulp.task('build', function() {
   runSequence('clean', 'ts', 'inject');
});

Problem

When I execute gulp ts && gulp inject it works perfectly.

When I excute gulp build the inject doesn't work with no message print out.

I think there are problems with run-sequence. Could you please help me to figure out the problems and how to solve it?


Solution

  • After several hours of digging, I realized that when a task returns an in-appropriate stream, run-sequence stops running with no warning or error. Hope this will help anyone else who have the same issue.