DFS – Dart Flutter 脚本
警告:所有内容都在开发中。
一系列用于 dart 或 flutter 项目的实用脚本。
这些脚本可以在任何 dart 或 flutter 项目的工作目录中执行。
安装
在软件包发布到 pub.dev 之前,可以按以下方式安装:
[~] dart pub global activate --source git https://github.com/osaxma/dfs.git
运行任何脚本
[~/path/to/project] dfs <script-command>
注意:每个脚本仅在当前工作目录中有效(即不能传递路径到另一个目录——至少目前是这样)。
每个 <script-command> 都在下面的可用脚本中展示。
可用脚本
-
查找未使用的软件包 (状态:MVP)
区域:项目卫生
命令:find-unused-packages
别名:fup描述
借助 dart 的analyzer和pubspec包,该脚本会检查pubspec.yaml文件和lib中的所有 dart 文件,以查找任何未使用的依赖项。示例输出
[~/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
-
查找未使用的顶级声明 (状态:MVP)
区域:项目卫生
命令:find-unused-top-level
别名:futl查找未使用的顶级元素(类、typedef、getter、setter、函数和字段)。这对于非软件包的 dart/flutter 项目非常有用。
示例输出
[~/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要忽略特定文件,您可以传递 glob 模式到
--ignore,例如dfs find-unused-top-level --ignore="lib/**.g.dart","lib/**.freezed.dart","**/genl10n/*.dart"有关默认忽略文件的更多信息,请运行帮助命令
dfs find-unused-top-level --help
-
生成数据类 (状态:MVP)
区域:实用程序
命令:generate-data-classes
别名:gdc为现有类生成以下内容(就地修改)
copyWith方法。- 序列化方法(
toMap/toJson)和反序列化工厂(fromMap/fromJson)。 - 相等性(
operator ==)和hashcode。
查看在运行脚本之前和之后数据外观的示例,请访问
输入数据通过解析抽象语法树(AST)来读取,使用的是
analyzer package,然后使用code builder package构建数据类。
未来脚本的构思
-
更改项目名称 (状态:待定)
区域:痛苦
命令:待定
别名:待定这主要针对 Flutter,特别是多平台代码,其中名称需要在多个地方进行更改。
-
运行脚本 (状态:待定)
区域:实用程序
命令: run
别名:不适用[~/cwd] dfs run <script>其中 <script> 在
pubspec.yaml中定义script: build: flutter pub run build_runner build --delete-conflicting-outputs data: dfs generate-data-classes --endsWith="_data.dart" --directory="lib"
-
获取所有包 (状态:待定)
区域:实用程序
命令:待定
别名:待定[~/cwd] dfs get packages --all或
[~/cwd] dfs get all为 monorepo 或包含多个包的 repo 中的所有包运行
dart pub get或flutter packages get。