nocobase/docs/zh-CN/development/nocobase-cli.md
chenos 6410bc8a75
feat: build, cli, devtools, sdk, docs...
* feat: nocobase build

* chore: update build scripts

* chore: update build scripts

* chore(versions): 😊 publish v0.7.0-alpha.33

* chore: independent version

* chore: nocobase build

* chore(versions): 😊 publish v0.7.0-alpha.34

* feat: nocobase-cli

* feat: nocobase-cli

* chore: update dependencies

* feat: improve code

* refactor: create-nocobase-app

* chore(versions): 😊 publish v0.7.0-alpha.35

* feat: @nocobase/devtools

* chore(versions): 😊 publish v0.7.0-alpha.36

* chore: update dependencies

* chore(versions): 😊 publish v0.7.0-alpha.37

* feat: improve code

* chore(versions): 😊 publish v0.7.0-alpha.38

* feat: improve code

* chore(versions): 😊 publish v0.7.0-alpha.39

* feat: update deps

* chore(versions): 😊 publish v0.7.0-alpha.40

* chore: update devDependencies

* chore(versions): 😊 publish v0.7.0-alpha.41

* fix: postinstall

* chore(versions): 😊 publish v0.7.0-alpha.42

* chore: improve code

* chore(versions): 😊 publish v0.7.0-alpha.43

* chore: execa

* chore(versions): 😊 publish v0.7.0-alpha.44

* chore(cli): allow unknown option

* chore(versions): 😊 publish v0.7.0-alpha.45

* fix: default envs

* chore(versions): 😊 publish v0.7.0-alpha.45

* fix: package argument for build command

* chore(versions): 😊 publish v0.7.0-alpha.46

* fix: improve code

* chore(versions): 😊 publish v0.7.0-alpha.48

* feat: clean & doc

* chore(versions): 😊 publish v0.7.0-alpha.49

* feat: compilation tips

* feat: upgrade command

* chore(versions): 😊 publish v0.7.0-alpha.50

* fix: unexpected token ] in JSON

* chore(versions): 😊 publish v0.7.0-alpha.51

* fix: upgrade command

* chore(versions): 😊 publish v0.7.0-alpha.52

* fix: remove export action from available action

* fix: db sync after upgrade

* chore(versions): 😊 publish v0.7.0-alpha.53

* feat: upgrade log

* chore(versions): 😊 publish v0.7.0-alpha.54

* docs: updates

* feat: updates

* docs(cli): update usage description

* feat: updates

* docs: updates

* docs: updates

* docs: toc

* feat: sdk

* docs: updates

* docs: updates

* docs: updates

* Update index.md

* docs: updates

* Update release-notes.md

* Update roadmap.md

* Update index.md

* Update contributing.md

* Update contributing.md

* Update index.md

* Update index.md

* Update nocobase-cli.md

* Update nocobase-cli.md

* fix: user plugin initialization data

* Update env.md

* Update env.md

* Update directory-structure.md

* Update index.md

* Update action-api.md

* Update filter-operators.md

* docs: update thanks.md

* Update index.md

* Update javascript-sdk.md

* Update rest-api.md

* Update installation.md

* Update installation.md

* Update upgrading.md

* Update upgrading.md

* Update upgrading.md

* Update installation.md

* Update installation.md

* Create release-notes.md

* Update release-notes.md

* feat: updates

* feat: update docs

* feat: update release-notes.md

* feat: switch language

* feat: updates

* Add files via upload

* Add files via upload

* Update important-features.md

* Update thanks.md

* feat: nocobase postinstall

* Update index.md

* Create why-different.md

* Update why-different.md

* Create who-is-for.md

* Rename who-is-for.md to who.md

* feat: update docs

* Rename why-different.md to why.md

* Update why.md

* Update menus.ts

* Update why-nocobase.md

* Create who.md

* Create why.md

* feat: updates

* chore(versions): 😊 publish v0.7.0-alpha.55

* feat: tips

* Update who.md

* Update who.md

* feat: update docs

* feat: update doc menus

* fix: plugin client dist

* docs: update contributing.md

* docs: update readme.md

* docs: update readme.md

* docs: update readme.md

* Update functional-zoning.md

* fix: br

Co-authored-by: Zhou <zhou.working@gmail.com>
2022-05-19 00:40:55 +08:00

5.6 KiB
Raw Blame History

order
2

NocoBase CLI

NocoBase CLI 旨在帮助你开发、构建和部署 NocoBase 应用。

NocoBase CLI 支持 ts-node 和 node 两种运行模式

  • ts-node 模式(默认):用于开发环境,支持实时编译,但是响应较慢
  • node 模式:用于生产环境,响应迅速,但需要先执行 yarn nocobase build 将全部源码进行编译

使用说明

$ yarn nocobase -h

Usage: nocobase [command] [options]

Options:
  -h, --help

Commands:
  create-plugin         创建插件脚手架
  console
  db:auth               校验数据库是否连接成功
  db:sync               通过 collections 配置生成相关数据表和字段
  install               安装
  start                 生产环境启动应用
  build                 编译打包
  clean                 删除编译之后的文件
  dev                   启动应用,用于开发环境,支持实时编译
  doc                   文档开发
  test                  测试
  umi
  upgrade               升级
  help

在脚手架里应用

应用脚手架 package.json 里的 scripts 如下:

{
  "scripts": {
    "dev": "nocobase dev",
    "start": "nocobase start",
    "clean": "nocobase clean",
    "build": "nocobase build",
    "test": "nocobase test",
    "postinstall": "nocobase umi generate tmp"
  }
}

命令行扩展

NocoBase CLI 基于 commander 构建,你可以自由扩展命令,扩展的 command 可以写在 app/server/index.ts 里:

const app = new Application(config);

app.command('hello').action(() => {});

或者,写在插件里:

class MyPlugin extends Plugin {
  beforeLoad() {
    this.app.command('hello').action(() => {});
  }
}

终端运行

$ yarn nocobase hello

内置命令行

按使用频率排序

dev

开发环境下,启动应用,代码实时编译。

NocoBase 未安装时,会自动安装(参考 install 命令)
Usage: nocobase dev [options]

Options:
  -p, --port [port]
  --client
  --server
  -h, --help

示例

# 启动应用,用于开发环境,实时编译
yarn nocobase dev
# 只启动服务端
yarn nocobase dev --server
# 只启动客户端
yarn nocobase dev --client

start

生产环境下,启动应用,代码需要 yarn build。

  • NocoBase 未安装时,会自动安装(参考 install 命令)
  • 源码有修改时,需要重新打包(参考 build 命令)
$ yarn nocobase start -h

Usage: nocobase start [options]

Options:
  -p, --port
  -s, --silent
  -h, --help

示例

# 启动应用,用于生产环境,
yarn nocobase start

install

安装

$ yarn nocobase install -h

Usage: nocobase install [options]

Options:
  -f, --force
  -c, --clean
  -s, --silent
  -l, --lang [lang]
  -e, --root-email <rootEmail>
  -p, --root-password <rootPassword>
  -n, --root-nickname [rootNickname]
  -h, --help

示例

# 初始安装
yarn nocobase install -l zh-CN -e admin@nocobase.com -p admin123
# 删除 NocoBase 的所有数据表,并重新安装
yarn nocobase install -f -l zh-CN -e admin@nocobase.com -p admin123
# 清空数据库,并重新安装
yarn nocobase install -c -l zh-CN -e admin@nocobase.com -p admin123

-f/--force-c/--clean 的区别

  • -f/--force 删除 NocoBase 的数据表
  • -c/--clean 清空数据库,所有数据表都会被删除

upgrade

升级

yarn nocobase upgrade

test

jest 测试,支持所有 jest-cli 的 options除此之外还扩展了 -c, --db-clean 的支持。

$ yarn nocobase test -h

Usage: nocobase test [options]

Options:
  -c, --db-clean        运行所有测试前清空数据库
  -h, --help

示例

# 运行所有测试文件
yarn nocobase test
# 运行指定文件夹下所有测试文件
yarn nocobase test packages/core/server
# 运行指定文件里的所有测试
yarn nocobase test packages/core/database/src/__tests__/database.test.ts

# 运行测试前,清空数据库
yarn nocobase test -c
yarn nocobase test packages/core/server -c

build

代码部署到生产环境前,需要将源码编译打包,如果代码有修改,也需要重新构建。

# 所有包
yarn nocobase build
# 指定包
yarn nocobase build app/server app/client

clean

删除编译之后的文件

yarn clean
# 等同于
yarn rimraf -rf packages/*/*/{lib,esm,es,dist}

doc

文档开发

# 启动文档
yarn doc  --lang=zh-CN # 等同于 yarn doc dev
# 构建文档,默认输出到 ./docs/dist/ 目录下
yarn doc build
# 查看 dist 输出的文档最终效果
yarn doc serve --lang=zh-CN

db:auth

校验数据库是否连接成功

$ yarn nocobase db:auth -h

Usage: nocobase db:auth [options]

Options:
  -r, --repeat [repeat]  重连次数
  -h, --help

db:sync

通过 collections 配置生成数据表和字段

$ yarn nocobase db:sync -h

Usage: nocobase db:sync [options]

Options:
  -f, --force
  -h, --help   display help for command

umi

app/client 基于 umi 构建,可以通过 nocobase umi 来执行其他相关命令。

# 生成开发环境所需的 .umi 缓存
yarn nocobase umi generate tmp

help

帮助命令,也可以用 option 参数,-h--help

# 查看所有 cli
yarn nocobase help
# 也可以用 -h
yarn nocobase -h
# 或者 --help
yarn nocobase --help
# 查看 db:sync 命令的 option
yarn nocobase db:sync -h