@nocobase/cli 1.8.0-alpha.10 → 1.8.0-alpha.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "1.8.0-alpha.10",
3
+ "version": "1.8.0-alpha.11",
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.10",
11
+ "@nocobase/app": "1.8.0-alpha.11",
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.10"
30
+ "@nocobase/devtools": "1.8.0-alpha.11"
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": "31b2895b847f6998492e20bb923c2791e896951d"
37
+ "gitHead": "ca21882066ded53ac54e7340d3f5fdd2d4275a76"
38
38
  }
@@ -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;
@@ -175,6 +175,9 @@ class PackageManager {
175
175
  });
176
176
  this.token = res1.data.token;
177
177
  } catch (error) {
178
+ if (error?.response?.data?.error === 'license not valid') {
179
+ showLicenseInfo(LicenseKeyError.notValid);
180
+ }
178
181
  console.error(chalk.redBright(`Login failed: ${this.baseURL}`));
179
182
  }
180
183
  }
@@ -249,7 +252,7 @@ module.exports = (cli) => {
249
252
  NOCOBASE_PKG_USERNAME,
250
253
  NOCOBASE_PKG_PASSWORD,
251
254
  } = process.env;
252
- const { accessKeyId, accessKeySecret } = getAccessKeyPair();
255
+ const { accessKeyId, accessKeySecret } = await getAccessKeyPair();
253
256
  if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
254
257
  return;
255
258
  }
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 _ = require('lodash');
22
23
 
23
24
  exports.isPackageValid = (pkg) => {
24
25
  try {
@@ -490,20 +491,75 @@ exports.generatePlugins = function () {
490
491
  }
491
492
  };
492
493
 
493
- exports.getAccessKeyPair = function () {
494
+ exports.getAccessKeyPair = async function () {
494
495
  const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
495
496
  if (!fs.existsSync(keyFile)) {
496
- console.log(chalk.yellow('license-key file not found', keyFile));
497
+ // showLicenseInfo(LicenseKeyError.notExist);
497
498
  return {};
498
499
  }
500
+
501
+ let keyData = {};
499
502
  try {
500
503
  const str = fs.readFileSync(keyFile, 'utf-8');
501
504
  const keyDataStr = keyDecrypt(str);
502
- const keyData = JSON.parse(keyDataStr);
503
- const { accessKeyId, accessKeySecret } = keyData;
504
- return { accessKeyId, accessKeySecret };
505
+ keyData = JSON.parse(keyDataStr);
505
506
  } catch (error) {
506
- console.log(chalk.yellow('Key parse failed, please check your key'));
507
+ showLicenseInfo(LicenseKeyError.parseFailed);
508
+ return {};
509
+ }
510
+
511
+ const currentEnv = await getEnvAsync();
512
+ if (!_.isEqual(_.omit(keyData?.instanceData, ['timestamp']), _.omit(currentEnv, ['timestamp']))) {
513
+ showLicenseInfo(LicenseKeyError.notMatch);
507
514
  return {};
508
515
  }
516
+
517
+ const { accessKeyId, accessKeySecret } = keyData;
518
+ return { accessKeyId, accessKeySecret };
519
+ };
520
+
521
+ const LicenseKeyError = {
522
+ notExist: {
523
+ title: 'License key not exist',
524
+ content:
525
+ '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.',
526
+ },
527
+ parseFailed: {
528
+ title: 'License key parse failed',
529
+ content: 'Please check your license key, or regenerate the license key on the service platform.',
530
+ },
531
+ notMatch: {
532
+ title: 'License key not matched',
533
+ content:
534
+ '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.',
535
+ },
536
+ notValid: {
537
+ title: 'License key not valid',
538
+ content:
539
+ '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.',
540
+ },
509
541
  };
542
+
543
+ exports.LicenseKeyError = LicenseKeyError;
544
+
545
+ function showLicenseInfo({ title, content }) {
546
+ const rows = [];
547
+ const length = 80;
548
+ let row = '';
549
+ content.split(' ').forEach((word) => {
550
+ if (row.length + word.length > length) {
551
+ rows.push(row);
552
+ row = '';
553
+ }
554
+ row += word + ' ';
555
+ });
556
+ if (row) {
557
+ rows.push(row);
558
+ }
559
+ console.log(Array(length).fill('-').join(''));
560
+ console.log(chalk.yellow(title));
561
+ console.log(chalk.yellow(rows.join('\n')));
562
+ console.log(Array(length).fill('-').join(''));
563
+ }
564
+
565
+ exports.showLicenseInfo = showLicenseInfo;