feat: add inst commond and pkg commond support .key

This commit is contained in:
Jian Lu 2025-03-25 15:11:10 +08:00
parent cf3f6ba156
commit 9780d2a686
5 changed files with 37 additions and 16 deletions

2
.gitignore vendored
View File

@ -32,3 +32,5 @@ ncc-cache/
yarn--**
v8-compile-cache-**
vitest.config.mts.timestamp-*
.key
InstanceID.*

View File

@ -9,6 +9,7 @@
},
"dependencies": {
"@nocobase/app": "1.7.0-beta.1",
"@nocobase/license-kit": "^0.1.0",
"@types/fs-extra": "^11.0.1",
"@umijs/utils": "3.5.20",
"chalk": "^4.1.1",

View File

@ -10,8 +10,9 @@
const chalk = require('chalk');
const { Command } = require('commander');
const { run, isDev } = require('../util');
const { keygen } = require('../environment-keygen');
const { genInstanceId } = require('@nocobase/license-kit');
const path = require('path');
const fs = require('fs');
/**
*
* @param {Command} cli
@ -19,16 +20,17 @@ const path = require('path');
module.exports = (cli) => {
cli
.command('inst')
.description('Generate InstanceID')
.allowUnknownOption()
.action(() => {
// if (!isDev()) {
// return;
// }
// run('rimraf', ['-rf', './storage/app-dev']);
// run('rimraf', ['-rf', 'packages/*/*/{lib,esm,es,dist,node_modules}']);
// run('rimraf', ['-rf', 'packages/*/@*/*/{lib,esm,es,dist,node_modules}']);
const filePath = path.resolve(process.cwd(), 'instance.enc');
keygen({ filePath });
console.log(chalk.greenBright(`Instance key saved to ${filePath}`));
console.log('Generating InstanceID...');
try {
const filePath = path.resolve(process.cwd(), 'InstanceID.txt');
const instanceId = genInstanceId();
fs.writeFileSync(filePath, instanceId);
console.log(chalk.greenBright(`InstanceID saved to ${filePath}`));
} catch (e) {
console.log(e);
}
});
};

View File

@ -15,6 +15,8 @@ const tar = require('tar');
const path = require('path');
const { createStoragePluginsSymlink } = require('@nocobase/utils/plugin-symlink');
const chalk = require('chalk');
const { getKey } = require('../util');
const { keyDecrypt } = require('@nocobase/license-kit');
class Package {
data;
@ -248,10 +250,15 @@ module.exports = (cli) => {
NOCOBASE_PKG_USERNAME,
NOCOBASE_PKG_PASSWORD,
} = process.env;
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
const key = getKey(); // TODO 需执行本地环境校验
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !key) {
return;
}
const credentials = { username: NOCOBASE_PKG_USERNAME, password: NOCOBASE_PKG_PASSWORD };
const keyDataStr = keyDecrypt(key);
const { accessKeyId, accessSecret } = JSON.parse(keyDataStr);
const credentials = accessKeyId
? { username: accessKeyId, password: accessSecret }
: { username: NOCOBASE_PKG_USERNAME, password: NOCOBASE_PKG_PASSWORD };
const pm = new PackageManager({ baseURL: NOCOBASE_PKG_URL });
await pm.login(credentials);
const file = path.resolve(__dirname, '../../package.json');

View File

@ -165,10 +165,11 @@ exports.promptForTs = () => {
};
exports.downloadPro = async () => {
const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
return;
}
// 此处不再判定由pkgg命令处理
// const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
// if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
// return;
// }
await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']);
};
@ -471,3 +472,11 @@ exports.generatePlugins = function () {
return;
}
};
exports.getKey = function () {
const keyFile = resolve(process.cwd(), './.key');
if (!fs.existsSync(keyFile)) {
return;
}
return fs.readFileSync(keyFile, 'utf-8');
};