I'm using Gulp
to build my Typescript
application for Node.js
.
For my purposes I need to scan all .ts
files, retrieve some information, and then append this information to some of .ts
files.
I'm using gulp-modify
to inject my file handler to the pipe()
.
gulp.task(...., function() {
return gulp.src('*.ts')
.pipe(modify(statisticsProccesor))
.pipe(modify(injectData))
.pipe(gulp.dest(...))
});
Where statisticsProccesor
and injectData
are function(file, content)
implementations to process exact file from sources stream.
Using this approach I can retrieve some statistics from sources. But I can not inject it back because gulp.src()
processes all files one by one (and calls all handlers too).
Once I have 2 files 1.ts
and 2.ts
this task will process it in such order:
1.ts: statisticsProccesor(), injectData()
2.ts: statisticsProccesor(), injectData()
while I need to do such magic:
1.ts: statisticsProccesor()
1.ts: statisticsProccesor()
2.ts: injectData()
2.ts: injectData()
I've tried to add 2 gulp.src().pipe(modify)
commands to the task. And also to separate these parts to 2 different tasks to launch one by one. But Gulp optimizes execution, so I can't preprocess sources and iterate them twice.