@nocobase/cli 2.1.0-beta.29 → 2.1.0-beta.32
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/README.md +14 -0
- package/README.zh-CN.md +14 -0
- package/bin/run.js +3 -0
- package/bin/session-env.js +27 -0
- package/dist/commands/app/down.js +47 -9
- package/dist/commands/app/logs.js +17 -0
- package/dist/commands/app/restart.js +23 -1
- package/dist/commands/app/start.js +17 -0
- package/dist/commands/app/stop.js +17 -0
- package/dist/commands/app/upgrade.js +22 -2
- package/dist/commands/db/check.js +6 -4
- package/dist/commands/db/ps.js +1 -1
- package/dist/commands/env/add.js +3 -2
- package/dist/commands/env/auth.js +1 -1
- package/dist/commands/env/current.js +21 -0
- package/dist/commands/env/info.js +4 -3
- package/dist/commands/env/list.js +8 -14
- package/dist/commands/env/remove.js +2 -2
- package/dist/commands/env/status.js +90 -0
- package/dist/commands/env/update.js +1 -1
- package/dist/commands/env/use.js +11 -1
- package/dist/commands/install.js +10 -4
- package/dist/commands/license/activate.js +20 -24
- package/dist/commands/license/id.js +17 -2
- package/dist/commands/license/plugins/clean.js +17 -2
- package/dist/commands/license/plugins/list.js +17 -2
- package/dist/commands/license/plugins/sync.js +22 -5
- package/dist/commands/license/shared.js +15 -6
- package/dist/commands/license/status.js +17 -2
- package/dist/commands/plugin/disable.js +25 -4
- package/dist/commands/plugin/enable.js +25 -4
- package/dist/commands/plugin/list.js +25 -4
- package/dist/commands/session/id.js +24 -0
- package/dist/commands/session/remove.js +57 -0
- package/dist/commands/session/setup.js +62 -0
- package/dist/commands/source/dev.js +19 -1
- package/dist/commands/source/download.js +10 -8
- package/dist/lib/app-managed-resources.js +5 -3
- package/dist/lib/app-runtime.js +1 -1
- package/dist/lib/auth-store.js +28 -11
- package/dist/lib/docker-image.js +37 -0
- package/dist/lib/env-guard.js +61 -0
- package/dist/lib/generated-command.js +16 -0
- package/dist/lib/plugin-storage.js +1 -64
- package/dist/lib/resource-command.js +15 -0
- package/dist/lib/runtime-generator.js +1 -1
- package/dist/lib/session-id.js +17 -0
- package/dist/lib/session-integration.js +703 -0
- package/dist/lib/session-store.js +118 -0
- package/package.json +3 -3
|
@@ -0,0 +1,118 @@
|
|
|
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 { promises as fs } from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { resolveCliHomeDir } from './cli-home.js';
|
|
12
|
+
export function getSessionId() {
|
|
13
|
+
const value = String(process.env.NB_SESSION_ID ?? '').trim();
|
|
14
|
+
return value || undefined;
|
|
15
|
+
}
|
|
16
|
+
function sessionsDir(scope) {
|
|
17
|
+
return path.join(resolveCliHomeDir(scope), 'sessions');
|
|
18
|
+
}
|
|
19
|
+
export function getSessionFilePath(sessionId, scope) {
|
|
20
|
+
return path.join(sessionsDir(scope), `${sessionId}.json`);
|
|
21
|
+
}
|
|
22
|
+
export async function loadSessionState(sessionId, scope) {
|
|
23
|
+
try {
|
|
24
|
+
const content = await fs.readFile(getSessionFilePath(sessionId, scope), 'utf8');
|
|
25
|
+
const parsed = JSON.parse(content);
|
|
26
|
+
return parsed && typeof parsed === 'object' ? parsed : undefined;
|
|
27
|
+
}
|
|
28
|
+
catch (_error) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function saveSessionState(sessionId, state, scope) {
|
|
33
|
+
const filePath = getSessionFilePath(sessionId, scope);
|
|
34
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
35
|
+
await fs.writeFile(filePath, JSON.stringify(state, null, 2));
|
|
36
|
+
}
|
|
37
|
+
export async function deleteSessionState(sessionId, scope) {
|
|
38
|
+
await fs.rm(getSessionFilePath(sessionId, scope), { force: true });
|
|
39
|
+
}
|
|
40
|
+
export async function getSessionCurrentEnv(scope) {
|
|
41
|
+
const sessionId = getSessionId();
|
|
42
|
+
if (!sessionId) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const state = await loadSessionState(sessionId, scope);
|
|
46
|
+
const currentEnv = String(state?.currentEnv ?? '').trim();
|
|
47
|
+
return currentEnv || undefined;
|
|
48
|
+
}
|
|
49
|
+
export async function setSessionCurrentEnv(envName, scope) {
|
|
50
|
+
const sessionId = getSessionId();
|
|
51
|
+
if (!sessionId) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
await saveSessionState(sessionId, {
|
|
55
|
+
currentEnv: envName,
|
|
56
|
+
updatedAt: new Date().toISOString(),
|
|
57
|
+
}, scope);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
export async function clearSessionCurrentEnv(scope) {
|
|
61
|
+
const sessionId = getSessionId();
|
|
62
|
+
if (!sessionId) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
await deleteSessionState(sessionId, scope);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
export async function resolveEffectiveCurrentEnv(validEnvNames, options = {}) {
|
|
69
|
+
const sessionId = getSessionId();
|
|
70
|
+
const normalizedValidNames = validEnvNames.filter(Boolean);
|
|
71
|
+
if (sessionId) {
|
|
72
|
+
const state = await loadSessionState(sessionId, options.scope);
|
|
73
|
+
const sessionEnv = String(state?.currentEnv ?? '').trim();
|
|
74
|
+
if (sessionEnv && normalizedValidNames.includes(sessionEnv)) {
|
|
75
|
+
return sessionEnv;
|
|
76
|
+
}
|
|
77
|
+
if (sessionEnv) {
|
|
78
|
+
const lastEnv = String(options.lastEnv ?? '').trim();
|
|
79
|
+
const fallbackEnv = lastEnv && normalizedValidNames.includes(lastEnv)
|
|
80
|
+
? lastEnv
|
|
81
|
+
: normalizedValidNames[0];
|
|
82
|
+
if (fallbackEnv) {
|
|
83
|
+
await saveSessionState(sessionId, {
|
|
84
|
+
currentEnv: fallbackEnv,
|
|
85
|
+
updatedAt: new Date().toISOString(),
|
|
86
|
+
}, options.scope);
|
|
87
|
+
return fallbackEnv;
|
|
88
|
+
}
|
|
89
|
+
await deleteSessionState(sessionId, options.scope);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const lastEnv = String(options.lastEnv ?? '').trim();
|
|
93
|
+
if (lastEnv && normalizedValidNames.includes(lastEnv)) {
|
|
94
|
+
return lastEnv;
|
|
95
|
+
}
|
|
96
|
+
return normalizedValidNames[0] || 'default';
|
|
97
|
+
}
|
|
98
|
+
export async function cleanupCurrentSessionAfterEnvRemoval(removedEnv, options = {}) {
|
|
99
|
+
const sessionId = getSessionId();
|
|
100
|
+
if (!sessionId) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const state = await loadSessionState(sessionId, options.scope);
|
|
104
|
+
const sessionEnv = String(state?.currentEnv ?? '').trim();
|
|
105
|
+
if (sessionEnv !== removedEnv) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const fallbackEnv = String(options.fallbackEnv ?? '').trim();
|
|
109
|
+
if (fallbackEnv) {
|
|
110
|
+
await saveSessionState(sessionId, {
|
|
111
|
+
currentEnv: fallbackEnv,
|
|
112
|
+
updatedAt: new Date().toISOString(),
|
|
113
|
+
}, options.scope);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
await deleteSessionState(sessionId, options.scope);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.32",
|
|
4
4
|
"description": "NocoBase Command Line Tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/generated/command-registry.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "node ./scripts/clean.mjs",
|
|
9
9
|
"build": "node ./scripts/build.mjs",
|
|
10
|
-
"test": "NB_CLI_ROOT=. TEST_ENV=server-side yarn --cwd ../../.. vitest run packages/core/cli"
|
|
10
|
+
"test": "yarn cross-env NB_CLI_ROOT=. TEST_ENV=server-side yarn --cwd ../../.. vitest run packages/core/cli/src"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"type": "git",
|
|
104
104
|
"url": "git+https://github.com/nocobase/nocobase.git"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "659c5efe992da7118d33c768bbd9e837a2c4716f"
|
|
107
107
|
}
|