"feat: 升级本地应用管理依赖,新增应用删除功能及强制覆盖下载选项"
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { AssistantApp } from '@/module/assistant/index.ts';
|
||||
import { program, Command, assistantConfig } from '@/program.ts';
|
||||
import { AppDownload } from '@/services/app/index.ts';
|
||||
|
||||
const appManagerCommand = new Command('app-manager').alias('am').description('Manage Assistant Apps 管理本地的应用模块');
|
||||
program.addCommand(appManagerCommand);
|
||||
@@ -38,18 +39,20 @@ appManagerCommand
|
||||
manager.start(appKey);
|
||||
console.log('Start App:', appKey);
|
||||
});
|
||||
|
||||
const stop = async (appKey: string) => {
|
||||
const manager = new AssistantApp(assistantConfig);
|
||||
try {
|
||||
await manager.loadConfig();
|
||||
await manager.stop(appKey);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
appManagerCommand
|
||||
.command('stop')
|
||||
.argument('<app-key-name>', '应用的 key 名称')
|
||||
.action(async (appKey: string) => {
|
||||
const manager = new AssistantApp(assistantConfig);
|
||||
try {
|
||||
await manager.loadConfig();
|
||||
await manager.stop(appKey);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
await stop(appKey);
|
||||
console.log('Stop App:', appKey);
|
||||
});
|
||||
|
||||
@@ -67,6 +70,22 @@ appManagerCommand
|
||||
console.log('Restart App:', appKey);
|
||||
});
|
||||
|
||||
appManagerCommand
|
||||
.command('delete')
|
||||
.alias('del')
|
||||
.argument('<app-key-name>', '应用的 key 名称, apps 中的 文件名')
|
||||
.action(async (id) => {
|
||||
const app = new AppDownload(assistantConfig);
|
||||
if (id) {
|
||||
if (id.includes('/')) {
|
||||
const [_user, appName] = id.split('/');
|
||||
id = appName;
|
||||
await stop(id);
|
||||
}
|
||||
await app.deleteApp({ id, type: 'app' });
|
||||
}
|
||||
});
|
||||
|
||||
const pageListCommand = new Command('page-list')
|
||||
.alias('pl')
|
||||
.option('-a, --all', '列出前端页面的所有信息')
|
||||
|
||||
@@ -9,14 +9,16 @@ const downloadCommand = new Command('download')
|
||||
.option('-i, --id <id>', '应用名称')
|
||||
.option('-t, --type <type>', '应用类型', 'web')
|
||||
.option('-r, --registry <registry>', '应用源 https://kevisual.cn')
|
||||
.option('-f --force', '强制覆盖')
|
||||
.option('-y --yes', '覆盖的时候不提示')
|
||||
.action(async (options) => {
|
||||
const { id, type } = options;
|
||||
const { id, type, force, yes } = options;
|
||||
assistantConfig.checkMounted();
|
||||
const registry = options.registry || assistantConfig.getRegistry();
|
||||
// console.log('registry', registry);
|
||||
const app = new AppDownload(assistantConfig);
|
||||
if (id) {
|
||||
await app.downloadApp({ id, type, registry });
|
||||
await app.downloadApp({ id, type, registry, force, yes });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@ import { parseIfJson } from '@/module/assistant/index.ts';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import glob from 'fast-glob';
|
||||
import type { App } from '@kevisual/router';
|
||||
export class AssistantApp extends Manager {
|
||||
config: AssistantConfig;
|
||||
pagesPath: string;
|
||||
constructor(config: AssistantConfig) {
|
||||
constructor(config: AssistantConfig, mainApp?: App) {
|
||||
config.checkMounted();
|
||||
const appsPath = config?.configPath?.appsDir || path.join(process.cwd(), 'apps');
|
||||
const pagesPath = config?.configPath?.pagesDir || path.join(process.cwd(), 'pages');
|
||||
@@ -16,6 +17,7 @@ export class AssistantApp extends Manager {
|
||||
super({
|
||||
appsPath,
|
||||
configFilename: configFimename,
|
||||
mainApp: mainApp,
|
||||
});
|
||||
this.pagesPath = pagesPath;
|
||||
this.config = config;
|
||||
|
||||
@@ -6,6 +6,7 @@ import getPort, { portNumbers } from 'get-port';
|
||||
import { program } from 'commander';
|
||||
import { spawnSync } from 'child_process';
|
||||
import chalk from 'chalk';
|
||||
import { AssistantApp } from './lib.ts';
|
||||
export const runServer = async (port?: number) => {
|
||||
let _port: number | undefined;
|
||||
if (port) {
|
||||
@@ -29,6 +30,12 @@ export const runServer = async (port?: number) => {
|
||||
});
|
||||
app.server.on(proxyRoute);
|
||||
proxyWs();
|
||||
const manager = new AssistantApp(assistantConfig, app);
|
||||
setTimeout(() => {
|
||||
manager.load({ runtime: 'client' }).then(() => {
|
||||
console.log('Assistant App Loaded');
|
||||
});
|
||||
}, 1000);
|
||||
return {
|
||||
app,
|
||||
port: _port,
|
||||
|
||||
@@ -35,6 +35,8 @@ type DownloadAppOptions = {
|
||||
* 应用名称,默认为 user/app的 app
|
||||
*/
|
||||
appName?: string;
|
||||
force?: boolean;
|
||||
yes?: boolean;
|
||||
};
|
||||
type DeleteAppOptions = {
|
||||
/**
|
||||
@@ -53,7 +55,7 @@ export class AppDownload {
|
||||
this.config = config;
|
||||
}
|
||||
async downloadApp(opts: DownloadAppOptions) {
|
||||
const { id, type = 'web' } = opts;
|
||||
const { id, type = 'web', force } = opts;
|
||||
const configDir = this.config.configDir;
|
||||
this.config?.checkMounted();
|
||||
const appsDir = this.config.configPath?.appsDir;
|
||||
@@ -75,6 +77,12 @@ export class AppDownload {
|
||||
} else {
|
||||
throw new Error('应用类型错误,只能是 web 或 app');
|
||||
}
|
||||
if (force) {
|
||||
args.push('-f');
|
||||
if (opts.yes) {
|
||||
args.push('-y');
|
||||
}
|
||||
}
|
||||
if (opts.registry) {
|
||||
args.push('-r', opts.registry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user