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

Add support for watching additional directories #1884

Merged
merged 5 commits into from
Nov 13, 2022

Conversation

willcrichton
Copy link
Contributor

When using mdBook preprocessors like mdbook-quiz, the book depends on files outside the source directory, such as TOML files describing quizzes. It would be very convenient as an author for the book to automatically rebuild when these files change. However, the watch and serve commands (via trigger_on_change) only watch a fixed set of directories.

Probably the ideal solution would be for preprocessors to register files to be watched, similar to how extensible build systems like esbuild manage plugins. However, this would be a big change with a lot of work. A much cheaper solution is to allow mdbook CLI users to pass desired directories-to-watch on the command line.

Therefore this PR adds a new flag to watch and serve, --extra-watch-dirs. For example, a user could write:

mdbook serve --extra-watch-dirs quizzes,snippets

The --extra-watch-dirs flag takes as input a comma-separated list of directories. Each of these directories is added to the file watcher, so the book is regenerated when a file in these directories is changed.

@ehuss
Copy link
Contributor

ehuss commented Oct 14, 2022

Might it be better to add this to book.toml instead of a CLI flag? That way, all users will get the benefit of proper watch behavior without needing to know a specific CLI flag to pass?

@willcrichton
Copy link
Contributor Author

Ah yeah that's a good suggestion. Plus it makes the implementation simpler! Now the configuration looks like:

[build]
extra-watch-dirs = ["quizzes", "snippets"]

@ehuss
Copy link
Contributor

ehuss commented Nov 12, 2022

Thanks! It looks like CI is failing?

Also, when adding new config options, the documentation needs to be updated, too.

@willcrichton
Copy link
Contributor Author

Ah, didn't realize that CI was using an older version of Rust. That's been fixed. I just added documentation.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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.

2 participants