tschaub / gulp-newer

Pass through newer source files only
https://npmjs.org/package/gulp-newer
226 stars 24 forks source link

map without dest not allowed #25

Closed rogierschouten closed 8 years ago

rogierschouten commented 8 years ago

Minor issue: I tried to provide a map function in opts.map but I was then forced to also provide an opts.dest (error 'Requires a dest string'). There are cases where I want to do my own dest directory mapping, so providing dest doesn't always make sense.

tschaub commented 8 years ago

@rogierschouten if you could provide a complete (and simple) example, it would make it easier for someone to respond with a fix (if appropriate). Thanks.

rogierschouten commented 8 years ago

@tschaub Maybe if you were a bit nicer to people who tried to help you improve your module they would actually give you more feedback.

Here is a simplified example.

var gulp = require("gulp");
var newer = require("gulp-newer");
var rename = require("gulp-rename");

gulp.task("default", function() {
    return gulp.src([
            "lib/**/bundle-release.js",
        ], {base: "."})
        .pipe(newer({ map: function(srcPath) {
            return path.join("dist", srcPath.substr(0, srcPath.length - 11) + ".js");
        }}))
        .pipe(rename(function(p) {
            p.basename = p.basename.replace("-release", "");
        }))
        .pipe(gulp.dest("dist"))
        .pipe(sink());
});

This is the output you get:

$ gulp
[09:29:04] Using gulpfile gulpfile.js
[09:29:04] Starting 'default'...
[09:29:04] 'default' errored after 7.45 ms
[09:29:04] Error in plugin 'gulp-newer'
Message:
    Requires a dest string

Obviously, the workaround is simply letting gulp-newer handle the directory change:

var gulp = require("gulp");
var newer = require("gulp-newer");
var rename = require("gulp-rename");

gulp.task("default", function() {
    return gulp.src([
            "lib/**/bundle-release.js",
        ], {base: "."})
        .pipe(newer({ dest: "dist", map: function(srcPath) {
            return srcPath.substr(0, srcPath.length - 11) + ".js";
        }}))
        .pipe(rename(function(p) {
            p.basename = p.basename.replace("-release", "");
        }))
        .pipe(gulp.dest("dist"))
        .pipe(sink());
});

However, I don't see why you would not allow the user to mangle his own directories as well. As I said, a very minor issue that you could view as a simple improvement to your module.

tschaub commented 8 years ago

@rogierschouten it sounds like you may have misinterpreted my response above. It was an honest and straightforward request for more information - not intended as mean spirited or snarky. Though we all know that tone doesn't carry well in short messages between people who don't know one another.

I don't have time right now to dig into the issue that you brought up. I was honestly hoping that if you provided a bit more detail, someone else might come along and volunteer some time to address it. It looks like you have provided some good additional detail above.