@flowxjs/typeservice
v1.0.4
Published
Native nodejs server container framework
Downloads
14
Maintainers
Readme
TypeService
基于Nodejs
的容器服务启动器,通过插件模式可扩展具体应用实例。
Usage
安装模块
$ npm i @flowxjs/typeservice
创建一个日志文件 src/app.logger.ts
export type TTypeServiceLogger = Console;
export const TypeServiceLogger = console;
创建一个启动文件 src/app.bootstrap.ts
import { Factory, TTypeServiceFactoryBootstrapInstance, TypeServiceFactoryInstance, TAnnotationScanerResult } from '@flowxjs/typeservice';
import { TTypeServiceLogger, TypeServiceLogger } from './app.logger';
import { Plugin } from './app.plugin';
@Factory.Logger(TypeServiceLogger)
@Factory.Setup(Plugin)
export class ApplicationFactory extends TypeServiceFactoryInstance<TTypeServiceLogger> implements TTypeServiceFactoryBootstrapInstance {
message(value: any) {
if (value instanceof Error) return this.factory.logger.error(value);
this.factory.logger.info(value);
}
initialize(meta: TAnnotationScanerResult) {
console.log('factory initialize', meta);
}
terminate(meta: TAnnotationScanerResult) {
console.log('factory terminate', meta);
}
}
创建一个插件文件 src/app.plugin.ts
import { TypeServiceFactoryInstance, TTypeServiceLifeCycleInstance, TAnnotationScanerResult } from '@flowxjs/typeservice';
import { TTypeServiceLogger } from './app.logger';
export class Plugin extends TypeServiceFactoryInstance<TTypeServiceLogger> implements TTypeServiceLifeCycleInstance {
async initialize(meta: TAnnotationScanerResult) {
console.log('plugin initialize', meta);
await new Promise(resolve => setTimeout(resolve, 2000));
}
async terminate(meta: TAnnotationScanerResult) {
await new Promise(resolve => setTimeout(resolve, 3000));
console.log('plugin terminate', meta);
}
}
CLI
使用命令行工具
- 启动开发程序
ts-dev
- 启动PM2托管
ts-pm2-start
- 停止PM2托管
ts-pm2-stop
- 重启PM2托管
ts-pm2-restart
- 删除PM2托管
ts-pm2-delete