DFS – Dart Flutter Scripts
Warning: everything is WIP.
A collection of useful scripts for dart or flutter projects.
The scripts can be executed in the working directory of any dart or flutter project.
Until the package is published to
pub.dev, it can be installed as follow:
[~] dart pub global activate --source git https://github.com/osaxma/dfs.git
To run any script:
[~/path/to/project] dfs <script-command>
Note: each script will only work in the current working directory (i.e. one cannot pass a path to a different directory — at least for now).
<script-command> is shown below under the available scripts.
Find Unused Packages (status: MVP)
Area: project hygiene
with the help of dart’s
pubspecpackages, the script inpset both the
pubspec.yamlfile and all dart files within
libto find any unused dependencies.
[~/cwd] dfs find-unused-packages The following packages are not used anywhere in the lib directory. If they are used elsewhere (e.g. /test), consider moving them to `dev_dependencies` in `pubspec.yaml` - code_builder - dart_style - logging
Find Unused Top Level Declaration (status: MVP)
Area: project hygiene
Finds unused top-level elements (classes, typedefs, getters, setters, functions and fields). This useful for dart/flutter projects that are not packages.
[~/cwd]$ dfs find-unused-top-level finding unused top level declarations... The following top level declarations are not used anywhere - /cwd/lib/src/version.dart:7:7 - /cwd/lib/src/common/ast_utils.dart:7:9
To ignore specific files, you can pass globs to
dfs find-unused-top-level --ignore="lib/**.g.dart","lib/**.freezed.dart","**/genl10n/*.dart"
For more info about the default ignored files, run the help command:
dfs find-unused-top-level --help
Generate Data Classes (status: MVP)
Generate the following for an existing class (in place):
- serialization methods (
toJson) and deserialization factories (
- Equality (
operator ==) and
See how the data looks like before and after running the script at:
Ideas for future scripts
Change Project Name (status: TBD)
This is mainly for Flutter, and especially for multi-platform code where the name has to be changed in various places.
Run Script (status: TBD)
[~/cwd] dfs run <script>
Where <script> is defined in
script: build: flutter pub run build_runner build --delete-conflicting-outputs data: dfs generate-data-classes --endsWith="_data.dart" --directory="lib"
Get Packages For All (status: TBD)
[~/cwd] dfs get packages --all
[~/cwd] dfs get all
dart pub getor
flutter packages getfor all packages within a monorepo or a repo with multiple packages.