feat: add app serve
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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 命令
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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
40
src/command/serve.ts
Normal 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);
|
||||
Reference in New Issue
Block a user