cloudflare-docs-engine
cloudflare-docs-engine copied to clipboard
Using the engine’s `npm run develop` command doesn’t watch for changes
Here’s the command as it is now:
https://github.com/cloudflare/cloudflare-docs-engine/blob/765bc30127b0e80b570aade7044036925928c3ea/bin/commands.sh#L63-L74
What it does is it copies the host project’s content into the engine’s .docs/src/content directory and then runs npm run develop in there. The problem with this is that changes to content inside src/content aren’t watched by the npm run develop watcher inside .docs.
A quick-ish hack would be to have the engine run its own watcher when you run npm run develop, and have it re-run copysrc on changes to src/content, copying files into .docs/src/content which would kick off the watcher in there. This seems like a really bad approach which is why we have not implemented it yet.
While no solution we’ve found yet is ideal, one current workaround is to run npm run develop and then once it’s running, make your changes to .docs/src/content. These will be watched by the internal npm run develop’s watcher, and everything will function normally as developers are used to. The big caveat is that once you’re done with all of your local changes, then you need to _manually copy .docs/src/content back into src/content. Worse, if you accidentally run npm run develop again (in the root) you’ll end up overwriting what you had been working on inside .docs/src/content when copysrc is called. So yea, pretty gross.
The more straight-forward alternative is to simply cancel and re-run npm run develop every time you want to see your changes. The problem with this of course is it’s slow, requiring Gatsby to start up again each time, and labor intensive as it requires you to manually run a command to see changes rather than see them change immediately.
All of this is to say, the current local development setup needs work.
As a temporary workaround, we’ve added the npm run savechanges command (see https://github.com/cloudflare/cloudflare-docs/commit/0dd348cfae223d4be8faa4af63ccd84a79922d03) to make it easier to copy changes from .docs/src/content into src/content.
https://github.com/cloudflare/cloudflare-docs-engine/blob/db743a0183f161fd58cced63d6c90c72fac3b422/bin/commands.sh#L104-L108
Here's how I get around this issue:
- I work entirely outside of the .docs folder
- In parallel I run
npm run developandwatch rsync -av src/content/ .docs/src/content
The second command syncs everything from the main location into .docs and if I remove or add folders it takes care of the sync. So I can move things around and delete while working no problem.
$