feat: add view-license-ke commond

This commit is contained in:
Jian Lu 2025-04-16 20:30:26 +08:00
parent f54dae2e66
commit 17f7fb8dab
3 changed files with 60 additions and 10 deletions

View File

@ -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);
}

View File

@ -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);
}
}
});
};

View 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}`));
});
};