diff --git a/package.json b/package.json index ae11d31..03e2176 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.0.73", + "version": "0.0.74", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli", diff --git a/src/command/config-secret-remote.ts b/src/command/config-secret-remote.ts new file mode 100644 index 0000000..9a34073 --- /dev/null +++ b/src/command/config-secret-remote.ts @@ -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 ', '配置键名') + .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') + .option('-t, --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); \ No newline at end of file diff --git a/src/command/publish.ts b/src/command/publish.ts index 0d11767..2babd68 100644 --- a/src/command/publish.ts +++ b/src/command/publish.ts @@ -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); diff --git a/src/index.ts b/src/index.ts index 390e0b4..05f4a72 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/src/query/query-secret/query-secret.ts b/src/query/query-secret/query-secret.ts new file mode 100644 index 0000000..237e82e --- /dev/null +++ b/src/query/query-secret/query-secret.ts @@ -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, + }); + } +} \ No newline at end of file