clear code
This commit is contained in:
@@ -119,3 +119,15 @@ const command = new Command('me')
|
||||
});
|
||||
|
||||
program.addCommand(command);
|
||||
|
||||
const logoutCommand = new Command('logout').description('退出登陆').action(async () => {
|
||||
try {
|
||||
await queryLogin.logout();
|
||||
storage.removeItem('token');
|
||||
console.log('退出成功');
|
||||
} catch (error) {
|
||||
console.log('退出失败', error);
|
||||
}
|
||||
});
|
||||
|
||||
program.addCommand(logoutCommand);
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { program as app, Command } from '@/program.ts';
|
||||
import { getConfig, writeConfig } from '@/module/index.ts';
|
||||
|
||||
const command = new Command('logout')
|
||||
.description('')
|
||||
.action(async () => {
|
||||
const config = getConfig();
|
||||
writeConfig({ ...config, token: '' });
|
||||
});
|
||||
|
||||
app.addCommand(command);
|
||||
@@ -13,7 +13,7 @@ const tokenList = new Command('list')
|
||||
// .option('-r --remove <number>', 'remove token by number')
|
||||
.action(async (opts) => {
|
||||
console.log('show token list');
|
||||
queryLogin.cacheStore.init()
|
||||
queryLogin.cacheStore.init();
|
||||
// const res = await queryLogin.cacheStore.cache.get('token');
|
||||
console.log(queryLogin.cacheStore.cacheData);
|
||||
// console.log(util.inspect(res, { colors: true, depth: 4 }));
|
||||
@@ -33,6 +33,11 @@ const baseURL = new Command('baseURL')
|
||||
.action(async (opts) => {
|
||||
let config = getConfig();
|
||||
let list = (config.baseURLList as Array<string>) || [];
|
||||
if (!config.baseURL) {
|
||||
list = ['https://kevisual.cn'];
|
||||
writeConfig({ ...config, baseURL: 'https://kevisual.cn', baseURLList: list });
|
||||
config = getConfig();
|
||||
}
|
||||
const quineList = (list: string[]) => {
|
||||
const newList = new Set(list);
|
||||
return Array.from(newList);
|
||||
|
||||
@@ -3,7 +3,6 @@ import inquirer from 'inquirer';
|
||||
import { query } from '../module/index.ts';
|
||||
import chalk from 'chalk';
|
||||
import util from 'util';
|
||||
import { runApp } from '@/app-run.ts';
|
||||
|
||||
const router = new Command('router').description('router get');
|
||||
program.addCommand(router);
|
||||
@@ -58,45 +57,3 @@ const command = new Command('service')
|
||||
});
|
||||
|
||||
router.addCommand(command);
|
||||
|
||||
const localRouter = new Command('local')
|
||||
.description('router local get')
|
||||
.option('-p, --path <path>', '第一路径 path')
|
||||
.option('-k, --key <key>', '第二路径 key')
|
||||
.action(async (options) => {
|
||||
let { path, key } = options;
|
||||
// 如果没有传递参数,则通过交互式输入
|
||||
if (!path) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'path',
|
||||
required: true,
|
||||
message: 'Enter your path:',
|
||||
when: () => !path, // 当 username 为空时,提示用户输入
|
||||
},
|
||||
]);
|
||||
path = answers.path || path;
|
||||
}
|
||||
if (!key) {
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
required: false,
|
||||
name: 'key',
|
||||
message: 'Enter your key:',
|
||||
},
|
||||
]);
|
||||
key = answers.key || key;
|
||||
}
|
||||
const res = await runApp({ path, key });
|
||||
if (res?.code === 200) {
|
||||
console.log('query success');
|
||||
|
||||
console.log(chalk.green(util.inspect(res, { colors: true, depth: 4 })));
|
||||
} else {
|
||||
console.log('error query', res.code, res.message || '');
|
||||
}
|
||||
});
|
||||
|
||||
router.addCommand(localRouter);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import { program as app, Command } from '@/program.ts';
|
||||
import { getConfig, writeConfig, pidFilePath, checkFileExists } from '@/module/index.ts';
|
||||
import { createApp } from '@/app.ts';
|
||||
import fs from 'fs';
|
||||
|
||||
const command = new Command('serve')
|
||||
.description('serve manager')
|
||||
.option('-e, --exit', '退出进程')
|
||||
.option('-s, --start', '启动进程')
|
||||
.action(async (options) => {
|
||||
console.log('options', options);
|
||||
if (options.exit) {
|
||||
if (checkFileExists(pidFilePath)) {
|
||||
console.log('服务已经启动, 准备退出');
|
||||
const pid = fs.readFileSync(pidFilePath, 'utf-8');
|
||||
// 通知进程退出
|
||||
process.kill(Number(pid), 'SIGTERM');
|
||||
setTimeout(() => {
|
||||
if (checkFileExists(pidFilePath)) {
|
||||
// 强制删除 pid 文件
|
||||
fs.unlinkSync(pidFilePath);
|
||||
}
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (options.start) {
|
||||
const config = getConfig();
|
||||
await createApp();
|
||||
}
|
||||
});
|
||||
|
||||
app.addCommand(command);
|
||||
|
||||
const start = new Command('start').description('start serve').action(async () => {
|
||||
const config = getConfig();
|
||||
await createApp();
|
||||
});
|
||||
|
||||
app.addCommand(start);
|
||||
@@ -1,71 +0,0 @@
|
||||
import { program as app, Command } from '@/program.ts';
|
||||
import { getConfig, writeConfig, checkFileExists, query } from '@/module/index.ts';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { startContainerServer } from '@/module/run-vite.ts';
|
||||
// web 开发模块
|
||||
const command = new Command('web')
|
||||
.description('web dev manager')
|
||||
.option('-e, --exit', '退出进程')
|
||||
.option('-s, --start', '启动进程')
|
||||
|
||||
.action(async (options) => {
|
||||
const { exit, start } = options || {};
|
||||
});
|
||||
app.addCommand(command);
|
||||
|
||||
// container 开发模块
|
||||
const container = new Command('container')
|
||||
.description('container manager')
|
||||
.option('-d, --container <id>', '下载镜像')
|
||||
.option('-f, --force', '下载镜像')
|
||||
.option('-u, --upload <id>', '上传镜像')
|
||||
.action(async (options) => {
|
||||
const { container, upload, force } = options || {};
|
||||
const config = getConfig();
|
||||
const workdir = config.workdir;
|
||||
if (!workdir) {
|
||||
console.log('请先配置工作目录');
|
||||
return;
|
||||
}
|
||||
if (!config.token) {
|
||||
console.log('请先登录');
|
||||
return;
|
||||
}
|
||||
// 32210aa6-3d5a-4687-b769-ae4e8137ec1e
|
||||
if (container) {
|
||||
console.log('下载镜像', container);
|
||||
const res = await query.post({ path: 'container', key: 'get', id: container });
|
||||
if (res.code !== 200) {
|
||||
console.log('error', res.message || '');
|
||||
return;
|
||||
}
|
||||
await startContainerServer(res.data, force);
|
||||
}
|
||||
if (upload) {
|
||||
console.log('上传镜像', upload);
|
||||
const directory = path.join(workdir, 'container', upload);
|
||||
if (!checkFileExists(directory)) {
|
||||
console.log('文件夹不存在');
|
||||
return;
|
||||
}
|
||||
const code = fs.readFileSync(path.join(directory, 'index.js'), 'utf-8');
|
||||
if (!code) {
|
||||
console.log('文件不能为空');
|
||||
return;
|
||||
}
|
||||
const res = await query.post({
|
||||
path: 'container', //
|
||||
key: 'update',
|
||||
data: { id: upload, code },
|
||||
});
|
||||
if (res.code !== 200) {
|
||||
console.log('error', res.message || '');
|
||||
console.log(res);
|
||||
return;
|
||||
}
|
||||
console.log('上传成功');
|
||||
}
|
||||
});
|
||||
|
||||
app.addCommand(container);
|
||||
Reference in New Issue
Block a user