Build and test a Dart CLI package
8 steps · about 2 h 20 min · Intermediate
- Scaffolding a project with dart create (doc, Dart Documentation, 15 min)
Generate the standard console package skeleton with separate bin, lib and test entry points.
- Dart package layout conventions (doc, Dart Documentation, 15 min)
Keep public library APIs in lib/ and internal implementation under lib/src/ so the CLI entrypoint stays thin and testable.
- Configuring pubspec.yaml and CLI executables (doc, Dart Documentation, 20 min)
Declare SDK constraints, dependencies and executable mappings in pubspec.yaml.
- Writing command-line apps with package:args (tutorial, Dart Documentation, 25 min)
Parse flags, options and exit codes cleanly using the official args parser and standard I/O streams.
- Static checking with dart analyze (doc, Dart Documentation, 15 min)
Catch null-safety gaps, dead code and lint violations via analysis_options.yaml before running tests.
- Consistent formatting with dart format (doc, Dart Documentation, 10 min)
Enforce canonical Dart formatting across bin/, lib/ and test/ in local checks and CI.
- Writing and running tests with dart test (doc, Dart Documentation, 25 min)
Write unit and CLI integration tests with package:test, groups, matchers and platform selectors.
- Compiling a native executable with dart compile exe (doc, Dart Documentation, 15 min)
Package the tested CLI into a self-contained AOT binary that runs without a Dart SDK installed.