JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25
  • Score
    100M100P100Q21362F
  • License MIT

basic xboot engine

Package Exports

  • brick-engine

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (brick-engine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

brick-engine

基于依赖注入模式(xprovide)的基础工具engine.提供环境变量,配置文件内容以及功能模型注入插件.作为搭建应用的最基本engine使用.

Install

npm install --save brick-engine

Usage

可以通过xboot加载使用项目.

Configuration

// {cwd}/xboot.config.js
// {cwd}/node_modules/{xxx engine}/xboot.config.js

exports.engine = 'brick-engine'

StartUp

npm install xboot
npx xboot

Plugins

Env

将环境变量注入当前应用的xprovide中.根据NODE_ENV设置默认XBLOCK_CONFIG环境变量.

  • 未设置XBLOCK_CONFIG,且NODE_ENV为production : XBLOCK_CONFIG为prod
  • 未设置XBLOCK_CONFIG,且NODE_ENV不production : XBLOCK_CONFIG为local

Config

根据Env插件注入的XBLOCK_CONFIG,加载合并配置文件config/{env.XBLOCK_CONFIG}.js以及config/default.js.并将最终配置内容注入到当前应用的xprovide中.

config/{env.XBLOCK_CONFIG}.js将合并覆盖config/default.js中的内容.

Inject

注入自定义匹配的功能模型到当前应用的xprovide中.适用于定义业务逻辑模型对象(eggjs中的service),数据模型对象(mvc中的model),以及辅助功能模型对象(eggjs中的helper)等.

Inject Config

通过config定义需要注入的模型名称,以及模型相关文件的xboot引导加载参数.

// {cwd}/config/*.js
// {cwd}/node_modules/config/*.js

exports.inject = {
    // 注入名称
    service: { 
        patterns: 'services/**/*.js',
        // 请参考xboot中BootLoader的opts参数说明
        opts:{}
    },
    model: { patterns: 'models/**/*.js' },
    helper: { patterns: 'helpers/**/*.js' },
};

Inject Describe

在模型相关的源码文件中,需要定义该文件模块依赖的上下文模块(比如各种db client模块,redis client模块以及http client模块等),以及该文件模块在模型中对应的属性名称.

// {cwd}/models/simple.js

const {inject,provide} = require('brick-engine');
 
 class SimpleModel {
  constructor(env, config) {
    this._env = env;
    this._config = config;
  }

  get env() {
    return this._env;
  }

  getConfig() {
    return this._config;
  }

}

module.exports = SimpleModel;

// 定义生成类实例时候,作为构造参数使用的依赖模块
// 即同等于: new SimpleModel(env,config);
inject(SimpleModel,{ deps:[ 'env', 'config?' ], name:'modelA'})
// 将依赖模块直接定义到类的实例中
// 即同等于: const instance = new SimpleModel(...)
//           Object.defineProperty(instance,'cfg',{value:config,writable: false});
provide(SimpleModel, {property:'cfg', dep:'config?'});

函数说明

  • inject: 定义构造模块所需要使用的依赖模块,以及构造模块命名
  • provide: 往模块指定属性,写入依赖模块

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