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

Don't destroy existing outputPath on fail #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

remy
Copy link
Contributor

@remy remy commented Feb 21, 2014

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.

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.
@kevinsimper
Copy link

Nice as i have also experienced the same thing and I had not put it in git.

This properly fixes this issue #92

@remy
Copy link
Contributor Author

remy commented Feb 21, 2014

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.

@kennethormandy
Copy link
Collaborator

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.

@sintaxi
Copy link
Owner

sintaxi commented Feb 21, 2014

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))
Copy link
Contributor Author

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.

@kennethormandy
Copy link
Collaborator

We will either have to add a -f flag (or something) or change how the tests work. Unfortunately it seems like the ones using compile don’t run properly.

@kennethormandy kennethormandy modified the milestone: Harp v0.12.0 Mar 14, 2014
@remy
Copy link
Contributor Author

remy commented Sep 5, 2014

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.

@sintaxi
Copy link
Owner

sintaxi commented Oct 3, 2014

I've dropped the ball on this one. This really should get merged. Sorry @remy

@ixley
Copy link

ixley commented Oct 24, 2014

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?

@kevinsimper
Copy link

@ixley You can follow this tutorial on how to do it with github pages

http://harpjs.com/docs/deployment/github-pages

@ixley
Copy link

ixley commented Oct 24, 2014

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.

@kevinsimper
Copy link

@ixley I do have it like you say, I have that on a master branch and then have a script which automaticly checkouts gh-pages and commits on that branch.

@ixley
Copy link

ixley commented Oct 24, 2014

Thanks @kevinsimper. Just emailed you directly so I don't clutter up this thread more.

@mderazon
Copy link

mderazon commented Nov 1, 2014

@kevinsimper can you share a gist of your script perhaps ? are you able to automate the process somehow with GH post commit hooks ?

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

Successfully merging this pull request may close these issues.

6 participants