flutter_setup 0.1.0
flutter_setup: ^0.1.0 copied to clipboard
A reusable Flutter project scaffolding CLI tool.
flutter_setup #
A reusable Flutter project scaffolding CLI tool.
Overview #
flutter_setup is a Dart CLI package designed to automate the scaffolding of Flutter applications using customizable architecture templates, predefined folder structures, dependency packages, configuration, and boilerplate.
- Phase 1: Built the CLI engine foundation, argument parsing, command architecture, template discovery/loading, template configuration validation, and terminal output formatting.
- Phase 2: Built a standalone, framework-agnostic Template Engine (variable case conversions, token substitution in file names and contents, YAML folder creation, destination safety).
- Phase 3: Built real Flutter Project Generation by orchestrating
flutter createprocess execution with template rendering. - Phase 4: Built the Package Manager (
dependenciesanddev_dependenciesinstallation viaflutter pub addandflutter pub get). - Phase 5: Built the Assets Generator (binary file preservation, automated asset scanner,
pubspec.yamlassets:registration, and type-safeAssetsconstant class generation). - Phase 6: Populated real Production Boilerplate into the
defaulttemplate (Dio network client, GoRouter navigation, Material 3 light/dark theme, Riverpod state management, failure handling, and an end-to-end example feature). - Phase 7: Built Multiple Template Support (
defaultandminimal) driven entirely by directory discovery (templates/<name>/) with zero engine hardcoding. - Phase 8: Built Interactive Mode (
flutter_setup createwith no args) using a decoupledPrompterabstraction and a unifiedCreateProjectRequestpipeline. - Phase 9: Built Safety Hardening & Full-Pipeline Test Audit (automatic project rollback on partial failure,
--force(-f) flag for non-interactive overwrite, interactive destination conflict prompts (Cancel,Overwrite,Choose a different name), SDK & process failure guards, and full-pipeline integration tests). - Phase 10: Built the Feature & Sub-Component Generator (
feature,screen,model,repositorygeneration into existing Flutter projects with project validation, conflict detection, scoped rollback, and route wiring reminders).
Interactive Mode & CLI Usage #
Running flutter_setup create with no arguments triggers Interactive Mode:
$ flutter_setup create
? Project name: ecommerce_app
? Description (A new Flutter project.): My E-Commerce App
? Template
1) default (default)
2) minimal
Select an option (1-2) [default]: 1
Non-interactive usage (flutter_setup create my_app --template minimal [--force]) remains 100% supported and scriptable.
Working Commands: #
flutter_setup/flutter_setup --help/flutter_setup -hflutter_setup --version/flutter_setup version/flutter_setup -vflutter_setup templatesflutter_setup info <template_name>flutter_setup create(Interactive mode)flutter_setup create <project_name> [--template <template_name>] [--force](Non-interactive project creation)flutter_setup feature <feature_name> [--path <path>](Generate feature skeleton)flutter_setup screen <name> --feature <feature_name> [--path <path>](Generate screen)flutter_setup model <name> --feature <feature_name> [--path <path>](Generate domain model)flutter_setup repository <name> --feature <feature_name> [--path <path>](Generate repository)
Safety & Destination Conflict Resolution #
1. Existing Destination Handling #
- Non-Interactive Mode: Refuses to overwrite existing project directories unless the
--force(-f) flag is explicitly supplied. - Interactive Mode: Automatically detects existing directories and prompts for user action via
Prompter:Cancel: Aborts generation cleanly without altering disk.Overwrite: Deletes existing directory contents before runningflutter create.Choose a different name: Re-prompts for a new project name and validates destination.
2. Automatic Partial-Failure Rollback #
If an error occurs at any point after flutter create spawns (e.g. template rendering failure, invalid package name, network disconnection during pub add/pub get, asset generation error), flutter_setup automatically deletes the partially-created project directory from disk. No corrupted or incomplete project files are left behind.
How Project Generation & Asset Registration Work #
When you execute:
flutter_setup create my_app
The CLI executes the following orchestration steps:
- Validation: Validates
my_appas a valid Flutter/Dart package identifier. - Destination Check: Verifies
./my_appdoes not already exist on disk (unless--forceis used orOverwriteis selected interactively). - Flutter Baseline Scaffolding: Executes
flutter create my_appto generate standard Flutter platform folders (android/,ios/,web/),.gitignore, andpubspec.yaml. - Template Overlay: Invokes
TemplateRendererto layer template files (lib/main.dart,app_constants.dart, assets, etc.) and YAML-declared folders over the generated project. Binary files (.png,.jpg,.ttf, etc.) are preserved byte-for-byte. - Package Installation: Installs
dependenciesanddev_dependenciesdeclared intemplate.yamlviaflutter pub addand resolves packages withflutter pub get. - Asset Processing:
- Scanner: Discovers all files inside the project's
assets/folder. - Pubspec Registration: Safely inserts/merges discovered asset paths into
pubspec.yamlunderflutter: assets:. - Assets Class Generation: Generates a type-safe
Assetsclass (atlib/core/constants/assets.dartor custom path declared ingenerated_files.assets_class).
- Scanner: Discovers all files inside the project's
- Summary Report: Prints success metrics, installed packages, asset registration status, and next steps.
Asset Conventions & Usage #
1. Template Structure #
Place assets inside the template's files/assets/ directory:
templates/default/files/assets/
├── images/
│ └── logo.png
└── icons/
└── app_icon.png
2. Type-Safe Assets Class #
The generator automatically builds lib/core/constants/assets.dart:
// GENERATED FILE - DO NOT EDIT BY HAND
class Assets {
Assets._();
static const String iconsAppIcon = 'assets/icons/app_icon.png';
static const String imagesLogo = 'assets/images/logo.png';
}
Usage in Flutter widgets:
Image.asset(Assets.imagesLogo)
Feature & Sub-Component Generation #
Generate code into an existing Flutter project cleanly and safely.
1. Generate a Full Feature Skeleton #
cd my_app
flutter_setup feature payments
Generates:
lib/features/payments/
├── data/
│ ├── datasources/
│ │ └── payments_remote_datasource.dart
│ └── repositories/
│ └── payments_repository.dart
├── domain/
│ └── payments_model.dart
└── presentation/
├── providers/
│ └── payments_provider.dart
└── screens/
└── payments_screen.dart
Prints manual route reminder:
Don't forget to add a route for PaymentsScreen in lib/core/router/app_router.dart
2. Generate Single Sub-Components #
Add individual screens, domain models, or repositories to an existing feature:
flutter_setup screen checkout --feature payments
flutter_setup model payment_intent --feature payments
flutter_setup repository payment --feature payments
3. Safety & Scoped Rollback #
- Project Validation: Confirms execution inside a valid Flutter project (checks for
pubspec.yamlwithflutter:key). - Conflict Prevention: Refuses to overwrite pre-existing user files.
- Scoped Rollback: If multi-file generation fails halfway, ONLY files created during that specific invocation are cleaned up. Pre-existing project files remain untouched.
Getting Started #
Prerequisites #
- Dart SDK 3.0.0 or higher
- Flutter SDK on system PATH
Installation & Execution #
Run locally with dart:
dart pub get
dart run bin/flutter_setup.dart create my_app
Or activate globally:
dart pub global activate --source path "."
flutter_setup create my_app
Running Tests #
# Full test suite with randomized ordering
dart test --test-randomize-ordering-seed=random