# ts-plugin-legions

> typescript plugin Framework

Latest version **0.0.10-beta.1** (published 2020-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-plugin-legions
pnpm add ts-plugin-legions
yarn add ts-plugin-legions
bun add ts-plugin-legions
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10-beta.1 |
| Published | 2020-09-24 |
| First published | 2019-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | duanguang |
| Maintainers | duanguang |

## Links

- npm: https://www.npmjs.com/package/ts-plugin-legions
- Repository: https://github.com/duanguang/ts-plugin-legions
- Homepage: https://github.com/duanguang/ts-plugin-legions.git
- Issues: https://github.com/duanguang/ts-plugin-legions/issues
- npm.io page: https://npm.io/package/ts-plugin-legions

## Dependencies (2)

- [warning](https://npm.io/package/warning.md) ^3.0.0
- [invariant](https://npm.io/package/invariant.md) ^2.2.1

## Recent versions

- 0.0.10-beta.1 (latest) — 2020-09-24
- 0.0.9 — 2019-12-30

## README

# ts-plugin-legions

基于 typescript 编译时运行插件库,
Compatible with ts-loader(^2.2.0) and awesome-typescript-loader(^3.1.3)

## Install

```js
npm i ts-plugin-legions -D
```

## Usage

### createTransformer

```md
主要用于查找指定 import modulesSpecifier,及修饰器 bindings,抓取文件相对路径，挂载在对象上，如生成唯一组件 UID，可以根据组件文件路径来保证唯一
```

```js
import { createTransformer } from 'ts-plugin-legions';
import { StoreModules } from 'legions/store';

@StoreModules
export default class UserStore {}
var config = {
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        options: {
          transpileOnly: true,
          compilerOptions: {
            module: 'es2015',
          },
          getCustomTransformers: () => ({
            before: [
              // transform Store/ViewModel of mmlpx by default
              createTransformer(),
              // manual config mobx action
              createTransformer([
                {
                  libraryName: 'legions/store',
                  bindings: ['StoreModules'],
                },
              ]),
            ],
          }),
        },
      },
    ],
  },
};
```

### createTransformerReactJsxProps

```md
在 ts 编译运行阶段抓取指定组件，并往组件上挂载指定 props 参数,如果有指定值则用指定，没有指定则以文件路径作为结果
```

```js
import { createTransformerReactJsxProps } from 'ts-plugin-legions';
var config = {
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        options: {
          transpileOnly: true,
          compilerOptions: {
            module: 'es2015',
          },
          getCustomTransformers: () => ({
            before: [
              // transform Store/ViewModel of mmlpx by default
              createTransformerReactJsxProps({
                components: [
                  {
                    name: 'HLTable',
                    props: 'uniqueUid',
                    value: '',
                  },
                  {
                    name: 'HLFormContainer',
                    props: 'uniqueUid',
                  },
                  {
                    name: 'QueryConditions',
                    props: 'uniqueUid',
                  },
                  {
                    name: 'HLTableForm',
                    props: 'uniqueUid',
                  },
                ],
              }),
            ],
          }),
        },
      },
    ],
  },
};
```

### createTransformerMapImportModulesSpecifier

```md
在 ts 运行时编译替换指定的 import mudlues Specifier 名称
```

```js
import { createTransformerMapImportModulesSpecifier } from 'ts-plugin-legions';
import { schedule } from '../schedule';
import { warning } from '../warning';
var config = {
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        options: {
          transpileOnly: true,
          compilerOptions: {
            module: 'es2015',
          },
          getCustomTransformers: () => ({
            before: [
              // transform Store/ViewModel of mmlpx by default
              createTransformerMapImportModulesSpecifier([
                {
                  libraryName: '../schedule',
                  mapLibraryName: 'legions-lunar/schedule',
                },
                {
                  libraryName: '../warning',
                  mapLibraryName: 'legions-lunar/warning',
                },
              ]),
            ],
          }),
        },
      },
    ],
  },
};
// output
import { schedule } from 'legions-lunar/schedule';
import { warning } from 'legions-lunar/warning';
```

# Licensing

MIT license

---
_Source: https://npm.io/package/ts-plugin-legions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
