# @reinjs/rein-loader

> rein framework

Latest version **1.0.4** (published 2018-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @reinjs/rein-loader
pnpm add @reinjs/rein-loader
yarn add @reinjs/rein-loader
bun add @reinjs/rein-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-05-23 |
| First published | 2018-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | reinjs |
| Maintainers | reinjs |
| Keywords | loader |

## Links

- npm: https://www.npmjs.com/package/@reinjs/rein-loader
- Repository: https://github.com/reinjs/rein-loader
- Homepage: https://github.com/reinjs/rein-loader#readme
- Issues: https://github.com/reinjs/rein-loader/issues
- npm.io page: https://npm.io/package/@reinjs/rein-loader

## Dependencies (4)

- [globby](https://npm.io/package/globby.md) ^8.0.1
- [utility](https://npm.io/package/utility.md) ^1.13.1
- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.0
- [@reinjs/rein-utils](https://npm.io/package/@reinjs/rein-utils.md) ^1.0.0

## Recent versions

- 1.0.4 (latest) — 2018-05-23
- 1.0.3 — 2018-05-20
- 1.0.2 — 2018-05-19
- 1.0.1 — 2018-05-16
- 1.0.0 — 2018-05-16

## README

# rein-loader

The framework loader of rein.

## Install

```shell
npm i @reinjs/rein-loader
```

## Usage

We can use `addCompiler` to expose compilers.

```javascript
const Loader = require('@reinjs/rein-loader');
const loader = new Loader();
loader.addCompiler(name, callback);
loader.addProgram(dir);
loader.compile();
```

- `addCompiler` it has two args.
  - `name` the compiler name
  - `callback` how to build data with args of `dir`
- `addProgram` it has one arg of `dir` which tell compiler how to build under the dir.
- `compile` build the data method.

## System Compilers

We can got some compilers easily by system.

### Controller Compiler

**Arguments:**

- `options`
  - `pathname` <function> how to build dir by arg of dir.
  - ...args

e.g.

```javascript
loader.addControllerCompiler(Object.assign(
  config.controller || {},
  {
    inject: this.app,
    target: this.app.controller = {},
    pathname: this.makePathname(scope, 'controller')
  }
));
```

### Middleware Compiler

**Arguments:**

- `options`
  - `pathname` <function> how to build dir by arg of dir.
  - ...args

e.g.

```javascript
loader.addMiddlewareCompiler(Object.assign(
  config.middleware || {},
  {
    inject: this.app,
    target: this.app.middleware = {},
    pathname: this.makePathname(scope, 'middleware')
  }
));
```

### Service Compiler

**Arguments:**

- `options`
  - `pathname` <function> how to build dir by arg of dir.
  - ...args

e.g.

```javascript
loader.addServiceCompiler(Object.assign(
  config.service || {},
  {
    inject: this.app,
    target: this.app.service = {},
    pathname: this.makePathname(scope, 'service')
  }
));
```

### Extend Compiler

`loader.addExtendCompiler(property, file, options)`

**Arguments:**

- `property` <string> the name of extending
- `filecallback` <function> how to get dir by arg of dir?
- `options` <object>
 * `target` which object can been built on?
 * `inject` inject object
 * `override` can override properties?
 * `originalPrototypes` original prototypes from koa or other framework




It also has four custom methods by alias name:

In KOA:

- `addContextCompiler` extend context.js
- `addRequestCompiler` extend request.js
- `addResponseCompiler` extend response.js
- `addApplicationCompiler` extend application.js

```javascript
this.loader
  .addContextCompiler(this.extendCondition(this.app.context, scope, 'extend/context.js'))
  .addRequestCompiler(this.extendCondition(this.app.request, scope, 'extend/request.js'))
  .addResponseCompiler(this.extendCondition(this.app.response, scope, 'extend/response.js'))
  .addApplicationCompiler(this.extendCondition(this.app, scope, 'extend/application.js'));
```

### Message Compiler

On agent you should add this compiler for ipc sender.

`this.loader.addMessageCompiler(inject, fileCallback)`;

**Arguments:**

- `inject` inject object
- `fileCallback` <function> hwo to get dir by arg of dir?

```javascript
this.loader.addMessageCompiler(this.app, ({ type, pathname }) => {
  if (type === 'project') return path.resolve(pathname, `app/${this.app.name}.js`);
  return path.resolve(pathname, 'app/message.js');
});
```

# License

It is [MIT licensed](https://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/@reinjs/rein-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
