deepsweet / start

:red_circle: Functional task runner for Node.js
https://start.js.org/
MIT License
476 stars 19 forks source link

Pipe additional data #37

Closed fmal closed 6 years ago

fmal commented 6 years ago

@deepsweet wonder what's your opinion on letting the user pass some extra input to the plugins?

Currently we're limited to files as input, but I have a case where i would like to measure some file sizes as first step and pass those sizes to another plugin further in the sequence. The sequence looks something like this [measureFileSizesBeforeBuild, cleanDist, copyAssets, build, printFileSizesAfterBuild], where printFileSizesAfterBuild needs sizes from measureFileSizesBeforeBuild to output difference. I thought it would be easiest to just return additional prop resolve({ files, sizes }) and pass that trough the chain.

To make it work i guess a tiny change would be required in https://github.com/deepsweet/start/blob/d8a323ac62e551d738b837be59e8ab0d94f95440/packages/plugin/src/index.ts#L29

{ reporter, files, ...additionalProps } and then spreading additionalProps in payload to pluginFn()

deepsweet commented 6 years ago

Sounds like a good idea, I'm going to work on PR so we can try it out first.

Guessing how sequence might look:

export default (...plugins: StartPlugin[]) =>
  plugin('sequence', (props) =>
    plugins.reduce(
      async (prev, next) => {
        const nextRunner = await next
        const prevResult = await prev

        return nextRunner({
          ...props,
          ...prevResult,
        })
      },
      Promise.resolve(props)
    )
  )
deepsweet commented 6 years ago

You can track its progress in #38 – I really enjoyed the idea, it makes a lot of sense now.

fmal commented 6 years ago

@deepsweet looking great, i think it will make start runner more powerful. The same concept is implemented in Cerebral's actions (https://cerebraljs.com/docs/api/index.html#action-props) where action's output extends the payload for later actions in the sequence.

deepsweet commented 6 years ago

Going to publish as soon as it's possible :) Thanks again for the idea. Could you try it from master?

deepsweet commented 6 years ago

📦 plugin@0.2.0

Also every single plugin got updated.

fmal commented 6 years ago

@deepsweet thanks a lot, great job with that - just how i imagined it! Upgraded to 0.2.0 and love the flexibility it offers 👍