adamayres / gulp-extend

A gulp plugin to extend (merge) json contents
https://npmjs.org/package/gulp-extend
MIT License
19 stars 6 forks source link

merging gulp-rev #1

Closed jney closed 10 years ago

jney commented 10 years ago

i'm trying to use gulp-extend but nothing is "extended". my code :

gulp.src('src/js/*.js')
.pipe(concat('index.js'))
.pipe(rev())
.pipe(gulp.dest('build'))
.pipe(rev.manifest())
.pipe(intercept(function(f){
  console.log('content :', f.contents.toString());
  return f;
}))
.pipe(extend('./config/rev-manifest.json'))
.pipe(intercept(function(f){
  console.log('content :', f.contents.toString());
  return f;
}))
.pipe(gulp.dest('config'));

console.log output :

content : {
  "index.js": "index-9040c48c.js"
}
content : {"index.js":"index-9040c48c.js"}

and :

$ cat ./config/rev-manifest.json
{
  "index.css": "index-9c4d4d78.css"
}
jney commented 10 years ago

to complete my description, i expected file ./config/rev-manifest.json to look like that :

{
  "index.js": "index-9040c48c.js",
  "index.css": "index-9c4d4d78.css"
}
Dragory commented 10 years ago

I also had this problem. The filename you give gulp-extend is actually the resulting file's name; it doesn't read it. The only files that are merged are the ones present in the stream.

One solution:

var es = require('event-stream');
var manifest = './config/rev-manifest.json';

gulp.task('something', function() {
    var stream = gulp.src('src/js/*.js')
        // <insert substeps here>
        .pipe(rev.manifest());

    // Include both the current manifest file and the new one in a stream
    es.concat(
        gulp.src(manifest),
        stream
    )
        .pipe(extend(manifest))
        .pipe(gulp.dest('config'));
}