运行 Pubspec 脚本 (RPS)
从您的 pubspec.yaml 文件中定义和使用脚本。
入门
-
安装此包。
dart pub global activate rps
-
在 pubspec.yaml 中定义脚本
name: my_great_app version: 1.0.0 scripts: # run is a default script. To use it, simply type # in the command line: "rps" - that's all! run: "flutter run -t lib/main_development.dart --flavor development" # you can define more commands like this: "rps gen" gen: "flutter pub run build_runner watch --delete-conflicting-outputs" # and even nest them! build: android: # rps build android apk apk: "flutter build --release apk --flavor production" # rps build android appbundle appbundle: "flutter build --release appbundle --flavor production" # and so on... # the rest of your pubspec file... dependencies: path: ^1.7.0
-
使用您的自定义命令。
就像我们在上一步中定义的
gen命令一样rps gen
而不是
flutter pub run build_runner watch --delete-conflicting-outputs
-
节省时间,成为一个高级用户!?
键入长命令的时间更少,观看搞笑猫咪的时间更多。?
Hooks
您可以使用将在某个命令之前或之后执行的命令。看看 pubspec.yaml 文件中的这些脚本。
scripts:
test:
before-echo: echo "before-test"
echo: echo "test"
after-echo: echo "after-test"
运行 rps test echo 命令会产生以下输出
> test before-echo
$ echo "before-test"
before-test
> test echo
$ echo "test"
test
> test after-echo
$ echo "after-test"
after-test
动机
我厌倦了一遍又一遍地输入相同的长命令……我甚至厌倦了按下那个无聊的(在 MacBook 上甚至很小)向上箭头键来在历史中查找我之前的命令。因此,作为一名程序员,为了节省时间,我花了比过去一年搜索/编写命令更多的时间来编写这个库……
即将推出
- 进一步的钩子改进。
嘿!此包仍处于开发阶段(可能会出现错误??)。
