@qiwi/uniconfig-plugin-api-file
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

@qiwi/uniconfig-plugin-api-file

Uniconfig File API plugin

Install

  npm i @qiwi/uniconfig-plugin-api-file
  yarn add @qiwi/uniconfig-plugin-api-file

Usage

import uniconfig, {rollupPlugin} from '@qiwi/uniconfig-core'
import uniconfigFileApiPlugin from '@qiwi/uniconfig-plugin-api-file'
import uniconfigJsonParserPlugin from '@qiwi/uniconfig-plugin-parser-json'
    
rollupPlugin(uniconfigFileApiPlugin)
rollupPlugin(uniconfigJsonParserPlugin)

const target = './foo.json'
/** foo.json content:
{
  "foo": "bar"
}
*/

const config = uniconfig({
  data: {
    someParam: '$fromFile:foo'
  },
  source: {
    fromFile: {
      data: '<some path>',
      pipeline: 'file>json'
    }
  }
}, {
  mode: 'sync',
  pipeline: 'datatree'
})    

config.get('someParam') // "bar"

const missingTarget = './foo-missing.json' // this file does not exist
const target2 = './foo2.json'
/** foo2.json content:
 {
  "foo2": "bar2"
}
 */

const config = uniconfig({
  data: {
    someParam: '$fromFile:foo'
  },
  source: {
    fromFile: {
      data: [missingTarget, target2, target], // in this mode the content of the first existing file is returned
      pipeline: 'file>json'
    }
  }
}, {
  mode: 'sync',
  pipeline: 'datatree'
})

config.get('someParam') // "bar2"

Package Sidebar

Install

npm i @qiwi/uniconfig-plugin-api-file

Weekly Downloads

23

Version

4.0.1

License

MIT

Unpacked Size

16.4 kB

Total Files

9

Last publish

Collaborators

  • antongolub
  • qiwibot