MR.AspNetCore.Staller

Executes commands in response to triggers and stalls requests while waiting (waiting for changed sass files to compile for example).


Keywords
aspnetcore, stall, middleware, client
License
MIT
Install
Install-Package MR.AspNetCore.Staller -Version 0.2.0

Documentation

MR.AspNetCore.Staller

AppVeyor Travis
Build status Travis

NuGet version License

Executes commands in response to triggers and stalls requests while waiting (waiting for changed sass files to compile for example).

Use case

When you want to work with languages that compile down to client-side resources, you usually register watchers in development (through gulp for example) to recompile the files. At this point you'll have to wait a bit before refreshing the page which is annoying because the compile time is often unpredictable, so you end up waiting a bit too long or having to refresh again.

Using MR.AspNetCore.Staller will allow you to directly refresh the page and a middleware will stall the requests while files are being compiled.

Usage

In ConfigureServices:

if (_env.IsDevelopment())
{
    services.AddStaller(...);
}

In Configure:

if (_env.IsDevelopment())
{
    app.UseStaller();
}

Configuring triggers-commands

services.AddStaller(options => {
    // Register custom trigger-command pairs.
    options.RegisterPair(trigger, command);

    // You'll probably often use this as a shortcut to using the related classes.
    // The trigger will be file changes that match
    // "wwwroot/src/**/*.scss" and the command in
    // response will be executing "gulp compile:sass".
    options.RegisterFileWatcherWithExternalShellCommand(
        "gulp compile:sass",
        "wwwroot/src/**/*.scss");
});

After this, when a trigger occurs the related command will be executed and all requests will automatically be stalled until the command finishes.

Using "staller-watcher.json" instead

Use the following instead of manually registering pairs:

options.UseWatcherFile();

You'll want to add a "staller-watcher.json" file with the following structure:

{
  "pairs": [
    {
      "command": "gulp compile:sass",
      "patterns": "src/sass/**/*.scss"
    },
    {
      ...
    }
  ]
}

Samples