1.1.7 • Published 9 months ago

@eljs/pluggable v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@eljs/pluggable

Make pluggable easily.

Installation

$ pnpm add @eljs/pluggable
// or
$ yarn add @eljs/pluggable
// ro
$ npm i @eljs/pluggable -S

Usage

// refer to: https://github.com/chnliquan/eljs/blob/master/packages/release/src/runner.ts
import { Pluggable } from '@eljs/pluggable'

export class Runner extends Pluggable {
  public constructor(options: Config) {
    super(options)
  }

  public async run() {
    // load presets plugins and user config
    await this.load()
    // apply customize plugins
    await this.applyPlugins('')
  }
}

new Runner({
  cwd: 'path/to/working/directory',
  presets: [],
  plugins: [],
}).run()

API

PluggablePluginApi

export interface PluggablePluginApi {
  // #region Plugin class fields
  /**
   * Working directory
   */
  cwd: typeof Pluggable.prototype.cwd
  // #endregion

  // #region Plugin methods
  /**
   * Apply plugins
   */
  applyPlugins: typeof Pluggable.prototype.applyPlugins
  /**
   * Register presets
   * @param presets preset declarations
   */
  registerPresets: (presets: PluginDeclaration[]) => void
  /**
   * Register plugins
   * @param plugins plugin declarations
   */
  registerPlugins: (plugins: PluginDeclaration[]) => void
  // #endregion
}

PluginApi

export interface PluginApi {
  /**
   * Describe plugin
   * @param options.key plugin key
   * @param options.enable whether plugin enable
   */
  describe: (options: { key?: string; enable?: Enable }) => void
  /**
   * Register hook
   * @param key hook key
   * @param fn execute function
   * @param options options
   */
  register: (
    key: HookOptions['key'],
    fn: HookOptions['fn'],
    options: Omit<HookOptions, 'plugin' | 'key' | 'fn'>,
  ) => void
  /**
   * Register method
   * @param name method name
   * @param fn execute function
   */
  registerMethod: (name: string, fn?: MaybePromiseFunction<any>) => void
  /**
   * Skip plugin
   * @param keys plugin key
   */
  skipPlugins: (keys: string[]) => void
}
1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.0

12 months ago

1.0.0-next.11

12 months ago

1.0.0-next.10

12 months ago

1.0.0-next.9

12 months ago

1.0.0-next.8

12 months ago

1.0.0-next.7

12 months ago

1.0.0-next.6

12 months ago

1.0.0-next.5

12 months ago

1.0.0-next.4

12 months ago

1.0.0-next.3

12 months ago

1.0.0-next.2

12 months ago

1.0.0-next.1

12 months ago

1.0.0-next.0

12 months ago

1.0.0-beta.10

12 months ago

1.0.0-beta.9

12 months ago

1.0.0-beta.8

12 months ago

1.0.0-beta.7

12 months ago

1.0.0-beta.6

12 months ago

1.0.0-beta.5

12 months ago

1.0.0-beta.4

12 months ago

1.0.0-beta.3

12 months ago

1.0.0-beta.2

12 months ago

1.0.0-beta.1

12 months ago

1.0.0-beta.0

12 months ago

0.33.3

12 months ago

0.33.2

1 year ago

0.33.1

1 year ago

0.33.0

1 year ago