@nocobase/cli 2.1.0-beta.15 → 2.1.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +107 -0
- package/README.md +307 -63
- package/README.zh-CN.md +332 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +114 -0
- package/dist/commands/api/resource/create.js +15 -0
- package/dist/commands/api/resource/destroy.js +15 -0
- package/dist/commands/api/resource/get.js +15 -0
- package/dist/commands/api/resource/index.js +20 -0
- package/dist/commands/api/resource/list.js +16 -0
- package/dist/commands/api/resource/query.js +15 -0
- package/dist/commands/api/resource/update.js +15 -0
- package/dist/commands/build.js +57 -0
- package/dist/commands/db/logs.js +85 -0
- package/dist/commands/db/ps.js +60 -0
- package/dist/commands/db/shared.js +81 -0
- package/dist/commands/db/start.js +70 -0
- package/dist/commands/db/stop.js +70 -0
- package/dist/commands/dev.js +149 -0
- package/dist/commands/down.js +193 -0
- package/dist/commands/download.js +779 -0
- package/dist/commands/env/add.js +327 -0
- package/dist/commands/env/auth.js +62 -0
- package/dist/commands/env/list.js +41 -0
- package/dist/commands/env/remove.js +65 -0
- package/dist/commands/env/update.js +73 -0
- package/dist/commands/env/use.js +36 -0
- package/dist/commands/init.js +813 -0
- package/dist/commands/install.js +1850 -0
- package/dist/commands/logs.js +90 -0
- package/dist/commands/pm/disable.js +63 -0
- package/dist/commands/pm/enable.js +63 -0
- package/dist/commands/pm/list.js +54 -0
- package/dist/commands/prompts-stages.js +150 -0
- package/dist/commands/prompts-test.js +181 -0
- package/dist/commands/ps.js +116 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/start.js +211 -0
- package/dist/commands/stop.js +90 -0
- package/dist/commands/upgrade.js +583 -0
- package/dist/generated/command-registry.js +133 -0
- package/dist/help/runtime-help.js +20 -0
- package/dist/lib/api-client.js +243 -0
- package/dist/lib/app-runtime.js +142 -0
- package/dist/lib/auth-store.js +241 -0
- package/dist/lib/bootstrap.js +387 -0
- package/dist/lib/build-config.js +10 -0
- package/dist/lib/cli-home.js +30 -0
- package/dist/lib/cli-locale.js +115 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/env-auth.js +872 -0
- package/dist/lib/generated-command.js +142 -0
- package/dist/lib/naming.js +70 -0
- package/dist/lib/openapi.js +62 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog.js +574 -0
- package/dist/lib/prompt-validators.js +185 -0
- package/dist/lib/prompt-web-ui.js +2061 -0
- package/dist/lib/resource-command.js +335 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +123 -0
- package/dist/lib/runtime-generator.js +419 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/ui.js +175 -0
- package/dist/locale/en-US.json +319 -0
- package/dist/locale/zh-CN.json +319 -0
- package/dist/post-processors/data-modeling.js +66 -0
- package/dist/post-processors/data-source-manager.js +114 -0
- package/dist/post-processors/index.js +19 -0
- package/nocobase-ctl.config.json +287 -0
- package/package.json +53 -25
- package/LICENSE +0 -201
- package/bin/index.js +0 -39
- package/nocobase.conf.tpl +0 -95
- package/src/cli.js +0 -19
- package/src/commands/benchmark.js +0 -73
- package/src/commands/build.js +0 -49
- package/src/commands/clean.js +0 -30
- package/src/commands/client.js +0 -166
- package/src/commands/create-nginx-conf.js +0 -37
- package/src/commands/create-plugin.js +0 -33
- package/src/commands/dev.js +0 -200
- package/src/commands/doc.js +0 -76
- package/src/commands/e2e.js +0 -265
- package/src/commands/global.js +0 -43
- package/src/commands/index.js +0 -45
- package/src/commands/instance-id.js +0 -47
- package/src/commands/locale/cronstrue.js +0 -122
- package/src/commands/locale/react-js-cron/en-US.json +0 -75
- package/src/commands/locale/react-js-cron/index.js +0 -17
- package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
- package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
- package/src/commands/locale.js +0 -81
- package/src/commands/p-test.js +0 -88
- package/src/commands/perf.js +0 -63
- package/src/commands/pkg.js +0 -321
- package/src/commands/pm2.js +0 -37
- package/src/commands/postinstall.js +0 -88
- package/src/commands/start.js +0 -148
- package/src/commands/tar.js +0 -36
- package/src/commands/test-coverage.js +0 -55
- package/src/commands/test.js +0 -107
- package/src/commands/umi.js +0 -33
- package/src/commands/update-deps.js +0 -72
- package/src/commands/upgrade.js +0 -47
- package/src/commands/view-license-key.js +0 -44
- package/src/index.js +0 -14
- package/src/license.js +0 -76
- package/src/logger.js +0 -75
- package/src/plugin-generator.js +0 -80
- package/src/util.js +0 -517
- package/templates/bundle-status.html +0 -338
- package/templates/create-app-package.json +0 -39
- package/templates/plugin/.npmignore.tpl +0 -2
- package/templates/plugin/README.md.tpl +0 -1
- package/templates/plugin/client.d.ts +0 -2
- package/templates/plugin/client.js +0 -1
- package/templates/plugin/package.json.tpl +0 -11
- package/templates/plugin/server.d.ts +0 -2
- package/templates/plugin/server.js +0 -1
- package/templates/plugin/src/client/client.d.ts +0 -249
- package/templates/plugin/src/client/index.tsx.tpl +0 -1
- package/templates/plugin/src/client/locale.ts +0 -21
- package/templates/plugin/src/client/models/index.ts +0 -12
- package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
- package/templates/plugin/src/index.ts +0 -2
- package/templates/plugin/src/locale/en-US.json +0 -1
- package/templates/plugin/src/locale/zh-CN.json +0 -1
- package/templates/plugin/src/server/collections/.gitkeep +0 -0
- package/templates/plugin/src/server/index.ts.tpl +0 -1
- package/templates/plugin/src/server/plugin.ts.tpl +0 -19
|
@@ -0,0 +1,85 @@
|
|
|
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 } from '../../lib/app-runtime.js';
|
|
11
|
+
import { run } from '../../lib/run-npm.js';
|
|
12
|
+
import { printInfo } from '../../lib/ui.js';
|
|
13
|
+
import { formatUnmanagedDbLogsMessage, resolveDbRuntime } from './shared.js';
|
|
14
|
+
function formatDbLogsFailure(envName, message) {
|
|
15
|
+
if (/does not exist/i.test(message)) {
|
|
16
|
+
return [
|
|
17
|
+
`Can't show database logs for "${envName}" yet.`,
|
|
18
|
+
'The saved built-in database container for this env could not be found on this machine.',
|
|
19
|
+
'Try reinstalling the env, or check whether the container was removed outside the CLI.',
|
|
20
|
+
`Details: ${message}`,
|
|
21
|
+
].join('\n');
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
`Couldn't show database logs for "${envName}".`,
|
|
25
|
+
'Check that the built-in database runtime for this env is still available, then try again.',
|
|
26
|
+
`Details: ${message}`,
|
|
27
|
+
].join('\n');
|
|
28
|
+
}
|
|
29
|
+
export default class DbLogs extends Command {
|
|
30
|
+
static description = 'Show logs for the built-in database container of the selected env.';
|
|
31
|
+
static examples = [
|
|
32
|
+
'<%= config.bin %> <%= command.id %>',
|
|
33
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
34
|
+
'<%= config.bin %> <%= command.id %> --env app1 --tail 200',
|
|
35
|
+
'<%= config.bin %> <%= command.id %> --env app1 --no-follow',
|
|
36
|
+
];
|
|
37
|
+
static flags = {
|
|
38
|
+
env: Flags.string({
|
|
39
|
+
char: 'e',
|
|
40
|
+
description: 'CLI env name to inspect built-in database logs for. Defaults to the current env when omitted',
|
|
41
|
+
}),
|
|
42
|
+
tail: Flags.integer({
|
|
43
|
+
description: 'Number of recent log lines to show before following',
|
|
44
|
+
default: 100,
|
|
45
|
+
min: 0,
|
|
46
|
+
}),
|
|
47
|
+
follow: Flags.boolean({
|
|
48
|
+
char: 'f',
|
|
49
|
+
description: 'Keep streaming new log lines',
|
|
50
|
+
default: true,
|
|
51
|
+
allowNo: true,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
async run() {
|
|
55
|
+
const { flags } = await this.parse(DbLogs);
|
|
56
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
57
|
+
const runtime = await resolveDbRuntime(requestedEnv);
|
|
58
|
+
if (!runtime) {
|
|
59
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
60
|
+
}
|
|
61
|
+
if (runtime.kind !== 'builtin') {
|
|
62
|
+
this.error(formatUnmanagedDbLogsMessage(runtime));
|
|
63
|
+
}
|
|
64
|
+
const tail = String(flags.tail ?? 100);
|
|
65
|
+
const follow = flags.follow !== false;
|
|
66
|
+
printInfo(follow
|
|
67
|
+
? `Showing built-in database logs for "${runtime.envName}" (press Ctrl+C to stop).`
|
|
68
|
+
: `Showing recent built-in database logs for "${runtime.envName}".`);
|
|
69
|
+
const dockerArgs = ['logs', '--tail', tail];
|
|
70
|
+
if (follow) {
|
|
71
|
+
dockerArgs.push('--follow');
|
|
72
|
+
}
|
|
73
|
+
dockerArgs.push(runtime.containerName);
|
|
74
|
+
try {
|
|
75
|
+
await run('docker', dockerArgs, {
|
|
76
|
+
errorName: 'docker logs',
|
|
77
|
+
stdio: 'inherit',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
82
|
+
this.error(formatDbLogsFailure(runtime.envName, message));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 } from '../../lib/app-runtime.js';
|
|
11
|
+
import { listEnvs } from '../../lib/auth-store.js';
|
|
12
|
+
import { renderTable } from '../../lib/ui.js';
|
|
13
|
+
import { builtinDbStatus, resolveDbRuntime } from './shared.js';
|
|
14
|
+
export default class DbPs extends Command {
|
|
15
|
+
static description = 'Show built-in database runtime status for configured envs without starting or stopping anything.';
|
|
16
|
+
static examples = [
|
|
17
|
+
'<%= config.bin %> <%= command.id %>',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
env: Flags.string({
|
|
22
|
+
char: 'e',
|
|
23
|
+
description: 'CLI env name to inspect. Omit to show all configured envs',
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(DbPs);
|
|
28
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
29
|
+
const envNames = requestedEnv
|
|
30
|
+
? [requestedEnv]
|
|
31
|
+
: Object.keys((await listEnvs()).envs).sort();
|
|
32
|
+
if (!envNames.length) {
|
|
33
|
+
this.log('No NocoBase env is configured yet. Run `nb init` to create one first.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const rows = [];
|
|
37
|
+
for (const envName of envNames) {
|
|
38
|
+
const runtime = await resolveDbRuntime(envName);
|
|
39
|
+
if (!runtime) {
|
|
40
|
+
if (requestedEnv) {
|
|
41
|
+
this.error(formatMissingManagedAppEnvMessage(envName));
|
|
42
|
+
}
|
|
43
|
+
rows.push([envName, '-', '-', 'missing', '']);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const type = runtime.kind === 'builtin' ? 'builtin' : runtime.status;
|
|
47
|
+
const status = runtime.kind === 'builtin'
|
|
48
|
+
? await builtinDbStatus(runtime.containerName)
|
|
49
|
+
: runtime.status;
|
|
50
|
+
rows.push([
|
|
51
|
+
runtime.envName,
|
|
52
|
+
type,
|
|
53
|
+
runtime.dbDialect,
|
|
54
|
+
status,
|
|
55
|
+
runtime.address,
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
this.log(renderTable(['Env', 'Type', 'Dialect', 'Status', 'Address'], rows));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { buildDockerDbContainerName, dockerContainerExists, dockerContainerIsRunning, resolveManagedAppRuntime, } from '../../lib/app-runtime.js';
|
|
10
|
+
function formatAddress(host, port, fallbackHost) {
|
|
11
|
+
const normalizedHost = String(host ?? '').trim() || String(fallbackHost ?? '').trim();
|
|
12
|
+
const normalizedPort = String(port ?? '').trim();
|
|
13
|
+
if (normalizedHost && normalizedPort) {
|
|
14
|
+
return `${normalizedHost}:${normalizedPort}`;
|
|
15
|
+
}
|
|
16
|
+
return normalizedHost || normalizedPort || '';
|
|
17
|
+
}
|
|
18
|
+
export async function resolveDbRuntime(envName) {
|
|
19
|
+
const runtime = await resolveManagedAppRuntime(envName);
|
|
20
|
+
if (!runtime) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const source = runtime.kind === 'remote' ? 'remote' : runtime.source;
|
|
24
|
+
const dbDialect = String(runtime.env.config.dbDialect ?? 'postgres').trim() || 'postgres';
|
|
25
|
+
if (runtime.kind !== 'remote' && runtime.env.config.builtinDb) {
|
|
26
|
+
const containerName = buildDockerDbContainerName(runtime.envName, dbDialect, runtime.workspaceName);
|
|
27
|
+
return {
|
|
28
|
+
kind: 'builtin',
|
|
29
|
+
envName: runtime.envName,
|
|
30
|
+
source,
|
|
31
|
+
dbDialect,
|
|
32
|
+
containerName,
|
|
33
|
+
address: formatAddress(runtime.env.config.dbHost, runtime.env.config.dbPort, containerName),
|
|
34
|
+
appRuntime: runtime,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
kind: 'external',
|
|
39
|
+
envName: runtime.envName,
|
|
40
|
+
source,
|
|
41
|
+
dbDialect,
|
|
42
|
+
address: formatAddress(runtime.env.config.dbHost, runtime.env.config.dbPort),
|
|
43
|
+
status: runtime.kind === 'remote' ? 'remote' : 'external',
|
|
44
|
+
appRuntime: runtime,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function builtinDbStatus(containerName) {
|
|
48
|
+
if (!(await dockerContainerExists(containerName))) {
|
|
49
|
+
return 'missing';
|
|
50
|
+
}
|
|
51
|
+
return await dockerContainerIsRunning(containerName) ? 'running' : 'stopped';
|
|
52
|
+
}
|
|
53
|
+
export function formatUnmanagedDbMessage(action, runtime) {
|
|
54
|
+
const verb = action === 'start' ? 'start' : 'stop';
|
|
55
|
+
if (runtime.appRuntime.kind === 'remote') {
|
|
56
|
+
return [
|
|
57
|
+
`Can't ${verb} the database for "${runtime.envName}" from this machine.`,
|
|
58
|
+
'This env only has an API connection, so there is no CLI-managed database container here.',
|
|
59
|
+
'If you need CLI-managed database start and stop, create a local env with the built-in database option enabled.',
|
|
60
|
+
].join('\n');
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
`Can't ${verb} the database for "${runtime.envName}" from this machine.`,
|
|
64
|
+
'This env does not use a CLI-managed built-in database, so there is no saved database container to manage here.',
|
|
65
|
+
'If you need CLI-managed database start and stop, recreate the env with the built-in database option enabled.',
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
export function formatUnmanagedDbLogsMessage(runtime) {
|
|
69
|
+
if (runtime.appRuntime.kind === 'remote') {
|
|
70
|
+
return [
|
|
71
|
+
`Can't show database logs for "${runtime.envName}" from this machine.`,
|
|
72
|
+
'This env only has an API connection, so there is no CLI-managed database container here.',
|
|
73
|
+
'If you need CLI-managed database logs, create a local env with the built-in database option enabled.',
|
|
74
|
+
].join('\n');
|
|
75
|
+
}
|
|
76
|
+
return [
|
|
77
|
+
`Can't show database logs for "${runtime.envName}" from this machine.`,
|
|
78
|
+
'This env does not use a CLI-managed built-in database, so there is no saved database container to read logs from here.',
|
|
79
|
+
'If you need CLI-managed database logs, recreate the env with the built-in database option enabled.',
|
|
80
|
+
].join('\n');
|
|
81
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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, startDockerContainer, } from '../../lib/app-runtime.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../lib/ui.js';
|
|
12
|
+
import { formatUnmanagedDbMessage, resolveDbRuntime } from './shared.js';
|
|
13
|
+
function formatDbStartFailure(envName, message) {
|
|
14
|
+
if (/does not exist/i.test(message)) {
|
|
15
|
+
return [
|
|
16
|
+
`Can't start the database for "${envName}" yet.`,
|
|
17
|
+
'The saved built-in database container for this env could not be found on this machine.',
|
|
18
|
+
'Try reinstalling the env, or check whether the container was removed outside the CLI.',
|
|
19
|
+
`Details: ${message}`,
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
`Couldn't start the database for "${envName}".`,
|
|
24
|
+
'Check that the built-in database runtime for this env is still available, then try again.',
|
|
25
|
+
`Details: ${message}`,
|
|
26
|
+
].join('\n');
|
|
27
|
+
}
|
|
28
|
+
export default class DbStart extends Command {
|
|
29
|
+
static description = 'Start the built-in database container for the selected env.';
|
|
30
|
+
static examples = [
|
|
31
|
+
'<%= config.bin %> <%= command.id %>',
|
|
32
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
33
|
+
'<%= config.bin %> <%= command.id %> --env app1 --verbose',
|
|
34
|
+
];
|
|
35
|
+
static flags = {
|
|
36
|
+
env: Flags.string({
|
|
37
|
+
char: 'e',
|
|
38
|
+
description: 'CLI env name to start the built-in database for. Defaults to the current env when omitted',
|
|
39
|
+
}),
|
|
40
|
+
verbose: Flags.boolean({
|
|
41
|
+
description: 'Show raw startup output from the underlying Docker command',
|
|
42
|
+
default: false,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
async run() {
|
|
46
|
+
const { flags } = await this.parse(DbStart);
|
|
47
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
48
|
+
const runtime = await resolveDbRuntime(requestedEnv);
|
|
49
|
+
if (!runtime) {
|
|
50
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
51
|
+
}
|
|
52
|
+
if (runtime.kind !== 'builtin') {
|
|
53
|
+
this.error(formatUnmanagedDbMessage('start', runtime));
|
|
54
|
+
}
|
|
55
|
+
startTask(`Starting the built-in database for "${runtime.envName}"...`);
|
|
56
|
+
try {
|
|
57
|
+
const state = await startDockerContainer(runtime.containerName, {
|
|
58
|
+
stdio: flags.verbose ? 'inherit' : 'ignore',
|
|
59
|
+
});
|
|
60
|
+
succeedTask(state === 'already-running'
|
|
61
|
+
? `The built-in database is already running for "${runtime.envName}"${runtime.address ? ` at ${runtime.address}` : ''}.`
|
|
62
|
+
: `The built-in database is running for "${runtime.envName}"${runtime.address ? ` at ${runtime.address}` : ''}.`);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
failTask(`Failed to start the built-in database for "${runtime.envName}".`);
|
|
67
|
+
this.error(formatDbStartFailure(runtime.envName, message));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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, stopDockerContainer, } from '../../lib/app-runtime.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../lib/ui.js';
|
|
12
|
+
import { formatUnmanagedDbMessage, resolveDbRuntime } from './shared.js';
|
|
13
|
+
function formatDbStopFailure(envName, message) {
|
|
14
|
+
if (/does not exist/i.test(message)) {
|
|
15
|
+
return [
|
|
16
|
+
`Can't stop the database for "${envName}" yet.`,
|
|
17
|
+
'The saved built-in database container for this env could not be found on this machine.',
|
|
18
|
+
'If it was removed manually, reinstall or reconnect the env before trying again.',
|
|
19
|
+
`Details: ${message}`,
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
`Couldn't stop the database for "${envName}".`,
|
|
24
|
+
'Check that the built-in database runtime for this env is still available, then try again.',
|
|
25
|
+
`Details: ${message}`,
|
|
26
|
+
].join('\n');
|
|
27
|
+
}
|
|
28
|
+
export default class DbStop extends Command {
|
|
29
|
+
static description = 'Stop the built-in database container for the selected env.';
|
|
30
|
+
static examples = [
|
|
31
|
+
'<%= config.bin %> <%= command.id %>',
|
|
32
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
33
|
+
'<%= config.bin %> <%= command.id %> --env app1 --verbose',
|
|
34
|
+
];
|
|
35
|
+
static flags = {
|
|
36
|
+
env: Flags.string({
|
|
37
|
+
char: 'e',
|
|
38
|
+
description: 'CLI env name to stop the built-in database for. Defaults to the current env when omitted',
|
|
39
|
+
}),
|
|
40
|
+
verbose: Flags.boolean({
|
|
41
|
+
description: 'Show raw shutdown output from the underlying Docker command',
|
|
42
|
+
default: false,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
async run() {
|
|
46
|
+
const { flags } = await this.parse(DbStop);
|
|
47
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
48
|
+
const runtime = await resolveDbRuntime(requestedEnv);
|
|
49
|
+
if (!runtime) {
|
|
50
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
51
|
+
}
|
|
52
|
+
if (runtime.kind !== 'builtin') {
|
|
53
|
+
this.error(formatUnmanagedDbMessage('stop', runtime));
|
|
54
|
+
}
|
|
55
|
+
startTask(`Stopping the built-in database for "${runtime.envName}"...`);
|
|
56
|
+
try {
|
|
57
|
+
const state = await stopDockerContainer(runtime.containerName, {
|
|
58
|
+
stdio: flags.verbose ? 'inherit' : 'ignore',
|
|
59
|
+
});
|
|
60
|
+
succeedTask(state === 'already-stopped'
|
|
61
|
+
? `The built-in database is already stopped for "${runtime.envName}".`
|
|
62
|
+
: `The built-in database has stopped for "${runtime.envName}".`);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
failTask(`Failed to stop the built-in database for "${runtime.envName}".`);
|
|
67
|
+
this.error(formatDbStopFailure(runtime.envName, message));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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, runLocalNocoBaseCommand, } from '../lib/app-runtime.js';
|
|
11
|
+
import { printInfo } from '../lib/ui.js';
|
|
12
|
+
function formatUnsupportedRuntimeMessage(kind, envName) {
|
|
13
|
+
if (kind === 'docker') {
|
|
14
|
+
return [
|
|
15
|
+
`Can't run dev mode for "${envName}".`,
|
|
16
|
+
'This env is managed by Docker, but `nb dev` requires a local npm or Git source directory.',
|
|
17
|
+
`Use \`nb logs --env ${envName}\` to inspect the Docker app, or create a source-based env with \`nb init --env ${envName} --source git\`.`,
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
|
20
|
+
return [
|
|
21
|
+
`Can't run dev mode for "${envName}".`,
|
|
22
|
+
'This env only has an API connection, but `nb dev` requires a local npm or Git source directory.',
|
|
23
|
+
`Create a source-based env with \`nb init --env ${envName} --source git\` if you want local development mode.`,
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
26
|
+
function appUrlForPort(port) {
|
|
27
|
+
const value = String(port ?? '').trim();
|
|
28
|
+
if (!value) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return `http://127.0.0.1:${value}`;
|
|
32
|
+
}
|
|
33
|
+
async function isAppAlreadyRunning(appUrl) {
|
|
34
|
+
if (!appUrl) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timeout = setTimeout(() => controller.abort(), 1500);
|
|
39
|
+
try {
|
|
40
|
+
const response = await fetch(`${appUrl}/api/__health_check`, {
|
|
41
|
+
signal: controller.signal,
|
|
42
|
+
});
|
|
43
|
+
const text = await response.text();
|
|
44
|
+
return response.ok && text.trim().toLowerCase() === 'ok';
|
|
45
|
+
}
|
|
46
|
+
catch (_error) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
clearTimeout(timeout);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export default class Dev extends Command {
|
|
54
|
+
static description = 'Run NocoBase in local development mode for an npm or Git source env.';
|
|
55
|
+
static examples = [
|
|
56
|
+
'<%= config.bin %> <%= command.id %>',
|
|
57
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
58
|
+
'<%= config.bin %> <%= command.id %> --env app1 --db-sync',
|
|
59
|
+
'<%= config.bin %> <%= command.id %> --env app1 --port 12000',
|
|
60
|
+
'<%= config.bin %> <%= command.id %> --env app1 --client',
|
|
61
|
+
'<%= config.bin %> <%= command.id %> --env app1 --server',
|
|
62
|
+
'<%= config.bin %> <%= command.id %> --env app1 --inspect 9229',
|
|
63
|
+
];
|
|
64
|
+
static flags = {
|
|
65
|
+
env: Flags.string({
|
|
66
|
+
char: 'e',
|
|
67
|
+
description: 'CLI env name for dev mode. Defaults to the current env when omitted',
|
|
68
|
+
required: false,
|
|
69
|
+
}),
|
|
70
|
+
'db-sync': Flags.boolean({
|
|
71
|
+
description: 'Synchronize the database before starting dev mode',
|
|
72
|
+
required: false,
|
|
73
|
+
}),
|
|
74
|
+
port: Flags.string({
|
|
75
|
+
description: 'Development server port',
|
|
76
|
+
char: 'p',
|
|
77
|
+
required: false,
|
|
78
|
+
}),
|
|
79
|
+
client: Flags.boolean({
|
|
80
|
+
description: 'Run client dev mode only',
|
|
81
|
+
char: 'c',
|
|
82
|
+
required: false,
|
|
83
|
+
}),
|
|
84
|
+
server: Flags.boolean({
|
|
85
|
+
description: 'Run server dev mode only',
|
|
86
|
+
char: 's',
|
|
87
|
+
required: false,
|
|
88
|
+
}),
|
|
89
|
+
inspect: Flags.string({
|
|
90
|
+
description: 'Node.js inspect port for server debugging',
|
|
91
|
+
char: 'i',
|
|
92
|
+
required: false,
|
|
93
|
+
}),
|
|
94
|
+
};
|
|
95
|
+
async run() {
|
|
96
|
+
const { flags } = await this.parse(Dev);
|
|
97
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
98
|
+
const runtime = await resolveManagedAppRuntime(requestedEnv);
|
|
99
|
+
if (!runtime) {
|
|
100
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
101
|
+
}
|
|
102
|
+
if (runtime.kind === 'docker' || runtime.kind === 'remote') {
|
|
103
|
+
this.error(formatUnsupportedRuntimeMessage(runtime.kind, runtime.envName));
|
|
104
|
+
}
|
|
105
|
+
const devPort = flags.port
|
|
106
|
+
|| (runtime.env.appPort !== undefined && runtime.env.appPort !== null
|
|
107
|
+
? String(runtime.env.appPort).trim()
|
|
108
|
+
: undefined);
|
|
109
|
+
const appUrl = appUrlForPort(devPort);
|
|
110
|
+
if (await isAppAlreadyRunning(appUrl)) {
|
|
111
|
+
this.error([
|
|
112
|
+
`NocoBase is already running for "${runtime.envName}"${appUrl ? ` at ${appUrl}` : ''}.`,
|
|
113
|
+
flags.port
|
|
114
|
+
? `Choose another dev port with --port, or stop the running app with \`nb stop --env ${runtime.envName}\` first.`
|
|
115
|
+
: `Run \`nb stop --env ${runtime.envName}\` before starting dev mode, or choose another dev port with --port.`,
|
|
116
|
+
].join('\n'));
|
|
117
|
+
}
|
|
118
|
+
const npmArgs = ['dev', '--rsbuild'];
|
|
119
|
+
if (flags['db-sync']) {
|
|
120
|
+
npmArgs.push('--db-sync');
|
|
121
|
+
}
|
|
122
|
+
if (devPort) {
|
|
123
|
+
npmArgs.push('--port', devPort);
|
|
124
|
+
}
|
|
125
|
+
if (flags.client) {
|
|
126
|
+
npmArgs.push('--client');
|
|
127
|
+
}
|
|
128
|
+
if (flags.server) {
|
|
129
|
+
npmArgs.push('--server');
|
|
130
|
+
}
|
|
131
|
+
if (flags.inspect) {
|
|
132
|
+
npmArgs.push('--inspect', flags.inspect);
|
|
133
|
+
}
|
|
134
|
+
printInfo(`Starting NocoBase dev mode for "${runtime.envName}" from ${runtime.projectRoot}. Press Ctrl+C to stop.`);
|
|
135
|
+
try {
|
|
136
|
+
await runLocalNocoBaseCommand(runtime, npmArgs, {
|
|
137
|
+
stdio: 'inherit',
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
142
|
+
this.error([
|
|
143
|
+
`Couldn't start dev mode for "${runtime.envName}".`,
|
|
144
|
+
'Check that dependencies are installed and the saved env settings are valid, then try again.',
|
|
145
|
+
`Details: ${message}`,
|
|
146
|
+
].join('\n'));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|