This commit is contained in:
2025-12-06 18:55:43 +08:00
parent ee33208e6c
commit eca7b42377
5 changed files with 148 additions and 5 deletions

View File

@@ -0,0 +1,78 @@
import { program, Command } from '@/program.ts';
import { query } from '@/module/query.ts';
import { QueryConfig } from '@/query/query-secret/query-secret.ts';
import { showMore } from '@/uitls/show-more.ts';
import fs from 'node:fs';
import path from 'node:path';
const queryConfig = new QueryConfig({ query: query as any });
const command = new Command('remote-secret')
.alias('rs').description('获取或设置远程配置');
const getCommand = new Command('get')
.option('-k, --key <key>', '配置键名')
.action(async (options) => {
const { key } = options || {};
if (!key) {
console.log('Please provide a key using -k or --key option.');
return;
}
const res = await queryConfig.getItem({ id: key });
console.log('res Config Result:', showMore(res.data));
})
const listCommand = new Command('list')
.description('列出所有配置')
.action(async () => {
const res = await queryConfig.listItems();
if (res.code === 200) {
const list = res.data?.list || [];
list.forEach(item => {
console.log(item.id, item.key, showMore(item));
});
} else {
console.log('获取错误:', res.message);
}
});
const updateCommand = new Command('update')
.description('更新远程配置')
.option('-i, --id <id>', '配置ID')
.option('-t, --title <title>', '配置值')
.option('-d, --description <description>', '配置数据JSON格式')
.action(async (options) => {
const { id, title, description } = options || {};
let updateData: any = {};
if (title) {
updateData.title = title;
}
if (description) {
updateData.description = description;
}
if (id) {
updateData.id = id;
}
const res = await queryConfig.updateItem(updateData);
console.log('修改结果:', showMore(res));
});
const deleteCommand = new Command('delete')
.description('删除远程配置')
.option('-i, --id <id>', '配置ID')
.option('-k, --key <key>', '配置键名')
.action(async (options) => {
const { key, id } = options || {};
if (!key && !id) {
console.log('请提供配置键名或配置ID使用 -k 或 --key 选项,或 -i 或 --id 选项。');
return;
}
const res = await queryConfig.deleteItem({ key, id });
console.log('Delete Config Result:', showMore(res));
});
command.addCommand(listCommand);
command.addCommand(getCommand);
command.addCommand(updateCommand);
command.addCommand(deleteCommand);
program.addCommand(command);

View File

@@ -188,7 +188,7 @@ const publishCommand = new Command('publish')
console.log('发布逻辑实现', { key, version, config });
});
const deployLoadFn = async (id: string, fileKey: string, force = false, install = false) => {
const deployLoadFn = async (id: string, fileKey: string, force = true, install = false) => {
if (!id) {
console.error(chalk.red('id is required'));
return;
@@ -312,11 +312,10 @@ const packCommand = new Command('pack')
const packDeployCommand = new Command('pack-deploy')
.argument('<id>', 'id')
.option('-k, --key <key>', 'fileKey, 服务器的部署文件夹的列表')
.option('-f --force', 'force')
.option('-i, --install ', 'install dependencies')
.action(async (id, opts) => {
let { force, key, install } = opts || {};
const res = await deployLoadFn(id, key, force, install);
let { key, install } = opts || {};
const res = await deployLoadFn(id, key, true, install);
});
program.addCommand(packDeployCommand);