dfs
dfs copied to clipboard
A collection of useful scripts for dart or flutter projects.
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.
Installation:
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).
Each <script-command> is shown below under the available scripts.
Available Scripts
-
Find Unused Packages (status: MVP)
Area: project hygiene
command:find-unused-packages
alias:fupDescription:
with the help of dart'sanalyzerandpubspecpackages, the script inpset both thepubspec.yamlfile and all dart files withinlibto find any unused dependencies.Sample Output:
[~/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
command:find-unused-top-level
alias:futlFinds unused top-level elements (classes, typedefs, getters, setters, functions and fields). This useful for dart/flutter projects that are not packages.
Sample output
[~/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:9To ignore specific files, you can pass globs to
--ignoresuch as: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)
Area: utility
command:generate-data-classes
alias:gdcGenerate the following for an existing class (in place):
copyWithmethod.- serialization methods (
toMap/toJson) and deserialization factories (fromMap/fromJson). - Equality (
operator ==) andhashcode.
See how the data looks like before and after running the script at:
- before running the script
- after running the script
The input data is read by parsing the Abstract Syntax Tree (AST) using the
analyzer package, and then the data class is built using thecode builder package.
Ideas for future scripts
-
Change Project Name (status: TBD)
Area: pain
command: TBD
alias: TBDThis is mainly for Flutter, and especially for multi-platform code where the name has to be changed in various places.
-
Run Script (status: TBD)
Area: utility
command: run
alias: N/A[~/cwd] dfs run <script>Where <script> is defined in
pubspec.yamlscript: 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)
Area: utility
command: TBD
alias: TBD[~/cwd] dfs get packages --allOr
[~/cwd] dfs get allRun
dart pub getorflutter packages getfor all packages within a monorepo or a repo with multiple packages.