Skip to content

Setting Up the Monorepo Toolkit

What you'll learn

  • Generating the devtools/ CLI toolkit for your monorepo
  • Available commands for dependency management and code generation
  • Running affected-only builds in CI
  • Extending the toolkit with custom scripts

Prerequisites

Step 1: Generate the Monorepo Toolkit

bash
archipelago generate monorepo_toolkit

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • organizationMyCompany (your organization name)
  • isForMonorepotrue

Or use a config file:

json
{
  "appName": "MyApp",
  "organization": "MyCompany",
  "isForMonorepo": true
}
bash
archipelago generate monorepo_toolkit --config toolkit_config.json

Step 2: Understand the Generated Structure

devtools/
├── monorepo_toolkit/
│   ├── bin/
│   │   └── monorepo_toolkit.dart    # CLI entry point
│   ├── lib/src/
│   │   ├── commands/                # All CLI commands
│   │   ├── utils/                   # Shared utilities
│   │   └── monorepo_toolkit.dart    # Command runner
│   └── pubspec.yaml
└── scripts/
    ├── affected/                    # Detect changed packages
    ├── coverage/                    # Aggregate coverage reports
    ├── build_prepare/               # Flavor-based dependency swapping
    └── dependency_graph/            # Visualize package dependencies

Step 3: Activate the Toolkit

bash
cd devtools/monorepo_toolkit
dart pub get
dart run bin/monorepo_toolkit.dart --help

Or activate globally for convenience:

bash
dart pub global activate --source path devtools/monorepo_toolkit
monorepo_toolkit --help

Step 4: Key Commands

CommandPurpose
affectedList packages changed since a git ref
coverageAggregate test coverage across packages
build-prepareSwap impl/noop dependencies per flavor
dep-graphGenerate a dependency graph visualization

Example: run tests only on affected packages in CI:

bash
monorepo_toolkit affected --since origin/main | xargs -I {} sh -c 'cd {} && flutter test'

Step 5: CI Integration

Add the toolkit to your GitHub Actions workflow:

yaml
- name: Get affected packages
  run: |
    dart pub global activate --source path devtools/monorepo_toolkit
    AFFECTED=$(monorepo_toolkit affected --since ${{ github.event.pull_request.base.sha }})
    echo "affected=$AFFECTED" >> $GITHUB_OUTPUT

Common Customizations

CustomizationHow
Add a new commandCreate a Command class in commands/
Change affected detectionModify scripts/affected/ logic
Custom coverage thresholdsEdit scripts/coverage/ configuration
Add pre-build hooksExtend build_prepare script

Next Steps

Built by Banua Coder