@nocobase/cli 2.1.0-beta.2 → 2.1.0-beta.21
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 +131 -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 +95 -0
- package/dist/commands/db/start.js +70 -0
- package/dist/commands/db/stop.js +70 -0
- package/dist/commands/dev.js +156 -0
- package/dist/commands/down.js +197 -0
- package/dist/commands/download.js +865 -0
- package/dist/commands/env/add.js +307 -0
- package/dist/commands/env/auth.js +55 -0
- package/dist/commands/env/list.js +36 -0
- package/dist/commands/env/remove.js +59 -0
- package/dist/commands/env/update.js +67 -0
- package/dist/commands/env/use.js +28 -0
- package/dist/commands/init.js +950 -0
- package/dist/commands/install.js +1927 -0
- package/dist/commands/logs.js +97 -0
- package/dist/commands/pm/disable.js +63 -0
- package/dist/commands/pm/enable.js +63 -0
- package/dist/commands/pm/list.js +61 -0
- package/dist/commands/prompts-stages.js +150 -0
- package/dist/commands/prompts-test.js +181 -0
- package/dist/commands/ps.js +119 -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 +86 -0
- package/dist/commands/skills/check.js +69 -0
- package/dist/commands/skills/index.js +20 -0
- package/dist/commands/skills/install.js +71 -0
- package/dist/commands/skills/update.js +71 -0
- package/dist/commands/start.js +218 -0
- package/dist/commands/stop.js +97 -0
- package/dist/commands/test.js +466 -0
- package/dist/commands/upgrade.js +594 -0
- package/dist/generated/command-registry.js +133 -0
- package/dist/help/runtime-help.js +20 -0
- package/dist/lib/api-client.js +244 -0
- package/dist/lib/app-runtime.js +153 -0
- package/dist/lib/auth-store.js +357 -0
- package/dist/lib/bootstrap.js +388 -0
- package/dist/lib/build-config.js +10 -0
- package/dist/lib/cli-home.js +61 -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 +150 -0
- package/dist/lib/http-request.js +49 -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 +343 -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 +269 -0
- package/dist/lib/startup-update.js +203 -0
- package/dist/lib/ui.js +175 -0
- package/dist/locale/en-US.json +336 -0
- package/dist/locale/zh-CN.json +336 -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,185 @@
|
|
|
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 { spawn } from 'node:child_process';
|
|
10
|
+
import net from 'node:net';
|
|
11
|
+
import { translateCli } from "./cli-locale.js";
|
|
12
|
+
const API_BASE_URL_EXAMPLE = 'http://localhost:13000/api';
|
|
13
|
+
const ENV_KEY_PATTERN = /^[A-Za-z0-9]+$/;
|
|
14
|
+
const TCP_PORT_EXAMPLE = '13000';
|
|
15
|
+
export function validateApiBaseUrl(value) {
|
|
16
|
+
const raw = String(value ?? '').trim();
|
|
17
|
+
if (raw === '') {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
let url;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(raw);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return translateCli('validators.apiBaseUrl.invalid', { example: API_BASE_URL_EXAMPLE });
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
28
|
+
return translateCli('validators.apiBaseUrl.invalidProtocol', { example: API_BASE_URL_EXAMPLE });
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
export function validateEnvKey(value) {
|
|
33
|
+
const raw = String(value ?? '').trim();
|
|
34
|
+
if (raw === '') {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
if (!ENV_KEY_PATTERN.test(raw)) {
|
|
38
|
+
return translateCli('validators.envKey.invalid');
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function parseTcpPort(value) {
|
|
43
|
+
const raw = String(value ?? '').trim();
|
|
44
|
+
if (raw === '') {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (!/^\d+$/.test(raw)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const port = Number(raw);
|
|
51
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return port;
|
|
55
|
+
}
|
|
56
|
+
export function validateTcpPort(value) {
|
|
57
|
+
const raw = String(value ?? '').trim();
|
|
58
|
+
if (raw === '') {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const port = parseTcpPort(raw);
|
|
62
|
+
if (port === undefined) {
|
|
63
|
+
return translateCli('validators.tcpPort.invalid', { example: TCP_PORT_EXAMPLE });
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
async function canListenOnTcpPort(port) {
|
|
68
|
+
return await new Promise((resolve) => {
|
|
69
|
+
const server = net.createServer();
|
|
70
|
+
const resolveAndCleanup = (result) => {
|
|
71
|
+
server.removeAllListeners();
|
|
72
|
+
if (server.listening) {
|
|
73
|
+
server.close(() => resolve(result));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolve(result);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
server.once('error', () => {
|
|
80
|
+
resolveAndCleanup(false);
|
|
81
|
+
});
|
|
82
|
+
server.once('listening', () => {
|
|
83
|
+
resolveAndCleanup(true);
|
|
84
|
+
});
|
|
85
|
+
server.listen(port, '127.0.0.1');
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function parseDockerPublishedTcpPorts(output) {
|
|
89
|
+
const ports = new Set();
|
|
90
|
+
for (const line of output.split(/\r?\n/)) {
|
|
91
|
+
for (const segment of line.split(',')) {
|
|
92
|
+
const match = segment.trim().match(/^(?:.+:)?(\d+)->\d+(?:-\d+)?\/tcp$/i);
|
|
93
|
+
if (!match) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const port = Number.parseInt(match[1], 10);
|
|
97
|
+
if (Number.isInteger(port) && port >= 1 && port <= 65535) {
|
|
98
|
+
ports.add(port);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return ports;
|
|
103
|
+
}
|
|
104
|
+
async function getDockerPublishedTcpPorts() {
|
|
105
|
+
return await new Promise((resolve) => {
|
|
106
|
+
let settled = false;
|
|
107
|
+
const stdoutChunks = [];
|
|
108
|
+
const finish = (ports) => {
|
|
109
|
+
if (settled) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
settled = true;
|
|
113
|
+
resolve(ports);
|
|
114
|
+
};
|
|
115
|
+
const child = spawn('docker', ['ps', '--format', '{{.Ports}}']);
|
|
116
|
+
child.stdout?.on('data', (chunk) => {
|
|
117
|
+
stdoutChunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
118
|
+
});
|
|
119
|
+
child.once('error', () => {
|
|
120
|
+
finish(new Set());
|
|
121
|
+
});
|
|
122
|
+
child.once('close', (code) => {
|
|
123
|
+
if (code !== 0) {
|
|
124
|
+
finish(new Set());
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
finish(parseDockerPublishedTcpPorts(Buffer.concat(stdoutChunks).toString('utf8')));
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async function allocateAvailableTcpPort() {
|
|
132
|
+
return await new Promise((resolve, reject) => {
|
|
133
|
+
const server = net.createServer();
|
|
134
|
+
server.once('error', reject);
|
|
135
|
+
server.listen(0, '127.0.0.1', () => {
|
|
136
|
+
const address = server.address();
|
|
137
|
+
const port = address && typeof address === 'object'
|
|
138
|
+
? address.port
|
|
139
|
+
: undefined;
|
|
140
|
+
if (!port) {
|
|
141
|
+
server.close(() => {
|
|
142
|
+
reject(new Error(translateCli('validators.tcpPort.allocateFailed')));
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
server.close((error) => {
|
|
147
|
+
if (error) {
|
|
148
|
+
reject(error);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
resolve(String(port));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export async function findAvailableTcpPort() {
|
|
157
|
+
const dockerPorts = await getDockerPublishedTcpPorts();
|
|
158
|
+
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
159
|
+
const candidate = await allocateAvailableTcpPort();
|
|
160
|
+
if (!dockerPorts.has(Number.parseInt(candidate, 10))) {
|
|
161
|
+
return candidate;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw new Error(translateCli('validators.tcpPort.allocateNotDockerPublished'));
|
|
165
|
+
}
|
|
166
|
+
export async function validateAvailableTcpPort(value) {
|
|
167
|
+
const raw = String(value ?? '').trim();
|
|
168
|
+
if (raw === '') {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
const formatError = validateTcpPort(raw);
|
|
172
|
+
if (formatError) {
|
|
173
|
+
return formatError;
|
|
174
|
+
}
|
|
175
|
+
const port = parseTcpPort(raw);
|
|
176
|
+
const available = await canListenOnTcpPort(port);
|
|
177
|
+
if (!available) {
|
|
178
|
+
return translateCli('validators.tcpPort.alreadyInUse', { port });
|
|
179
|
+
}
|
|
180
|
+
const dockerPorts = await getDockerPublishedTcpPorts();
|
|
181
|
+
if (dockerPorts.has(port)) {
|
|
182
|
+
return translateCli('validators.tcpPort.alreadyInUseByDocker', { port });
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|