statamic / ssg

The official Statamic Static Site Generator
232 stars 24 forks source link

Add `--disable-clear` option #136

Closed simonhamp closed 1 year ago

simonhamp commented 1 year ago

Edit by @jesseleite: We decided to keep default functionality and add this as opt-in functionality via --disable-clear 👍


The SSG generate method currently always destroys all files on a run... this can become problematic when you're trying to figure out why certain pages are failing if it doesn't reliably generate all pages on each run

This won't necessarily save much time yet, as it will still process all entries and other URLs and try to write the final copies to disk... but if you have other steps in your build process and don't want to always start from scratch, this allows you that flexibility

NB: This changes the default behaviour. If you want to maintain the old behaviour, you have to pass --fresh on the CLI

This is somewhat related to #135 as non-deterministic builds are tricky to manage

jesseleite commented 1 year ago

This is somewhat related to https://github.com/statamic/ssg/pull/135 as non-deterministic builds are tricky to manage

Curious what you mean here?

simonhamp commented 1 year ago

Curious what you mean here?

Basically some of this stuff came out of me trying to use the SSG incrementally. The reason I was wanting to do that is because it was failing in ways that were hard to investigate (minimal output, especially when running multiple threads).

I needed a way for it to run deterministically multiple times without wiping everything out - that way I could eventually get it to run to completion.

(I believe my problems related specifically to rendering images in Glide - I'm using Spatie's Responsive Images addon) and it doesn't play particularly nicely with the SSG in my setup)

This PR came out of that but isn't directly related to trying to solve those issues - I think this is useful aside of those issues.

Though you may want to maintain current behaviour (where ssg:generate deletes all files in the build folders and starts from scratch every time) and the flag be the thing that prevents that... so maybe something like --gentle instead

jesseleite commented 1 year ago

For sure, but after an internal discussion we want to keep clearDirectory() as default behaviour. We're definitely open to an inverse flag though, maybe something like --disable-clear?

simonhamp commented 1 year ago

Makes sense. I'll rework this after Laracon 😉

jesseleite commented 1 year ago

All good, I gotchyoo. Just going to add a test here once #140 gets merged, as I added some basic generator test coverage over there 👍