0.12.1 • Published 3 years ago

brick-engine v0.12.1

Weekly downloads
296
License
MIT
Repository
github
Last release
3 years ago

brick-engine

基于nodejs的应用程序引擎包.通过插件和模块机制,赋予应用对框架或模块的良好适配和扩展性.

summary

Install

npm install --save brick-engine

Usage

使用bin/brick-engine来启动应用.

# 默认为当前执行路径
npx brick-engine

# 指定应用路径(应用包路径/应用入口文件路径)
npx brick-engine {path 1} {...} {path N}

Entry Point

引擎需要使用应用入口来启动应用程序

const { defineApplication,defineModule } = require('brick-engine');
// 模块
const {OtherModule} = require('xxx_module_path');
// 插件
const {PluginModule} = require('xxx_plugin_path');
// 依赖注入对象
const {InjectModule} = require('xxx_inject_path');

class App{
}

// 定义应用入口
defineApplication(exports,App);

// 定义应用子模块
defineModule(App,OtherModule);
// 定义应用插件模块
defineModule(App,PluginModule);
// 定义应用注入对象
defineModule(App,InjectModule);

Engine Module

应用在brick-engine中加载处理的模块.例如:引擎插件,依赖注入模块,应用子模块(模块集合)等

const { defineModule } = require('brick-engine');

// 模块
const {OtherModule} = require('xxx_module_path');
// 插件
const {PluginModule} = require('xxx_plugin_path');
// 依赖注入对象
const {InjectModule} = require('xxx_inject_path');

class SubModule {
  constructor() {
    console.log('sub_module:new');
  }
}

exports.SubModule = SubModule;

// 定义应用子模块
defineModule(SubModule,OtherModule);
// 定义应用插件模块
defineModule(SubModule,PluginModule);
// 定义应用注入对象
defineModule(SubModule,InjectModule);

Engine Plugin

使用Engine Module来实现特定功能的扩展模块.插件模块本身也可以作为Engine Module提供给其他插件模块使用.

const { definePlugin } = require('brick-engine');

// 依赖注入对象
const {InjectModule} = require('xxx_inject_path');

class Plugin {
  match(module) {
    // 插件筛选匹配模块代码.(返回: true/false)
    return true;
  }
  async use(module) {
     // 插件使用模块功能代码
  }
}


exports.Plugin = Plugin;

// 定义插件,指定构建插件所需要的依赖模块
definePlugin(SubPlugin, { deps: [{ id: InjectModule }] });

Engine Inject

应用使用的依赖注入对象,也可以作为Engine Module提供给其他插件模块使用.

const { defineProviderFactory } = require('brick-engine');

// 依赖注入对象
const {OtherInjectModule} = require('xxx_inject_path');

class InjectModule {
    constructor(otherInjectModule) {
       // 初始化注入对象代码
    }
}

exports.InjectModule = InjectModule;

// 定义依赖对象,指定构建对象所需要的依赖模块
defineProviderFactory(InjectModule, { deps: [{ id: OtherInjectModule }] });

Documentations

使用jsdoc生成注释文档

git clone https://github.com/kiba-zhao/brick-engine.git
cd brick-engine
npm install
npm run docs
open docs/index.html

License

MIT

0.12.1

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.10.4

3 years ago

0.10.5

3 years ago

0.10.6

3 years ago

0.10.3

3 years ago

0.10.0

3 years ago

0.10.1

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.2

3 years ago

0.5.0

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago