@nocobase/ctl 0.1.5

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.
Files changed (38) hide show
  1. package/README.md +164 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +14 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +20 -0
  6. package/dist/commands/env/add.js +51 -0
  7. package/dist/commands/env/index.js +27 -0
  8. package/dist/commands/env/list.js +31 -0
  9. package/dist/commands/env/remove.js +54 -0
  10. package/dist/commands/env/update.js +54 -0
  11. package/dist/commands/env/use.js +26 -0
  12. package/dist/commands/resource/create.js +15 -0
  13. package/dist/commands/resource/destroy.js +15 -0
  14. package/dist/commands/resource/get.js +15 -0
  15. package/dist/commands/resource/index.js +7 -0
  16. package/dist/commands/resource/list.js +16 -0
  17. package/dist/commands/resource/query.js +15 -0
  18. package/dist/commands/resource/update.js +15 -0
  19. package/dist/generated/command-registry.js +81 -0
  20. package/dist/lib/api-client.js +196 -0
  21. package/dist/lib/auth-store.js +92 -0
  22. package/dist/lib/bootstrap.js +263 -0
  23. package/dist/lib/build-config.js +10 -0
  24. package/dist/lib/cli-home.js +30 -0
  25. package/dist/lib/generated-command.js +113 -0
  26. package/dist/lib/naming.js +70 -0
  27. package/dist/lib/openapi.js +254 -0
  28. package/dist/lib/post-processors.js +23 -0
  29. package/dist/lib/resource-command.js +331 -0
  30. package/dist/lib/resource-request.js +103 -0
  31. package/dist/lib/runtime-generator.js +383 -0
  32. package/dist/lib/runtime-store.js +56 -0
  33. package/dist/lib/ui.js +154 -0
  34. package/dist/post-processors/data-modeling.js +66 -0
  35. package/dist/post-processors/data-source-manager.js +114 -0
  36. package/dist/post-processors/index.js +19 -0
  37. package/nocobase-ctl.config.json +327 -0
  38. package/package.json +61 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { postProcessorRegistry } from "../lib/post-processors.js";
10
+ function toArray(value) {
11
+ if (Array.isArray(value)) {
12
+ return value;
13
+ }
14
+ if (Array.isArray(value?.data)) {
15
+ return value.data;
16
+ }
17
+ return [];
18
+ }
19
+ function parseAssociatedIndex(value) {
20
+ if (typeof value !== 'string') {
21
+ return {};
22
+ }
23
+ const separatorIndex = value.indexOf('.');
24
+ if (separatorIndex === -1) {
25
+ return {};
26
+ }
27
+ return {
28
+ dataSourceKey: value.slice(0, separatorIndex),
29
+ collectionName: value.slice(separatorIndex + 1),
30
+ };
31
+ }
32
+ function pickCollectionSummary(item) {
33
+ return {
34
+ name: item?.name,
35
+ title: item?.title ?? item?.options?.title ?? item?.displayName,
36
+ description: item?.description ?? item?.options?.description,
37
+ dataSourceKey: item?.dataSourceKey,
38
+ };
39
+ }
40
+ function pickFieldSummary(item) {
41
+ return {
42
+ name: item?.name,
43
+ type: item?.type,
44
+ title: item?.uiSchema?.title,
45
+ description: item?.description,
46
+ dataSourceKey: item?.dataSourceKey,
47
+ collectionName: item?.collectionName,
48
+ };
49
+ }
50
+ function pickRemoteFieldSummary(item, defaults) {
51
+ return {
52
+ name: item?.name,
53
+ type: item?.type,
54
+ title: item?.uiSchema?.title,
55
+ description: item?.description,
56
+ dataSourceKey: item?.dataSourceKey,
57
+ collectionName: item?.collectionName,
58
+ ...defaults,
59
+ };
60
+ }
61
+ function pickDataSourceSummary(item) {
62
+ const summary = {
63
+ displayName: item?.displayName,
64
+ key: item?.key,
65
+ type: item?.type,
66
+ status: item?.status,
67
+ };
68
+ if (Array.isArray(item?.collections)) {
69
+ summary.collections = item.collections.map((collection) => {
70
+ const nextCollection = pickCollectionSummary({
71
+ ...collection,
72
+ dataSourceKey: collection?.dataSourceKey ?? item?.key,
73
+ });
74
+ if (Array.isArray(collection?.fields)) {
75
+ nextCollection.fields = collection.fields.map((field) => pickRemoteFieldSummary(field, {
76
+ dataSourceKey: collection?.dataSourceKey ?? item?.key,
77
+ collectionName: collection?.name,
78
+ }));
79
+ }
80
+ return nextCollection;
81
+ });
82
+ }
83
+ return summary;
84
+ }
85
+ export function simplifyDataSourceListResult(result) {
86
+ const items = toArray(result);
87
+ return {
88
+ data: items.map((item) => pickDataSourceSummary(item)),
89
+ meta: result?.meta,
90
+ };
91
+ }
92
+ export function simplifyDataSourceCollectionsListResult(result) {
93
+ const items = toArray(result);
94
+ return {
95
+ data: items.map((item) => pickCollectionSummary(item)),
96
+ meta: result?.meta,
97
+ };
98
+ }
99
+ export function simplifyDataSourceFieldsListResult(result, options) {
100
+ const items = toArray(result);
101
+ const defaults = parseAssociatedIndex(options?.flags?.['associated-index']);
102
+ return {
103
+ data: items.map((item) => item?.dataSourceKey || item?.collectionName ? pickFieldSummary(item) : pickRemoteFieldSummary(item, defaults)),
104
+ meta: result?.meta,
105
+ };
106
+ }
107
+ export function registerDataSourceManagerPostProcessors() {
108
+ postProcessorRegistry.register('data-sources', 'list', simplifyDataSourceListResult);
109
+ postProcessorRegistry.register('data-sources', 'list-enabled', simplifyDataSourceListResult);
110
+ postProcessorRegistry.register('data-sources.collections', 'list', simplifyDataSourceCollectionsListResult);
111
+ postProcessorRegistry.register('data-sources-collections.fields', 'list', (result, context) => simplifyDataSourceFieldsListResult(result, {
112
+ flags: context.flags,
113
+ }));
114
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { registerDataModelingPostProcessors } from "./data-modeling.js";
10
+ import { registerDataSourceManagerPostProcessors } from "./data-source-manager.js";
11
+ let initialized = false;
12
+ export function registerPostProcessors() {
13
+ if (initialized) {
14
+ return;
15
+ }
16
+ registerDataModelingPostProcessors();
17
+ registerDataSourceManagerPostProcessors();
18
+ initialized = true;
19
+ }
@@ -0,0 +1,327 @@
1
+ {
2
+ "moduleGroups": [
3
+ {
4
+ "match": [
5
+ "workflow*",
6
+ "@nocobase/plugin-workflow*"
7
+ ],
8
+ "module": "workflow"
9
+ },
10
+ {
11
+ "match": [
12
+ "@nocobase/plugin-data-source-main",
13
+ "@nocobase/plugin-data-source-manager"
14
+ ],
15
+ "module": "data-modeling"
16
+ }
17
+ ],
18
+ "modules": {
19
+ "core": {
20
+ "name": "core",
21
+ "description": "NocoBase core resource APIs.",
22
+ "include": true,
23
+ "resources": {
24
+ "includes": [
25
+ "app",
26
+ "pm"
27
+ ],
28
+ "excludes": [],
29
+ "overrides": {
30
+ "app": {
31
+ "name": "app",
32
+ "description": "Application management commands.",
33
+ "topLevel": true
34
+ },
35
+ "pm": {
36
+ "name": "pm",
37
+ "description": "Plugin manager commands.",
38
+ "topLevel": true
39
+ }
40
+ }
41
+ }
42
+ },
43
+ "acl": {
44
+ "name": "acl",
45
+ "description": "Based on roles, resources, and actions, access control can precisely manage interface configuration permissions, data operation permissions, menu access permissions, and plugin permissions.",
46
+ "include": true,
47
+ "resources": {
48
+ "includes": [
49
+ "availableActions",
50
+ "dataSources",
51
+ "roles",
52
+ "rolesResourcesScopes"
53
+ ],
54
+ "excludes": [],
55
+ "overrides": {
56
+ "availableActions": {
57
+ "name": "available-actions",
58
+ "description": "List and inspect configurable ACL actions.",
59
+ "topLevel": false
60
+ },
61
+ "dataSources": {
62
+ "name": "data-sources",
63
+ "description": "Manage ACL strategies for data sources.",
64
+ "topLevel": false
65
+ },
66
+ "roles": {
67
+ "name": "roles",
68
+ "description": "Manage roles and role-level ACL settings.",
69
+ "topLevel": false
70
+ },
71
+ "rolesResourcesScopes": {
72
+ "name": "roles-resources-scopes",
73
+ "description": "Manage role resource scopes and permissions.",
74
+ "topLevel": false
75
+ }
76
+ }
77
+ }
78
+ },
79
+ "api-keys": {
80
+ "name": "api-keys",
81
+ "description": "Allow users to access the HTTP API with API keys.",
82
+ "include": true,
83
+ "resources": {
84
+ "includes": [
85
+ "apiKeys"
86
+ ],
87
+ "excludes": [],
88
+ "overrides": {
89
+ "apiKeys": {
90
+ "name": "api-keys",
91
+ "description": "Manage API keys.",
92
+ "topLevel": false
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "auth": {
98
+ "name": "authenticators",
99
+ "description": "User authentication management, including password auth, SMS auth, SSO protocols, and extensible providers.",
100
+ "include": true,
101
+ "resources": {
102
+ "includes": [
103
+ "authenticators"
104
+ ],
105
+ "excludes": [],
106
+ "overrides": {
107
+ "auth": {
108
+ "name": "auth",
109
+ "description": "Authenticate users and manage auth sessions.",
110
+ "topLevel": false
111
+ },
112
+ "authenticators": {
113
+ "name": "authenticators",
114
+ "description": "Manage authentication providers and authenticators.",
115
+ "topLevel": false
116
+ }
117
+ }
118
+ }
119
+ },
120
+ "client": {
121
+ "name": "client",
122
+ "description": "Provide the web client interface for the NocoBase server.",
123
+ "include": true,
124
+ "resources": {
125
+ "includes": [
126
+ "desktopRoutes",
127
+ "roles"
128
+ ],
129
+ "excludes": [],
130
+ "overrides": {
131
+ "desktopRoutes": {
132
+ "name": "desktop-routes",
133
+ "description": "Manage desktop route permissions and visibility.",
134
+ "topLevel": true
135
+ },
136
+ "roles": {
137
+ "name": "roles",
138
+ "description": "Manage client permissions scoped by role.",
139
+ "topLevel": false
140
+ }
141
+ }
142
+ }
143
+ },
144
+ "data-modeling": {
145
+ "name": "data-modeling",
146
+ "description": "Manage data sources, collections, and database modeling resources.",
147
+ "include": true,
148
+ "resources": {
149
+ "includes": [
150
+ "collections",
151
+ "fields",
152
+ "dbViews"
153
+ ],
154
+ "excludes": [],
155
+ "overrides": {
156
+ "collections": {
157
+ "name": "collections",
158
+ "description": "Manage collections and collection metadata.",
159
+ "topLevel": false,
160
+ "operations": {
161
+ "includes": [
162
+ "apply",
163
+ "collections:list",
164
+ "collections:get",
165
+ "collections:destroy",
166
+ "collections/{collectionName}/fields:list"
167
+ ]
168
+ }
169
+ },
170
+ "fields": {
171
+ "name": "fields",
172
+ "description": "Manage fields with the compact high-level modeling interface.",
173
+ "topLevel": false,
174
+ "operations": {
175
+ "includes": [
176
+ "apply"
177
+ ]
178
+ }
179
+ },
180
+ "dbViews": {
181
+ "name": "db-views",
182
+ "description": "Inspect and query database views.",
183
+ "topLevel": false,
184
+ "operations": {
185
+ "includes": [
186
+ "dbViews:list",
187
+ "dbViews:get"
188
+ ]
189
+ }
190
+ }
191
+ }
192
+ }
193
+ },
194
+ "file-manager": {
195
+ "name": "file-manager",
196
+ "description": "Provide file storage services, file collections, and attachment fields.",
197
+ "include": true,
198
+ "resources": {
199
+ "includes": [
200
+ "storages"
201
+ ],
202
+ "excludes": [],
203
+ "overrides": {
204
+ "storages": {
205
+ "name": "storages",
206
+ "description": "Manage storage backends and file storage settings.",
207
+ "topLevel": false
208
+ }
209
+ }
210
+ }
211
+ },
212
+ "flow-engine": {
213
+ "name": "flow-engine",
214
+ "description": "Manage flow surface composition, configuration, layout, and mutation APIs.",
215
+ "include": true,
216
+ "resources": {
217
+ "includes": [
218
+ "flowSurfaces"
219
+ ],
220
+ "excludes": [],
221
+ "overrides": {
222
+ "flowSurfaces": {
223
+ "name": "flow-surfaces",
224
+ "description": "Compose and mutate page, tab, block, field, and action surfaces.",
225
+ "topLevel": true
226
+ }
227
+ }
228
+ }
229
+ },
230
+ "map": {
231
+ "name": "map",
232
+ "description": "Map blocks with support for AMap, Google Maps, and extensible providers.",
233
+ "include": true,
234
+ "resources": {
235
+ "includes": [
236
+ "map-configuration"
237
+ ],
238
+ "excludes": [],
239
+ "overrides": {
240
+ "map-configuration": {
241
+ "name": "map-configuration",
242
+ "description": "Manage map provider configuration.",
243
+ "topLevel": false
244
+ }
245
+ }
246
+ }
247
+ },
248
+ "system-settings": {
249
+ "name": "system-settings",
250
+ "description": "Adjust system title, logo, language, and other global settings.",
251
+ "include": true,
252
+ "resources": {
253
+ "includes": [
254
+ "systemSettings"
255
+ ],
256
+ "excludes": [],
257
+ "overrides": {
258
+ "systemSettings": {
259
+ "name": "system-settings",
260
+ "description": "Manage global system settings.",
261
+ "topLevel": false
262
+ }
263
+ }
264
+ }
265
+ },
266
+ "theme-editor": {
267
+ "name": "theme-editor",
268
+ "description": "Customize UI colors and dimensions, save themes, and switch between them.",
269
+ "include": true,
270
+ "resources": {
271
+ "includes": [
272
+ "themeConfig"
273
+ ],
274
+ "excludes": [],
275
+ "overrides": {
276
+ "themeConfig": {
277
+ "name": "theme-config",
278
+ "description": "Manage theme configuration.",
279
+ "topLevel": false
280
+ }
281
+ }
282
+ }
283
+ },
284
+ "workflow": {
285
+ "name": "workflow",
286
+ "description": "A powerful BPM tool that provides the foundation for business automation and extensible triggers and nodes.",
287
+ "include": true,
288
+ "resources": {
289
+ "includes": [
290
+ "executions",
291
+ "flow_nodes",
292
+ "jobs",
293
+ "userWorkflowTasks",
294
+ "workflows"
295
+ ],
296
+ "excludes": [],
297
+ "overrides": {
298
+ "executions": {
299
+ "name": "executions",
300
+ "description": "Manage workflow execution records.",
301
+ "topLevel": false
302
+ },
303
+ "flow_nodes": {
304
+ "name": "flow-nodes",
305
+ "description": "Manage workflow nodes.",
306
+ "topLevel": false
307
+ },
308
+ "jobs": {
309
+ "name": "jobs",
310
+ "description": "Manage workflow jobs.",
311
+ "topLevel": false
312
+ },
313
+ "userWorkflowTasks": {
314
+ "name": "user-workflow-tasks",
315
+ "description": "Query current user workflow tasks.",
316
+ "topLevel": false
317
+ },
318
+ "workflows": {
319
+ "name": "workflows",
320
+ "description": "Manage workflows and workflow revisions.",
321
+ "topLevel": false
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@nocobase/ctl",
3
+ "version": "0.1.5",
4
+ "description": "NocoBase Command Line Tool",
5
+ "type": "module",
6
+ "main": "dist/generated/command-registry.js",
7
+ "scripts": {
8
+ "clean": "rm -rf dist",
9
+ "build": "pnpm run clean && tsc -p tsconfig.json",
10
+ "dev": "./bin/dev.js",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "Apache-2.0",
16
+ "files": [
17
+ "bin",
18
+ "dist",
19
+ "nocobase-ctl.config.json"
20
+ ],
21
+ "bin": {
22
+ "nbctl": "./bin/run.js",
23
+ "nocobase-ctl": "./bin/run.js"
24
+ },
25
+ "oclif": {
26
+ "bin": "nocobase-ctl",
27
+ "additionalHelpFlags": [
28
+ "-h"
29
+ ],
30
+ "commands": {
31
+ "strategy": "explicit",
32
+ "target": "./dist/generated/command-registry.js"
33
+ },
34
+ "dirname": "nocobase-ctl",
35
+ "topicSeparator": " ",
36
+ "topics": {
37
+ "env": {
38
+ "description": "Manage NocoBase project environments and update command runtimes."
39
+ },
40
+ "resource": {
41
+ "description": "Work with generic collection resources."
42
+ }
43
+ }
44
+ },
45
+ "dependencies": {
46
+ "@apidevtools/swagger-parser": "^12.1.0",
47
+ "@oclif/core": "^4.10.4",
48
+ "openapi-types": "^12.1.3",
49
+ "ora": "^8.2.0",
50
+ "picocolors": "^1.1.1",
51
+ "typescript": "^6.0.2"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^18.19.130",
55
+ "tsx": "^4.20.6"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/nocobase/ctl.git"
60
+ }
61
+ }