sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 217 forks source link

Added option to specify custom transformer for the manifest file. #164

Closed ajaybc closed 8 years ago

ajaybc commented 8 years ago

I added an option to specify a custom transformer for the output rev file. For example if the user wants the output in YAML format instead of the default JSON format, he can specify like this .pipe(rev.manifest('assets-manifest.yaml', {merge:true, transformer : require('yamljs')}))

The transformer can be any object which has a parse and stringify function. The yamljs library in the above example already has those 2 functions, so it can be used directly. This way even if the user wants the manifest in some specific format like for example, PHP associative array, then he can write a transformer for that.

bobthecow commented 8 years ago

I feel like it might be gulpier to keep the JSON output here and use a transformer as the next step in the pipeline. Composition rather than configuration, and all :)

ajaybc commented 8 years ago

@bobthecow I thought like that at first. But the thing is that gulp-rev has this feature where it tries to read an existing manifest in JSON and tries to merge the current values on to it. If we put the transformer next in the pipeline, it wont be able to read that file as it might not be JSON depending on the transformer used. By specifying the transformer while calling the manifest function, we can avoid this problem. Also IMO the actual transformation logic is decoupled from the gulp-rev logic.

bobthecow commented 8 years ago

@ajaybc This is a good point. :+1:

lukeed commented 8 years ago

This was never released on NPM 😿