@domestika/mono

1.9.0 • Public • Published

mono

Simple CLI for monorepo/multipackage.

mono is a tool that aims to simplify management for monorepo/multipackage projects but it also works with monopackage projects.

mono provides:

  • Commit template → mono commit
  • Release manager (parses commits to publish packages according to their changes) → mono check, mono release
  • Run commands inside each package → mono run npm install, mono run-parallel npm install

We use:

mono provides, among other things, a standard template for commit messages (mono commit) and is able to decide what needs to be released for you (mono check & mono release).

Installation

$ npm install @domestika/mono --save-dev

Usage

run command on all packages

You can run a single command on each package of the monorepo (each subfolder with its own package.json), in series

$ mono run <command>
$ mono run npx rimraf node_modules
$ mono run npm install

You can also run them in parallel

$ mono run-parallel <command>
$ mono run-parallel npx rimraf node_modules
$ mono run-parallel npm install

phoenix

To reset your project and all its contained packages.

mono phoenix

Equivalent to npx rimraf node_modules && npm i but it works on any environment and mono phoenix executes it concurrently on each package (and/or on your project root folder).

By default commands will be executed on chunks of 20 packages, but you can change it with -c, --chunk option:

mono phoenix -c 5

So, if executing many commands as the same time in your machine is too heavy, you can adjust it. You can also disable the chunks with 0 value and always execute all commands in parallel:

mono phoenix -c 0

If you don't want a fancy progress output (for instance in CI env), you can force a plain text output:

mono phoenix --no-progress

Reinstalls all scope packages but ignores the node_modules folder and package-lock.json file at the root level of your project

mono phoenix --no-root

Ables you to just reinstall the dependencies from a single scope

mono phoenix --no-root --scope atom/button

commit

You do your normal git workflow, but when commiting you should use:

mono commit

It will prompt you with questions regarding your changes and will generate a standard commit message for you

commit-all commit for all contained packages

You can commit the same message for all packages that actually contained stageable files.

mono commit-all -t "feat" -m "Refactor of dependencies"

The precommit will be executed only for the first commit.

check & release

In order to release the steps are:

Preview what will be released

mono check

Release all the packages

mono release

In case you want to release a single package use the --scope param

mono release --scope "packages/test"

Your packages must implement script npm run build or npm run prepublish that will be executed before any release.

👉 mono creates a new MINOR version for the package only when fix, perf or feat commits are detected, and a new MAJOR version if there is some commit marked as BREAKING CHANGES. Otherwise (any other types of commits detected), no new version will be generated and nothing will be released

Automatic release (only CI)

In case you want to release via CI the --github-user --github-email and --github-token must be passed by like follows:

mono release --github-user [username] --github-email [user email] --github-token [TOKEN]

How to configure your project

First you need to install the @domestika/mono package in your project

npm i --save-dev @domestika/mono

Then, you can configure your package.json to suit your needs

mono allows you to configure some parts of its functioning, but it also defines a few defaults for convenience.

Here'domestikafull example of the options

"private": true,
"config": {
  "mono": {
    "access": "public",
    "packagesFolder": "test/components",
    "deepLevel": 2,
    "customScopes": [
      "cz-config",
      "check",
      "release"
    ]
  },
  "validate-commit-msg": {
    "types": "@domestika/mono/src/types"
  },
}

private

If you specify that your package is private ("private": true,), it will not get pushed to npm repository

access

By default packages will be published as restricted in npm. If you want them to be public you will need to set "access": "public"

Scope (packagesFolder, deepLevel, customScopes)

👉 Setting the proper scope in the commit message is important, because this is used for mono check and mono release to assign changes to specific packages and release them to the proper packages

We provide a simple tool to automate the way the scopes are retrieved. If you follow a structure where do you have:

  • a main folder and
  • inside this folder you have all the packages (subfolders, each one of them with its own package.jsonscopes)

...this configuration will work for you

In order to specify the main folder you need to provide packagesFolder by default its value is src By default we check only 1 level inside the main folder, but if you have categories for each package and inside the packages you can configure deepLevel

This information will be used for releases and commitizen scopes.

Examples

Project Example

So, if you have a project like this:

src/
  i18n/
  users/
  search/
  ...

The default options will give you a list of scopes like this one for your commit:

i18n
users
search
Case studio

In the case of studio, which generates a folder like this one:

components/
 ads/
  big/
  small/
 card/
  featured/
  normal/

If you set the configuration of your project like this:

"packagesFolder": "components"
"deepLevel": 2

You will have a list of scopes like this one when performing a commit:

ads/big
ads/small
card/featured
card/normal

Manual scopes

There may be cases that you may want to add scopes for informative purposes but not related in any way with the releases

Take in care that this scopes will not be relevant for the release, and if you commit to one package that has his own scope, but you use a custom scope, a release will not be generated. Custom scopes are for a very rare cases and you may not need it most of the times.

Use customScopes in this cases like in the example. The scopes will be added to the automatically generated ones.

Readme

Keywords

Package Sidebar

Install

npm i @domestika/mono

Weekly Downloads

4

Version

1.9.0

License

MIT

Unpacked Size

36.7 kB

Total Files

16

Last publish

Collaborators

  • domestika-dev
  • soyellupi
  • cvz
  • davecarter
  • lacedoniadavid
  • antoniojrossi