2023-06-20 09:11:18 +00:00
# @nocobase/cli
2022-10-31 03:52:17 +00:00
2023-02-20 15:18:02 +00:00
The NocoBase CLI is designed to help you develop, build, and deploy NocoBase applications.
2022-10-31 03:52:17 +00:00
< Alert >
2023-02-20 15:18:02 +00:00
NocoBase CLI supports < i > ts-node< / i > and < i > node< / i > two operation modes.
2022-10-31 03:52:17 +00:00
2023-02-20 15:18:02 +00:00
- ts-node mode (Default): Used for development environment, support real-time compilation, with relatively slow response
- node mode: Used for production environment, with quick response, but you need to execute `yarn nocobase build` to compile the entire source code first
2022-10-31 03:52:17 +00:00
< / Alert >
2023-02-20 15:18:02 +00:00
## Instructions For Use
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase -h
Usage: nocobase [command] [options]
Options:
-h, --help
Commands:
console
2023-02-20 15:18:02 +00:00
db:auth Verify if the database is successfully connected
db:sync Generate relevant data tables and fields through the configuration of collections
install Install
start Start application in production environment
build Compile and package
clean Delete the compiled files
dev Start application for development environment with real-time compilation
doc Documentation development
test Testing
2022-10-31 03:52:17 +00:00
umi
2023-02-20 15:18:02 +00:00
upgrade Upgrade
migrator Data migration
pm Plugin manager
2022-10-31 03:52:17 +00:00
help
```
2023-02-20 15:18:02 +00:00
## Application in Scaffolding
2022-10-31 03:52:17 +00:00
2023-02-20 15:18:02 +00:00
`scripts` in the application scaffolding `package.json` is as below:
2022-10-31 03:52:17 +00:00
```json
{
"scripts": {
"dev": "nocobase dev",
"start": "nocobase start",
"clean": "nocobase clean",
"build": "nocobase build",
"test": "nocobase test",
"pm": "nocobase pm",
"postinstall": "nocobase postinstall"
}
}
```
2023-02-20 15:18:02 +00:00
## Command Line Extensions
2022-10-31 03:52:17 +00:00
2023-02-20 15:18:02 +00:00
NocoBase CLI is built based on [commander ](https://github.com/tj/commander.js ). You can write the extended commands freely in `app/server/index.ts` :
2022-10-31 03:52:17 +00:00
```ts
const app = new Application(config);
app.command('hello').action(() => {});
```
2023-02-20 15:18:02 +00:00
or in the plugin:
2022-10-31 03:52:17 +00:00
```ts
class MyPlugin extends Plugin {
beforeLoad() {
this.app.command('hello').action(() => {});
}
}
```
2023-02-20 15:18:02 +00:00
Run in the terminal:
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase hello
```
2023-02-20 15:18:02 +00:00
## Built-in Commands
2022-10-31 03:52:17 +00:00
2023-02-20 15:18:02 +00:00
Sorted by frequency of use.
2022-10-31 03:52:17 +00:00
### `dev`
2023-02-20 15:18:02 +00:00
Start application and compile code in real time in development environment.
2022-10-31 03:52:17 +00:00
< Alert >
2023-02-20 15:18:02 +00:00
NocoBase is installed automatically if it is not installed (Refer to the `install` command).
2022-10-31 03:52:17 +00:00
< / Alert >
```bash
Usage: nocobase dev [options]
Options:
-p, --port [port]
--client
--server
-h, --help
```
2023-02-20 15:18:02 +00:00
Example:
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Launch application for development environment, with real-time compilation
2022-10-31 03:52:17 +00:00
yarn nocobase dev
2023-02-20 15:18:02 +00:00
# Start the server side only
2022-10-31 03:52:17 +00:00
yarn nocobase dev --server
2023-02-20 15:18:02 +00:00
# Start the client side only
2022-10-31 03:52:17 +00:00
yarn nocobase dev --client
```
### `start`
2023-02-20 15:18:02 +00:00
Start application in production environment, the code needs < i > yarn build< / i > .
2022-10-31 03:52:17 +00:00
< Alert >
2023-02-20 15:18:02 +00:00
- NocoBase is installed automatically if it is not installed (Refer to the `install` command).
- The source code needs to be re-packaged if it has any modification (Refer to the `build` command).
2022-10-31 03:52:17 +00:00
< / Alert >
```bash
$ yarn nocobase start -h
Usage: nocobase start [options]
Options:
-p, --port
-s, --silent
-h, --help
```
2023-02-20 15:18:02 +00:00
Example:
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Launch application for production environment
2022-10-31 03:52:17 +00:00
yarn nocobase start
```
### `install`
2023-02-20 15:18:02 +00:00
Install.
2022-10-31 03:52:17 +00:00
```bash
$ 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
```
2023-02-20 15:18:02 +00:00
Example:
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Initial installation
2022-10-31 03:52:17 +00:00
yarn nocobase install -l zh-CN -e admin@nocobase.com -p admin123
2023-02-20 15:18:02 +00:00
# Delete all data tables from NocoBase and reinstall
2022-10-31 03:52:17 +00:00
yarn nocobase install -f -l zh-CN -e admin@nocobase.com -p admin123
2023-02-20 15:18:02 +00:00
# Clear database and reinstall
2022-10-31 03:52:17 +00:00
yarn nocobase install -c -l zh-CN -e admin@nocobase.com -p admin123
```
< Alert >
2023-02-20 15:18:02 +00:00
Difference between `-f/--force` and `-c/--clean` :
- `-f/--force` Delete data tables of NocoBase
- `-c/--clean` Clear database, all data tables are deleted
2022-10-31 03:52:17 +00:00
< / Alert >
### `upgrade`
2023-02-20 15:18:02 +00:00
Upgrade.
2022-10-31 03:52:17 +00:00
```bash
yarn nocobase upgrade
```
### `test`
2023-02-20 15:18:02 +00:00
< i > jest</ i > test, which supports all [jest-cli ](https://jestjs.io/docs/cli ) options, also supports `-c, --db-clean` .
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase test -h
Usage: nocobase test [options]
Options:
2023-02-20 15:18:02 +00:00
-c, --db-clean Clear database before running all tests
2022-10-31 03:52:17 +00:00
-h, --help
```
2023-02-20 15:18:02 +00:00
Example:
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Run all test files
2022-10-31 03:52:17 +00:00
yarn nocobase test
2023-02-20 15:18:02 +00:00
# Run all test files in the specified folder
2022-10-31 03:52:17 +00:00
yarn nocobase test packages/core/server
2023-02-20 15:18:02 +00:00
# Run all tests in the specified file
2022-10-31 03:52:17 +00:00
yarn nocobase test packages/core/database/src/__tests__/database.test.ts
2023-02-20 15:18:02 +00:00
# Clear database before running all tests
2022-10-31 03:52:17 +00:00
yarn nocobase test -c
yarn nocobase test packages/core/server -c
```
### `build`
2023-02-20 15:18:02 +00:00
The source code needs to be compiled and packaged before the code is deployed to the production environment; and you need to re-build the code if it has any modification.
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# All packages
2022-10-31 03:52:17 +00:00
yarn nocobase build
2023-02-20 15:18:02 +00:00
# Specified packages
2022-10-31 03:52:17 +00:00
yarn nocobase build app/server app/client
```
### `clean`
2023-02-20 15:18:02 +00:00
Delete the compiled files.
2022-10-31 03:52:17 +00:00
```bash
yarn clean
2023-02-20 15:18:02 +00:00
# Equivalent to
2022-10-31 03:52:17 +00:00
yarn rimraf -rf packages/*/*/{lib,esm,es,dist}
```
### `doc`
2023-02-20 15:18:02 +00:00
Documentation development.
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Start the documentation
yarn doc --lang=zh-CN # Equivalent to yarn doc dev
# Build the documentation, and output it to . /docs/dist/ directory by default
2022-10-31 03:52:17 +00:00
yarn doc build
2023-02-20 15:18:02 +00:00
# View the final result of the output documentation of dist
2022-10-31 03:52:17 +00:00
yarn doc serve --lang=zh-CN
```
### `db:auth`
2023-02-20 15:18:02 +00:00
Verify if the database is successfully connected.
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase db:auth -h
Usage: nocobase db:auth [options]
Options:
2023-02-20 15:18:02 +00:00
-r, --retry [retry] Number of retries
2022-10-31 03:52:17 +00:00
-h, --help
```
### `db:sync`
2023-02-20 15:18:02 +00:00
Generate relevant data tables and fields through the configuration of collections.
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase db:sync -h
Usage: nocobase db:sync [options]
Options:
-f, --force
-h, --help display help for command
```
### `migrator`
2023-02-20 15:18:02 +00:00
Data migration.
2022-10-31 03:52:17 +00:00
```bash
$ yarn nocobase migrator
Positional arguments:
< command >
up Applies pending migrations
down Revert migrations
pending Lists pending migrations
executed Lists executed migrations
create Create a migration file
```
### `pm`
2023-02-20 15:18:02 +00:00
Plugin manager.
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Create plugin
2022-10-31 03:52:17 +00:00
yarn pm create hello
2023-02-20 15:18:02 +00:00
# Register plugin
2022-10-31 03:52:17 +00:00
yarn pm add hello
2023-02-20 15:18:02 +00:00
# Enable plugin
2022-10-31 03:52:17 +00:00
yarn pm enable hello
2023-02-20 15:18:02 +00:00
# Disable plugin
2022-10-31 03:52:17 +00:00
yarn pm disable hello
2023-02-20 15:18:02 +00:00
# Remove plugin
2022-10-31 03:52:17 +00:00
yarn pm remove hello
```
2023-02-20 15:18:02 +00:00
Not achieved yet:
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Upgrade plugin
2022-10-31 03:52:17 +00:00
yarn pm upgrade hello
2023-02-20 15:18:02 +00:00
# Publish plugin
2022-10-31 03:52:17 +00:00
yarn pm publish hello
```
### `umi`
2023-02-20 15:18:02 +00:00
`app/client` is built based on [umi ](https://umijs.org/ ), you can run other relevant commands through `nocobase umi` .
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# Generate the .umi cache needed for the development environment
2022-10-31 03:52:17 +00:00
yarn nocobase umi generate tmp
```
### `help`
2023-02-20 15:18:02 +00:00
The help command, you can also use the option parameter, `-h` and `--help` .
2022-10-31 03:52:17 +00:00
```bash
2023-02-20 15:18:02 +00:00
# View all cli
2022-10-31 03:52:17 +00:00
yarn nocobase help
2023-02-20 15:18:02 +00:00
# Use -h instead
2022-10-31 03:52:17 +00:00
yarn nocobase -h
2023-02-20 15:18:02 +00:00
# Or --help
2022-10-31 03:52:17 +00:00
yarn nocobase --help
2023-02-20 15:18:02 +00:00
# View options of command db:sync
2022-10-31 03:52:17 +00:00
yarn nocobase db:sync -h
```