@nocobase/cli 1.8.0-alpha.10 → 1.8.0-alpha.12
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/package.json +4 -4
- package/src/commands/pkg.js +22 -2
- package/src/util.js +74 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "1.8.0-alpha.
|
|
3
|
+
"version": "1.8.0-alpha.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "1.8.0-alpha.
|
|
11
|
+
"@nocobase/app": "1.8.0-alpha.12",
|
|
12
12
|
"@nocobase/license-kit": "^0.2.3",
|
|
13
13
|
"@types/fs-extra": "^11.0.1",
|
|
14
14
|
"@umijs/utils": "3.5.20",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"tsx": "^4.19.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@nocobase/devtools": "1.8.0-alpha.
|
|
30
|
+
"@nocobase/devtools": "1.8.0-alpha.12"
|
|
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": "e4c03b505e9d34ca81278ea86b36f3d4a470080d"
|
|
38
38
|
}
|
package/src/commands/pkg.js
CHANGED
|
@@ -15,7 +15,7 @@ const tar = require('tar');
|
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
|
|
17
17
|
const chalk = require('chalk');
|
|
18
|
-
const { getAccessKeyPair } = require('../util');
|
|
18
|
+
const { getAccessKeyPair, showLicenseInfo, LicenseKeyError } = require('../util');
|
|
19
19
|
|
|
20
20
|
class Package {
|
|
21
21
|
data;
|
|
@@ -143,6 +143,17 @@ class Package {
|
|
|
143
143
|
});
|
|
144
144
|
console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
|
|
145
145
|
} catch (error) {
|
|
146
|
+
if (error?.response?.data && typeof error?.response?.data?.pipe === 'function') {
|
|
147
|
+
let errorMessageBuffer = '';
|
|
148
|
+
error.response.data.on?.('data', (chunk) => {
|
|
149
|
+
errorMessageBuffer += chunk.toString('utf8'); // 收集错误信息
|
|
150
|
+
});
|
|
151
|
+
error.response.data.on?.('end', () => {
|
|
152
|
+
if (error.response.status === 403) {
|
|
153
|
+
console.error(chalk.redBright('You do not have permission to download this package version.'));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
146
157
|
console.log(chalk.redBright(`Download failed: ${this.packageName}`));
|
|
147
158
|
}
|
|
148
159
|
}
|
|
@@ -175,6 +186,9 @@ class PackageManager {
|
|
|
175
186
|
});
|
|
176
187
|
this.token = res1.data.token;
|
|
177
188
|
} catch (error) {
|
|
189
|
+
if (error?.response?.data?.error === 'license not valid') {
|
|
190
|
+
showLicenseInfo(LicenseKeyError.notValid);
|
|
191
|
+
}
|
|
178
192
|
console.error(chalk.redBright(`Login failed: ${this.baseURL}`));
|
|
179
193
|
}
|
|
180
194
|
}
|
|
@@ -249,7 +263,13 @@ module.exports = (cli) => {
|
|
|
249
263
|
NOCOBASE_PKG_USERNAME,
|
|
250
264
|
NOCOBASE_PKG_PASSWORD,
|
|
251
265
|
} = process.env;
|
|
252
|
-
|
|
266
|
+
let accessKeyId;
|
|
267
|
+
let accessKeySecret;
|
|
268
|
+
try {
|
|
269
|
+
({ accessKeyId, accessKeySecret } = await getAccessKeyPair());
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
253
273
|
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
|
|
254
274
|
return;
|
|
255
275
|
}
|
package/src/util.js
CHANGED
|
@@ -18,7 +18,8 @@ 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 } = require('@nocobase/license-kit');
|
|
21
|
+
const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
|
|
22
|
+
const omit = require('lodash/omit');
|
|
22
23
|
|
|
23
24
|
exports.isPackageValid = (pkg) => {
|
|
24
25
|
try {
|
|
@@ -490,20 +491,85 @@ exports.generatePlugins = function () {
|
|
|
490
491
|
}
|
|
491
492
|
};
|
|
492
493
|
|
|
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'])) ===
|
|
499
|
+
JSON.stringify(omit(keyData?.instanceData, ['timestamp', 'container', 'hostname']))
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return JSON.stringify(omit(env, ['timestamp'])) === JSON.stringify(omit(keyData?.instanceData, ['timestamp']));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
exports.getAccessKeyPair = async function () {
|
|
494
506
|
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
|
495
507
|
if (!fs.existsSync(keyFile)) {
|
|
496
|
-
console.log(chalk.yellow('license-key file not found', keyFile));
|
|
497
508
|
return {};
|
|
498
509
|
}
|
|
510
|
+
|
|
511
|
+
let keyData = {};
|
|
499
512
|
try {
|
|
500
513
|
const str = fs.readFileSync(keyFile, 'utf-8');
|
|
501
514
|
const keyDataStr = keyDecrypt(str);
|
|
502
|
-
|
|
503
|
-
const { accessKeyId, accessKeySecret } = keyData;
|
|
504
|
-
return { accessKeyId, accessKeySecret };
|
|
515
|
+
keyData = JSON.parse(keyDataStr);
|
|
505
516
|
} catch (error) {
|
|
506
|
-
|
|
507
|
-
|
|
517
|
+
showLicenseInfo(LicenseKeyError.parseFailed);
|
|
518
|
+
throw new Error(LicenseKeyError.parseFailed.title);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const isEnvMatched = await isEnvMatch(keyData);
|
|
522
|
+
if (!isEnvMatched) {
|
|
523
|
+
showLicenseInfo(LicenseKeyError.notMatch);
|
|
524
|
+
throw new Error(LicenseKeyError.notMatch.title);
|
|
508
525
|
}
|
|
526
|
+
|
|
527
|
+
const { accessKeyId, accessKeySecret } = keyData;
|
|
528
|
+
return { accessKeyId, accessKeySecret };
|
|
509
529
|
};
|
|
530
|
+
|
|
531
|
+
const LicenseKeyError = {
|
|
532
|
+
notExist: {
|
|
533
|
+
title: 'License key not found',
|
|
534
|
+
content:
|
|
535
|
+
'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.',
|
|
536
|
+
},
|
|
537
|
+
parseFailed: {
|
|
538
|
+
title: 'Invalid license key format',
|
|
539
|
+
content: 'Please check your license key, or regenerate the license key on the service platform.',
|
|
540
|
+
},
|
|
541
|
+
notMatch: {
|
|
542
|
+
title: 'License key mismatch',
|
|
543
|
+
content:
|
|
544
|
+
'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.',
|
|
545
|
+
},
|
|
546
|
+
notValid: {
|
|
547
|
+
title: 'Invalid license key',
|
|
548
|
+
content:
|
|
549
|
+
'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.',
|
|
550
|
+
},
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
exports.LicenseKeyError = LicenseKeyError;
|
|
554
|
+
|
|
555
|
+
function showLicenseInfo({ title, content }) {
|
|
556
|
+
const rows = [];
|
|
557
|
+
const length = 80;
|
|
558
|
+
let row = '';
|
|
559
|
+
content.split(' ').forEach((word) => {
|
|
560
|
+
if (row.length + word.length > length) {
|
|
561
|
+
rows.push(row);
|
|
562
|
+
row = '';
|
|
563
|
+
}
|
|
564
|
+
row += word + ' ';
|
|
565
|
+
});
|
|
566
|
+
if (row) {
|
|
567
|
+
rows.push(row);
|
|
568
|
+
}
|
|
569
|
+
console.log(Array(length).fill('-').join(''));
|
|
570
|
+
console.log(chalk.yellow(title));
|
|
571
|
+
console.log(chalk.yellow(rows.join('\n')));
|
|
572
|
+
console.log(Array(length).fill('-').join(''));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
exports.showLicenseInfo = showLicenseInfo;
|