@nocobase/cli 2.1.0-beta.20 → 2.1.0-beta.22

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 (74) hide show
  1. package/README.md +32 -50
  2. package/README.zh-CN.md +29 -46
  3. package/bin/run.js +15 -0
  4. package/dist/commands/app/down.js +260 -0
  5. package/dist/commands/app/info.js +140 -0
  6. package/dist/commands/app/logs.js +98 -0
  7. package/dist/commands/app/ps.js +60 -0
  8. package/dist/commands/app/restart.js +75 -0
  9. package/dist/commands/app/shared.js +95 -0
  10. package/dist/commands/app/start.js +252 -0
  11. package/dist/commands/app/stop.js +98 -0
  12. package/dist/commands/app/upgrade.js +595 -0
  13. package/dist/commands/build.js +3 -48
  14. package/dist/commands/db/shared.js +19 -5
  15. package/dist/commands/dev.js +3 -140
  16. package/dist/commands/down.js +3 -184
  17. package/dist/commands/download.js +4 -856
  18. package/dist/commands/env/add.js +33 -48
  19. package/dist/commands/env/auth.js +6 -13
  20. package/dist/commands/env/list.js +10 -15
  21. package/dist/commands/env/remove.js +4 -10
  22. package/dist/commands/env/update.js +7 -13
  23. package/dist/commands/env/use.js +5 -13
  24. package/dist/commands/{prompts-stages.js → examples/prompts-stages.js} +3 -3
  25. package/dist/commands/{prompts-test.js → examples/prompts-test.js} +3 -3
  26. package/dist/commands/init.js +262 -63
  27. package/dist/commands/install.js +352 -86
  28. package/dist/commands/logs.js +3 -81
  29. package/dist/commands/plugin/disable.js +64 -0
  30. package/dist/commands/plugin/enable.js +64 -0
  31. package/dist/commands/plugin/list.js +62 -0
  32. package/dist/commands/pm/disable.js +3 -54
  33. package/dist/commands/pm/enable.js +3 -54
  34. package/dist/commands/pm/list.js +3 -45
  35. package/dist/commands/ps.js +3 -107
  36. package/dist/commands/restart.js +3 -65
  37. package/dist/commands/scaffold/migration.js +1 -1
  38. package/dist/commands/scaffold/plugin.js +1 -1
  39. package/dist/commands/self/check.js +1 -1
  40. package/dist/commands/self/update.js +13 -3
  41. package/dist/commands/skills/check.js +11 -5
  42. package/dist/commands/skills/index.js +1 -1
  43. package/dist/commands/skills/install.js +20 -7
  44. package/dist/commands/skills/remove.js +71 -0
  45. package/dist/commands/skills/update.js +27 -7
  46. package/dist/commands/source/build.js +58 -0
  47. package/dist/commands/source/dev.js +157 -0
  48. package/dist/commands/source/download.js +866 -0
  49. package/dist/commands/source/test.js +467 -0
  50. package/dist/commands/start.js +3 -202
  51. package/dist/commands/stop.js +3 -81
  52. package/dist/commands/test.js +3 -457
  53. package/dist/commands/upgrade.js +3 -574
  54. package/dist/help/runtime-help.js +3 -0
  55. package/dist/lib/api-client.js +3 -2
  56. package/dist/lib/app-health.js +126 -0
  57. package/dist/lib/app-managed-resources.js +264 -0
  58. package/dist/lib/app-runtime.js +16 -5
  59. package/dist/lib/auth-store.js +162 -43
  60. package/dist/lib/bootstrap.js +13 -12
  61. package/dist/lib/cli-home.js +38 -6
  62. package/dist/lib/cli-locale.js +15 -1
  63. package/dist/lib/env-auth.js +3 -3
  64. package/dist/lib/env-config.js +80 -0
  65. package/dist/lib/generated-command.js +10 -2
  66. package/dist/lib/http-request.js +49 -0
  67. package/dist/lib/resource-command.js +10 -2
  68. package/dist/lib/runtime-generator.js +1 -1
  69. package/dist/lib/self-manager.js +1 -1
  70. package/dist/lib/skills-manager.js +173 -79
  71. package/dist/lib/startup-update.js +203 -0
  72. package/dist/locale/en-US.json +4 -1
  73. package/dist/locale/zh-CN.json +4 -1
  74. package/package.json +26 -3
@@ -6,85 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runLocalNocoBaseCommand, } from '../lib/app-runtime.js';
11
- import { run } from '../lib/run-npm.js';
12
- import { printInfo } from '../lib/ui.js';
13
- function formatLogsFailure(envName, message) {
14
- return [
15
- `Couldn't show logs for "${envName}".`,
16
- 'Check that the saved local app or Docker container still exists on this machine, then try again.',
17
- `Details: ${message}`,
18
- ].join('\n');
19
- }
20
- export default class Logs extends Command {
21
- static description = 'Show NocoBase logs for the selected env. Local npm/git installs use pm2 logs, and Docker installs use docker logs.';
22
- static examples = [
23
- '<%= config.bin %> <%= command.id %>',
24
- '<%= config.bin %> <%= command.id %> --env app1',
25
- '<%= config.bin %> <%= command.id %> --env app1 --tail 200',
26
- '<%= config.bin %> <%= command.id %> --env app1 --no-follow',
27
- ];
28
- static flags = {
29
- env: Flags.string({
30
- char: 'e',
31
- description: 'CLI env name to inspect logs for. Defaults to the current env when omitted',
32
- }),
33
- tail: Flags.integer({
34
- description: 'Number of recent log lines to show before following',
35
- default: 100,
36
- min: 0,
37
- }),
38
- follow: Flags.boolean({
39
- char: 'f',
40
- description: 'Keep streaming new log lines',
41
- default: true,
42
- allowNo: true,
43
- }),
44
- };
45
- async run() {
46
- const { flags } = await this.parse(Logs);
47
- const requestedEnv = flags.env?.trim() || undefined;
48
- const runtime = await resolveManagedAppRuntime(requestedEnv);
49
- if (!runtime) {
50
- this.error(formatMissingManagedAppEnvMessage(requestedEnv));
51
- }
52
- if (runtime.kind === 'remote') {
53
- this.error([
54
- `Can't show runtime logs for "${runtime.envName}" from this machine.`,
55
- 'This env only has an API connection, so there is no saved local app or Docker container to read logs from.',
56
- 'Connect it to a local checkout or reinstall it with npm, git, or Docker if you want CLI-managed logs.',
57
- ].join('\n'));
58
- }
59
- const tail = String(flags.tail ?? 100);
60
- const follow = flags.follow !== false;
61
- printInfo(follow
62
- ? `Showing logs for "${runtime.envName}" (press Ctrl+C to stop).`
63
- : `Showing recent logs for "${runtime.envName}".`);
64
- try {
65
- if (runtime.kind === 'docker') {
66
- const dockerArgs = ['logs', '--tail', tail];
67
- if (follow) {
68
- dockerArgs.push('--follow');
69
- }
70
- dockerArgs.push(runtime.containerName);
71
- await run('docker', dockerArgs, {
72
- errorName: 'docker logs',
73
- stdio: 'inherit',
74
- });
75
- return;
76
- }
77
- const localArgs = ['pm2', 'logs', '--lines', tail];
78
- if (!follow) {
79
- localArgs.push('--nostream');
80
- }
81
- await runLocalNocoBaseCommand(runtime, localArgs, {
82
- stdio: 'inherit',
83
- });
84
- }
85
- catch (error) {
86
- const message = error instanceof Error ? error.message : String(error);
87
- this.error(formatLogsFailure(runtime.envName, message));
88
- }
89
- }
9
+ import AppLogs from './app/logs.js';
10
+ export default class Logs extends AppLogs {
11
+ static hidden = true;
90
12
  }
@@ -0,0 +1,64 @@
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 { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
+ export default class PluginDisable extends Command {
12
+ static hidden = false;
13
+ static args = {
14
+ packages: Args.string({
15
+ required: true,
16
+ multiple: true,
17
+ description: 'Plugin package name(s) to disable (e.g. `@nocobase/plugin-sample`). Pass one or more names as separate arguments.',
18
+ }),
19
+ };
20
+ static description = 'Disable one or more plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container)';
21
+ static examples = [
22
+ '<%= config.bin %> <%= command.id %> @nocobase/plugin-sample',
23
+ '<%= config.bin %> <%= command.id %> @nocobase/plugin-a @nocobase/plugin-b',
24
+ '<%= config.bin %> <%= command.id %> -e local @nocobase/plugin-sample',
25
+ ];
26
+ static flags = {
27
+ env: Flags.string({
28
+ char: 'e',
29
+ description: 'CLI env name (from `nb env` / `nb init`). Defaults to the current env when omitted',
30
+ }),
31
+ };
32
+ async run() {
33
+ const { args, flags } = await this.parse(PluginDisable);
34
+ const packages = args.packages;
35
+ if (!Array.isArray(packages) || packages.length === 0) {
36
+ this.error('Pass at least one plugin package name.');
37
+ }
38
+ const runtime = await resolveManagedAppRuntime(flags.env);
39
+ if (!runtime) {
40
+ this.error(formatMissingManagedAppEnvMessage(flags.env));
41
+ }
42
+ if (runtime.kind === 'local') {
43
+ try {
44
+ await runLocalNocoBaseCommand(runtime, ['pm', 'disable', ...packages]);
45
+ }
46
+ catch (error) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ this.error(message);
49
+ }
50
+ return;
51
+ }
52
+ if (runtime.kind === 'docker') {
53
+ try {
54
+ await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'disable', ...packages]);
55
+ }
56
+ catch (error) {
57
+ const message = error instanceof Error ? error.message : String(error);
58
+ this.error(message);
59
+ }
60
+ return;
61
+ }
62
+ await this.config.runCommand('api:pm:disable', ['--await-response', '--filter-by-tk', packages.join(',')]);
63
+ }
64
+ }
@@ -0,0 +1,64 @@
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 { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
+ export default class PluginEnable extends Command {
12
+ static hidden = false;
13
+ static args = {
14
+ packages: Args.string({
15
+ required: true,
16
+ multiple: true,
17
+ description: 'Plugin package name(s) to enable (e.g. `@nocobase/plugin-sample`). Pass one or more names as separate arguments.',
18
+ }),
19
+ };
20
+ static description = 'Enable one or more plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container)';
21
+ static examples = [
22
+ '<%= config.bin %> <%= command.id %> @nocobase/plugin-sample',
23
+ '<%= config.bin %> <%= command.id %> @nocobase/plugin-a @nocobase/plugin-b',
24
+ '<%= config.bin %> <%= command.id %> -e local @nocobase/plugin-sample',
25
+ ];
26
+ static flags = {
27
+ env: Flags.string({
28
+ char: 'e',
29
+ description: 'CLI env name (from `nb env` / `nb init`). Defaults to the current env when omitted',
30
+ }),
31
+ };
32
+ async run() {
33
+ const { args, flags } = await this.parse(PluginEnable);
34
+ const packages = args.packages;
35
+ if (!Array.isArray(packages) || packages.length === 0) {
36
+ this.error('Pass at least one plugin package name.');
37
+ }
38
+ const runtime = await resolveManagedAppRuntime(flags.env);
39
+ if (!runtime) {
40
+ this.error(formatMissingManagedAppEnvMessage(flags.env));
41
+ }
42
+ if (runtime.kind === 'local') {
43
+ try {
44
+ await runLocalNocoBaseCommand(runtime, ['pm', 'enable', ...packages]);
45
+ }
46
+ catch (error) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ this.error(message);
49
+ }
50
+ return;
51
+ }
52
+ if (runtime.kind === 'docker') {
53
+ try {
54
+ await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'enable', ...packages]);
55
+ }
56
+ catch (error) {
57
+ const message = error instanceof Error ? error.message : String(error);
58
+ this.error(message);
59
+ }
60
+ return;
61
+ }
62
+ await this.config.runCommand('api:pm:enable', ['--await-response', '--filter-by-tk', packages.join(',')]);
63
+ }
64
+ }
@@ -0,0 +1,62 @@
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 { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
+ export default class PluginList extends Command {
12
+ static hidden = false;
13
+ static args = {};
14
+ static summary = 'List plugins for the selected env';
15
+ static description = 'List installed plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container, HTTP envs fall back to the API)';
16
+ static examples = [
17
+ '<%= config.bin %> <%= command.id %>',
18
+ '<%= config.bin %> <%= command.id %> -e local',
19
+ '<%= config.bin %> <%= command.id %> -e local-docker',
20
+ ];
21
+ static flags = {
22
+ env: Flags.string({
23
+ char: 'e',
24
+ description: 'CLI env name (from `nb env` / `nb init`). Defaults to the current env when omitted',
25
+ }),
26
+ };
27
+ async run() {
28
+ const { flags } = await this.parse(PluginList);
29
+ const runtime = await resolveManagedAppRuntime(flags.env);
30
+ if (!runtime) {
31
+ this.error(formatMissingManagedAppEnvMessage(flags.env));
32
+ }
33
+ if (runtime.kind === 'local') {
34
+ try {
35
+ await runLocalNocoBaseCommand(runtime, ['pm', 'list']);
36
+ }
37
+ catch (error) {
38
+ const message = error instanceof Error ? error.message : String(error);
39
+ this.error(message);
40
+ }
41
+ return;
42
+ }
43
+ if (runtime.kind === 'docker') {
44
+ try {
45
+ await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'list']);
46
+ }
47
+ catch (error) {
48
+ const message = error instanceof Error ? error.message : String(error);
49
+ this.error(message);
50
+ }
51
+ return;
52
+ }
53
+ if (runtime.kind === 'ssh') {
54
+ this.error([
55
+ `Can't list plugins for "${runtime.envName}" yet.`,
56
+ 'SSH env support is reserved but not implemented yet.',
57
+ 'Use a local, Docker, or HTTP env for plugin inspection right now.',
58
+ ].join('\n'));
59
+ }
60
+ await this.config.runCommand('api:pm:list', ['--mode=summary']);
61
+ }
62
+ }
@@ -6,58 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Args, Command, Flags } from '@oclif/core';
10
- import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
- export default class PmDisable extends Command {
12
- static args = {
13
- packages: Args.string({
14
- required: true,
15
- multiple: true,
16
- description: 'Plugin package name(s) to disable (e.g. `@nocobase/plugin-sample`). Pass one or more names as separate arguments.',
17
- }),
18
- };
19
- static description = 'Disable one or more plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container)';
20
- static examples = [
21
- '<%= config.bin %> <%= command.id %> @nocobase/plugin-sample',
22
- '<%= config.bin %> <%= command.id %> @nocobase/plugin-a @nocobase/plugin-b',
23
- '<%= config.bin %> <%= command.id %> -e local @nocobase/plugin-sample',
24
- ];
25
- static flags = {
26
- env: Flags.string({
27
- char: 'e',
28
- description: 'CLI env name (from `nb env` / `nb install`). Defaults to the current env when omitted',
29
- }),
30
- };
31
- async run() {
32
- const { args, flags } = await this.parse(PmDisable);
33
- const packages = args.packages;
34
- if (!Array.isArray(packages) || packages.length === 0) {
35
- this.error('Pass at least one plugin package name.');
36
- }
37
- const runtime = await resolveManagedAppRuntime(flags.env);
38
- if (!runtime) {
39
- this.error(formatMissingManagedAppEnvMessage(flags.env));
40
- }
41
- if (runtime.kind === 'local') {
42
- try {
43
- await runLocalNocoBaseCommand(runtime, ['pm', 'disable', ...packages]);
44
- }
45
- catch (error) {
46
- const message = error instanceof Error ? error.message : String(error);
47
- this.error(message);
48
- }
49
- return;
50
- }
51
- if (runtime.kind === 'docker') {
52
- try {
53
- await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'disable', ...packages]);
54
- }
55
- catch (error) {
56
- const message = error instanceof Error ? error.message : String(error);
57
- this.error(message);
58
- }
59
- return;
60
- }
61
- await this.config.runCommand('api:pm:disable', ['--await-response', '--filter-by-tk', packages.join(',')]);
62
- }
9
+ import PluginDisable from '../plugin/disable.js';
10
+ export default class PmDisable extends PluginDisable {
11
+ static hidden = true;
63
12
  }
@@ -6,58 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Args, Command, Flags } from '@oclif/core';
10
- import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
- export default class PmEnable extends Command {
12
- static args = {
13
- packages: Args.string({
14
- required: true,
15
- multiple: true,
16
- description: 'Plugin package name(s) to enable (e.g. `@nocobase/plugin-sample`). Pass one or more names as separate arguments.',
17
- }),
18
- };
19
- static description = 'Enable one or more plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container)';
20
- static examples = [
21
- '<%= config.bin %> <%= command.id %> @nocobase/plugin-sample',
22
- '<%= config.bin %> <%= command.id %> @nocobase/plugin-a @nocobase/plugin-b',
23
- '<%= config.bin %> <%= command.id %> -e local @nocobase/plugin-sample',
24
- ];
25
- static flags = {
26
- env: Flags.string({
27
- char: 'e',
28
- description: 'CLI env name (from `nb env` / `nb install`). Defaults to the current env when omitted',
29
- }),
30
- };
31
- async run() {
32
- const { args, flags } = await this.parse(PmEnable);
33
- const packages = args.packages;
34
- if (!Array.isArray(packages) || packages.length === 0) {
35
- this.error('Pass at least one plugin package name.');
36
- }
37
- const runtime = await resolveManagedAppRuntime(flags.env);
38
- if (!runtime) {
39
- this.error(formatMissingManagedAppEnvMessage(flags.env));
40
- }
41
- if (runtime.kind === 'local') {
42
- try {
43
- await runLocalNocoBaseCommand(runtime, ['pm', 'enable', ...packages]);
44
- }
45
- catch (error) {
46
- const message = error instanceof Error ? error.message : String(error);
47
- this.error(message);
48
- }
49
- return;
50
- }
51
- if (runtime.kind === 'docker') {
52
- try {
53
- await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'enable', ...packages]);
54
- }
55
- catch (error) {
56
- const message = error instanceof Error ? error.message : String(error);
57
- this.error(message);
58
- }
59
- return;
60
- }
61
- await this.config.runCommand('api:pm:enable', ['--await-response', '--filter-by-tk', packages.join(',')]);
62
- }
9
+ import PluginEnable from '../plugin/enable.js';
10
+ export default class PmEnable extends PluginEnable {
11
+ static hidden = true;
63
12
  }
@@ -6,49 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, runDockerNocoBaseCommand, runLocalNocoBaseCommand, } from '../../lib/app-runtime.js';
11
- export default class PmList extends Command {
12
- static args = {};
13
- static summary = 'List plugins for the selected env';
14
- static description = 'List installed plugins in the selected env (npm/git runs locally, Docker runs inside the saved app container, remote envs fall back to the API)';
15
- static examples = [
16
- '<%= config.bin %> <%= command.id %>',
17
- '<%= config.bin %> <%= command.id %> -e local',
18
- '<%= config.bin %> <%= command.id %> -e local-docker',
19
- ];
20
- static flags = {
21
- env: Flags.string({
22
- char: 'e',
23
- description: 'CLI env name (from `nb env` / `nb install`). Defaults to the current env when omitted',
24
- }),
25
- };
26
- async run() {
27
- const { flags } = await this.parse(PmList);
28
- const runtime = await resolveManagedAppRuntime(flags.env);
29
- if (!runtime) {
30
- this.error(formatMissingManagedAppEnvMessage(flags.env));
31
- }
32
- if (runtime.kind === 'local') {
33
- try {
34
- await runLocalNocoBaseCommand(runtime, ['pm', 'list']);
35
- }
36
- catch (error) {
37
- const message = error instanceof Error ? error.message : String(error);
38
- this.error(message);
39
- }
40
- return;
41
- }
42
- if (runtime.kind === 'docker') {
43
- try {
44
- await runDockerNocoBaseCommand(runtime.containerName, ['pm', 'list']);
45
- }
46
- catch (error) {
47
- const message = error instanceof Error ? error.message : String(error);
48
- this.error(message);
49
- }
50
- return;
51
- }
52
- await this.config.runCommand('api:pm:list', ['--mode=summary']);
53
- }
9
+ import PluginList from '../plugin/list.js';
10
+ export default class PmList extends PluginList {
11
+ static hidden = true;
54
12
  }
@@ -6,111 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- import { buildDockerDbContainerName, dockerContainerExists, dockerContainerIsRunning, formatMissingManagedAppEnvMessage, resolveManagedAppRuntime, } from '../lib/app-runtime.js';
11
- import { listEnvs } from '../lib/auth-store.js';
12
- import { renderTable } from '../lib/ui.js';
13
- function appUrl(runtime) {
14
- const port = String(runtime.env.config.appPort ?? '').trim();
15
- if (port) {
16
- return `http://127.0.0.1:${port}`;
17
- }
18
- const baseUrl = String(runtime.env.config.baseUrl ?? '').trim();
19
- return baseUrl.replace(/\/api\/?$/, '');
20
- }
21
- async function isLocalAppHealthy(runtime) {
22
- const port = String(runtime.env.config.appPort ?? '').trim();
23
- if (!port) {
24
- return false;
25
- }
26
- const controller = new AbortController();
27
- const timeout = setTimeout(() => controller.abort(), 1500);
28
- try {
29
- const response = await fetch(`http://127.0.0.1:${port}/api/__health_check`, {
30
- signal: controller.signal,
31
- });
32
- const text = await response.text();
33
- return response.ok && text.trim().toLowerCase() === 'ok';
34
- }
35
- catch (_error) {
36
- return false;
37
- }
38
- finally {
39
- clearTimeout(timeout);
40
- }
41
- }
42
- async function dockerStatus(containerName) {
43
- if (!(await dockerContainerExists(containerName))) {
44
- return 'missing';
45
- }
46
- return await dockerContainerIsRunning(containerName) ? 'running' : 'stopped';
47
- }
48
- async function dbStatus(runtime) {
49
- if (!runtime.env.config.builtinDb) {
50
- return runtime.kind === 'remote' ? 'external' : '-';
51
- }
52
- if (runtime.kind === 'remote') {
53
- return 'external';
54
- }
55
- const dbDialect = String(runtime.env.config.dbDialect ?? 'postgres').trim() || 'postgres';
56
- const containerName = buildDockerDbContainerName(runtime.envName, dbDialect, runtime.workspaceName);
57
- return await dockerStatus(containerName);
58
- }
59
- async function appStatus(runtime) {
60
- if (runtime.kind === 'remote') {
61
- return 'remote';
62
- }
63
- if (runtime.kind === 'docker') {
64
- return await dockerStatus(runtime.containerName);
65
- }
66
- return await isLocalAppHealthy(runtime) ? 'running' : 'stopped';
67
- }
68
- function sourceLabel(runtime) {
69
- if (runtime.kind === 'remote') {
70
- return 'remote';
71
- }
72
- return runtime.source;
73
- }
74
- export default class Ps extends Command {
75
- static description = 'Show NocoBase runtime status for configured envs without starting or stopping anything.';
76
- static examples = [
77
- '<%= config.bin %> <%= command.id %>',
78
- '<%= config.bin %> <%= command.id %> --env app1',
79
- ];
80
- static flags = {
81
- env: Flags.string({
82
- char: 'e',
83
- description: 'CLI env name to inspect. Omit to show all configured envs',
84
- }),
85
- };
86
- async run() {
87
- const { flags } = await this.parse(Ps);
88
- const requestedEnv = flags.env?.trim() || undefined;
89
- const envNames = requestedEnv
90
- ? [requestedEnv]
91
- : Object.keys((await listEnvs()).envs).sort();
92
- if (!envNames.length) {
93
- this.log('No NocoBase env is configured yet. Run `nb init` to create one first.');
94
- return;
95
- }
96
- const rows = [];
97
- for (const envName of envNames) {
98
- const runtime = await resolveManagedAppRuntime(envName);
99
- if (!runtime) {
100
- if (requestedEnv) {
101
- this.error(formatMissingManagedAppEnvMessage(envName));
102
- }
103
- rows.push([envName, '-', 'missing', '-', '']);
104
- continue;
105
- }
106
- rows.push([
107
- runtime.envName,
108
- sourceLabel(runtime),
109
- await appStatus(runtime),
110
- await dbStatus(runtime),
111
- appUrl(runtime),
112
- ]);
113
- }
114
- this.log(renderTable(['Env', 'Source', 'App', 'Database', 'URL'], rows));
115
- }
9
+ import AppPs from './app/ps.js';
10
+ export default class Ps extends AppPs {
11
+ static hidden = true;
116
12
  }
@@ -6,69 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Command, Flags } from '@oclif/core';
10
- function argvHasToken(argv, tokens) {
11
- return tokens.some((token) => argv.includes(token));
12
- }
13
- function pushFlag(argv, flag, value) {
14
- if (value !== undefined) {
15
- argv.push(flag, String(value));
16
- }
17
- }
18
- export default class Restart extends Command {
19
- static description = 'Restart NocoBase for the selected env by stopping it first, then starting it again.';
20
- static examples = [
21
- '<%= config.bin %> <%= command.id %>',
22
- '<%= config.bin %> <%= command.id %> --env local',
23
- '<%= config.bin %> <%= command.id %> --env local --quickstart',
24
- '<%= config.bin %> <%= command.id %> --env local --port 12000',
25
- '<%= config.bin %> <%= command.id %> --env local --daemon',
26
- '<%= config.bin %> <%= command.id %> --env local --no-daemon',
27
- '<%= config.bin %> <%= command.id %> --env local --instances 2',
28
- '<%= config.bin %> <%= command.id %> --env local --launch-mode pm2',
29
- '<%= config.bin %> <%= command.id %> --env local --verbose',
30
- '<%= config.bin %> <%= command.id %> --env local-docker',
31
- ];
32
- static flags = {
33
- env: Flags.string({
34
- char: 'e',
35
- description: 'CLI env name to restart. Defaults to the current env when omitted',
36
- }),
37
- quickstart: Flags.boolean({ description: 'Quickstart the application after stopping it', required: false }),
38
- port: Flags.string({ description: 'Port (overrides appPort from env config when set)', char: 'p', required: false }),
39
- daemon: Flags.boolean({
40
- description: 'Run the application as a daemon after stopping it (default: true; use --no-daemon to stay in the foreground)',
41
- char: 'd',
42
- required: false,
43
- default: true,
44
- allowNo: true,
45
- }),
46
- instances: Flags.integer({ description: 'Number of instances to run after stopping it', char: 'i', required: false }),
47
- 'launch-mode': Flags.string({ description: 'Launch Mode', required: false, options: ['pm2', 'node'] }),
48
- verbose: Flags.boolean({
49
- description: 'Show raw shutdown/startup output from the underlying local or Docker command',
50
- default: false,
51
- }),
52
- };
53
- async run() {
54
- const { flags } = await this.parse(Restart);
55
- const stopArgv = [];
56
- const daemonFlagWasProvided = argvHasToken(this.argv, ['--daemon', '--no-daemon']);
57
- pushFlag(stopArgv, '--env', flags.env?.trim() || undefined);
58
- if (flags.verbose) {
59
- stopArgv.push('--verbose');
60
- }
61
- await this.config.runCommand('stop', stopArgv);
62
- const startArgv = [...stopArgv];
63
- if (flags.quickstart) {
64
- startArgv.push('--quickstart');
65
- }
66
- pushFlag(startArgv, '--port', flags.port);
67
- if (daemonFlagWasProvided) {
68
- startArgv.push(flags.daemon === false ? '--no-daemon' : '--daemon');
69
- }
70
- pushFlag(startArgv, '--instances', flags.instances);
71
- pushFlag(startArgv, '--launch-mode', flags['launch-mode']);
72
- await this.config.runCommand('start', startArgv);
73
- }
9
+ import AppRestart from './app/restart.js';
10
+ export default class Restart extends AppRestart {
11
+ static hidden = true;
74
12
  }
@@ -12,7 +12,7 @@ export default class ScaffoldMigration extends Command {
12
12
  static args = {
13
13
  name: Args.string({ description: 'migration name', required: true }),
14
14
  };
15
- static description = 'Run the legacy NocoBase scaffold migration (forwards to `npm run scaffold:migration` in the repo root)';
15
+ static description = 'Generate a plugin migration file.';
16
16
  static examples = [
17
17
  '<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl',
18
18
  '<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl --on afterLoad',
@@ -12,7 +12,7 @@ export default class ScaffoldPlugin extends Command {
12
12
  static args = {
13
13
  pkg: Args.string({ description: 'plugin package name', required: true }),
14
14
  };
15
- static description = 'Run the legacy NocoBase scaffold plugin (forwards to `npm run scaffold:plugin` in the repo root)';
15
+ static description = 'Generate a NocoBase plugin scaffold.';
16
16
  static examples = [
17
17
  '<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello',
18
18
  '<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello --force-recreate',