@nocobase/cli 1.7.19 → 1.8.0-alpha.10
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 +5 -4
- package/src/commands/index.js +2 -0
- package/src/commands/instance-id.js +46 -0
- package/src/commands/pkg.js +6 -2
- package/src/commands/view-license-key.js +44 -0
- package/src/util.js +24 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"nocobase": "./bin/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@nocobase/app": "1.
|
|
11
|
+
"@nocobase/app": "1.8.0-alpha.10",
|
|
12
|
+
"@nocobase/license-kit": "^0.2.3",
|
|
12
13
|
"@types/fs-extra": "^11.0.1",
|
|
13
14
|
"@umijs/utils": "3.5.20",
|
|
14
15
|
"chalk": "^4.1.1",
|
|
@@ -26,12 +27,12 @@
|
|
|
26
27
|
"tsx": "^4.19.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@nocobase/devtools": "1.
|
|
30
|
+
"@nocobase/devtools": "1.8.0-alpha.10"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|
|
32
33
|
"type": "git",
|
|
33
34
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
34
35
|
"directory": "packages/core/cli"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "31b2895b847f6998492e20bb923c2791e896951d"
|
|
37
38
|
}
|
package/src/commands/index.js
CHANGED
|
@@ -35,6 +35,8 @@ module.exports = (cli) => {
|
|
|
35
35
|
require('./upgrade')(cli);
|
|
36
36
|
require('./postinstall')(cli);
|
|
37
37
|
require('./pkg')(cli);
|
|
38
|
+
require('./instance-id')(cli);
|
|
39
|
+
require('./view-license-key')(cli);
|
|
38
40
|
if (isPackageValid('@umijs/utils')) {
|
|
39
41
|
require('./create-plugin')(cli);
|
|
40
42
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { Command } = require('commander');
|
|
12
|
+
const { run, isDev } = require('../util');
|
|
13
|
+
const { getInstanceIdAsync } = require('@nocobase/license-kit');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {Command} cli
|
|
20
|
+
*/
|
|
21
|
+
module.exports = (cli) => {
|
|
22
|
+
cli
|
|
23
|
+
.command('generate-instance-id')
|
|
24
|
+
.description('Generate InstanceID')
|
|
25
|
+
.option('--force', 'Force generate InstanceID')
|
|
26
|
+
.action(async (options) => {
|
|
27
|
+
console.log('Generating InstanceID...');
|
|
28
|
+
const dir = path.resolve(process.cwd(), 'storage/.license');
|
|
29
|
+
const filePath = path.resolve(dir, 'instance-id');
|
|
30
|
+
if (fs.existsSync(filePath) && !options.force) {
|
|
31
|
+
console.log('InstanceID already exists at ' + filePath);
|
|
32
|
+
return;
|
|
33
|
+
} else {
|
|
34
|
+
if (!fs.existsSync(dir)) {
|
|
35
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const instanceId = await getInstanceIdAsync();
|
|
39
|
+
fs.writeFileSync(filePath, instanceId + '\n');
|
|
40
|
+
console.log(chalk.greenBright(`InstanceID saved to ${filePath}`));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.log(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
package/src/commands/pkg.js
CHANGED
|
@@ -15,6 +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
19
|
|
|
19
20
|
class Package {
|
|
20
21
|
data;
|
|
@@ -248,10 +249,13 @@ module.exports = (cli) => {
|
|
|
248
249
|
NOCOBASE_PKG_USERNAME,
|
|
249
250
|
NOCOBASE_PKG_PASSWORD,
|
|
250
251
|
} = process.env;
|
|
251
|
-
|
|
252
|
+
const { accessKeyId, accessKeySecret } = getAccessKeyPair();
|
|
253
|
+
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
|
|
252
254
|
return;
|
|
253
255
|
}
|
|
254
|
-
const credentials =
|
|
256
|
+
const credentials = accessKeyId
|
|
257
|
+
? { username: accessKeyId, password: accessKeySecret }
|
|
258
|
+
: { username: NOCOBASE_PKG_USERNAME, password: NOCOBASE_PKG_PASSWORD };
|
|
255
259
|
const pm = new PackageManager({ baseURL: NOCOBASE_PKG_URL });
|
|
256
260
|
await pm.login(credentials);
|
|
257
261
|
const file = path.resolve(__dirname, '../../package.json');
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { Command } = require('commander');
|
|
12
|
+
const { keyDecrypt } = require('@nocobase/license-kit');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {Command} cli
|
|
19
|
+
*/
|
|
20
|
+
module.exports = (cli) => {
|
|
21
|
+
cli
|
|
22
|
+
.command('view-license-key')
|
|
23
|
+
.description('View License Key')
|
|
24
|
+
.action(async (options) => {
|
|
25
|
+
const dir = path.resolve(process.cwd(), 'storage/.license');
|
|
26
|
+
const filePath = path.resolve(dir, 'license-key');
|
|
27
|
+
if (!fs.existsSync(filePath)) {
|
|
28
|
+
console.log('License key not found at ' + filePath);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const key = fs.readFileSync(filePath, 'utf-8');
|
|
32
|
+
let keyDataStr;
|
|
33
|
+
try {
|
|
34
|
+
keyDataStr = keyDecrypt(key);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.log('License key decrypt failed', e);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const keyData = JSON.parse(keyDataStr);
|
|
40
|
+
const { accessKeyId, accessKeySecret } = keyData;
|
|
41
|
+
console.log(chalk.greenBright(`Access Key ID: ${accessKeyId}`));
|
|
42
|
+
console.log(chalk.greenBright(`Access Key Secret: ${accessKeySecret}`));
|
|
43
|
+
});
|
|
44
|
+
};
|
package/src/util.js
CHANGED
|
@@ -18,6 +18,7 @@ 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
22
|
|
|
22
23
|
exports.isPackageValid = (pkg) => {
|
|
23
24
|
try {
|
|
@@ -165,10 +166,11 @@ exports.promptForTs = () => {
|
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
exports.downloadPro = async () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
// 此处不再判定,由pkgg命令处理
|
|
170
|
+
// const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
|
|
171
|
+
// if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
|
|
172
|
+
// return;
|
|
173
|
+
// }
|
|
172
174
|
await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']);
|
|
173
175
|
};
|
|
174
176
|
|
|
@@ -487,3 +489,21 @@ exports.generatePlugins = function () {
|
|
|
487
489
|
return;
|
|
488
490
|
}
|
|
489
491
|
};
|
|
492
|
+
|
|
493
|
+
exports.getAccessKeyPair = function () {
|
|
494
|
+
const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
|
|
495
|
+
if (!fs.existsSync(keyFile)) {
|
|
496
|
+
console.log(chalk.yellow('license-key file not found', keyFile));
|
|
497
|
+
return {};
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
const str = fs.readFileSync(keyFile, 'utf-8');
|
|
501
|
+
const keyDataStr = keyDecrypt(str);
|
|
502
|
+
const keyData = JSON.parse(keyDataStr);
|
|
503
|
+
const { accessKeyId, accessKeySecret } = keyData;
|
|
504
|
+
return { accessKeyId, accessKeySecret };
|
|
505
|
+
} catch (error) {
|
|
506
|
+
console.log(chalk.yellow('Key parse failed, please check your key'));
|
|
507
|
+
return {};
|
|
508
|
+
}
|
|
509
|
+
};
|