0.0.7 • Published 3 years ago

@vonage/monowatch v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

What is Monowatch?

Monowatch is a basic file watcher/npm runner made especially for use with monorepos hosting NPM packages.

How it works

  • It automatically detects:
    • Yarn/Npm CLIs
    • Repository root
    • Yarn workspaces and Lerna packages
  • Ignores unaltered files.
  • Runs dependant packages builds concurrently.

Installation

To install monowatch, run

npm i -g @vonage/monowatch

Notice: This package is only available through our private Github repository atm.

Then just run

monowatch

anywhere within your monorepo (don't worry, it will detect your project root and packages automatically)

Usage

Monowatch comes pre-configured (batteries included) to watch for changes in Typescript Sass and Less code files and launch the build script. Simply run:

monowatch

from anywhere within your monorepo to get it started and ready for battle!

Configuration

Monowatch supports three configuration methods:

1) Command line arguments 2) .monowatch file (in each package) 3) monowatch.json file (in monorepo root)

The configuration is applied in the order mentioned above, meaning that a command line argument will always take precedence over configuration that is applied in a configuration file etc.

monowatch.json

This file should be positioned at the root of your monorepo to setup Monowatch configuration.

Configuration Fields

script

Sets which npm script to run in each package. Defaults to build.

watch

A list of glob strings, defining which files to watch in each package.

ignore

A list of glob string to exclude from files selected with watch

include_dependants

Sets whether a change in a specific package will trigger all dependant packages as well. Defaults to false.

abort_on_errors

Sets Monowatch to abort the build process upon errors (applicable in case include_dependants has been set). Defaults to true.

npm_cli

Sets which NPM client Monowatch should use. If not defined, Monowatch will try to detect the correct client according to hints.

packages

A hash map that can be used to override configuration settings for a specific package. For instance:

{ 
  "watch": "*.ts",
  "script" : "build",
  "packages": {
    "@myuser/my-script-name": {
      "watch": "*.scss",
      "script": "my-custom-build"
    }    
  }
}

Will watch *.ts in all packages except @myuser/my-script-name where *.scss. Similarly, changes in any package will trigger the build script, except for @myuser/my-script-name where my-script-build will be launched.

Usage samples

This configuration will listen to changes on .ts and .scss files excluding files ending with *.css.ts, *.autogenerated.*, *.d.ts

{
  "watch": ["**/*.ts", "**/*.scss"],
  "ignore": ["**/*.d.ts", "**/*.css.ts", "**/*.autogenerated.*"],
  "include_dependants": true,
  "abort_on_errors": true
}

Command line arguments

You can pass any of following fields as command line arguments to override any general configuration file field:

include-dependants (overrides "include_dependants"), npm-script (overrides "script"), abort-on-errors (overrides "abort_on_errors"), npm-client (overrides "client"), watch (overrides "watch"), ignore (overrides "ignore") The following additional arguments are also available:

project-root

Set the monorepo's root folder (it usually being detected automatically)

output-format

Determines what the watcher will output:

  • human - Will display human-friendly progress indication.
  • debug - Will output a JSON line stream containing rich debug information.