monoinfuse

1.4.8 • Public • Published

monoinfuse

Watching and moving shared resources automagically, monoinfuse is a helpful CLI tool to handle monorepo workflows

installation

# install with npm 
npm i monoinfuse
 
# install with yarn 
yarn add monoinfuse
 
 
# install globally with npm 
npm i -g monoinfuse
 
# install globally with yarn 
yarn global add monoinfuse

usage

To use monoinfuse, first create a configuration file. The monoinfuse configuration is split up into two core components, resources and services. Resources are objects that represent either single files or whole directories, which will be watched for changes and copied into services which consume them. A small config example would look like the following

monoinfuse.json

{
  "resources": [
    {
      "name": "shared-interfaces",
      "path": "./shared/interfaces",
      "exclude": ["node_modules"]
    }
  ],
  "services": [
    {
      "name": "gateway",
      "path": "./services/gateway",
      "infuse": ["shared-interfaces"]
    }
  ]
}

If you continue by running monoinfuse in the same directory where you just created the config, and look into your git client/file manager of choice, you can see a directory being created inside of your service directory, named .monoinfuse, which contains further directories, e.g shared-interfaces and the files from your resource (except the ones you've specified in the exclude option of the resource). It's strongly advised to add the .monoinfuse directory to your gitignore file to prevent these temporary files from being pushed to version control.

Every time you start developing your project, you can just launch monoinfuse and let it sit in the background, managing watching your shared files for changes and copying them to the specified target locations. Example use cases would be local npm modules which could then be installed using a relative file path.

options

config

The config option allows you to change the configuration file path, which is a monoinfuse.json file in your current working directory by default.

Supplied by:

  • environment: MONOINFUSE_CONFIG
  • command-line argument: --config [config path]

prefix

The prefix option allows you to customize the name under which all resources will be infused into your services. The default option is a .monoinfuse directory inside of your service.

Supplied by:

  • environment: MONOINFUSE_TEMP_DIR_PREFIX
  • command-line argument: --prefix [prefix]
  • configuration: "prefix": "some_prefix/"

hooks

To create an interactive setup integrating with external tools like build utilities, you can use monoinfuse hooks!

Available events: preStart, postStart, preInfuse, postInfuse, preServiceInfuse, postServiceInfuse

An example project configuration could look like the following:

monoinfuse.json

{
  "services": [
    {
      "name": "example-service",
      "path": "./services/example",
      "infuse": ["shared-library"]
    }
  ],
  "resources": [
    {
      "name": "shared-library",
      "path": "./shared",
      "exclude": ["node_modules/**", "src/**"],
      "ignore": ["build/**"],
      "hooks": {
        "postServiceInfuse": [
          {
            "name": "shared yarn install",
            "background": "false",
            "command": {
              "name": "yarn",
              "args": ["install"],
              "env": {
                "NODE_ENV": "production"
              }
            },
            "runInServiceDir": true
          }
        ],
        "postStart": [
          {
            "name": "typescript watcher",
            "background": "true",
            "command": {
              "name": "tsc",
              "args": ["--watch"]
            }
          }
        ]
      }
    }
  ]
}

The configuration above will run a background job, in this case a TypeScript compiler in watch mode, once all resources are being watched, as well as a yarn install script every time a resource is infused. The latter command is run inside of the service directory the resource got infused to.

The process environment (env) and current working directory (cwd) can be configured inside of the command object of a hook.

Readme

Keywords

none

Package Sidebar

Install

npm i monoinfuse

Weekly Downloads

0

Version

1.4.8

License

MIT

Unpacked Size

121 kB

Total Files

28

Last publish

Collaborators

  • brunoscheufler