Folder structure:
project
|
+-coffee
| |
| +-main.coffee
| |
| +-testDir
| | |
| | +-models.coffee
| | |
| | +-views.coffee
| |
| +-anotherDir
| | |
| | +-routes.coffee
| | |
| | +-views.coffee
| | |
| | +-modules.coffee
| |
| +- etc...
|
+-www
The idea is to keep the folder structure from the coffee/
directory when writing files to the www/
directory. There can be an arbitrary number of subfolders in coffee/
. All .coffee
files from each folder should be concatened into a modules.js
file:
www
|
+-modules.js
|
+-testDir
| |
| +-modules.js
|
+-anotherDir
| |
| +-modules.js
|
+- etc...
I currently have this gulp task:
gulp.task('coffee', function() {
gulp.src('./coffee/**/*.coffee', {base: './coffee/'})
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(uglify())
// .pipe(concat('modules.js'))
.pipe(gulp.dest('./www'))
});
Without the concat()
the files are placed into the correct subfolders (but they're not concatened). With the concat()
all files are concatened into a single modules.js
file:
www
|
+-modules.js
How I can realize this correctly?
Here's a solution using
gulp-flatmap
:This first puts the
coffee/
directory and all of its direct subdirectories in a stream. Each of those directories then gets mapped to a new stream that concatenates all.coffee
files in the respective directory. Finally the appropriate destination folder for each resultingmodules.js
file is determined by usingpath.relative()
.