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

Check if dest is a directory #107

Open
sevarubbo opened this issue Nov 1, 2016 · 3 comments
Open

Check if dest is a directory #107

sevarubbo opened this issue Nov 1, 2016 · 3 comments

Comments

@sevarubbo
Copy link

There should be an option to use only changed files from src if dest is a directory. I have a task that makes operation in files and moves them to a folder and I want to perform these operations only on changed files, not all of them.

@matatk
Copy link

matatk commented Nov 15, 2016

I think this would help me, too. I have a task that converts an SVG to several PNGs in a destination folder. This takes some time, so I only really want to run it again when the single src SVG file has changed. But grunt-newer always runs the SVG-to-PNGs task because it expects to find a file in the dest directory with the same name as the source SVG file (of course it won't, because there are multiple dest files with different names and .png instead of .svg for their extensions).

So, I think what we are asking for is:

if dest is a directory:
   treat task as if it were a source-files-only task (only check the timestamp(s) of the source file(s))

Does this make sense? Happy to provide further info if you're interested.

[ Note: I'm trying grunt-newer in a different branch to the one I linked to above, which is why it's not in the Gruntfile (yet) ]

@sevarubbo
Copy link
Author

@matatk Check out my fork, where I fixed this issue: sevarubbo/grunt-newer. Since it looks like this project is not being supported for quite a long time, I think the only option is to make forks :)

It's quite easy to use, actually. In your package.json just replace "grunt-newer": "^1.2.0" with "grunt-newer": "sevarubbo/grunt-newer"

@matatk
Copy link

matatk commented Nov 16, 2016

Hi @sevarubbo, and thanks for your reply. I checked out your fork, and it does exactly what you said it does; thanks. However, I now realise this is not actually exactly what I need...

My problem is that when I configure grunt-phantom-rasterize to generate output files in the correct output directory, grunt-newer thinks that the output files are not there, and always re-runs the task. This is the output from grunt -v

Running "newer:rasterize:chrome" (newer) task
Options: cache="/Users/matatk/projects/landmarks/node_modules/grunt-newer/.cache", override=undefined, tolerance=0
Files: src/assemble/landmarks.svg -> ../../cache/landmarks.svg

The problem is that the output files have names like "landmarks-32.png" and "landmarks-48.png" and not just "landmarks.svg". My current files objects look like this:

                    files: [{
                        expand: true,
                        cwd: srcAssembleDir,
                        src: 'landmarks.svg',
                        dest: path.join('..', '..', pngCacheDir)
                    }]

I did try to reconfigure the files object in my Gruntfile in order to ensure that grunt-newer sees dest as a directory:

                    files: [{
                        src: path.join(srcAssembleDir, 'landmarks.svg'),
                        dest: path.join('..', '..', pngCacheDir)
                    }]

In this case, your fork of grunt-newer behaves perfectly, detecting that dest is a directory and ignoring it if landmarks.svg has not changed.

Running "newer:rasterize:chrome" (newer) task
Options: cache="/Users/matatk/projects/landmarks/node_modules/grunt-newer/.cache", override=undefined, tolerance=0
Files: src/assemble/landmarks.svg -> ../../cache

However, when I set up the files object in this way, grunt-phantom-rasterize always outputs the PNG files in the root directory of the repo, rather than the "cache" directory.

I can think of a hacky solution: simply move the PNG files to the cache directory when they have been generated, but this feels totally wrong.

However, this is now somewhat off topic for grunt-newer I think! So I will try to figure it out. Thanks to @tschaub for writing this in the first place and to you @sevarubbo for your updates.

Update: actually I just re-checked and grunt-newer doesn't work if I use ../../cache as the dest path, as it appears that grunt-newer is treating dest as relative to Gruntfile.js, but grunt-phantom-rasterize is treating dest as relative to src. My head hurts! :-) Suspect I'm making a n00b error here; will keep researching...

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

2 participants