Skip to content

v0.6.0

Choose a tag to compare

@emmenko emmenko released this 18 Jul 14:47
· 129 commits to master since this release
d33ace1

<a name"v0.6.0">

v0.6.0 (2016-07-18)

Features

  • import: allow to pass a custom plugin when running the import command

Sometimes the default importers do not meet specific customer requirements and you end up writing your own importer from scratch.

In such cases, you can write a custom plugin to process and let the cli do the dirty work (streaming). When running the command, simply provide the path to your custom plugin script.

# using the `custom-stock.js` example in the plugins folder
$ sphere import --plugin $(pwd)/plugins/custom-stock.js -f stocks.json

The plugin must export a function which returns specific objects:

export default function myCustomPlugin (options) {
  // `options` are the command options
  return [
    options,
    // This is the parsing path used by the JSON stream, following the schema
    // https://github.com/sphereio/sphere-node-cli#sphere-import
    'stocks.*',
    // The function to process the stream (see below)
    processFn,
    // The function called when the import is finished
    finishFn
  ]
}

// `data` is an array of the parsed chunks
// `next` is the function that should be called to get the next array of chunks
function processFn (data, next) {
  // return a Promise
  return new Promise(function (/* resolve, reject */) {
    setTimeout(function () {
      console.log(data)
      next()
    }, 500)
  })
}