dotnet-websharper / dotnet-ws

The `dotnet ws` tool
Apache License 2.0
1 stars 3 forks source link

Add ability to watch source files #22

Open granicz opened 1 year ago

granicz commented 1 year ago

While one can watch a project for changes using dotnet watch, it's relatively slow and it triggers dotnet build instead of the more tailored dotnet ws build command. Furthermore, often times, incremental changes occur only to template HTML files, and one is forced to touch an actual F#/C# source file to trigger recompilation.

This ticket adds the ability to watch various files (single or multiple F# files, design files, project files, etc.) and offer an enhanced version of dotnet ws compile (see ticket #17 ) where appropriate, and otherwise falling back to dotnet ws build for the remaining cases to provide a uniform watch capability.

There a few cases to cover:

  1. Single file compilation - basically, all dotnet ws compile shapes - here, we could just take a watch option at the end. This would take the source file specified, establish a file system watcher, and retrigger the underlying build pipeline on change.
  2. Multi file compilation (new mode) - dotnet ws watch [pattern], where [pattern], if left unspecified, defaults to all .fs[x] and certain .html files (see below) in the current folder and all of its subdirectories.
  3. Project compilation - where dotnet ws watch [pattern] includes .fsproj file(s), separate watches should be set up for each project triggering an ordinary dotnet ws build. The files to watch for each project consist of the project file itself and any source/other files we can reasonably infer to belong to the project using a simple heuristics (as opposed to having to crack the project file via msbuild or introducing a more elaborate project cracking library, for now) by extracting all files from <Compile|None Include="<filename>" /> sections.

To avoid colliding with generated HTML files vs template HTML files, the default search pattern should exclude the likely subfolders where generated HTML files might end up. Examples: bin|obj, dist, out|output, etc.

granicz commented 1 year ago

Still TODO: Current version doesn't have support for triggering builds if changes occur in transitive project dependencies.