<commit_before># @start/plugin

Start plugin "creator".

## Install

```sh
$ yarn add @start/plugin
```

## Usage

### Types

```ts
type StartFile = {
  path: string,
  data: null | string,
  map: null | {}
}

type StartFiles = StartFile[]

type StartPluginProps = {
  files: StartFiles,
  reporter: NodeJS.EventEmitter,
  logFile: (file: string) => void,
  logMessage: (message: string) => void
}

type StartPluginOut = StartFiles | Promise<StartFiles>

type StartPlugin = (props: StartPluginProps) => StartPluginOut
```

### Example

```js
import plugin from '@start/plugin'

export default plugin('noop', ({ files }) => files)
```

```js
import plugin from '@start/plugin'

export default plugin('foo', async ({ files, logFile }) => {
  const { default: fooTransform } = await import('foo-lib')

  return Promise.all(
    files.map((file) =>
      fooTransform(file.data).then(({ transformedData, sourceMap }) => {
        logFile(file.path)

        return {
          path: file.path,
          data: transformedData,
          map: sourceMap
        }
      })
    )
  )
})
```

```js
import plugin from '@start/plugin'

export default (barOptions) =>
  plugin('bar', async ({ files, logMessage }) => {
    const { default: barCheck } = await import('bar-lib')

    const barResult = barCheck(files, barOptions)

    if (barResult.issues.length === 0) {
      logMessage('¯\\_(ツ)_/¯')
    }

    return files
  })
```

## Notes

* Dynamic imports – [it's a good idea](https://github.com/gulpjs/gulp/issues/632) to "lazyload" dependencies inside of a plugin function instead of importing them at top.<commit_msg>📝 plugin: update readme [skip ci]<commit_after># @start/plugin

Start plugin "creator".

## Install

```sh
$ yarn add @start/plugin
```

## Usage

### Types

```ts
type StartFile = {
  path: string,
  data: null | string,
  map: null | {}
}

type StartFiles = StartFile[]

type StartPluginProps = {
  files: StartFiles,
  reporter: NodeJS.EventEmitter,
  logFile: (file: string) => void,
  logMessage: (message: string) => void
}

type StartPluginOut = StartFiles | Promise<StartFiles>

type StartPlugin = (props: StartPluginProps) => StartPluginOut
```

### Example

```js
import plugin from '@start/plugin'

export default plugin('noop', ({ files }) => files)
```

```js
import plugin from '@start/plugin'

export default plugin('foo', async ({ files, logFile }) => {
  const { default: fooTransform } = await import('foo-lib')

  return Promise.all(
    files.map((file) =>
      fooTransform(file.data).then(({ transformedData, sourceMap }) => {
        logFile(file.path)

        return {
          path: file.path,
          data: transformedData,
          map: sourceMap
        }
      })
    )
  )
})
```

```js
import plugin from '@start/plugin'

export default (barOptions) =>
  plugin('bar', async ({ files, logMessage }) => {
    const { default: barCheck } = await import('bar-lib')

    const barResult = barCheck(files, barOptions)

    if (barResult.issues.length === 0) {
      logMessage('¯\\_(ツ)_/¯')
    }

    return files
  })
```

## Notes

* Dynamic imports – [it's a good idea](https://github.com/gulpjs/gulp/issues/632) to "lazyload" dependencies inside of a plugin function instead of importing them at top.
* `files` – `StartFiles | Promise<StartFiles>` – a requirement even if this means to just pass it through.
* `logMessage` – any random message from plugin.
* `logFile` – current file path to indicate some kind of progress.
* `reporter` – advanced prop which should be passed through if plugin operates other plugins, like [sequence](../plugin-sequence) or [watch](../plugin-watch).
{'fraction_non_alphanumeric': 0.15099009900990099, 'fraction_numerical': 0.0022002200220022, 'mean_word_length': 3.419198055893074, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '87767', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1117, 'n_words': 332}