mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 15:09:27 +08:00
feat: add view-license-ke commond
This commit is contained in:
parent
f54dae2e66
commit
17f7fb8dab
@ -34,6 +34,7 @@ module.exports = (cli) => {
|
||||
require('./postinstall')(cli);
|
||||
require('./pkg')(cli);
|
||||
require('./instance-id')(cli);
|
||||
require('./view-license-key')(cli);
|
||||
if (isPackageValid('@umijs/utils')) {
|
||||
require('./create-plugin')(cli);
|
||||
}
|
||||
|
@ -22,20 +22,25 @@ module.exports = (cli) => {
|
||||
cli
|
||||
.command('generate-instance-id')
|
||||
.description('Generate InstanceID')
|
||||
.allowUnknownOption()
|
||||
.action(async () => {
|
||||
.option('--force', 'Force generate InstanceID')
|
||||
.action(async (options) => {
|
||||
console.log('Generating InstanceID...');
|
||||
try {
|
||||
const dir = path.resolve(process.cwd(), 'storage/.license');
|
||||
const filePath = path.resolve(dir, 'instance-id');
|
||||
if (fs.existsSync(filePath) && !options.force) {
|
||||
console.log('InstanceID already exists at ' + filePath);
|
||||
return;
|
||||
} else {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
const filePath = path.resolve(dir, 'InstanceID');
|
||||
try {
|
||||
const instanceId = await getInstanceIdAsync();
|
||||
fs.writeFileSync(filePath, instanceId + '\n');
|
||||
console.log(chalk.greenBright(`InstanceID saved to ${filePath}`));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
44
packages/core/cli/src/commands/view-license-key.js
Normal file
44
packages/core/cli/src/commands/view-license-key.js
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
const chalk = require('chalk');
|
||||
const { Command } = require('commander');
|
||||
const { keyDecrypt } = require('@nocobase/license-kit');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Command} cli
|
||||
*/
|
||||
module.exports = (cli) => {
|
||||
cli
|
||||
.command('view-license-key')
|
||||
.description('View License Key')
|
||||
.action(async (options) => {
|
||||
const dir = path.resolve(process.cwd(), 'storage/.license');
|
||||
const filePath = path.resolve(dir, 'license-key');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.log('License key not found at ' + filePath);
|
||||
return;
|
||||
}
|
||||
const key = fs.readFileSync(filePath, 'utf-8');
|
||||
let keyDataStr;
|
||||
try {
|
||||
keyDataStr = keyDecrypt(key);
|
||||
} catch (e) {
|
||||
console.log('License key decrypt failed', e);
|
||||
return;
|
||||
}
|
||||
const keyData = JSON.parse(keyDataStr);
|
||||
const { accessKeyId, accessSecret } = keyData;
|
||||
console.log(chalk.greenBright(`Access Key ID: ${accessKeyId}`));
|
||||
console.log(chalk.greenBright(`Access Secret: ${accessSecret}`));
|
||||
});
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user