tachybase_todo/docs/en-US/api/cli.md

351 lines
6.9 KiB
Markdown
Raw Normal View History

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