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

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 (116) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +165 -19
  3. package/bin/run.cmd +3 -0
  4. package/bin/run.js +95 -0
  5. package/dist/commands/api/resource/create.js +15 -0
  6. package/dist/commands/api/resource/destroy.js +15 -0
  7. package/dist/commands/api/resource/get.js +15 -0
  8. package/dist/commands/api/resource/index.js +20 -0
  9. package/dist/commands/api/resource/list.js +16 -0
  10. package/dist/commands/api/resource/query.js +15 -0
  11. package/dist/commands/api/resource/update.js +15 -0
  12. package/dist/commands/build.js +51 -0
  13. package/dist/commands/db/start.js +22 -0
  14. package/dist/commands/dev.js +58 -0
  15. package/dist/commands/download.js +293 -0
  16. package/dist/commands/env/add.js +198 -0
  17. package/dist/commands/env/auth.js +61 -0
  18. package/dist/commands/env/list.js +41 -0
  19. package/dist/commands/env/remove.js +65 -0
  20. package/dist/commands/env/update.js +73 -0
  21. package/dist/commands/env/use.js +36 -0
  22. package/dist/commands/init.js +186 -0
  23. package/dist/commands/install.js +703 -0
  24. package/dist/commands/pm/disable.js +31 -0
  25. package/dist/commands/pm/enable.js +31 -0
  26. package/dist/commands/pm/list.js +21 -0
  27. package/dist/commands/restart.js +32 -0
  28. package/dist/commands/scaffold/migration.js +38 -0
  29. package/dist/commands/scaffold/plugin.js +37 -0
  30. package/dist/commands/start.js +55 -0
  31. package/dist/commands/upgrade.js +35 -0
  32. package/dist/generated/command-registry.js +133 -0
  33. package/dist/help/runtime-help.js +20 -0
  34. package/dist/lib/api-client.js +199 -0
  35. package/dist/lib/auth-store.js +200 -0
  36. package/dist/lib/bootstrap.js +383 -0
  37. package/dist/lib/build-config.js +10 -0
  38. package/dist/lib/cli-home.js +30 -0
  39. package/dist/lib/command-discovery.js +39 -0
  40. package/dist/lib/env-auth.js +527 -0
  41. package/dist/lib/generated-command.js +142 -0
  42. package/dist/lib/init-browser-wizard.js +431 -0
  43. package/dist/lib/naming.js +70 -0
  44. package/dist/lib/openapi.js +62 -0
  45. package/dist/lib/post-processors.js +23 -0
  46. package/dist/lib/resource-command.js +335 -0
  47. package/dist/lib/resource-request.js +104 -0
  48. package/dist/lib/run-npm.js +59 -0
  49. package/dist/lib/runtime-generator.js +408 -0
  50. package/dist/lib/runtime-store.js +56 -0
  51. package/dist/lib/ui.js +175 -0
  52. package/dist/post-processors/data-modeling.js +66 -0
  53. package/dist/post-processors/data-source-manager.js +114 -0
  54. package/dist/post-processors/index.js +19 -0
  55. package/nocobase-ctl.config.json +287 -0
  56. package/package.json +52 -26
  57. package/LICENSE +0 -661
  58. package/bin/index.js +0 -39
  59. package/nocobase.conf.tpl +0 -95
  60. package/src/cli.js +0 -19
  61. package/src/commands/benchmark.js +0 -73
  62. package/src/commands/build.js +0 -49
  63. package/src/commands/clean.js +0 -30
  64. package/src/commands/client.js +0 -166
  65. package/src/commands/create-nginx-conf.js +0 -37
  66. package/src/commands/create-plugin.js +0 -33
  67. package/src/commands/dev.js +0 -200
  68. package/src/commands/doc.js +0 -76
  69. package/src/commands/e2e.js +0 -265
  70. package/src/commands/global.js +0 -43
  71. package/src/commands/index.js +0 -45
  72. package/src/commands/instance-id.js +0 -47
  73. package/src/commands/locale/cronstrue.js +0 -122
  74. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  75. package/src/commands/locale/react-js-cron/index.js +0 -17
  76. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  77. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  78. package/src/commands/locale.js +0 -81
  79. package/src/commands/p-test.js +0 -88
  80. package/src/commands/perf.js +0 -63
  81. package/src/commands/pkg.js +0 -321
  82. package/src/commands/pm2.js +0 -37
  83. package/src/commands/postinstall.js +0 -88
  84. package/src/commands/start.js +0 -148
  85. package/src/commands/tar.js +0 -36
  86. package/src/commands/test-coverage.js +0 -55
  87. package/src/commands/test.js +0 -107
  88. package/src/commands/umi.js +0 -33
  89. package/src/commands/update-deps.js +0 -72
  90. package/src/commands/upgrade.js +0 -47
  91. package/src/commands/view-license-key.js +0 -44
  92. package/src/index.js +0 -14
  93. package/src/license.js +0 -76
  94. package/src/logger.js +0 -75
  95. package/src/plugin-generator.js +0 -80
  96. package/src/util.js +0 -517
  97. package/templates/bundle-status.html +0 -338
  98. package/templates/create-app-package.json +0 -39
  99. package/templates/plugin/.npmignore.tpl +0 -2
  100. package/templates/plugin/README.md.tpl +0 -1
  101. package/templates/plugin/client.d.ts +0 -2
  102. package/templates/plugin/client.js +0 -1
  103. package/templates/plugin/package.json.tpl +0 -11
  104. package/templates/plugin/server.d.ts +0 -2
  105. package/templates/plugin/server.js +0 -1
  106. package/templates/plugin/src/client/client.d.ts +0 -249
  107. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  108. package/templates/plugin/src/client/locale.ts +0 -21
  109. package/templates/plugin/src/client/models/index.ts +0 -12
  110. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  111. package/templates/plugin/src/index.ts +0 -2
  112. package/templates/plugin/src/locale/en-US.json +0 -1
  113. package/templates/plugin/src/locale/zh-CN.json +0 -1
  114. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  115. package/templates/plugin/src/server/index.ts.tpl +0 -1
  116. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
package/LICENSE.txt ADDED
@@ -0,0 +1,107 @@
1
+ Updated Date: February 24, 2026
2
+
3
+ NocoBase License Agreement
4
+
5
+ NOCOBASE PTE. LTD.,a Singaporean Exempt Private Company Limited by Shares with its principal place of business located at 112 ROBINSON ROAD, #03-01, SINGAPORE ("The Company") https://www.nocobase.com/ issues this License Agreement ("Agreement") to you. You, as an individual or a company ("The User"), will be deemed to voluntarily accept all terms of this Agreement by using NocoBase (including but not limited to obtaining NocoBase source code or installation package in any form, installing and using NocoBase, purchasing NocoBase commercial license and services, purchasing NocoBase commercial plugins). If the User does not agree to any term of this Agreement, or cannot accurately understand our interpretation of the relevant terms, please stop using it immediately.
6
+
7
+ This Agreement applies to any use, quotation, contract, invoice, and all software delivered by the Company. The User and the Company or NocoBase's agents can no longer sign a separate license agreement for the sale and delivery of the software.
8
+
9
+ The Company reserves the right to formulate and modify this Agreement from time to time as needed. If there are changes, the Company will announce them in the form of website announcements, without further individual notification. The changed Agreement will automatically take effect once it is announced, becoming part of this Agreement.
10
+
11
+ ==============
12
+ 1. Definitions
13
+ ==============
14
+
15
+ 1.1 "Software" refers to the NocoBase kernel and plugins placed in the same code repository as the kernel, including their source code, installation packages, images, and all their modifications, updates, and upgrades.
16
+
17
+ 1.2 "Community Edition" refers to the free version of the Software provided to the User through public channels.
18
+
19
+ 1.3 "Commercial Edition" refers to the paid version of the Software purchased by the User from the Company or its agents, downloaded through exclusive channels, and includes additional benefits. It consists of three versions: Standard Edition, Professional Edition, and Enterprise Edition.
20
+
21
+ 1.4 "Upper Layer Application" refers to a specific business use case application serving internal or external customers of the User, developed based on Software and Commercial Plugins, such as ERP/CRM.
22
+
23
+ 1.5 "Customer" refers to the clients who purchase the User's Upper Layer Application.
24
+
25
+ 1.6 "Third-Party Open Source Software" refers to open source software provided with Software and Commercial Plugins. They are licensed through various published open source software licenses or copyright notices accompanying such software.
26
+
27
+ ===================================
28
+ 2. Intellectual Property Protection
29
+ ===================================
30
+
31
+ Except for Third-Party Open Source Software, the Company owns all copyrights, trademark rights, patent rights, trade secrets, and other intellectual property rights of the Software, and has registered and protected them in relevant countries and regions according to the "Paris Convention" or "TRIPS Agreement", ensuring that the intellectual property rights of the Software and Commercial Plugins are internationally recognized and protected.
32
+
33
+ =============
34
+ 3. Disclaimer
35
+ =============
36
+
37
+ 3.1 The User shall not use the Software and Commercial Plugins to engage in activities that contravene applicable laws and regulations or offend against public order or religious prohibitions. All legal liabilities and consequences arising from the User’s use shall be borne by the User.
38
+
39
+ 3.2 The Company shall not be liable for any direct, indirect, special, incidental, or consequential damages (including but not limited to loss of profits, business interruption, data loss, or business information disclosure) caused by the User's use of the Software and Commercial Plugins, even if it has been previously informed of the possibility of such damages.
40
+
41
+ ===============
42
+ 4. License Type
43
+ ===============
44
+
45
+ 4.1 This Agreement serves as the unified license agreement for NocoBase Software, applying to both the Community Edition and the Commercial Editions.
46
+
47
+ 4.2 This Agreement incorporates and references the full text of the Apache License, Version 2.0 ("Apache-2.0", available at: https://www.apache.org/licenses/LICENSE-2.0 ). Users must comply with the Apache-2.0 License as well as the supplementary terms set forth in this Agreement. In case of any inconsistency between Apache-2.0 and this Agreement, the supplementary terms of this Agreement shall prevail.
48
+
49
+ ================================================
50
+ 5. Rights and Obligations of Open Source License
51
+ ================================================
52
+
53
+ 5.1 The Software can be used for commercial purposes.
54
+
55
+ 5.2 It is not allowed to remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface, except for the main LOGO in the upper left corner of the page.
56
+
57
+ 5.3 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
58
+
59
+ 5.4 It is not allowed to provide to the public any form of no-code, zero-code, low-code, AI platform SaaS/PaaS products using the original or modified Software.
60
+
61
+ ===============================
62
+ 6. Rights of Commercial License
63
+ ===============================
64
+
65
+ 6.1 Obtain a permanent commercial license of the Software.
66
+
67
+ 6.2 Get software upgrades and exclusive technical support during the upgrade validity period.
68
+
69
+ 6.3 The licensed Software can be used for commercial purposes with no restrictions on the number of applications and users.
70
+
71
+ 6.4 Can remove or change the brand, name, link, version number, license, and other information about NocoBase on the Software interface.
72
+
73
+ 6.5 The User holding a Professional or Enterprise Edition License can sell Upper Layer Application to its Customers.
74
+
75
+ 6.6 If there are other agreements in the contract for the above rights, the contract agreement shall prevail.
76
+
77
+ ====================================
78
+ 7. Obligations of Commercial License
79
+ ====================================
80
+
81
+ 7.1 It is not allowed to remove or change all intellectual property statements about NocoBase in the code.
82
+
83
+ 7.2 It is not allowed to sell, transfer, lease, share, gift, or distribute the Commercial License.
84
+
85
+ 7.3 It is not allowed to sell, transfer, lease, share, or distribute any form of no-code, zero-code, low-code, AI platform, or developer tools developed based on Software.
86
+
87
+ 7.4 It is not allowed to provide any form of no-code, zero-code, low-code, AI platform SaaS/PaaS products to the public using the original or modified Software.
88
+
89
+ 7.5 It is not allowed for the User holding a Standard Edition license to sell Upper Layer Application to Customers without a Commercial license.
90
+
91
+ 7.6 It is not allowed for the User holding a Professional or Enterprise Edition license to sell Upper Layer Application to Customers without a Commercial license with access to further development and configuration.
92
+
93
+ 7.7 If there is a violation of the above obligations or the terms of this Agreement, the rights owned by the User will be immediately terminated, the paid fees will not be refunded, and the Company reserves the right to pursue the User's legal responsibility.
94
+
95
+ 7.8 If there are other agreements in the contract for the above obligations, the contract agreement shall prevail.
96
+
97
+ =============================================================
98
+ 8. Legal Jurisdiction, Interpretation, and Dispute Resolution
99
+ =============================================================
100
+
101
+ 8.1 Except for Mainland China, the interpretation, application, and all matters related to this agreement are subject to the jurisdiction of Singapore law.
102
+
103
+ 8.2 Any dispute related to this Agreement should first be resolved through friendly negotiation. If the negotiation fails to resolve the dispute, the dispute should be submitted to the International Chamber of Commerce (ICC) for arbitration. The arbitration venue should be Singapore, conducted in English.
104
+
105
+ 8.3 All terms and conditions of this Agreement shall be deemed enforceable to the maximum extent permitted by applicable law. If any term of this Agreement is deemed invalid by any applicable law, the invalidity of that term does not affect the validity of any other term of this Agreement, and it should be deemed that the invalid term has been modified as much as possible to make it valid and enforceable, or if the term cannot be modified, it should be deemed to have been deleted from this Agreement.
106
+
107
+ 8.4 The arbitration award is final, binding on both parties, and can be enforced in any court with jurisdiction.
package/README.md CHANGED
@@ -1,30 +1,176 @@
1
- # NocoBase
1
+ # NocoBase CTL
2
2
 
3
- <video width="100%" controls>
4
- <source src="https://static-docs.nocobase.com/NocoBase0510.mp4" type="video/mp4">
5
- </video>
3
+ NocoBase CTL is a command-line tool for managing and controlling NocoBase applications. Its relationship with multiple NocoBase App instances is shown below:
6
4
 
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
+ +----------------+ +----------------+ +----------------+
18
+ ```
7
19
 
8
- ## What is NocoBase
20
+ NocoBase CTL combines:
9
21
 
10
- NocoBase is a scalability-first, open-source no-code development platform.
11
- Instead of investing years of time and millions of dollars in research and development, deploy NocoBase in a few minutes and you'll have a private, controllable, and extremely scalable no-code development platform!
22
+ - built-in commands for environment management and generic resource access
23
+ - runtime-generated commands loaded from your NocoBase application's Swagger schema
12
24
 
13
- Homepage:
14
- https://www.nocobase.com/
25
+ This allows the CLI to stay aligned with the target application instead of relying on a fixed command list.
15
26
 
16
- Online Demo:
17
- https://demo.nocobase.com/new
27
+ ## Quick Start
18
28
 
19
- Documents:
20
- https://docs.nocobase.com/
29
+ Install NocoBase CTL globally:
21
30
 
22
- Commericial license & plugins:
23
- https://www.nocobase.com/en/commercial
31
+ ```bash
32
+ npm install -g @nocobase/ctl@latest
33
+ ```
24
34
 
25
- License agreement:
26
- https://www.nocobase.com/en/agreement
35
+ Add an environment:
27
36
 
37
+ ```bash
38
+ nb env add local --base-url http://localhost:13000/api
39
+ ```
28
40
 
29
- ## Contact Us:
30
- hello@nocobase.com
41
+ Add an environment with an API key:
42
+
43
+ ```bash
44
+ nb env add local --base-url http://localhost:13000/api --auth-type token --token <api-key>
45
+ ```
46
+
47
+ Authenticate an environment with OAuth:
48
+
49
+ ```bash
50
+ nb env auth local
51
+ ```
52
+
53
+ Show the current environment:
54
+
55
+ ```bash
56
+ nb env
57
+ ```
58
+
59
+ List configured environments:
60
+
61
+ ```bash
62
+ nb env list
63
+ ```
64
+
65
+ Switch the current environment:
66
+
67
+ ```bash
68
+ nb env use local
69
+ ```
70
+
71
+ Update the runtime command cache from `swagger:get`:
72
+
73
+ ```bash
74
+ nb env update
75
+ nb env update local
76
+ ```
77
+
78
+ Use the generic resource commands:
79
+
80
+ ```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"}'
84
+ ```
85
+
86
+ ## Runtime Commands
87
+
88
+ When you execute a runtime command, the CLI will:
89
+
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
94
+
95
+ If the `API documentation plugin` is disabled, the CLI will prompt to enable it.
96
+
97
+ ## Environment Selection
98
+
99
+ `nb env update` and `nb env auth` take an optional environment name as the first argument (omit it to use the current env):
100
+
101
+ ```bash
102
+ nb env update prod
103
+ nb env auth prod
104
+ ```
105
+
106
+ Use `-e, --env` on **runtime / API** commands to temporarily select an environment:
107
+
108
+ ```bash
109
+ nb api resource list --resource users -e prod
110
+ ```
111
+
112
+ This does not change the current environment unless you explicitly run:
113
+
114
+ ```bash
115
+ nb env use <name>
116
+ ```
117
+
118
+ ## Config Scope
119
+
120
+ The `env` command supports two config scopes:
121
+
122
+ - `project`: use `./.nocobase-ctl` in the current working directory
123
+ - `global`: use the global `.nocobase-ctl` directory
124
+
125
+ Use `-s, --scope` to select one explicitly:
126
+
127
+ ```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
132
+ ```
133
+
134
+ If you do not pass `--scope`, the CLI uses automatic resolution:
135
+
136
+ 1. current working directory if `./.nocobase-ctl` exists
137
+ 2. `NOCOBASE_HOME_CLI`
138
+ 3. your home directory
139
+
140
+ ## Built-in Commands
141
+
142
+ Current built-in topics:
143
+
144
+ - `env`
145
+ - `api`
146
+
147
+ Check available commands at any time:
148
+
149
+ ```bash
150
+ nb --help
151
+ nb env --help
152
+ nb api resource --help
153
+ ```
154
+
155
+ ## Common Flags
156
+
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
162
+
163
+ Example:
164
+
165
+ ```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
169
+ ```
170
+
171
+ ## Local Data
172
+
173
+ The CLI stores its local state in `.nocobase-ctl`, including:
174
+
175
+ - `config.json`: environment definitions and current selection
176
+ - `versions/<version>/commands.json`: cached runtime commands for a generated version
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
package/bin/run.js ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const root = path.resolve(__dirname, '..');
10
+ const realRoot = fs.realpathSync(root);
11
+ const isSourcePackage = realRoot.split(path.sep).join('/').endsWith('/packages/core/cli');
12
+ let isDev = isSourcePackage;
13
+ if (process.env.NB_CLI_USE_DIST === '1') {
14
+ isDev = false;
15
+ }
16
+
17
+ /**
18
+ * In the monorepo, plain `node` cannot load `.ts`. Re-exec once with `--import tsx`
19
+ * (same effect as a dedicated dev entry with `#!/usr/bin/env -S node --import tsx`).
20
+ */
21
+ function reexecWithTsx() {
22
+ const result = spawnSync(
23
+ process.execPath,
24
+ ['--import', 'tsx', '--disable-warning=ExperimentalWarning', ...process.argv.slice(1)],
25
+ {
26
+ stdio: 'inherit',
27
+ env: {
28
+ ...process.env,
29
+ _NOCO_CLI_TSX_CHILD: '1',
30
+ NODE_ENV: 'development',
31
+ },
32
+ },
33
+ );
34
+ process.exit(result.status === null ? 1 : result.status);
35
+ }
36
+
37
+ if (isDev && !process.env._NOCO_CLI_TSX_CHILD) {
38
+ reexecWithTsx();
39
+ }
40
+
41
+ const bootstrapPath = isDev ? path.join(root, 'src/lib/bootstrap.ts') : path.join(root, 'dist/lib/bootstrap.js');
42
+ const { ensureRuntimeFromArgv } = await import(pathToFileURL(bootstrapPath).href);
43
+ const { flush, run, settings } = await import('@oclif/core');
44
+
45
+ if (isDev) {
46
+ settings.debug = true;
47
+ }
48
+
49
+ function getCommandToken(argv) {
50
+ const tokens = [];
51
+
52
+ for (const token of argv) {
53
+ if (!token || token.startsWith('-')) {
54
+ continue;
55
+ }
56
+
57
+ tokens.push(token);
58
+ }
59
+
60
+ if (tokens[0] === 'api') {
61
+ return tokens[1] ?? tokens[0];
62
+ }
63
+
64
+ return tokens[0];
65
+ }
66
+
67
+ function formatCliEntryError(error, argv) {
68
+ const message = error instanceof Error ? error.message : String(error);
69
+ const missingCommandMatch = message.match(/^Command (.+) not found\.$/);
70
+ if (missingCommandMatch) {
71
+ const commandToken = getCommandToken(argv) ?? missingCommandMatch[1];
72
+ return [
73
+ `Unknown command: \`${commandToken}\`.`,
74
+ 'If this is a built-in command or a typo, run `nb --help` to inspect available commands.',
75
+ `If \`${commandToken}\` should be a runtime command from your NocoBase app, run \`nb env update\` and try again.`,
76
+ ].join('\n');
77
+ }
78
+
79
+ return message;
80
+ }
81
+
82
+ try {
83
+ const argv = process.argv.slice(2);
84
+ if (argv[0] === 'api') {
85
+ await ensureRuntimeFromArgv(argv, {
86
+ configFile: path.join(root, 'nocobase-ctl.config.json'),
87
+ });
88
+ }
89
+ await run(argv, import.meta.url);
90
+ flush();
91
+ } catch (error) {
92
+ const message = formatCliEntryError(error, process.argv.slice(2));
93
+ console.error(message);
94
+ process.exitCode = 1;
95
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildCreateArgs, createFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
+ export default class ResourceCreate extends Command {
4
+ static summary = 'Create a record in a resource';
5
+ static description = 'Create a record in a generic resource. Pass record content through --values as a JSON object.';
6
+ static examples = [
7
+ `<%= config.bin %> <%= command.id %> --resource users --values '{"nickname":"Ada"}'`,
8
+ `<%= config.bin %> <%= command.id %> --resource posts.comments --source-id 1 --values '{"content":"Hello"}'`,
9
+ ];
10
+ static flags = createFlags;
11
+ async run() {
12
+ const { flags } = await this.parse(ResourceCreate);
13
+ await runResourceCommand(this, 'create', flags, buildCreateArgs(flags));
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildDestroyArgs, destroyFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
+ export default class ResourceDestroy extends Command {
4
+ static summary = 'Delete records from a resource';
5
+ static description = 'Delete records from a generic resource. Target records with --filter-by-tk or --filter.';
6
+ static examples = [
7
+ '<%= config.bin %> <%= command.id %> --resource users --filter-by-tk 1',
8
+ `<%= config.bin %> <%= command.id %> --resource posts --filter '{"status":"archived"}'`,
9
+ ];
10
+ static flags = destroyFlags;
11
+ async run() {
12
+ const { flags } = await this.parse(ResourceDestroy);
13
+ await runResourceCommand(this, 'destroy', flags, buildDestroyArgs(flags));
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildGetArgs, getFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
+ export default class ResourceGet extends Command {
4
+ static summary = 'Get a record from a resource';
5
+ static description = 'Get a record from a generic resource. Use --filter-by-tk for the primary key and association resource names with --source-id when needed.';
6
+ static examples = [
7
+ '<%= config.bin %> <%= command.id %> --resource users --filter-by-tk 1',
8
+ '<%= config.bin %> <%= command.id %> --resource posts.comments --source-id 1 --filter-by-tk 2',
9
+ ];
10
+ static flags = getFlags;
11
+ async run() {
12
+ const { flags } = await this.parse(ResourceGet);
13
+ await runResourceCommand(this, 'get', flags, buildGetArgs(flags));
14
+ }
15
+ }
@@ -0,0 +1,20 @@
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 { Command, loadHelpClass } from '@oclif/core';
10
+ export default class Resource extends Command {
11
+ static summary = 'Work with generic collection resources';
12
+ async run() {
13
+ await this.parse(Resource);
14
+ const Help = await loadHelpClass(this.config);
15
+ await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
16
+ this.id ?? 'api:resource',
17
+ ...this.argv,
18
+ ]);
19
+ }
20
+ }
@@ -0,0 +1,16 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildListArgs, listFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
+ export default class ResourceList extends Command {
4
+ static summary = 'List records from a resource';
5
+ static description = 'List records from a generic resource. Use association resource names like posts.comments with --source-id when needed.';
6
+ static examples = [
7
+ '<%= config.bin %> <%= command.id %> --resource users',
8
+ '<%= config.bin %> <%= command.id %> --resource posts.comments --source-id 1 --fields id --fields content',
9
+ `<%= config.bin %> <%= command.id %> --resource users --filter '{"status":"active"}' --sort=-createdAt`,
10
+ ];
11
+ static flags = listFlags;
12
+ async run() {
13
+ const { flags } = await this.parse(ResourceList);
14
+ await runResourceCommand(this, 'list', flags, buildListArgs(flags));
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildQueryArgs, queryFlags, runResourceCommand } from '../../../lib/resource-command.js';
3
+ export default class ResourceQuery extends Command {
4
+ static summary = 'Run an aggregate query on a resource';
5
+ static description = 'Run an aggregate query on a generic resource. Pass measures, dimensions, and orders as JSON arrays.';
6
+ static examples = [
7
+ `<%= config.bin %> <%= command.id %> --resource orders --measures '[{"field":["id"],"aggregation":"count","alias":"count"}]'`,
8
+ `<%= config.bin %> <%= command.id %> --resource orders --dimensions '[{"field":["status"],"alias":"status"}]' --orders '[{"field":["createdAt"],"order":"desc"}]'`,
9
+ ];
10
+ static flags = queryFlags;
11
+ async run() {
12
+ const { flags } = await this.parse(ResourceQuery);
13
+ await runResourceCommand(this, 'query', flags, buildQueryArgs(flags));
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from '@oclif/core';
2
+ import { buildUpdateArgs, runResourceCommand, updateFlags } from '../../../lib/resource-command.js';
3
+ export default class ResourceUpdate extends Command {
4
+ static summary = 'Update records in a resource';
5
+ static description = 'Update records in a generic resource. Target records with --filter-by-tk or --filter, and pass updated values through --values.';
6
+ static examples = [
7
+ `<%= config.bin %> <%= command.id %> --resource users --filter-by-tk 1 --values '{"nickname":"Grace"}'`,
8
+ `<%= config.bin %> <%= command.id %> --resource posts --filter '{"status":"draft"}' --values '{"status":"published"}'`,
9
+ ];
10
+ static flags = updateFlags;
11
+ async run() {
12
+ const { flags } = await this.parse(ResourceUpdate);
13
+ await runResourceCommand(this, 'update', flags, buildUpdateArgs(flags));
14
+ }
15
+ }
@@ -0,0 +1,51 @@
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 { Args, Command, Flags } from '@oclif/core';
10
+ import { runNocoBaseCommand } from "../lib/run-npm.js";
11
+ export default class Build extends Command {
12
+ static args = {
13
+ /** Matches `nb build @nocobase/acl @nocobase/actions` — zero or more package names. */
14
+ packages: Args.string({
15
+ description: 'package names to build',
16
+ multiple: true,
17
+ required: false,
18
+ }),
19
+ };
20
+ static description = 'Run the legacy NocoBase build (forwards to `npm run build` in the repo root)';
21
+ static examples = [
22
+ '<%= config.bin %> <%= command.id %>',
23
+ '<%= config.bin %> <%= command.id %> --no-dts',
24
+ '<%= config.bin %> <%= command.id %> --sourcemap',
25
+ '<%= config.bin %> <%= command.id %> @nocobase/acl',
26
+ '<%= config.bin %> <%= command.id %> @nocobase/acl @nocobase/actions',
27
+ ];
28
+ static flags = {
29
+ 'cwd': Flags.string({ description: 'Current working directory', char: 'c', required: false }),
30
+ 'no-dts': Flags.boolean({ description: 'not generate dts' }),
31
+ sourcemap: Flags.boolean({ description: 'generate sourcemap' }),
32
+ };
33
+ async run() {
34
+ const { args, flags } = await this.parse(Build);
35
+ const packages = args.packages ?? [];
36
+ const npmArgs = ['build', ...packages];
37
+ if (flags['no-dts']) {
38
+ npmArgs.push('--no-dts');
39
+ }
40
+ if (flags.sourcemap) {
41
+ npmArgs.push('--sourcemap');
42
+ }
43
+ try {
44
+ await runNocoBaseCommand(npmArgs, { cwd: flags['cwd'] });
45
+ }
46
+ catch (error) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ this.error(message);
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,22 @@
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 { Args, Command } from '@oclif/core';
10
+ export default class DbStart extends Command {
11
+ static args = {
12
+ file: Args.string({ description: 'file to read' }),
13
+ };
14
+ static description = 'describe the command here';
15
+ static examples = [
16
+ '<%= config.bin %> <%= command.id %>',
17
+ ];
18
+ static flags = {};
19
+ async run() {
20
+ const { args, flags } = await this.parse(DbStart);
21
+ }
22
+ }
@@ -0,0 +1,58 @@
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 { Args, Command, Flags } from '@oclif/core';
10
+ import { runNocoBaseCommand } from "../lib/run-npm.js";
11
+ export default class Dev extends Command {
12
+ static args = {
13
+ file: Args.string({ description: 'file to read' }),
14
+ };
15
+ static description = 'describe the command here';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> --db-sync',
19
+ '<%= config.bin %> <%= command.id %> --port 12000',
20
+ '<%= config.bin %> <%= command.id %> --client',
21
+ '<%= config.bin %> <%= command.id %> --server',
22
+ '<%= config.bin %> <%= command.id %> --inspect 9229',
23
+ ];
24
+ static flags = {
25
+ env: Flags.string({ description: 'Environment', char: 'e', required: false }),
26
+ 'db-sync': Flags.boolean({ description: 'Sync the database', required: false }),
27
+ port: Flags.string({ description: 'Port', char: 'p', required: false }),
28
+ client: Flags.boolean({ description: 'Client', char: 'c', required: false }),
29
+ server: Flags.boolean({ description: 'Server', char: 's', required: false }),
30
+ inspect: Flags.string({ description: 'Inspect port', char: 'i', required: false }),
31
+ };
32
+ async run() {
33
+ const { flags } = await this.parse(Dev);
34
+ const npmArgs = ['dev', '--rsbuild'];
35
+ if (flags['db-sync']) {
36
+ npmArgs.push('--db-sync');
37
+ }
38
+ if (flags.port) {
39
+ npmArgs.push('--port', flags.port);
40
+ }
41
+ if (flags.client) {
42
+ npmArgs.push('--client');
43
+ }
44
+ if (flags.server) {
45
+ npmArgs.push('--server');
46
+ }
47
+ if (flags.inspect) {
48
+ npmArgs.push('--inspect', flags.inspect);
49
+ }
50
+ try {
51
+ await runNocoBaseCommand(npmArgs);
52
+ }
53
+ catch (error) {
54
+ const message = error instanceof Error ? error.message : String(error);
55
+ this.error(message);
56
+ }
57
+ }
58
+ }