Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass filename to the replace function? #50

Comments

@yangg
Copy link

yangg commented Jun 23, 2015

Could you pass an argument filename to the replace function ?

@lazd
Copy link
Owner

lazd commented Jun 23, 2015

This is a very useful enhancement, and something that we should definitely include before 1.0.0 to avoid a breaking change.

This would change the function signature for regex replace, which way introduce an incompatibility with streaming regex replace. We'll have to explore further to know.

@lazd lazd mentioned this issue Jun 23, 2015
@keradus
Copy link

keradus commented Jun 23, 2015

Using stream as source and destination of replacement is great.
If you decided to add a file, please, could you made it as optional parameter or handled by second, dedicated method? It would be really great (and won't break interface).

@AStoker
Copy link

AStoker commented Jul 27, 2015

So I'm looking into trying and get that file functionality implemented. Since it technically is optional, I'm thinking of adding a RegExp option in the Options object to allow the user to specify with a regex string which files will receive this replace treatment.

Having it in the options object would keep any existing users from receiving breaking changes.

@AStoker
Copy link

AStoker commented Jul 27, 2015

However, if you're in need of this kind of functionality now, this plugin should accomplish what you need. https://github.com/sindresorhus/gulp-filter

@keradus
Copy link

keradus commented Jul 27, 2015

Yeah, and it keep everything KISS ;)

@ccbayer
Copy link

ccbayer commented Dec 4, 2015

+1 for this enhancement...

i am working on something similar whereby i replace a string with the current file name in the pipe. i'm not having a ton of luck Edit: i had to update my path being passed to replace but it seems gulp-tap is getting me the closest:

gulp.task('replaceWithCurrentUrl', function() {
  return gulp.src('app/*.html')
    .pipe($.tap(function(file) {
      var fileName = path.basename(file.path);
      return gulp.src('app/' + fileName)
        .pipe($.replace('%currentUrl%', fileName))
        .pipe(gulp.dest('app'));
    }));
});

@shawnjacobson
Copy link

I cannot get this to work at all, just trying to replace a file path from the server with a local one for debug...

gulp.task('server-debug', function () {
    const f = filter(['*', './src/app/models/hist.js'], {restore: true});

    return gulp.src(['./src/**/*','!./src/ngClient/**/*','!./src/ngClient'])
        .pipe(f)
        .pipe(replace('/var/lib/dbs/', 'C:/dbs/'))
        .pipe(f.restore)
        .pipe(gulp.dest('./deploy'));
});

I've tried it with and without the filter, tried wrapping the original text in new String('...') to prevent thinking its a RegEx, even tried a completely different string with no special characters, nothing is working. Any thoughts???

@lazd
Copy link
Owner

lazd commented Jun 20, 2017

Closed by 99474b3.

@lazd lazd closed this as completed Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment