@nocobase/cli 2.1.0-alpha.20 → 2.1.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,176 +1,343 @@
1
- # NocoBase CTL
1
+ # NocoBase CLI
2
2
 
3
- NocoBase CTL is a command-line tool for managing and controlling NocoBase applications. Its relationship with multiple NocoBase App instances is shown below:
3
+ NocoBase CLI (`nb`) is a command-line tool for setting up and managing NocoBase
4
+ apps in a local workspace. It helps you connect coding agents to NocoBase by
5
+ preparing the app, saving the CLI env config, and providing day-to-day commands
6
+ for start, stop, logs, upgrade, and cleanup.
4
7
 
5
- ```
6
- +----------------------+
7
- | NocoBase CTL |
8
- | Controller |
9
- +----------------------+
10
- |
11
- +----------------+----------------+
12
- | | |
13
- v v v
14
- +----------------+ +----------------+ +----------------+
15
- | NocoBase App | | NocoBase App | | NocoBase App |
16
- | Dev | | Test | | Prod |
17
- +----------------+ +----------------+ +----------------+
8
+ The CLI supports two common setup paths:
9
+
10
+ - Connect an existing NocoBase app so coding agents can use it.
11
+ - Install a new NocoBase app from Docker, npm, or Git, then connect it as a CLI env.
12
+
13
+ ## Prerequisites
14
+
15
+ - Node.js v20+
16
+ - Yarn 1.x
17
+ - Git, required when installing from Git source
18
+ - Docker, required when installing with Docker or using the built-in database
19
+
20
+ ## Installation
21
+
22
+ Install the CLI globally:
23
+
24
+ ```bash
25
+ npm install -g @nocobase/cli@alpha
18
26
  ```
19
27
 
20
- NocoBase CTL combines:
28
+ Check the available commands:
21
29
 
22
- - built-in commands for environment management and generic resource access
23
- - runtime-generated commands loaded from your NocoBase application's Swagger schema
30
+ ```bash
31
+ nb --help
32
+ nb init --help
33
+ ```
34
+
35
+ ## Core Concepts
24
36
 
25
- This allows the CLI to stay aligned with the target application instead of relying on a fixed command list.
37
+ - **Workspace**: the current project folder where `.nocobase` is stored.
38
+ - **Env**: a named NocoBase connection saved by the CLI. In `nb init`, the app name is also the env name.
39
+ - **Source**: how the local app is obtained. Supported values are `docker`, `npm`, and `git`.
40
+ - **Remote env**: an env that only stores an API connection to an existing NocoBase app.
41
+ - **Runtime resources**: local app process, Docker app container, built-in database container, source directory, and storage directory managed by CLI commands.
26
42
 
27
43
  ## Quick Start
28
44
 
29
- Install NocoBase CTL globally:
45
+ ### Guided Setup
46
+
47
+ Run the guided terminal flow:
30
48
 
31
49
  ```bash
32
- npm install -g @nocobase/ctl@latest
50
+ nb init
33
51
  ```
34
52
 
35
- Add an environment:
53
+ Use the browser-based setup form:
36
54
 
37
55
  ```bash
38
- nb env add local --base-url http://localhost:13000/api
56
+ nb init --ui
39
57
  ```
40
58
 
41
- Add an environment with an API key:
59
+ `nb init` can either connect to an existing NocoBase app or install a new one.
60
+ When creating a new app, it can also install NocoBase AI coding skills
61
+ (`nocobase/skills`) for the current workspace.
62
+
63
+ ### Non-Interactive Setup
64
+
65
+ When prompts are skipped, an app/env name is required:
42
66
 
43
67
  ```bash
44
- nb env add local --base-url http://localhost:13000/api --auth-type token --token <api-key>
68
+ nb init --env app1 --yes
45
69
  ```
46
70
 
47
- Authenticate an environment with OAuth:
71
+ Install with Docker:
48
72
 
49
73
  ```bash
50
- nb env auth local
74
+ nb init --env app1 --yes --source docker --version alpha
51
75
  ```
52
76
 
53
- Show the current environment:
77
+ Install from npm:
54
78
 
55
79
  ```bash
56
- nb env
80
+ nb init --env app1 --yes --source npm --version alpha --app-port 13080
57
81
  ```
58
82
 
59
- List configured environments:
83
+ Install from Git source:
60
84
 
61
85
  ```bash
62
- nb env list
86
+ nb init --env app1 --yes --source git --version alpha
87
+ ```
88
+
89
+ For Git source installs, `--version alpha` resolves to the `develop` branch.
90
+
91
+ Install from a Git branch:
92
+
93
+ ```bash
94
+ nb init --env app1 --yes --source git --version fix/cli-v2
95
+ ```
96
+
97
+ `--version` is the shared version input across sources:
98
+
99
+ - npm: package version
100
+ - Docker: image tag
101
+ - Git: git ref such as a branch or tag
102
+
103
+ By default, a new local app uses:
104
+
105
+ - Source directory: `./<envName>/source/`
106
+ - Storage directory: `./<envName>/storage/`
107
+
108
+ ### Resume an Interrupted Setup
109
+
110
+ If `nb init` was interrupted after the env config had already been saved, you can continue the same setup:
111
+
112
+ ```bash
113
+ nb init --env app1 --resume
114
+ ```
115
+
116
+ The advanced low-level equivalent is:
117
+
118
+ ```bash
119
+ nb install --env app1 --resume
120
+ ```
121
+
122
+ `--resume` reuses the saved workspace env config for app, source, database, and env connection settings. In interactive mode, it only asks for any missing setup-only values.
123
+
124
+ In non-interactive mode, pass these setup-only flags again because they are not saved in env config:
125
+
126
+ - `--lang`
127
+ - `--root-username`
128
+ - `--root-email`
129
+ - `--root-password`
130
+ - `--root-nickname`
131
+
132
+ ## Daily Commands
133
+
134
+ | Command | Description |
135
+ | --- | --- |
136
+ | `nb init` | Set up NocoBase and connect it as a CLI env for coding agents. |
137
+ | `nb install` | Advanced command used by `nb init` to install a local NocoBase app and save env config. In most cases, use `nb init` instead. |
138
+ | `nb download` | Advanced command used by `nb init` or `nb upgrade` to fetch NocoBase from Docker, npm, or Git. It is rarely used directly. |
139
+ | `nb start` | Start the selected local app or Docker container. |
140
+ | `nb stop` | Stop the selected local app or Docker container. |
141
+ | `nb dev` | Run development mode for npm/Git source envs. |
142
+ | `nb logs` | Show app logs for npm/Git or Docker envs. |
143
+ | `nb ps` | Show runtime status for configured envs. |
144
+ | `nb db` | Inspect or manage built-in database runtime status for local envs. |
145
+ | `nb upgrade` | Refresh code/image and restart the selected app. |
146
+ | `nb down` | Stop and remove local runtime containers for an env. |
147
+ | `nb env` | Manage saved CLI env connections. |
148
+ | `nb api` | Call NocoBase API resources from the CLI. |
149
+ | `nb pm` | Manage plugins for the selected NocoBase env. |
150
+
151
+ Recommended style: use `--env` explicitly for app/runtime commands. `-e` is the short form:
152
+
153
+ ```bash
154
+ nb start --env app1
155
+ nb logs --env app1
156
+ nb ps --env app1
157
+ nb db ps --env app1
63
158
  ```
64
159
 
65
- Switch the current environment:
160
+ Equivalent shorthand examples:
66
161
 
67
162
  ```bash
68
- nb env use local
163
+ nb start -e app1
164
+ nb logs -e app1
165
+ nb upgrade -e app1
166
+ nb db start -e app1
69
167
  ```
70
168
 
71
- Update the runtime command cache from `swagger:get`:
169
+ ## Runtime Types
170
+
171
+ ### Docker
172
+
173
+ Docker envs are managed through saved Docker containers and images:
72
174
 
73
175
  ```bash
74
- nb env update
75
- nb env update local
176
+ nb init --env app1 --yes --source docker --version alpha
177
+ nb start --env app1
178
+ nb logs --env app1
179
+ nb stop --env app1
76
180
  ```
77
181
 
78
- Use the generic resource commands:
182
+ Docker downloads support platform selection:
79
183
 
80
184
  ```bash
81
- nb api resource list --resource users
82
- nb api resource get --resource users --filter-by-tk 1
83
- nb api resource create --resource users --values '{"nickname":"Ada"}'
185
+ nb download --source docker --version alpha --docker-platform auto
186
+ nb download --source docker --version alpha --docker-platform linux/amd64
187
+ nb download --source docker --version alpha --docker-platform linux/arm64
84
188
  ```
85
189
 
86
- ## Runtime Commands
190
+ ### npm and Git
87
191
 
88
- When you execute a runtime command, the CLI will:
192
+ npm and Git envs use a local source directory and can run development mode:
89
193
 
90
- 1. resolve the target environment
91
- 2. read the application's Swagger schema from `swagger:get`
92
- 3. generate or reuse a cached runtime command set for that application version
93
- 4. execute the requested command
194
+ ```bash
195
+ nb init --env app1 --yes --source git --version alpha
196
+ nb dev --env app1
197
+ ```
94
198
 
95
- If the `API documentation plugin` is disabled, the CLI will prompt to enable it.
199
+ `nb dev` only supports npm/Git source envs. Docker envs can be inspected with
200
+ `nb logs`, and remote envs only support API/env operations.
96
201
 
97
- ## Environment Selection
202
+ ### Existing NocoBase App
98
203
 
99
- `nb env update` and `nb env auth` take an optional environment name as the first argument (omit it to use the current env):
204
+ To connect an existing app, use `nb init` and choose the existing-app setup
205
+ path, or add the env directly:
100
206
 
101
207
  ```bash
102
- nb env update prod
103
- nb env auth prod
208
+ nb env add app1 --base-url http://localhost:13000/api
104
209
  ```
105
210
 
106
- Use `-e, --env` on **runtime / API** commands to temporarily select an environment:
211
+ `nb env add` will start the authentication flow automatically when needed.
212
+
213
+ ## Upgrade
214
+
215
+ Upgrade refreshes the saved source or image, then restarts the app:
107
216
 
108
217
  ```bash
109
- nb api resource list --resource users -e prod
218
+ nb upgrade --env app1
110
219
  ```
111
220
 
112
- This does not change the current environment unless you explicitly run:
221
+ Use `--skip-code-update` or `-s` to restart with the saved local code or Docker
222
+ image without downloading updates first:
113
223
 
114
224
  ```bash
115
- nb env use <name>
225
+ nb upgrade --env app1 -s
116
226
  ```
117
227
 
118
- ## Config Scope
228
+ ## Database Commands
229
+
230
+ Use `nb db` to inspect or manage the built-in database runtime for a local env:
119
231
 
120
- The `env` command supports two config scopes:
232
+ ```bash
233
+ nb db ps
234
+ nb db ps --env app1
235
+ nb db start --env app1
236
+ nb db stop --env app1
237
+ nb db logs --env app1
238
+ ```
121
239
 
122
- - `project`: use `./.nocobase-ctl` in the current working directory
123
- - `global`: use the global `.nocobase-ctl` directory
240
+ Notes:
124
241
 
125
- Use `-s, --scope` to select one explicitly:
242
+ - `nb db start` and `nb db stop` only work for envs created with the built-in database option enabled.
243
+ - `nb db logs` only works for envs created with the built-in database option enabled.
244
+ - `nb db ps` can also show `external` or `remote` status for envs that do not have a CLI-managed database container.
245
+
246
+ ## Cleanup
247
+
248
+ Bring down a local env:
126
249
 
127
250
  ```bash
128
- nb env list -s project
129
- nb env add prod -s global --base-url http://example.com/api --auth-type token --token <api-key>
130
- nb env auth prod -s global
131
- nb env use local -s project
251
+ nb down --env app1
132
252
  ```
133
253
 
134
- If you do not pass `--scope`, the CLI uses automatic resolution:
254
+ By default, `nb down` stops the app and removes app/database containers if they
255
+ exist. It keeps user data, source files, and CLI env config.
135
256
 
136
- 1. current working directory if `./.nocobase-ctl` exists
137
- 2. `NOCOBASE_HOME_CLI`
138
- 3. your home directory
257
+ Use explicit flags for destructive cleanup:
139
258
 
140
- ## Built-in Commands
259
+ ```bash
260
+ nb down --env app1 --remove-data
261
+ nb down --env app1 --remove-source
262
+ nb down --env app1 --remove-env
263
+ ```
141
264
 
142
- Current built-in topics:
265
+ - `--remove-data`: delete storage and managed database data. This requires confirmation unless `--yes` is used.
266
+ - `--remove-source`: delete the npm/Git source directory.
267
+ - `--remove-env`: remove the saved CLI env config.
143
268
 
144
- - `env`
145
- - `api`
269
+ ## Environment Management
146
270
 
147
- Check available commands at any time:
271
+ Show the current env:
148
272
 
149
273
  ```bash
150
- nb --help
151
- nb env --help
152
- nb api resource --help
274
+ nb env
275
+ ```
276
+
277
+ List configured envs:
278
+
279
+ ```bash
280
+ nb env list
281
+ ```
282
+
283
+ Switch the current env:
284
+
285
+ ```bash
286
+ nb env use app1
153
287
  ```
154
288
 
155
- ## Common Flags
289
+ Re-authenticate an env when credentials need to be refreshed:
156
290
 
157
- - `-e, --env`: temporary environment selection
158
- - `-s, --scope`: config scope for `env` commands
159
- - `--role`: role override, sent as `X-Role`
160
- - `-t, --token`: API key override
161
- - `-j, --json-output`: print raw JSON response
291
+ ```bash
292
+ nb env auth app1
293
+ ```
162
294
 
163
- Example:
295
+ Update runtime command metadata from the selected app:
164
296
 
165
297
  ```bash
166
- nb env update prod -s global
167
- nb api resource list --resource users -e prod -j
168
- nb api resource list --resource users -e prod --role admin
298
+ nb env update app1
169
299
  ```
170
300
 
301
+ ## API Commands
302
+
303
+ The CLI can call NocoBase resources through the configured env:
304
+
305
+ ```bash
306
+ nb api resource list --resource users -e app1
307
+ nb api resource get --resource users --filter-by-tk 1 -e app1
308
+ nb api resource create --resource users --values '{"nickname":"Ada"}' -e app1
309
+ ```
310
+
311
+ Use `-j, --json-output` to print raw JSON when available:
312
+
313
+ ```bash
314
+ nb api resource list --resource users -e app1 -j
315
+ ```
316
+
317
+ Available API command topics:
318
+
319
+ | Command | Description |
320
+ | --- | --- |
321
+ | `nb api acl` | Manage access control based on roles, resources, and actions. |
322
+ | `nb api api-keys` | Manage API keys for HTTP API access. |
323
+ | `nb api app` | Manage application resources. |
324
+ | `nb api authenticators` | Manage user authentication, including password auth, SMS auth, SSO protocols, and extensible providers. |
325
+ | `nb api data-modeling` | Manage data sources, collections, and database modeling resources. |
326
+ | `nb api file-manager` | Manage file storage services, file collections, and attachment fields. |
327
+ | `nb api flow-surfaces` | Compose and mutate page, tab, block, field, and action surfaces. |
328
+ | `nb api pm` | Manage plugins through API commands. |
329
+ | `nb api resource` | Work with generic collection resources. |
330
+ | `nb api system-settings` | Adjust system title, logo, language, and other global settings. |
331
+ | `nb api theme-editor` | Customize UI colors and dimensions, save themes, and switch between them. |
332
+ | `nb api workflow` | Manage workflow resources for business automation. |
333
+
171
334
  ## Local Data
172
335
 
173
- The CLI stores its local state in `.nocobase-ctl`, including:
336
+ The CLI stores workspace-level config in `.nocobase`:
337
+
338
+ - `config.json`: env definitions, current env, and workspace-level settings.
339
+ - `versions/<version>/commands.json`: cached runtime commands generated from the target app.
174
340
 
175
- - `config.json`: environment definitions and current selection
176
- - `versions/<version>/commands.json`: cached runtime commands for a generated version
341
+ Runtime data such as source files, storage files, Docker containers, and
342
+ database data are managed separately according to the env source and install
343
+ options.