-
Notifications
You must be signed in to change notification settings - Fork 342
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
Don't destroy existing outputPath on fail #253
base: master
Are you sure you want to change the base?
Conversation
Compile writes out to os.tmpdir, and if successful, it then moves the directory to the user defined output path and cleans up after itself. This allows for a compile to fail, but won't blow away the existing directory. I was using Harp for our dev and was thrown off by it destroying the contents of www when it errored. So I fixed that. Hopefully useful to others and PR-mergable.
Nice as i have also experienced the same thing and I had not put it in git. This properly fixes this issue #92 |
For further context, we're planning to use Harp in production of jsbin.com in a submodule that will get a git hook to tell it to recompile. And even though we're doing all we can to protect from this hook being called if the tests fail, it's possible it could run, and I want to ensure the "live content" is protected. |
Fantastic, thank you for doing this! We weren’t happy with the existing behaviour, and this sounds a lot better. I believe @silentrob had started something that would improve #19 or #93, so hopefully both your solutions can work together. |
Yeah lets get @silentrob in the loop on this. He had a PR last week to address this issue but I had a few concerns with it. |
// harp will write the project out here first, and if successul, it'll get | ||
// moved across to the real outputPath - to allow for compile to fail, without | ||
// blowing away the previous version. | ||
var tmpOutputPath = path.join(tmp, "www" + (Math.random() * 1000 | 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "www"...
bit should probably just be a random hash: crypto.createHash('md5').update(Math.random() + '').digest('hex')
as the pathname.
We will either have to add a |
Though this doesn't merge anymore (I'm sure it'll be simple to resolve) what's the thoughts on preserving the output directory until the compile is successful? I keep coming across cases where I need this. The latest is a blog containing 300 posts takes about 120 seconds to compile, so that's 2 minutes where the entire web site is blown away whilst the compile does its job. |
I've dropped the ball on this one. This really should get merged. Sorry @remy |
Any update on this? I'm using Github pages to host a site (meaning I need to compile to the root directory first. Unfortunately, this was the first time I realized that Harp clears the target directory, which is great in most contexts, but not when I need to keep certain files like a subrepo, script and readme in the root but not source. I found this from #346. Does this issue also include the ability to flag to not overwrite the directory, or is it just addressing overwrites for failures? |
@ixley You can follow this tutorial on how to do it with github pages |
Thanks @kevinsimper - that's pretty much the process I am using, but the problem I'm having is that I have files in my build/root directory that I don't want to or can't duplicate in my src directory. These include the README (not a huge deal if it had to be duplicated), a shell script (would be confusing if it were duplicated unnecessarily), and a subrepository (which needs to exist as a protected directory in the root), but obviously all these things get overwritten when I compile my files. |
@ixley I do have it like you say, I have that on a |
Thanks @kevinsimper. Just emailed you directly so I don't clutter up this thread more. |
@kevinsimper can you share a gist of your script perhaps ? are you able to automate the process somehow with GH post commit hooks ? |
Compile writes out to os.tmpdir, and if successful, it then moves the directory to the user defined output path and cleans up after itself. This allows for a compile to fail, but won't blow away the existing directory.
I was using Harp for our dev and was thrown off by it destroying the contents of www when it errored. So I fixed that. Hopefully useful to others and PR-mergable.