-
Notifications
You must be signed in to change notification settings - Fork 24
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
Support multiple directory trees and filename changes #1
Comments
Thanks for trying this out. I'd like to better understand what you're running into. I think it would be easier to talk in terms of the existing plugins your using and how they are configured.
I assume this means you're configuring the gulp.task('stylus', function() {
gulp.src('./public/**/*.styl')
.pipe(stylus())
.pipe(gulp.dest('./working'));
}); The minimum extra information gulp.task('stylus', function() {
gulp.src('./public/**/*.styl')
.pipe(newer({dest: './working', ext: '.css'}))
.pipe(stylus())
.pipe(gulp.dest('./working'));
}); Does this treat the first case you mention? Can you give examples (with code) of other cases you'd like covered? |
Support for the |
These options are nice, but I think there is one further case that needs support. I've been trying to find a way for gulp-newer to play nicely with gulp-rev (sindresorhus/gulp-rev#32) In this scenario, the filename is changed, not just the extension. I'm contemplating something like a .pipe(newer({mapping: function(filename, dest, cb){
//... My custom logic to look in dest for filename ...
}})); |
Any word on this? I'm in a similar boat whereby I have a pipe with a big ol rename() at the end of it that absolutely mucks up this or gulp-changed. Personally, I'm thinking that gulp-newer should operate similar to gulp-rename in that 'dest' can be a string or a function that is passed the vinyl object and returns a string. |
See also #10 (comment). If you squint at it the right way, I think these are all the same suggestion. Something like @peterbraden's suggestion would be straightforward to implement. If people can post more complete example tasks where they'd use a |
I'll describe a use case I'm experiencing right now: I'm using gulp as a static site generator and I'm looking to have clean urls without extensions. Typically, a webserver will automatically serve the .pipe(rename(function(path) {
if(path.basename !== 'index') {
path.dirname += '/'+path.basename;
path.basename = 'index';
}
return path;
}) In order for |
@tschaub Yep, this solution works great! |
@oconnore TC ! gulp.task('images', function() {
return gulp.src('resources/uploads/**/*')
//.pipe(changed('webroot/galleries'))
//.pipe(cache('images'))
.pipe(newer({
dest: 'webroot/galleries',
map: function(pathDir) {
pathDir =
path.dirname(pathDir) + '/50-x-' +
path.basename(pathDir, path.extname(pathDir)) + '-thumb' +
path.extname(pathDir);
return pathDir;
}
}))
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(
responsive(
{
'**/*' : [{
width: 50,
rename: {
//path.dirname += "";
prefix: "50-x-",
suffix: "-thumb"
//path.extname = ".md"
}
}]
})
)
.pipe(gulp.dest('webroot/galleries'))
.pipe(notify({ message: 'Images task complete' }));
}); |
I have one other suggestion for this functionality. I've got an ES6 file with the extension .pipe($.newer({
dest: dest,
ext: '.js'
})) What I want is: ext: [
'.js',
'.min.js'
'.map'
] I can't figure out how to pipe in two gulp-newer operations because the first would cancel out the second if it exists. So this might be possible that way as well. |
gulp-newer currently only supports single directory targets with direct file matches, and single file 'all' targets. For my build I need to do things like:
I setup my build without using gulp-newer, but would like to contribute back to make this module work better for everyone (also me) in the future.
Currently, my API for these things looks like:
That's really [infinitely] flexible, but maybe preserving a nicer API is a good idea as well. Lets start with:
Nested directories
If we are OK requiring that the directory structure in the target is built beforehand, we can use it to find the deepest possible match (from the right) relative to the base directory, and require no change to the gulp-newer API. This heuristic should work most of the time:
(Until nodejs/node-v0.x-archive#6662 is resolved, this may require memoizing stat calls -- I had to do that for my build, but I would want to do more profiling before I committed that assumption to a public project.)
Pathname changes
Changes of file name (extension, append, replace, etc.) is a bit more complicated, and while I can imagine some ways to integrate it with the existing single-string configuration style, that seems messy, non obvious, and prone to error. For example, attempts to correlate output files on the first build with source files, and attempts to parse a change in filename from a globbed output pattern both seem really unpleasant to implement, support, and use.
We also (I think?) would like to not require users to write a conversion function when possible, but should allow it when necessary. Here are some thoughts:
options
object to be passed asnewer(destBase, { /* options */ })
sourceBase
option to change the cwd.path
,filename
, andfullpath
mutators:{filebase}.css
with keys like:{path [0-9]+(-[0-9]+)?}
{filebase}
and{fileext}
s/from/to/
style regexDiscussion
What do you think? Would you accept a pull request for something like this + feedback?
The text was updated successfully, but these errors were encountered: