Finch CLI

Finch CLI 是一个命令行工具,用于创建项目、运行开发服务器、构建、运行测试以及管理数据库迁移。它封装了常用的 Dart 命令并添加了 Finch 特定的任务。

安装

dart pub global activate finch

命令

运行 finch -h 查看所有可用命令:

finch -h
✔ templates
        Show the list of available templates
✔ create
        Make new project
        -p, --path       Path of the project
        -n, --name       Name of project
        -d, --docker     Use docker
        -t, --template   Project template [simple, example,...]
✔ get
        Get packages of project, (dart pub get)
✔ runner
        Build runner of project, (dart pub run build_runner build)
✔ run
        Run project, (dart run)
        -p, --path       Path of app file
        -a, --args       Arguments for app file
✔ serve
        Serve project with file watcher
        -p, --path       Path of app file
        -a, --args       Arguments for app file
✔ build
        Build Project (dart compile exe)
        -c, --cli        Build for cli
        -a, --appPath    Path of app file
        -l, --langPath   Languages path
        -p, --publicPath Public path
        -w, --widgetPath Widgets path
        -e, --envPath    Envitoment file (.env) path
        -o, --output     Output path
        -t, --type       Type of build (zip, exe)
✔ migrate
        Migrate project to new version of Finch
        -c, --create     Create new project and move files
        -n, --name       Name of migration file (only for create option)
        -s, --sqlite     Migrate SQLite files
✔ test
        Unit test of project, (dart test)
        -r, --reporter   Set how to print test results
✔ make:controller
        Make new controller
        -n, --name       Name of controller
        -p, --path       Path of controller (default: ./lib/controllers/)
✔ make:service
        Make new service
        -n, --name       Name of service
        -p, --path       Path of service (default: ./lib/services/)
✔ make:middleware
        Make new middleware
        -n, --name       Name of middleware
        -p, --path       Path of middleware (default: ./lib/middleware/)

        -h, --help       Show the help
        -v, --version    Finch Version
        -u, --update     Update Finch

常用示例

使用 example 模板创建新项目

finch create -n my_app -t example

使用文件监视器运行开发服务器

serve 命令会监视 widget 和语言文件的变更,并在不重启服务器的情况下自动重新加载:

finch serve

或指定入口文件:

finch serve -p lib/serve.dart

构建生产二进制文件

finch build -a lib/app.dart -o ./build/app

运行数据库迁移

# 应用所有待处理的 MySQL 迁移
finch migrate --init

# 创建新的 MySQL 迁移文件
finch migrate --create --name add_users_table

# 应用 SQLite 迁移
finch migrate --init --sqlite

migrate 命令委托给正在运行的应用内置迁移系统。详情请参阅 Database Migration