-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Should file.expandMapping support "src" tweaking? #680
Comments
Yes! I was just thinking I needed this for that static blog generator hack I made for tkellen.com. |
How would you use it? |
Haha, now I'm drawing a blank. I'll revisit this more later. I definitely think this would make sense in the glob expansion lib, though. I can't wait to start working on that with you. Back to work here. |
I like it and I could imagine that this has more use cases, but except for the one I brought up I can't think of anything real. |
It looks to me like this functionality is similar to the The use-case for me is module wrapping, similar to brunch: https://github.com/brunch/brunch/blob/master/docs/config.md#modules |
@cesutherland It's a bit different. @cowboy {
'build/output.js': buildSrc([
'src/wrapper/preamble.js',
[
'src/wrapper/before.js',
['src/main-file-*.js'],
'src/wrapper/after.js',
],
]),
} Maybe as part of a utility for common config transforms instead? |
It is at least sufficient for the task. |
@jonschlinkert I tried a while back to figure out how to do this declaratively and couldn't figure out anything sane. If it's ok that the values be resolved at init-time (and not when the task runs) you could just do: {
assemble: {
options: {
// _.load() mixin using resolve-dep
helpers: _.load("helper-*")
}
}
} Or better yet: {
assemble: {
options: {
// load helpers using resolve-dep
helpers: require('resolve-dep').load("helper-*")
}
}
} Also, totally unrelated issue. 😀 |
okay... I moved the topic to 896. feel free to delete these comments if you want to keep this clean. |
I've actually done this in the "async" branch of node-globule but haven't merged it into master yet. The next major release of Grunt will have this updated behavior. See examples here: https://github.com/cowboy/node-globule/blob/10fe13c755c34087c3028b615ec7ab7b70ed6d5d/test/mapping_test.js#L174-L217 |
So the
rename
method allows us to programmatically modify thedest
property as src-dest file mappings (viaexpand
) are created. Is there any value in being able to programmatically modify thesrc
property?I'll post an example where it could be useful: gruntjs/grunt-contrib-concat#9
In order to do what the OP wants, which is to "wrap" every
src/main-file-*.js
with some before/after content and concat all that together with an additional file prepended to the beginning, we can specify files like so:Or in an (arguably) more readable but (arguably) harder to maintain format, we can use multiple file objects and tempfiles:
We can currently specify this:
But it only gets us halfway there, because the
src
properties are single files:If we could somehow modify the
src
property however, it could allow code like this:To generate the object we want, dynamically:
Thoughts?
The text was updated successfully, but these errors were encountered: