feat: add silky cli tools

This commit is contained in:
2025-04-27 22:16:09 +08:00
parent 75d181ef43
commit 6867de838e
42 changed files with 3867 additions and 251 deletions

View File

@@ -0,0 +1,2 @@
import './init.ts'
import './init-env.ts'

View File

@@ -0,0 +1,68 @@
import { program, Command } from '@/program.ts';
import { TaskKey, silkyCommand } from '@/mdoules/talkshow.ts';
const description = `初始化运行环境,安装
1. @kevisual/cli
2. pm2
可选安装:
deno
bun
`;
const isDev = process.env.NODE_ENV === 'development';
const testEnv = new Command('init-env')
.description(description)
.option('-a --all')
.action((options) => {
let tag = options.all ? 'env' : 'must-env';
silkyCommand.isDebug = isDev ?? false;
const envTask = silkyCommand.getTasksArrayByTag(tag);
for (const value of envTask) {
try {
const res = silkyCommand.runTask(value);
if (res.code === 200) {
console.log('执行结果:', res.code, res.message);
} else {
console.log('执行结果错误:', res.task?.description, res.message);
}
} catch (error) {
console.log('error', error);
continue;
}
}
});
program.addCommand(testEnv);
const appDownloadDesc = `下载安装talkshow的应用模块
1. root/talkshow-admin
2. root/talkshow-code-center
3. root/center
`;
const appDownloadTask = new Command('init-talkshow')
.description(appDownloadDesc)
.option('-a --all', '下载所有应用模块或者只下载talkshow相关的')
.action((options) => {
//
let tag = options.all ? 'app' : 'talkshow';
const appTask = silkyCommand.getTasksArrayByTag(tag);
silkyCommand.isDebug = true;
for (const value of appTask) {
try {
const res = silkyCommand.runTask(value);
if (res.code === 200) {
console.log('执行结果:', res.task?.description, res.code);
} else {
console.log('执行结果错误:', res.task?.description, res.message);
}
} catch (error) {
console.log('error', error);
continue;
}
}
});
program.addCommand(appDownloadTask);

View File

@@ -0,0 +1,25 @@
import { program, Command } from '@/program.ts';
import path from 'node:path';
import { AssistantInit } from '@/services/init/index.ts';
type InitCommandOptions = {
path?: string;
};
const Init = new Command('init')
.description('初始化一个助手客户端,生成配置文件。')
.option('-p --path <path>', '助手路径,默认为执行命令的目录,如果助手路径不存在则创建。')
.action((opts: InitCommandOptions) => {
// 如果path参数存在检测path是否是相对路径如果是相对路径则转换为绝对路径
if (opts.path && !opts.path.startsWith('/')) {
opts.path = path.join(process.cwd(), opts.path);
} else if (opts.path) {
opts.path = path.resolve(opts.path);
}
const configDir = AssistantInit.detectConfigDir(opts.path);
const assistantInit = new AssistantInit({
path: configDir,
});
assistantInit.init();
});
program.addCommand(Init);