Monorepo Control is a command-line tool that simplifies the process of managing monorepos by automating tasks, such as running pre-commit hooks for modified packages. It's designed to work with Husky and other Git hooks tools.
- Automatically detects modified packages and runs pre-commit hooks.
- Customizable configuration to specify workspaces, extensions, and commands.
- Easy to integrate with existing Git hooks management tools.
- Supports passing a custom configuration file path.
- Can be used in "standalone" mode without adding it to the PATH.
To install Monorepo Control, follow these steps:
-
Clone the repository:
git clone git@github.com:minnek-digital-studio/monorepo-ctrl.git
-
Change to the repository directory:
cd monorepo-ctrl
-
Build the project:
go build -o monorepo-ctrl ./cmd
To use Monorepo Control globally, add the compiled binary to your PATH
:
export PATH=$PATH:/path/to/monorepo-ctrl
For standalone usage, you can place the compiled binary and the configuration file in the .husky
directory and use it without adding it to the PATH.
-
Create a
mnk-config.json
file in the root of your monorepo with the following structure:{ "monorepo-ctrl": { "global": { "workspaces": ["workspaces", "packages"], "extensions": [".js", ".ts", ".tsx"] }, "configs": [ { "name": "scopeName", "commands": ["npm run lint", "npm run test"] } ] } }
- Replace
scopeName
with the desired name for your scope. - Customize the
workspaces
,extensions
, andcommands
as needed.
- Replace
-
Run Monorepo Control with the desired scope:
monorepo-ctrl scopeName
Replace
scopeName
with the name you defined in themnk-config.json
file. A good example for a scope name is the type of hook you want to run, such ascommit
orpush
.If you want to use a custom configuration file path, use the
--config
or-c
option:monorepo-ctrl scopeName --config path/to/config/file.json
If Monorepo Control is not in your PATH and you have to add the binary and the
mnk-config.json
file to the.husky
directory, you can run it in standalone mode without adding it to the PATH.
To use Monorepo Control in your pre-commit hook when it is installed globally, create a .husky/pre-commit
file with the following content:
#!/bin/bash
# Execute the monorepo-ctrl with the "commit" argument and custom configuration file
monorepo-ctrl scopeName
This will ensure that Monorepo Control is executed with the specified scope and configuration file during the pre-commit process.
To use Monorepo Control in your pre-commit hook in standalone mode, create a .husky/pre-commit
file with the following content:
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Give execute permission to the monorepo-ctrl file
chmod +x $SCRIPT_DIR/monorepo-ctrl
# Execute the monorepo-ctrl file with the "commit" argument and custom configuration file
$SCRIPT_DIR/monorepo-ctrl scopeName -c "$SCRIPT_DIR/mnk-config.json"
This will ensure that Monorepo Control is executed with the specified scope and configuration file during the pre-commit process when used in standalone mode, without adding it to the PATH.
Contributions are welcome! If you find a bug, have a feature request, or want to improve the documentation, please create an issue or submit a pull request.
Monorepo Control is released under the MIT License.