Flutter Workspaces CLI
A command-line tool for scaffolding and managing monorepo-style Flutter workspace structures. This CLI automates the creation of a complete Flutter workspace with a core shared package, main application, and proper dependency configuration.
Features
- โ
Workspace Creation: Automatically creates a
<name>_workspacesfolder and sets up the workspace structure. - ๐ฆ Core Package Scaffolding: Creates a reusable
packages/corepackage for shared code. - โ Add Package: Easily add new packages to your existing workspace with a single command.
- ๐ฑ Flutter App Scaffolding: Generates a main Flutter application that imports and uses the core package.
- ๐ฏ Workspace Resolution: Configures
pubspec.yamlfiles with workspace resolution for monorepo support. - ๐ Environment Validation: Checks for Flutter and Dart SDK requirements (Dart 3.6.0+).
- ๐ Dependency Management: Automatically adds common Flutter dependencies (cupertino_icons, flutter_lints, custom_lint).
- ๐งน Error Handling: Reverts workspace creation on failure for clean error states.
- ๐๏ธ SOLID Architecture: Refactored to use Dependency Injection with
FileSystemandProcessRunnerabstractions for better testability and maintainability.
Requirements
- Dart SDK: 3.6.0 or higher
- Flutter SDK: Latest stable version (with Dart 3.6.0+)
- System: macOS, Linux, or Windows with shell support
Installation
dart pub global activate flutter_workspaces_cli
Usage
Create a New Workspace
Run the CLI with the required --name argument to create a new workspace:
flutter_workspaces_cli --name my_app
Or use the short flag:
flutter_workspaces_cli -n my_app
Add a New Package
To add a new package to an existing workspace, use the add-package command from the workspace root:
flutter_workspaces_cli add-package --name my_feature
Project Structure
The project follows a modular service-based structure in lib/:
bin/: CLI entry point.lib/:setup_runner.dart: Orchestrates the initial workspace setup.add_package_runner.dart: Orchestrates adding new packages.process_runner.dart: Abstraction for executing system processes.*_process.dart: Modular services handling specific parts of the workflow (Dart, Flutter, Workspace, Packages, etc.).
Generated Workspace Structure
After running the setup command, the following structure is created:
my_app_workspaces/
โโโ pubspec.yaml # Root workspace pubspec
โโโ analysis_options.yaml # Root workspace analysis options
โโโ my_app/ # Main Flutter application
โ โโโ lib/
โ โ โโโ main.dart # Main entry point (imports core)
โ โโโ pubspec.yaml
โโโ packages/
โโโ core/ # Shared core package
โโโ lib/
โ โโโ core.dart
โโโ pubspec.yaml
Command-Line Arguments
Setup (Default)
| Argument | Short | Required | Description |
|---|---|---|---|
--name |
-n |
Yes | The base name for your workspace and app (e.g., my_app) |
Add Package (add-package)
| Argument | Short | Required | Description |
|---|---|---|---|
--name |
-n |
Yes | The name of the new package to create in packages/ |
Exit Codes
0: Success1: General error (execution failed)64: Missing or invalid arguments (e.g.,--namenot provided)
Development
Running Tests
Run the test suite to verify all functionality:
dart test
The test suite leverages the FileSystem and ProcessRunner abstractions to provide 100% coverage without side effects on your local machine.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -am 'Add your feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
License
This project is provided as-is. See LICENSE for details.
Support
For issues, questions, or suggestions, please open an issue on the GitHub repository.
Author
Created by ThiagoEvoa
Enjoy building amazing Flutter workspaces! ๐