oneblink / blinkmrc.js

like https://github.com/yeoman/configstore but with private and project-specific files
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

blinkmrc.j npm module Travis CI Status AppVeyor Status Greenkeeper badge

bit like https://github.com/yeoman/configstore but with home-directory and project-specific files

We extracted this from blinkmobile/bmp-cli for the benefit of our other CLI projects.

What is this?

This is a basic configuration file management library, hardcoded with defaults that suit our purposes. Like git and npm, this library straddles configuration files in 2 locations:

This pair of configuration files are both JSON-formatted.

By default we use the following filenames (but this is configurable):

API

const blinkmrc = require('@blinkmobile/blinkmrc');
const pkg = require('./package.json');

userConfig (options: ConfigOptions) => ConfigStore

const userConfig = blinkmrc.userConfig({ name: pkg.name, /* ... */ });

UserConfigOptions

interface ConfigOptions {
  fileMode = 0o600: Number,
  userConfigDir?: String,
...ConfigOptions
}

project (options: ConfigOptions) => ConfigStore

const projectConfig = blinkmrc.projectConfig({ name: pkg.name, /* ... */ });

ProjectConfigOptions

interface ConfigOptions {
  cwd = process.cwd(): String,
  fileMode = 0o666: Number,
  ...ConfigOptions
}

ConfigOptions

interface ConfigOptions {
  name: String,
  filename = 'blinkmrc.json': String,
  fileMode?: Number
}

ConfigStore

interface ConfigStore {
  load () => Promise[Object],
  update (updater: UpdaterFunction) => Promise,
  write () => Promise
}

load () => Promise[Object]

Locate the configuration file. If found, parse it as JSON and return the Object. If not found:

update (updater: UpdaterFunction) => Promise[Object]

Load the configuration data as above. Then pass it to the provided UpdaterFunction. Write the result of the UpdaterFunction back to the configuration file.

UpdaterFunction (config: Object) => Object

This function receives the current configuration data. This function may or may not change this data (as you determine) before returning it.

write (config: Object) => Promise[Object]

Store the provided configuration data in the appropriate file.