feat: add silky cli tools
This commit is contained in:
2
assistant/tasks/silkyai-cli/src/command/check/index.ts
Normal file
2
assistant/tasks/silkyai-cli/src/command/check/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import './init.ts'
|
||||
import './init-env.ts'
|
||||
68
assistant/tasks/silkyai-cli/src/command/check/init-env.ts
Normal file
68
assistant/tasks/silkyai-cli/src/command/check/init-env.ts
Normal 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);
|
||||
25
assistant/tasks/silkyai-cli/src/command/check/init.ts
Normal file
25
assistant/tasks/silkyai-cli/src/command/check/init.ts
Normal 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);
|
||||
Reference in New Issue
Block a user