@nocobase/cli 2.0.0-alpha.6 → 2.0.0-alpha.61
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/nocobase.conf.tpl +3 -0
- package/package.json +5 -5
- package/src/commands/instance-id.js +5 -4
- package/src/commands/perf.js +2 -2
- package/src/commands/pkg.js +37 -16
- package/src/commands/start.js +25 -23
- package/src/commands/test.js +1 -1
- package/src/license.js +76 -0
- package/src/logger.js +75 -0
- package/src/util.js +0 -88
- package/templates/plugin/package.json.tpl +3 -3
package/nocobase.conf.tpl
CHANGED
|
@@ -73,7 +73,10 @@ server {
|
|
|
73
73
|
proxy_set_header Upgrade $http_upgrade;
|
|
74
74
|
proxy_set_header Connection 'upgrade';
|
|
75
75
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
76
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
76
77
|
proxy_set_header Host $host;
|
|
78
|
+
proxy_set_header Referer $http_referer;
|
|
79
|
+
proxy_set_header User-Agent $http_user_agent;
|
|
77
80
|
add_header Cache-Control 'no-cache, no-store';
|
|
78
81
|
proxy_cache_bypass $http_upgrade;
|
|
79
82
|
proxy_connect_timeout 600;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.61",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "2.0.0-alpha.
|
|
12
|
-
"@nocobase/license-kit": "^0.
|
|
11
|
+
"@nocobase/app": "2.0.0-alpha.61",
|
|
12
|
+
"@nocobase/license-kit": "^0.3.5",
|
|
13
13
|
"@types/fs-extra": "^11.0.1",
|
|
14
14
|
"@umijs/utils": "3.5.20",
|
|
15
15
|
"chalk": "^4.1.1",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"tsx": "^4.19.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@nocobase/devtools": "2.0.0-alpha.
|
|
30
|
+
"@nocobase/devtools": "2.0.0-alpha.61"
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
34
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
35
35
|
"directory": "packages/core/cli"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f48b11fd3842abbbbc7bbeb751943d80bc5134bb"
|
|
38
38
|
}
|
|
@@ -13,6 +13,7 @@ const { run, isDev } = require('../util');
|
|
|
13
13
|
const { getInstanceIdAsync } = require('@nocobase/license-kit');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
const fs = require('fs');
|
|
16
|
+
const { logger } = require('../logger');
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
*
|
|
@@ -24,11 +25,11 @@ module.exports = (cli) => {
|
|
|
24
25
|
.description('Generate InstanceID')
|
|
25
26
|
.option('--force', 'Force generate InstanceID')
|
|
26
27
|
.action(async (options) => {
|
|
27
|
-
|
|
28
|
+
logger.info('Generating InstanceID...');
|
|
28
29
|
const dir = path.resolve(process.cwd(), 'storage/.license');
|
|
29
30
|
const filePath = path.resolve(dir, 'instance-id');
|
|
30
31
|
if (fs.existsSync(filePath) && !options.force) {
|
|
31
|
-
|
|
32
|
+
logger.info('InstanceID already exists at ' + filePath);
|
|
32
33
|
return;
|
|
33
34
|
} else {
|
|
34
35
|
if (!fs.existsSync(dir)) {
|
|
@@ -37,9 +38,9 @@ module.exports = (cli) => {
|
|
|
37
38
|
try {
|
|
38
39
|
const instanceId = await getInstanceIdAsync();
|
|
39
40
|
fs.writeFileSync(filePath, instanceId + '\n');
|
|
40
|
-
|
|
41
|
+
logger.info(`InstanceID saved to ${filePath}`);
|
|
41
42
|
} catch (e) {
|
|
42
|
-
|
|
43
|
+
logger.error('Failed to generate InstanceID', e.message || e);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
});
|
package/src/commands/perf.js
CHANGED
|
@@ -53,8 +53,8 @@ module.exports = (cli) => {
|
|
|
53
53
|
dotenv.config({ path: envFilePath, override: true });
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
if (!process.env.
|
|
57
|
-
throw new Error('Please set
|
|
56
|
+
if (!process.env.TARGET_ORIGIN) {
|
|
57
|
+
throw new Error('Please set TARGET_ORIGIN in environment variables or in .env.perf file');
|
|
58
58
|
}
|
|
59
59
|
const args = command.args.filter((arg) => arg !== file);
|
|
60
60
|
await run(`k6`, ['run', f, ...(args.length ? ['--', ...args] : [])]);
|
package/src/commands/pkg.js
CHANGED
|
@@ -14,8 +14,8 @@ const zlib = require('zlib');
|
|
|
14
14
|
const tar = require('tar');
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
|
|
17
|
-
const
|
|
18
|
-
const {
|
|
17
|
+
const { getAccessKeyPair, showLicenseInfo, LicenseKeyError } = require('../license');
|
|
18
|
+
const { logger } = require('../logger');
|
|
19
19
|
|
|
20
20
|
class Package {
|
|
21
21
|
data;
|
|
@@ -78,7 +78,7 @@ class Package {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (!this.data.versions[version]) {
|
|
81
|
-
|
|
81
|
+
logger.error(`Download failed: ${this.packageName}@${version} package does not exist`);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
return [version, this.data.versions[version].dist.tarball];
|
|
@@ -93,10 +93,18 @@ class Package {
|
|
|
93
93
|
if (await fs.exists(file)) {
|
|
94
94
|
return true;
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async isDepPackage() {
|
|
100
|
+
const pkg1 = path.resolve(process.cwd(), 'node_modules', this.packageName, 'package.json');
|
|
101
|
+
const pkg2 = path.resolve(process.cwd(), process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
|
|
102
|
+
if ((await fs.exists(pkg1)) && (await fs.exists(pkg2))) {
|
|
103
|
+
const readPath1 = fs.realpathSync(pkg1);
|
|
104
|
+
const readPath2 = fs.realpathSync(pkg2);
|
|
105
|
+
if (readPath1 !== readPath2) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
100
108
|
}
|
|
101
109
|
return false;
|
|
102
110
|
}
|
|
@@ -114,7 +122,11 @@ class Package {
|
|
|
114
122
|
|
|
115
123
|
async download(options = {}) {
|
|
116
124
|
if (await this.isDevPackage()) {
|
|
117
|
-
|
|
125
|
+
logger.info(`Skipped: ${this.packageName} is dev package`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (await this.isDepPackage()) {
|
|
129
|
+
logger.info(`Skipped: ${this.packageName} is dependency package`);
|
|
118
130
|
return;
|
|
119
131
|
}
|
|
120
132
|
if (await this.isDownloaded(options.version)) {
|
|
@@ -122,7 +134,7 @@ class Package {
|
|
|
122
134
|
}
|
|
123
135
|
await this.getInfo();
|
|
124
136
|
if (!this.data) {
|
|
125
|
-
|
|
137
|
+
logger.error(`Download failed: ${this.packageName} package does not exist`);
|
|
126
138
|
return;
|
|
127
139
|
}
|
|
128
140
|
try {
|
|
@@ -146,7 +158,7 @@ class Package {
|
|
|
146
158
|
.on('finish', resolve)
|
|
147
159
|
.on('error', reject);
|
|
148
160
|
});
|
|
149
|
-
|
|
161
|
+
logger.info(`Downloaded: ${this.packageName}@${version}`);
|
|
150
162
|
} catch (error) {
|
|
151
163
|
if (error?.response?.data && typeof error?.response?.data?.pipe === 'function') {
|
|
152
164
|
let errorMessageBuffer = '';
|
|
@@ -155,11 +167,11 @@ class Package {
|
|
|
155
167
|
});
|
|
156
168
|
error.response.data.on?.('end', () => {
|
|
157
169
|
if (error.response.status === 403) {
|
|
158
|
-
|
|
170
|
+
logger.error('You do not have permission to download this package version.');
|
|
159
171
|
}
|
|
160
172
|
});
|
|
161
173
|
}
|
|
162
|
-
|
|
174
|
+
logger.error(`Download failed: ${this.packageName}`);
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
}
|
|
@@ -190,12 +202,13 @@ class PackageManager {
|
|
|
190
202
|
responseType: 'json',
|
|
191
203
|
});
|
|
192
204
|
this.token = res1.data.token;
|
|
205
|
+
logger.info('Login success');
|
|
193
206
|
} catch (error) {
|
|
194
207
|
if (error?.response?.data?.error === 'license not valid') {
|
|
195
208
|
showLicenseInfo(LicenseKeyError.notValid);
|
|
196
209
|
}
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
logger.error(`Login failed: ${this.baseURL}`);
|
|
211
|
+
logger.error(error?.message || error);
|
|
199
212
|
}
|
|
200
213
|
}
|
|
201
214
|
|
|
@@ -232,7 +245,7 @@ class PackageManager {
|
|
|
232
245
|
const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName);
|
|
233
246
|
const r = await fs.exists(dir);
|
|
234
247
|
if (r) {
|
|
235
|
-
|
|
248
|
+
logger.info(`Removed: ${packageName}`);
|
|
236
249
|
await fs.rm(dir, { force: true, recursive: true });
|
|
237
250
|
}
|
|
238
251
|
}
|
|
@@ -248,9 +261,11 @@ class PackageManager {
|
|
|
248
261
|
await this.removePackage(pkg);
|
|
249
262
|
}
|
|
250
263
|
}
|
|
264
|
+
logger.info(`Download plugins...`);
|
|
251
265
|
for (const pkg of licensed_plugins) {
|
|
252
266
|
await this.getPackage(pkg).download({ version });
|
|
253
267
|
}
|
|
268
|
+
logger.info('Download plugins done');
|
|
254
269
|
}
|
|
255
270
|
}
|
|
256
271
|
|
|
@@ -274,8 +289,14 @@ module.exports = (cli) => {
|
|
|
274
289
|
try {
|
|
275
290
|
({ accessKeyId, accessKeySecret } = await getAccessKeyPair());
|
|
276
291
|
} catch (e) {
|
|
292
|
+
// logger.error('Get AccessKey Pair error', e);
|
|
277
293
|
return;
|
|
278
294
|
}
|
|
295
|
+
if (NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD && !accessKeyId && !accessKeySecret) {
|
|
296
|
+
logger.warn(
|
|
297
|
+
'NOCOBASE_PKG_USERNAME and NOCOBASE_PKG_PASSWORD will be deprecated in future versions. Please log in to NocoBase Service and refer to the documentation to learn how to install and upgrade commercial plugins.\n',
|
|
298
|
+
);
|
|
299
|
+
}
|
|
279
300
|
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
|
|
280
301
|
return;
|
|
281
302
|
}
|
|
@@ -290,6 +311,6 @@ module.exports = (cli) => {
|
|
|
290
311
|
await createStoragePluginsSymlink();
|
|
291
312
|
});
|
|
292
313
|
pkg.command('export-all').action(async () => {
|
|
293
|
-
|
|
314
|
+
logger.info('Todo...');
|
|
294
315
|
});
|
|
295
316
|
};
|
package/src/commands/start.js
CHANGED
|
@@ -56,32 +56,34 @@ module.exports = (cli) => {
|
|
|
56
56
|
await downloadPro();
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
depth: 1, // 只监听第一层目录
|
|
65
|
-
});
|
|
59
|
+
if (process.env.NO_WATCH_PLUGINS === true || process.env.NO_WATCH_PLUGINS === 'true') {
|
|
60
|
+
const restart = _.debounce(async () => {
|
|
61
|
+
console.log('restarting...');
|
|
62
|
+
await run('yarn', ['nocobase', 'pm2-restart']);
|
|
63
|
+
}, 500);
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.on('ready', () => {
|
|
74
|
-
isReady = true;
|
|
75
|
-
})
|
|
76
|
-
.on('addDir', async (pathname) => {
|
|
77
|
-
if (!isReady) return;
|
|
78
|
-
restart();
|
|
79
|
-
})
|
|
80
|
-
.on('unlinkDir', async (pathname) => {
|
|
81
|
-
if (!isReady) return;
|
|
82
|
-
restart();
|
|
65
|
+
const watcher = chokidar.watch('./storage/plugins/**/*', {
|
|
66
|
+
cwd: process.cwd(),
|
|
67
|
+
ignoreInitial: true,
|
|
68
|
+
ignored: /(^|[\/\\])\../, // 忽略隐藏文件
|
|
69
|
+
persistent: true,
|
|
70
|
+
depth: 1, // 只监听第一层目录
|
|
83
71
|
});
|
|
84
72
|
|
|
73
|
+
watcher
|
|
74
|
+
.on('ready', () => {
|
|
75
|
+
isReady = true;
|
|
76
|
+
})
|
|
77
|
+
.on('addDir', async (pathname) => {
|
|
78
|
+
if (!isReady) return;
|
|
79
|
+
restart();
|
|
80
|
+
})
|
|
81
|
+
.on('unlinkDir', async (pathname) => {
|
|
82
|
+
if (!isReady) return;
|
|
83
|
+
restart();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
85
87
|
if (opts.port) {
|
|
86
88
|
process.env.APP_PORT = opts.port;
|
|
87
89
|
}
|
package/src/commands/test.js
CHANGED
|
@@ -54,7 +54,7 @@ function addTestCommand(name, cli) {
|
|
|
54
54
|
const first = paths?.[0];
|
|
55
55
|
if (!process.env.TEST_ENV && first) {
|
|
56
56
|
const key = first.split(path.sep).join('/');
|
|
57
|
-
if (key.includes('/client/') || key.includes('/flow-engine/')) {
|
|
57
|
+
if (key.includes('/client/') || key.includes('/client-v2/') || key.includes('/flow-engine/')) {
|
|
58
58
|
process.env.TEST_ENV = 'client-side';
|
|
59
59
|
} else {
|
|
60
60
|
process.env.TEST_ENV = 'server-side';
|
package/src/license.js
ADDED
|
@@ -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
|
+
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const { resolve } = require('path');
|
|
12
|
+
const fs = require('fs-extra');
|
|
13
|
+
const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
|
|
14
|
+
const { isEnvMatch } = require('@nocobase/plugin-license/utils/env');
|
|
15
|
+
const { logger } = require('./logger');
|
|
16
|
+
const { pick } = require('lodash');
|
|
17
|
+
|
|
18
|
+
exports.getAccessKeyPair = async function () {
|
|
19
|
+
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
|
20
|
+
if (!fs.existsSync(keyFile)) {
|
|
21
|
+
logger.error('License key not found');
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
logger.info('License key found');
|
|
25
|
+
let keyData = {};
|
|
26
|
+
try {
|
|
27
|
+
const str = fs.readFileSync(keyFile, 'utf-8');
|
|
28
|
+
const keyDataStr = keyDecrypt(str);
|
|
29
|
+
keyData = JSON.parse(keyDataStr);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
showLicenseInfo(LicenseKeyError.parseFailed);
|
|
32
|
+
throw new Error(LicenseKeyError.parseFailed.title);
|
|
33
|
+
}
|
|
34
|
+
const env = await getEnvAsync();
|
|
35
|
+
const isEnvMatched = await isEnvMatch(env, keyData);
|
|
36
|
+
if (!isEnvMatched) {
|
|
37
|
+
showLicenseInfo({
|
|
38
|
+
...LicenseKeyError.notMatch,
|
|
39
|
+
env,
|
|
40
|
+
});
|
|
41
|
+
throw new Error(LicenseKeyError.notMatch.title);
|
|
42
|
+
}
|
|
43
|
+
const { accessKeyId, accessKeySecret } = keyData;
|
|
44
|
+
return { accessKeyId, accessKeySecret };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const LicenseKeyError = {
|
|
48
|
+
notExist: {
|
|
49
|
+
title: 'License key not found',
|
|
50
|
+
content:
|
|
51
|
+
'Please go to the license settings page to obtain the Instance ID for the current environment, and then generate the license key on the service platform.',
|
|
52
|
+
},
|
|
53
|
+
parseFailed: {
|
|
54
|
+
title: 'Invalid license key format',
|
|
55
|
+
content: 'Please check your license key, or regenerate the license key on the service platform.',
|
|
56
|
+
},
|
|
57
|
+
notMatch: {
|
|
58
|
+
title: 'License key not match current environment',
|
|
59
|
+
content:
|
|
60
|
+
'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
|
|
61
|
+
},
|
|
62
|
+
notValid: {
|
|
63
|
+
title: 'Invalid license key',
|
|
64
|
+
content:
|
|
65
|
+
'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.LicenseKeyError = LicenseKeyError;
|
|
70
|
+
|
|
71
|
+
function showLicenseInfo({ title, content, env }) {
|
|
72
|
+
logger.error(title + '. ' + content);
|
|
73
|
+
logger.error('Current environment', pick(env, ['sys', 'osVer', 'db']));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.showLicenseInfo = showLicenseInfo;
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const winston = require('winston');
|
|
13
|
+
require('winston-daily-rotate-file');
|
|
14
|
+
|
|
15
|
+
function ensureDir(dir) {
|
|
16
|
+
if (!fs.existsSync(dir)) {
|
|
17
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createSystemLogger({ dirname, filename, defaultMeta = {} }) {
|
|
22
|
+
ensureDir(dirname);
|
|
23
|
+
|
|
24
|
+
const commonFormat = winston.format.combine(
|
|
25
|
+
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
26
|
+
winston.format.printf((info) => {
|
|
27
|
+
const meta = info.meta ? JSON.stringify(info.meta) : '';
|
|
28
|
+
return `${info.timestamp} [${info.level}] ${info.message} ${meta}`;
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const consoleFormat = winston.format.combine(winston.format.colorize(), commonFormat);
|
|
33
|
+
|
|
34
|
+
const fileTransport = new winston.transports.DailyRotateFile({
|
|
35
|
+
dirname,
|
|
36
|
+
filename: `${filename}_%DATE%.log`,
|
|
37
|
+
datePattern: 'YYYY-MM-DD',
|
|
38
|
+
zippedArchive: false,
|
|
39
|
+
format: commonFormat,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const consoleTransport = new winston.transports.Console({
|
|
43
|
+
format: consoleFormat,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const logger = winston.createLogger({
|
|
47
|
+
level: 'info',
|
|
48
|
+
transports: [consoleTransport, fileTransport],
|
|
49
|
+
defaultMeta,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const wrap = (level) => (message, meta) => {
|
|
53
|
+
logger.log({ level, message, meta });
|
|
54
|
+
return logger;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
info: wrap('info'),
|
|
59
|
+
warn: wrap('warn'),
|
|
60
|
+
error: wrap('error'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const getLoggerFilePath = (...paths) => {
|
|
65
|
+
return path.resolve(process.env.LOGGER_BASE_PATH || path.resolve(process.cwd(), 'storage', 'logs'), ...paths);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const logger = createSystemLogger({
|
|
69
|
+
dirname: getLoggerFilePath('main'),
|
|
70
|
+
filename: 'system',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
logger,
|
|
75
|
+
};
|
package/src/util.js
CHANGED
|
@@ -18,8 +18,6 @@ const dotenv = require('dotenv');
|
|
|
18
18
|
const fs = require('fs-extra');
|
|
19
19
|
const os = require('os');
|
|
20
20
|
const moment = require('moment-timezone');
|
|
21
|
-
const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
|
|
22
|
-
const omit = require('lodash/omit');
|
|
23
21
|
|
|
24
22
|
exports.isPackageValid = (pkg) => {
|
|
25
23
|
try {
|
|
@@ -490,89 +488,3 @@ exports.generatePlugins = function () {
|
|
|
490
488
|
return;
|
|
491
489
|
}
|
|
492
490
|
};
|
|
493
|
-
|
|
494
|
-
async function isEnvMatch(keyData) {
|
|
495
|
-
const env = await getEnvAsync();
|
|
496
|
-
if (env?.container?.id && keyData?.instanceData?.container?.id) {
|
|
497
|
-
return (
|
|
498
|
-
JSON.stringify(omit(env, ['timestamp', 'container', 'hostname', 'mac'])) ===
|
|
499
|
-
JSON.stringify(omit(keyData?.instanceData, ['timestamp', 'container', 'hostname', 'mac']))
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
return (
|
|
503
|
-
JSON.stringify(omit(env, ['timestamp', 'mac'])) ===
|
|
504
|
-
JSON.stringify(omit(keyData?.instanceData, ['timestamp', 'mac']))
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
exports.getAccessKeyPair = async function () {
|
|
509
|
-
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
|
510
|
-
if (!fs.existsSync(keyFile)) {
|
|
511
|
-
return {};
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
let keyData = {};
|
|
515
|
-
try {
|
|
516
|
-
const str = fs.readFileSync(keyFile, 'utf-8');
|
|
517
|
-
const keyDataStr = keyDecrypt(str);
|
|
518
|
-
keyData = JSON.parse(keyDataStr);
|
|
519
|
-
} catch (error) {
|
|
520
|
-
showLicenseInfo(LicenseKeyError.parseFailed);
|
|
521
|
-
throw new Error(LicenseKeyError.parseFailed.title);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const isEnvMatched = await isEnvMatch(keyData);
|
|
525
|
-
if (!isEnvMatched) {
|
|
526
|
-
showLicenseInfo(LicenseKeyError.notMatch);
|
|
527
|
-
throw new Error(LicenseKeyError.notMatch.title);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const { accessKeyId, accessKeySecret } = keyData;
|
|
531
|
-
return { accessKeyId, accessKeySecret };
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
const LicenseKeyError = {
|
|
535
|
-
notExist: {
|
|
536
|
-
title: 'License key not found',
|
|
537
|
-
content:
|
|
538
|
-
'Please go to the license settings page to obtain the Instance ID for the current environment, and then generate the license key on the service platform.',
|
|
539
|
-
},
|
|
540
|
-
parseFailed: {
|
|
541
|
-
title: 'Invalid license key format',
|
|
542
|
-
content: 'Please check your license key, or regenerate the license key on the service platform.',
|
|
543
|
-
},
|
|
544
|
-
notMatch: {
|
|
545
|
-
title: 'License key mismatch',
|
|
546
|
-
content:
|
|
547
|
-
'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
|
|
548
|
-
},
|
|
549
|
-
notValid: {
|
|
550
|
-
title: 'Invalid license key',
|
|
551
|
-
content:
|
|
552
|
-
'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
|
|
553
|
-
},
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
exports.LicenseKeyError = LicenseKeyError;
|
|
557
|
-
|
|
558
|
-
function showLicenseInfo({ title, content }) {
|
|
559
|
-
const rows = [];
|
|
560
|
-
const length = 80;
|
|
561
|
-
let row = '';
|
|
562
|
-
content.split(' ').forEach((word) => {
|
|
563
|
-
if (row.length + word.length > length) {
|
|
564
|
-
rows.push(row);
|
|
565
|
-
row = '';
|
|
566
|
-
}
|
|
567
|
-
row += word + ' ';
|
|
568
|
-
});
|
|
569
|
-
if (row) {
|
|
570
|
-
rows.push(row);
|
|
571
|
-
}
|
|
572
|
-
console.log(Array(length).fill('-').join(''));
|
|
573
|
-
console.log(chalk.yellow(title));
|
|
574
|
-
console.log(chalk.yellow(rows.join('\n')));
|
|
575
|
-
console.log(Array(length).fill('-').join(''));
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
exports.showLicenseInfo = showLicenseInfo;
|