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

Correct gulp install script's wrench config for src/site merges #1845

Closed
wants to merge 1 commit into from
Closed

Conversation

slife
Copy link
Contributor

@slife slife commented Feb 21, 2015

Even though the gulp install script outputs:
Site folder exists, merging files (no overwrite) project-dir/semantic/src/site/

The src/site directory is blown away (not preserving existing files) due to the forceDelete:true setting.

Even though the gulp install script outputs:
```Site folder exists, merging files (no overwrite) project-dir/semantic/src/site/```

The `src/site` directory is blown away, not preserving existing files, due to the `forceDelete:true` setting.
@slife slife changed the title Corrected wrench config for src/site merges Correct gulp install script's wrench config for src/site merges Feb 21, 2015
@jlukic
Copy link
Member

jlukic commented Feb 21, 2015

My understanding is that forceDelete is required to add new files to an existing directory, but preserveFiles: true makes sure that individual files are not overwritten.

See this big old note in WrenchJS readme

I'm worried that if we change forceDelete: false then we will not be able to add new element definitions into site/ in existing folders.

I will need to retest this.

@slife
Copy link
Contributor Author

slife commented Feb 21, 2015

You're correct. This PR doesn't correct the problem completely. This fix preserves the files in the site/ dir but makes it so any new files aren't copied into site/ during the script's install task.

There seems to be a wrench-js issue copying into an existing directory while preserving existing files. The preserveFiles: true isn't read before it deletes the existing directory.

As you mentioned, in wrench v1.5.0 there was a breaking change introduced which seems to be impacting the install script. If forceDelete: true, it will delete the existing directory, otherwise it will return new Error(...). Because wrench has return new Error() instead of a throw new Error() and the install gulp script doesn't check the return for wrench.copyDirSyncRecursive(), this fails silently.

From: https://github.com/ryanmcgrath/wrench-js/blob/master/lib/wrench.js

exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
    opts = opts || {};

    try {
        if(fs.statSync(newDirLocation).isDirectory()) { 
            if(opts.forceDelete) {
            exports.rmdirSyncRecursive(newDirLocation);
            } else {
                return new Error('You are trying to delete a directory that already exists. Specify forceDelete in the opts argument to override this. Bailing~');
            }
        }
    } catch(e) { }

    //...

I'll submit a PR to wrench-js to honor the preserveFiles option and bypass the rmdirSyncRecursive() if it is set to true. This seems to be the best option.

What are your thoughts?

@slife
Copy link
Contributor Author

slife commented Feb 22, 2015

PR created for correcting this behavior within wrench:
ryanmcgrath/wrench-js#100

@jlukic
Copy link
Member

jlukic commented Feb 23, 2015

Thanks @derekslife you present this all quite lucidly.

I think we can point to your forked wrench copy as an NPM dependency, add your patch, then wait for a response to your PR. The project seems to be relatively idle, so I'm not counting on it being quick.

jlukic added a commit that referenced this pull request Feb 23, 2015
@jlukic
Copy link
Member

jlukic commented Feb 23, 2015

Merged into next in 1ca71b0

jlukic added a commit that referenced this pull request Feb 23, 2015
@jlukic
Copy link
Member

jlukic commented Feb 23, 2015

I've tested install with changes and everything seems to be fine, files are preserved and new files are copied to existing directories. Pushing with next.

@jlukic jlukic closed this Feb 23, 2015
jlukic added a commit that referenced this pull request Feb 23, 2015
@slife
Copy link
Contributor Author

slife commented Feb 23, 2015

Thanks.

In the long term, due to wrench's stale project state, we should explore moving away from it all together. It would be more idiomatic to just use gulp's own vinyl-fs. However, we may have to submit a PR for this issue (gulpjs/vinyl-fs#30) to get the overwrite behavior needed.

@jlukic
Copy link
Member

jlukic commented Feb 23, 2015

Agreed. Would prefer to use something native. Its always nice to replace a 10 liner with a 1 liner though when it makes sense. Lets pray Gulp 4 won't require everything to be rewritten.

@slife
Copy link
Contributor Author

slife commented Feb 23, 2015

PR Submitted: gulpjs/vinyl-fs#59

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

Successfully merging this pull request may close these issues.

2 participants