feat: add app serve

This commit is contained in:
2024-10-17 01:18:03 +08:00
parent edb0d56094
commit 5c3f454d8c
17 changed files with 1314 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
import { app, Command } from '@/app.ts';
import { program as app, Command } from '@/program.ts';
import { glob } from 'glob';
import path from 'path';
import fs from 'fs';

View File

@@ -1,6 +1,6 @@
import { app, program, Command } from '@/app.ts';
import { program as app, Command } from '@/program.ts';
import { getConfig, writeConfig } from '@/module/get-config.ts';
import { queryLogin, queryMe, switchOrg, switchMe } from '@/route/index.ts';
import { queryLogin, queryMe, switchOrg, switchMe } from '@/query/index.ts';
import inquirer from 'inquirer';
// 导入 login 命令

View File

@@ -1,4 +1,4 @@
import { app, Command } from '@/app.ts';
import { program as app, Command } from '@/program.ts';
import { getConfig, writeConfig } from '@/module/index.ts';
const command = new Command('logout')

View File

@@ -1,4 +1,4 @@
import { app, Command } from '@/app.ts';
import { program as app, Command } from '@/program.ts';
import { getConfig, query, writeConfig } from '@/module/index.ts';
import inquirer from 'inquirer';

View File

@@ -1,6 +1,6 @@
import { app, Command } from '@/app.ts';
import { program as app, Command } from '@/program.ts';
import { getConfig, writeConfig } from '@/module/index.ts';
import {queryMe} from '../route/index.ts';
import {queryMe} from '../query/index.ts';
const command = new Command('me')

40
src/command/serve.ts Normal file
View File

@@ -0,0 +1,40 @@
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);