@nocobase/cli 2.1.0-beta.2 → 2.1.0-beta.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.
- package/LICENSE.txt +107 -0
- package/README.md +367 -19
- package/README.zh-CN.md +336 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +116 -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 +865 -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 +822 -0
- package/dist/commands/install.js +1888 -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/restart.js +74 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/self/check.js +71 -0
- package/dist/commands/self/index.js +20 -0
- package/dist/commands/self/update.js +76 -0
- package/dist/commands/skills/check.js +63 -0
- package/dist/commands/skills/index.js +20 -0
- package/dist/commands/skills/install.js +58 -0
- package/dist/commands/skills/update.js +58 -0
- package/dist/commands/start.js +211 -0
- package/dist/commands/stop.js +90 -0
- package/dist/commands/test.js +466 -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 +581 -0
- package/dist/lib/prompt-validators.js +185 -0
- package/dist/lib/prompt-web-ui.js +2096 -0
- package/dist/lib/resource-command.js +335 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +197 -0
- package/dist/lib/runtime-generator.js +419 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/self-manager.js +246 -0
- package/dist/lib/skills-manager.js +202 -0
- package/dist/lib/ui.js +175 -0
- package/dist/locale/en-US.json +333 -0
- package/dist/locale/zh-CN.json +333 -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 +60 -26
- package/LICENSE +0 -661
- 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,116 @@
|
|
|
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 { 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
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
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
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 ScaffoldMigration extends Command {
|
|
12
|
+
static args = {
|
|
13
|
+
name: Args.string({ description: 'migration name', required: true }),
|
|
14
|
+
};
|
|
15
|
+
static description = 'Run the legacy NocoBase scaffold migration (forwards to `npm run scaffold:migration` in the repo root)';
|
|
16
|
+
static examples = [
|
|
17
|
+
'<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> migration-name --pkg @nocobase/plugin-acl --on afterLoad',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
pkg: Flags.string({ description: 'plugin package name', required: true }),
|
|
22
|
+
on: Flags.string({ description: 'on', required: false, options: ['beforeLoad', 'afterSync', 'afterLoad'] }),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { args, flags } = await this.parse(ScaffoldMigration);
|
|
26
|
+
const npmArgs = ['create-migration', args.name, '--pkg', flags.pkg];
|
|
27
|
+
if (flags.on) {
|
|
28
|
+
npmArgs.push('--on', flags.on);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await runNocoBaseCommand(npmArgs, { env: { LOGGER_SILENT: 'true' } });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
+
this.error(message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 ScaffoldPlugin extends Command {
|
|
12
|
+
static args = {
|
|
13
|
+
pkg: Args.string({ description: 'plugin package name', required: true }),
|
|
14
|
+
};
|
|
15
|
+
static description = 'Run the legacy NocoBase scaffold plugin (forwards to `npm run scaffold:plugin` in the repo root)';
|
|
16
|
+
static examples = [
|
|
17
|
+
'<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> @nocobase-example/plugin-hello --force-recreate',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
'force-recreate': Flags.boolean({ description: 'Force recreate the plugin', char: 'f', required: false }),
|
|
22
|
+
};
|
|
23
|
+
async run() {
|
|
24
|
+
const { args, flags } = await this.parse(ScaffoldPlugin);
|
|
25
|
+
const npmArgs = ['pm', 'create', args.pkg];
|
|
26
|
+
if (flags['force-recreate']) {
|
|
27
|
+
npmArgs.push('--force-recreate');
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
await runNocoBaseCommand(npmArgs, { env: { LOGGER_SILENT: 'true' } });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
34
|
+
this.error(message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { getRecommendedSelfUpdateCommand, inspectSelfStatus, } from '../../lib/self-manager.js';
|
|
11
|
+
import { printInfo, renderTable } from '../../lib/ui.js';
|
|
12
|
+
export default class SelfCheck extends Command {
|
|
13
|
+
static summary = 'Check the installed NocoBase CLI version and self-update support';
|
|
14
|
+
static description = 'Inspect the current NocoBase CLI install, resolve the latest version for the selected channel, and report whether automatic self-update is supported.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %>',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --channel beta',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
channel: Flags.string({
|
|
22
|
+
description: 'Release channel to compare against. Defaults to the current CLI channel.',
|
|
23
|
+
options: ['auto', 'latest', 'beta', 'alpha'],
|
|
24
|
+
default: 'auto',
|
|
25
|
+
}),
|
|
26
|
+
json: Flags.boolean({
|
|
27
|
+
description: 'Output the result as JSON',
|
|
28
|
+
default: false,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
async run() {
|
|
32
|
+
const { flags } = await this.parse(SelfCheck);
|
|
33
|
+
const status = await inspectSelfStatus({
|
|
34
|
+
channel: flags.channel,
|
|
35
|
+
});
|
|
36
|
+
if (flags.json) {
|
|
37
|
+
this.log(JSON.stringify({
|
|
38
|
+
ok: true,
|
|
39
|
+
kind: 'self',
|
|
40
|
+
packageName: status.packageName,
|
|
41
|
+
currentVersion: status.currentVersion,
|
|
42
|
+
latestVersion: status.latestVersion,
|
|
43
|
+
channel: status.channel,
|
|
44
|
+
updateAvailable: status.updateAvailable,
|
|
45
|
+
installMethod: status.installMethod,
|
|
46
|
+
updatable: status.updatable,
|
|
47
|
+
updateBlockedReason: status.updateBlockedReason,
|
|
48
|
+
recommendedCommand: getRecommendedSelfUpdateCommand(status),
|
|
49
|
+
registryError: status.registryError,
|
|
50
|
+
}, null, 2));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.log(renderTable(['Field', 'Value'], [
|
|
54
|
+
['Current version', status.currentVersion || 'unknown'],
|
|
55
|
+
['Latest version', status.latestVersion || 'unknown'],
|
|
56
|
+
['Channel', status.channel],
|
|
57
|
+
['Install method', status.installMethod],
|
|
58
|
+
['Auto-update', status.updatable ? 'supported' : 'not supported'],
|
|
59
|
+
['Update available', status.updateAvailable ? 'yes' : 'no'],
|
|
60
|
+
]));
|
|
61
|
+
if (status.updateAvailable && status.updatable) {
|
|
62
|
+
printInfo('Run `nb self update` to update the CLI.');
|
|
63
|
+
}
|
|
64
|
+
else if (status.updateAvailable && status.updateBlockedReason) {
|
|
65
|
+
printInfo(status.updateBlockedReason);
|
|
66
|
+
}
|
|
67
|
+
if (status.registryError) {
|
|
68
|
+
printInfo(`Version check warning: ${status.registryError}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -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 Self extends Command {
|
|
11
|
+
static summary = 'Inspect or update the NocoBase CLI itself';
|
|
12
|
+
async run() {
|
|
13
|
+
await this.parse(Self);
|
|
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 ?? 'self',
|
|
17
|
+
...this.argv,
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 { confirmAction } from '../../lib/ui.js';
|
|
11
|
+
import { formatSelfUpdateUnavailableMessage, formatUnsupportedSelfUpdateMessage, inspectSelfStatus, updateSelf, } from '../../lib/self-manager.js';
|
|
12
|
+
export default class SelfUpdate extends Command {
|
|
13
|
+
static summary = 'Update the globally installed NocoBase CLI';
|
|
14
|
+
static description = 'Update the current NocoBase CLI install when it is managed by a standard global npm install.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %>',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --yes',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> --channel alpha --json',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
channel: Flags.string({
|
|
22
|
+
description: 'Release channel to update to. Defaults to the current CLI channel.',
|
|
23
|
+
options: ['auto', 'latest', 'beta', 'alpha'],
|
|
24
|
+
default: 'auto',
|
|
25
|
+
}),
|
|
26
|
+
yes: Flags.boolean({
|
|
27
|
+
char: 'y',
|
|
28
|
+
description: 'Skip the update confirmation prompt',
|
|
29
|
+
default: false,
|
|
30
|
+
}),
|
|
31
|
+
json: Flags.boolean({
|
|
32
|
+
description: 'Output the result as JSON',
|
|
33
|
+
default: false,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
async run() {
|
|
37
|
+
const { flags } = await this.parse(SelfUpdate);
|
|
38
|
+
const status = await inspectSelfStatus({
|
|
39
|
+
channel: flags.channel,
|
|
40
|
+
});
|
|
41
|
+
if (!status.updatable) {
|
|
42
|
+
this.error(formatUnsupportedSelfUpdateMessage(status));
|
|
43
|
+
}
|
|
44
|
+
if (!status.latestVersion && status.registryError) {
|
|
45
|
+
this.error(formatSelfUpdateUnavailableMessage(status));
|
|
46
|
+
}
|
|
47
|
+
if (!flags.yes && status.updateAvailable) {
|
|
48
|
+
const confirmed = await confirmAction(`Update ${status.packageName} from ${status.currentVersion} to ${status.latestVersion}?`, { defaultValue: false });
|
|
49
|
+
if (!confirmed) {
|
|
50
|
+
this.log('Skipped CLI update.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const result = await updateSelf({
|
|
55
|
+
channel: flags.channel,
|
|
56
|
+
});
|
|
57
|
+
if (flags.json) {
|
|
58
|
+
this.log(JSON.stringify({
|
|
59
|
+
ok: true,
|
|
60
|
+
kind: 'self',
|
|
61
|
+
action: result.action,
|
|
62
|
+
packageName: result.status.packageName,
|
|
63
|
+
packageSpec: result.packageSpec,
|
|
64
|
+
channel: result.status.channel,
|
|
65
|
+
fromVersion: result.status.currentVersion,
|
|
66
|
+
toVersion: result.targetVersion,
|
|
67
|
+
}, null, 2));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (result.action === 'noop') {
|
|
71
|
+
this.log(`NocoBase CLI is already up to date at ${result.status.currentVersion}.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.log(`Updated NocoBase CLI from ${result.status.currentVersion} using ${result.packageSpec}${result.targetVersion ? ` (latest ${result.status.channel} resolves to ${result.targetVersion})` : ''}.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { inspectSkillsStatus } from '../../lib/skills-manager.js';
|
|
11
|
+
import { printInfo, renderTable } from '../../lib/ui.js';
|
|
12
|
+
export default class SkillsCheck extends Command {
|
|
13
|
+
static summary = 'Check the NocoBase AI coding skills installed for this workspace';
|
|
14
|
+
static description = 'Inspect the current workspace for NocoBase AI coding skills and report whether they are managed by the CLI and whether an update is available.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %>',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
18
|
+
];
|
|
19
|
+
static flags = {
|
|
20
|
+
json: Flags.boolean({
|
|
21
|
+
description: 'Output the result as JSON',
|
|
22
|
+
default: false,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(SkillsCheck);
|
|
27
|
+
const status = await inspectSkillsStatus();
|
|
28
|
+
if (flags.json) {
|
|
29
|
+
this.log(JSON.stringify({
|
|
30
|
+
ok: true,
|
|
31
|
+
kind: 'skills',
|
|
32
|
+
workspaceRoot: status.workspaceRoot,
|
|
33
|
+
installed: status.installed,
|
|
34
|
+
managedByNb: status.managedByNb,
|
|
35
|
+
sourcePackage: status.sourcePackage,
|
|
36
|
+
installedSkillNames: status.installedSkillNames,
|
|
37
|
+
installedRef: status.installedRef,
|
|
38
|
+
latestRef: status.latestRef,
|
|
39
|
+
updateAvailable: status.updateAvailable,
|
|
40
|
+
recommendedCommand: status.installed ? 'nb skills update --yes' : 'nb skills install --yes',
|
|
41
|
+
registryError: status.registryError,
|
|
42
|
+
}, null, 2));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.log(renderTable(['Field', 'Value'], [
|
|
46
|
+
['Workspace', status.workspaceRoot],
|
|
47
|
+
['Installed', status.installed ? 'yes' : 'no'],
|
|
48
|
+
['Managed by nb', status.managedByNb ? 'yes' : 'no'],
|
|
49
|
+
['Installed skills', status.installedSkillNames.length ? status.installedSkillNames.join(', ') : '(none)'],
|
|
50
|
+
['Update available', status.updateAvailable === null ? 'unknown' : status.updateAvailable ? 'yes' : 'no'],
|
|
51
|
+
]));
|
|
52
|
+
if (!status.installed) {
|
|
53
|
+
printInfo('Run `nb skills install` to install the NocoBase AI coding skills for this workspace.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (status.updateAvailable) {
|
|
57
|
+
printInfo('Run `nb skills update` to refresh the NocoBase AI coding skills for this workspace.');
|
|
58
|
+
}
|
|
59
|
+
if (status.registryError) {
|
|
60
|
+
printInfo(`Update check warning: ${status.registryError}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -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 Skills extends Command {
|
|
11
|
+
static summary = 'Inspect or synchronize NocoBase AI coding skills for this workspace';
|
|
12
|
+
async run() {
|
|
13
|
+
await this.parse(Skills);
|
|
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 ?? 'skills',
|
|
17
|
+
...this.argv,
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -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 { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { confirmAction } from '../../lib/ui.js';
|
|
11
|
+
import { installNocoBaseSkills } from '../../lib/skills-manager.js';
|
|
12
|
+
export default class SkillsInstall extends Command {
|
|
13
|
+
static summary = 'Install the NocoBase AI coding skills for this workspace';
|
|
14
|
+
static description = 'Install the NocoBase AI coding skills for the current workspace. If they are already installed, this command does not update them.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %>',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --yes',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
yes: Flags.boolean({
|
|
22
|
+
char: 'y',
|
|
23
|
+
description: 'Skip the install confirmation prompt',
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
json: Flags.boolean({
|
|
27
|
+
description: 'Output the result as JSON',
|
|
28
|
+
default: false,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
async run() {
|
|
32
|
+
const { flags } = await this.parse(SkillsInstall);
|
|
33
|
+
if (!flags.yes) {
|
|
34
|
+
const confirmed = await confirmAction('Install the NocoBase AI coding skills for this workspace?', { defaultValue: true });
|
|
35
|
+
if (!confirmed) {
|
|
36
|
+
this.log('Skipped skills install.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const result = await installNocoBaseSkills();
|
|
41
|
+
if (flags.json) {
|
|
42
|
+
this.log(JSON.stringify({
|
|
43
|
+
ok: true,
|
|
44
|
+
kind: 'skills',
|
|
45
|
+
action: result.action,
|
|
46
|
+
workspaceRoot: result.status.workspaceRoot,
|
|
47
|
+
installedSkillNames: result.status.installedSkillNames,
|
|
48
|
+
installedRef: result.status.installedRef,
|
|
49
|
+
}, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (result.action === 'noop') {
|
|
53
|
+
this.log('NocoBase AI coding skills are already installed for this workspace. Run `nb skills update` to refresh them.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.log('Installed the NocoBase AI coding skills for this workspace.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -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 { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { confirmAction } from '../../lib/ui.js';
|
|
11
|
+
import { updateNocoBaseSkills } from '../../lib/skills-manager.js';
|
|
12
|
+
export default class SkillsUpdate extends Command {
|
|
13
|
+
static summary = 'Update the NocoBase AI coding skills for this workspace';
|
|
14
|
+
static description = 'Refresh the NocoBase AI coding skills for the current workspace. This command only updates an existing nocobase/skills install.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %>',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> --yes',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> --json',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
yes: Flags.boolean({
|
|
22
|
+
char: 'y',
|
|
23
|
+
description: 'Skip the update confirmation prompt',
|
|
24
|
+
default: false,
|
|
25
|
+
}),
|
|
26
|
+
json: Flags.boolean({
|
|
27
|
+
description: 'Output the result as JSON',
|
|
28
|
+
default: false,
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
async run() {
|
|
32
|
+
const { flags } = await this.parse(SkillsUpdate);
|
|
33
|
+
if (!flags.yes) {
|
|
34
|
+
const confirmed = await confirmAction('Update the NocoBase AI coding skills for this workspace?', { defaultValue: true });
|
|
35
|
+
if (!confirmed) {
|
|
36
|
+
this.log('Skipped skills update.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const result = await updateNocoBaseSkills();
|
|
41
|
+
if (flags.json) {
|
|
42
|
+
this.log(JSON.stringify({
|
|
43
|
+
ok: true,
|
|
44
|
+
kind: 'skills',
|
|
45
|
+
action: result.action,
|
|
46
|
+
workspaceRoot: result.status.workspaceRoot,
|
|
47
|
+
installedSkillNames: result.status.installedSkillNames,
|
|
48
|
+
installedRef: result.status.installedRef,
|
|
49
|
+
}, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (result.action === 'noop') {
|
|
53
|
+
this.log('NocoBase AI coding skills are already up to date for this workspace.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.log('Updated the NocoBase AI coding skills for this workspace.');
|
|
57
|
+
}
|
|
58
|
+
}
|