@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
@@ -0,0 +1,73 @@
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 path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { Args, Command, Flags } from '@oclif/core';
12
+ import { getCurrentEnvName } from '../../lib/auth-store.js';
13
+ import { updateEnvRuntime } from '../../lib/bootstrap.js';
14
+ import { formatCliHomeScope } from '../../lib/cli-home.js';
15
+ import { failTask, startTask, succeedTask } from '../../lib/ui.js';
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ export default class EnvUpdate extends Command {
18
+ static summary = 'Refresh an environment runtime from swagger:get and persist connection overrides';
19
+ static examples = [
20
+ '<%= config.bin %> <%= command.id %>',
21
+ '<%= config.bin %> <%= command.id %> prod',
22
+ ];
23
+ static args = {
24
+ name: Args.string({
25
+ description: 'Environment name (omit to use the current env)',
26
+ required: false,
27
+ }),
28
+ };
29
+ static flags = {
30
+ verbose: Flags.boolean({
31
+ description: 'Show detailed progress output',
32
+ default: false,
33
+ }),
34
+ scope: Flags.string({
35
+ char: 's',
36
+ description: 'Config scope',
37
+ options: ['project', 'global'],
38
+ }),
39
+ 'base-url': Flags.string({
40
+ description: 'NocoBase API base URL override. When provided, persist it to the target env before saving the refreshed runtime.',
41
+ }),
42
+ role: Flags.string({
43
+ description: 'Role override, sent as X-Role',
44
+ }),
45
+ token: Flags.string({
46
+ char: 't',
47
+ description: 'API key override. When provided, persist it to the target env before saving the refreshed runtime.',
48
+ }),
49
+ };
50
+ async run() {
51
+ const { args, flags } = await this.parse(EnvUpdate);
52
+ const scope = flags.scope;
53
+ const envName = args.name;
54
+ const envLabel = envName ?? (await getCurrentEnvName({ scope }));
55
+ startTask(`Updating env runtime: ${envLabel}${scope ? ` (${formatCliHomeScope(scope)})` : ''}`);
56
+ try {
57
+ const runtime = await updateEnvRuntime({
58
+ envName,
59
+ scope,
60
+ baseUrl: flags['base-url'],
61
+ role: flags.role,
62
+ token: flags.token,
63
+ configFile: path.join(path.dirname(path.dirname(path.dirname(__dirname))), 'nocobase-ctl.config.json'),
64
+ verbose: flags.verbose,
65
+ });
66
+ succeedTask(`Updated env "${envLabel}" to runtime "${runtime.version}"${scope ? ` in ${formatCliHomeScope(scope)} scope` : ''}.`);
67
+ }
68
+ catch (error) {
69
+ failTask(`Failed to update env "${envLabel}".`);
70
+ throw error;
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,36 @@
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 { setCurrentEnv } from '../../lib/auth-store.js';
11
+ import { formatCliHomeScope } from '../../lib/cli-home.js';
12
+ export default class EnvUse extends Command {
13
+ static summary = 'Switch the current environment';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> local',
16
+ ];
17
+ static flags = {
18
+ scope: Flags.string({
19
+ char: 's',
20
+ description: 'Config scope',
21
+ options: ['project', 'global'],
22
+ }),
23
+ };
24
+ static args = {
25
+ name: Args.string({
26
+ description: 'Configured environment name',
27
+ required: true,
28
+ }),
29
+ };
30
+ async run() {
31
+ const { args, flags } = await this.parse(EnvUse);
32
+ const scope = flags.scope;
33
+ await setCurrentEnv(args.name, { scope });
34
+ this.log(`Current env: ${args.name}${scope ? ` (${formatCliHomeScope(scope)} scope)` : ''}`);
35
+ }
36
+ }
@@ -0,0 +1,186 @@
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, Flags } from '@oclif/core';
10
+ import * as p from '@clack/prompts';
11
+ import pc from 'picocolors';
12
+ import { stdin as stdinStream, stdout as stdoutStream } from 'node:process';
13
+ import { buildEnvAddArgv, InitWizardCancelledError, runInitBrowserWizard, } from "../lib/init-browser-wizard.js";
14
+ import { run } from "../lib/run-npm.js";
15
+ export default class Init extends Command {
16
+ static summary = 'Initialize the NocoBase AI setup environment';
17
+ static description = `Initialize the current workspace for NocoBase CLI and agent workflows. You only run nb init; the following runs inside this command (not as separate manual steps):
18
+
19
+ 1. Optionally install NocoBase agent skills (\`npx -y skills add nocobase/skills\`)—you are prompted when using a TTY.
20
+ 2. If you already have a NocoBase application (anywhere): runs \`nb env add\` only (\`nb install\` is skipped).
21
+ 3. If not: runs \`nb install\` only (\`nb env add\` is not run afterward; configure the CLI with \`nb env add\` when you need it).
22
+
23
+ Internal ordering: (skills?) → (already have an app? → env add | install only).
24
+
25
+ Use \`-y\` / \`--yes\` to skip init prompts (defaults: install skills, then \`nb install\` only—same as choosing the first option, no existing app). When you choose an existing app in a TTY, \`nb env add\` may still prompt for URL and auth.
26
+
27
+ Use \`--ui\` to open a **browser** wizard (local HTTP server; default bind \`0.0.0.0\`, random port). Use \`--ui-host\` / \`--ui-port\` to override. The opened URL uses \`127.0.0.1\` when the bind address is all-interfaces. It can collect \`nb env add\` fields when you link an existing app, so the terminal env wizard is skipped. Cannot be combined with \`--yes\`.`;
28
+ static examples = [
29
+ '<%= config.bin %> <%= command.id %>',
30
+ '<%= config.bin %> <%= command.id %> --ui',
31
+ '<%= config.bin %> <%= command.id %> --ui --ui-host 127.0.0.1 --ui-port 3000',
32
+ '<%= config.bin %> <%= command.id %> -y',
33
+ ];
34
+ static flags = {
35
+ yes: Flags.boolean({
36
+ char: 'y',
37
+ description: 'Skip all prompts',
38
+ default: false,
39
+ }),
40
+ ui: Flags.boolean({
41
+ description: 'Open a browser-based setup wizard (local HTTP server; not valid with --yes)',
42
+ default: false,
43
+ }),
44
+ 'ui-host': Flags.string({
45
+ description: 'Bind address for the --ui wizard HTTP server (default 0.0.0.0; only with --ui)',
46
+ }),
47
+ 'ui-port': Flags.integer({
48
+ description: 'TCP port for the --ui wizard; 0 = OS-assigned ephemeral port (default 0; only with --ui)',
49
+ min: 0,
50
+ max: 65535,
51
+ }),
52
+ };
53
+ async run() {
54
+ const { flags } = await this.parse(Init);
55
+ if (flags.ui && flags.yes) {
56
+ this.error('--ui cannot be used with --yes.');
57
+ }
58
+ if (!flags.ui &&
59
+ (flags['ui-host'] !== undefined || flags['ui-port'] !== undefined)) {
60
+ this.error('--ui-host and --ui-port require --ui.');
61
+ }
62
+ const interactive = Boolean(stdinStream.isTTY && stdoutStream.isTTY);
63
+ const useBrowserUi = Boolean(flags.ui);
64
+ if (useBrowserUi) {
65
+ if (interactive) {
66
+ p.intro(`${pc.bold('nb init')} ${pc.dim('— browser wizard')}`);
67
+ }
68
+ else {
69
+ this.log('nb init — browser wizard');
70
+ }
71
+ this.log('Your browser should open; complete the form there to continue.');
72
+ }
73
+ else {
74
+ p.intro('Initialize the NocoBase AI setup environment');
75
+ }
76
+ /** Whether `nb install` / follow-up should avoid terminal prompts (`-y`). */
77
+ const skipInstallPrompts = Boolean(flags.yes) || !interactive;
78
+ let installSkills = true;
79
+ let hasNocobase = false;
80
+ /** When set, \`nb env add\` is invoked with these argv (from \`--ui\` form). */
81
+ let envAddArgvFromUi;
82
+ if (flags.yes) {
83
+ p.log.info('Skipping prompts (--yes): will install NocoBase agent skills.');
84
+ installSkills = true;
85
+ hasNocobase = false;
86
+ p.log.info('Skipping prompts (--yes): will run nb install only (same default as "I don\'t have a NocoBase application yet").');
87
+ }
88
+ else if (useBrowserUi) {
89
+ try {
90
+ const choice = await runInitBrowserWizard((line) => this.log(line), {
91
+ bindHost: flags['ui-host']?.trim() || '0.0.0.0',
92
+ port: flags['ui-port'] ?? 0,
93
+ });
94
+ installSkills = choice.installSkills;
95
+ hasNocobase = choice.hasNocobase;
96
+ if (choice.envAdd) {
97
+ envAddArgvFromUi = buildEnvAddArgv(choice.envAdd);
98
+ }
99
+ }
100
+ catch (error) {
101
+ if (error instanceof InitWizardCancelledError) {
102
+ if (interactive) {
103
+ p.cancel(error.message);
104
+ }
105
+ else {
106
+ this.log(error.message);
107
+ }
108
+ this.exit(0);
109
+ }
110
+ throw error;
111
+ }
112
+ }
113
+ else if (interactive) {
114
+ const skillsAnswer = await p.confirm({
115
+ message: 'Install NocoBase agent skills (nocobase/skills) for Cursor / Codex workflows?',
116
+ initialValue: true,
117
+ });
118
+ if (p.isCancel(skillsAnswer)) {
119
+ p.cancel('Init cancelled.');
120
+ this.exit(0);
121
+ }
122
+ installSkills = skillsAnswer;
123
+ const answer = await p.select({
124
+ message: 'Do you already have a NocoBase application?',
125
+ options: [
126
+ {
127
+ value: 'no',
128
+ label: "I don't have a NocoBase application yet",
129
+ },
130
+ {
131
+ value: 'yes',
132
+ label: 'I already have a NocoBase application',
133
+ },
134
+ ],
135
+ initialValue: 'no',
136
+ });
137
+ if (p.isCancel(answer)) {
138
+ p.cancel('Init cancelled.');
139
+ this.exit(0);
140
+ }
141
+ hasNocobase = answer === 'yes';
142
+ }
143
+ else {
144
+ p.log.warn('Non-interactive terminal: will install NocoBase agent skills (skip is not available without a TTY).');
145
+ installSkills = true;
146
+ hasNocobase = false;
147
+ p.log.warn('Non-interactive terminal: assuming you do not already have a NocoBase app (will run nb install only).');
148
+ }
149
+ if (installSkills) {
150
+ try {
151
+ p.log.step('Installing NocoBase agent skills (npx -y skills add nocobase/skills)');
152
+ await run('npx', ['-y', 'skills', 'add', 'nocobase/skills', '-y']);
153
+ }
154
+ catch (error) {
155
+ const message = error instanceof Error ? error.message : String(error);
156
+ p.outro(pc.red(`Skills install failed: ${message}`));
157
+ this.error(message);
158
+ }
159
+ }
160
+ else {
161
+ p.log.info('Skipped NocoBase agent skills install.');
162
+ }
163
+ try {
164
+ // oclif explicit registry keys use `:` (e.g. `env:add`); users still type `nb env add`.
165
+ if (hasNocobase) {
166
+ p.log.step('Running nb env add');
167
+ if (useBrowserUi && !envAddArgvFromUi) {
168
+ this.error('Browser wizard did not supply env add options.');
169
+ }
170
+ const envArgv = envAddArgvFromUi ??
171
+ (interactive ? ['--scope', 'project'] : ['default', '--scope', 'project']);
172
+ await this.config.runCommand('env:add', envArgv);
173
+ }
174
+ else {
175
+ p.log.step('Running nb install');
176
+ await this.config.runCommand('install', skipInstallPrompts ? ['-e', 'local', '-y'] : []);
177
+ }
178
+ }
179
+ catch (error) {
180
+ const message = error instanceof Error ? error.message : String(error);
181
+ p.outro(pc.red(message));
182
+ this.error(message);
183
+ }
184
+ p.outro('Workspace init finished.');
185
+ }
186
+ }