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

Preserve original dotted parts of filename when adding custom extension #67

Closed
getify opened this issue Oct 28, 2013 · 8 comments
Closed

Comments

@getify
Copy link

getify commented Oct 28, 2013

If I set up a task like this:

compress: {
    js: {
        options: {
            mode: "gzip"
        },
        files: [
            {
                expand: true,
                src: path.join(__dirname,"js","*.js"),
                ext: ".js.gz"
            }
        ]
    }
}

This works fine unless I have compound dotted file-names, such as:

js/foo.bar.js
js/foo.bar.bam.js

What I get created is a single js/foo.js.gz which both of those files seem to target, thus the subsequent overwrites the previous.

What I'd like is for a way to specify that the file-extension of a source filename is ".js", and I want only THAT extension replaced by the ".js.gz" in the target file, instead of treating ".bar.js" and "bar.bam.js" as the extensions in the source filenames to be replaced.

Is this possible already and I'm not aware?


I looked through the code to try and see if there was an easy fix, but I was a little confused by how it works and how it identifies the extensions.

I was thinking maybe something like this could work:

{
    expand: true,
    src: path.join(__dirname,"js","*.js"),
    orig_ext: ".js",
    ext: ".js.gz"
}

Is that workable? If so, I'd be happy to try (with some assistance/hints) to submit a patch for it.

@tkellen
Copy link
Member

tkellen commented Oct 28, 2013

@getify
Copy link
Author

getify commented Oct 30, 2013

@tkellen I tried this:

files: [
    {
        expand: true,
        src: path.join("js","*.js"),
        rename: function(dest,src) {
            console.log(arguments);

            return dest;
        }
    }
]

Unfortunately, dest parameter being passed in is undefined, so when I return the dest variable, grunt throws an error about not being able to call replace() on undefined. Any idea why the original src gets passed in, but the dest does not?

Update: I guess I only needed src for my purposes, but it's still weird that the first param, ostensibly the dest, is not being passed in. Docs could use a little more clarification, maybe an example or two of using rename(..).

@tkellen
Copy link
Member

tkellen commented Oct 31, 2013

Glad you're up and running! We've got an open issue on this in the grunt-docs repo. I'll reference this issue there and we'll try to get it sorted.

@getify
Copy link
Author

getify commented Oct 31, 2013

thanks. sounds like this bug can be closed then. :)

@btilford
Copy link

Kind of sounds like a match on 1st index of "." instead of last.

@tkellen
Copy link
Member

tkellen commented Mar 14, 2014

This has been resolved with the extDot option. See:
http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically

@gdennie
Copy link

gdennie commented Jul 10, 2014

Since the extension filter is a suffix and typically includes the ".", I think the default value for extDot should be "last", not "first".

I encountered this problem and wasn't aware of the extDot or why it was occurring. Took me awhile to figure out what was going on. Didn't help that "module.spec.coffee" worked while "ns.module.coffee" did not. My bad, of course, but still.

@getify
Copy link
Author

getify commented Jul 10, 2014

@gdennie +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants