nocobase/docs/en-US/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

6.2 KiB

order
2

NocoBase CLI

NocoBase CLI is designed to help you develop, build, and deploy NocoBase applications.

NocoBase CLI supports both ts-node and node modes

  • ts-node mode (default): used for development environment, supports real-time compilation, but slow response
  • node mode: for production environment, fast response, but need to execute yarn nocobase build to compile all source code first

Instructions

$ yarn nocobase -h

Usage: nocobase [command] [options]

Options:
  -h, --help

Commands:
  create-plugin         Create plugin scaffolding
  console
  db:auth               Verify that the database connection is successful
  db:sync               Generate relevant data tables and fields from collections configuration
  install               Install
  start                 Start the application in the production environment
  build                 Compile and package
  clean                 Delete the compiled files
  dev                   Start the application for the development environment and supports live compilation
  doc                   Documentation development
  test                  Test
  umi
  upgrade               Upgrade
  help

Use in scaffolding

The scripts in the application scaffolding package.json are as follows

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

Extensions

NocoBase CLI is built on commander, you can freely extend the command, the extended command can be written in app/server/index.ts.

const app = new Application(config);

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

Alternatively, write in the plugin.

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

Terminal runs

$ yarn nocobase hello

Built-in command line

Sort by frequency of use

dev

Start the application in the development environment and the code is compiled in real time.

NocoBase will be installed automatically if it is not installed (refer to the install command)
Usage: nocobase dev [options]

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

Example

# Start application for development environment, live compile
yarn nocobase dev
# Start only the server side
yarn nocobase dev --server
# Start only the client side
yarn nocobase dev --client

start

Start the application in a production environment, the code needs to be yarn build.

  • NocoBase will be installed automatically if it is not installed (refer to the install command)
  • If the source code has been modified, it needs to be repackaged (refer to the build command)
$ yarn nocobase start -h

Usage: nocobase start [options]

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

Example

# Start the application in a production environment
yarn nocobase start

install

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

Example

# Initial Installation
yarn nocobase install -l en-US -e admin@nocobase.com -p admin123
# Delete all data tables of NocoBase and reinstall
yarn nocobase install -f -l en-US -e admin@nocobase.com -p admin123
# Empty the database and reinstall
yarn nocobase install -c -l en-US -e admin@nocobase.com -p admin123

Difference between -f/--force and -c/--clean

  • -f/--force Delete all data tables of NocoBase
  • -c/--clean Delete all data tables of the database

upgrade

Upgrade

yarn nocobase upgrade

test

jest tests, supports all jest-cli options, and extends -c, --db-clean support in addition.

$ yarn nocobase test -h

Usage: nocobase test [options]

Options:
  -c, --db-clean        Empty the database before running all tests
  -h, --help

Example

# Run all test files
yarn nocobase test
# Run all test files in the specified folder
yarn nocobase test packages/core/server
# Run all tests in the specified file
yarn nocobase test packages/core/database/src/__tests__/database.test.ts

# Empty the database before running tests
yarn nocobase test -c
yarn nocobase test packages/core/server -c

build

Before deployed to the production environment, the source code needs to be compiled and packaged. It needs to be rebuilt if there are changes to the code.

# All packages
yarn nocobase build
# Specified package
yarn nocobase build app/server app/client

clean

Delete the compiled file

yarn clean
# Equivalent to
yarn rimraf -rf packages/*/*/{lib,esm,es,dist}

doc

Documentation development

# Start documentation
yarn doc  --lang=en-US # Equivalent to yarn doc dev
# Build the documentation and output it to . /docs/dist/ directory by default 
yarn doc build
# View the final result of the document output by dist
yarn doc serve --lang=en-US

db:auth

Verify that the database is successfully connected

$ yarn nocobase db:auth -h

Usage: nocobase db:auth [options]

Options:
  -r, --repeat [repeat]  Number of reconnections
  -h, --help

db:sync

Generate data tables and fields via collections configuration

$ yarn nocobase db:sync -h

Usage: nocobase db:sync [options]

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

umi

app/client is built based on umi and can be used to execute other related commands via nocobase umi.

# Generate the .umi cache required by the development environment
yarn nocobase umi generate tmp

help

The help command, also available with the option parameter, -h and --help

# View all cli
yarn nocobase help
# You can also use -h
yarn nocobase -h
# or --help
yarn nocobase --help
# Option to view the db:sync command
yarn nocobase db:sync -h