udpate
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/cli",
|
||||
"version": "0.0.73",
|
||||
"version": "0.0.74",
|
||||
"description": "envision 命令行工具",
|
||||
"type": "module",
|
||||
"basename": "/root/cli",
|
||||
|
||||
78
src/command/config-secret-remote.ts
Normal file
78
src/command/config-secret-remote.ts
Normal 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);
|
||||
@@ -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);
|
||||
|
||||
@@ -15,6 +15,7 @@ import './command/app/index.ts';
|
||||
|
||||
import './command/gist/index.ts';
|
||||
import './command/config-remote.ts';
|
||||
import './command/config-secret-remote.ts';
|
||||
|
||||
// program.parse(process.argv);
|
||||
|
||||
|
||||
65
src/query/query-secret/query-secret.ts
Normal file
65
src/query/query-secret/query-secret.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 配置查询
|
||||
* @updatedAt 2025-12-03 10:33:00
|
||||
*/
|
||||
import { Query } from '@kevisual/query';
|
||||
import type { Result } from '@kevisual/query/query';
|
||||
type QueryConfigOpts = {
|
||||
query?: Query;
|
||||
};
|
||||
export type Config<T = any> = {
|
||||
id?: string;
|
||||
title?: string;
|
||||
key?: string;
|
||||
description?: string;
|
||||
data?: T;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
};
|
||||
export type UploadConfig = {
|
||||
key?: string;
|
||||
version?: string;
|
||||
};
|
||||
type PostOpts = {
|
||||
token?: string;
|
||||
payload?: Record<string, any>;
|
||||
};
|
||||
|
||||
export class QueryConfig {
|
||||
query: Query;
|
||||
constructor(opts?: QueryConfigOpts) {
|
||||
this.query = opts?.query || new Query();
|
||||
}
|
||||
async post<T = Config>(data: any) {
|
||||
return this.query.post<T>({ path: 'secret', ...data });
|
||||
}
|
||||
async getItem({ id, key }: { id?: string; key?: string }, opts?: PostOpts) {
|
||||
return this.post({
|
||||
key: 'get',
|
||||
data: {
|
||||
id,
|
||||
key,
|
||||
},
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
async updateItem(data: Config, opts?: PostOpts) {
|
||||
return this.post({
|
||||
key: 'update',
|
||||
data,
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
async deleteItem(data: { id?: string, key?: string }, opts?: PostOpts) {
|
||||
return this.post({
|
||||
key: 'delete',
|
||||
data,
|
||||
});
|
||||
}
|
||||
async listItems(opts?: PostOpts) {
|
||||
return this.post<{ list: Config[] }>({
|
||||
key: 'list',
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user