UNPKG

africa

Version:

A library to interactively create and read configuration files.

59 lines (53 loc) 4.51 kB
const { __africa, _Group } = require('./africa') /** * Read package configuration from the home directory, or ask questions with readline interface to create a new configuration in `~/.${packageName}rc`. * @param {string} packageName The name of the package. * @param {!_reloquent.Questions} [questions] A set of questions. * @param {!_africa.Config} [config] The configuration object to configure additional functionality. * @param {boolean} [config.force=false] Ask questions and update the configuration file even if it already exists. Default `false`. * @param {string} [config.homedir="os.homedir()"] In which directory to save and search for configuration file. Default `os.homedir()`. * @param {number} [config.questionsTimeout] How log to wait in ms before timing out. Will wait forever by default. * @param {boolean} [config.local=false] Whether to read a local config file in the current working directory rather than in the `HOMEDIR`. When initialising, the default values will be taken from the home config if it exists so that it is easy to extend `.rc` files. Default `false`. * @param {boolean} [config.recursive=false] **`paid`** Read all configurations up to the root one from the home directory, and merge them together. Default `false`. * @param {boolean} [config.skipExisting=true] **`paid`** When creating nested configs, skip writing values that are taken from parent RCs. Default `true`. * @param {(packageName: string) => string} [config.rcNameFunction] Function used to generate the `.rc` name. Default: packageName => `.${packageName}rc`. * @return {Promise<!Object>} */ function africa(packageName, questions, config) { return __africa(packageName, questions, config) } module.exports = africa /** @type {new (questions: _reloquent.Questions) => Group} */ const $Group = _Group module.exports.Group = $Group /* typal types/index.xml namespace */ /** * @typedef {_africa.Config} Config `@record` The configuration object to configure additional functionality. * @typedef {Object} _africa.Config `@record` The configuration object to configure additional functionality. * @prop {boolean} [force=false] Ask questions and update the configuration file even if it already exists. Default `false`. * @prop {string} [homedir="os.homedir()"] In which directory to save and search for configuration file. Default `os.homedir()`. * @prop {number} [questionsTimeout] How log to wait in ms before timing out. Will wait forever by default. * @prop {boolean} [local=false] Whether to read a local config file in the current working directory rather than in the `HOMEDIR`. When initialising, the default values will be taken from the home config if it exists so that it is easy to extend `.rc` files. Default `false`. * @prop {boolean} [recursive=false] **`paid`** Read all configurations up to the root one from the home directory, and merge them together. Default `false`. * @prop {boolean} [skipExisting=true] **`paid`** When creating nested configs, skip writing values that are taken from parent RCs. Default `true`. * @prop {(packageName: string) => string} [rcNameFunction] Function used to generate the `.rc` name. Default: packageName => `.${packageName}rc`. * @typedef {_africa.Group} Group `@interface` * @typedef {Object} _africa.Group `@interface` * @prop {!_reloquent.Questions} questions The questions in the group. */ /* typal-embed node_modules/reloquent/types/index.xml namespace */ /** * @typedef {import('readline').ReadLineOptions} readline.ReadLineOptions * @typedef {_reloquent.Question} Question `@record` A question. * @typedef {_reloquent.$Question & readline.ReadLineOptions} _reloquent.Question `@record` A question. * @typedef {Object} _reloquent.$Question `@record` A question. * @prop {string} text The text to show to the user. * @prop {string} [defaultValue] The default answer to the question. * @prop {boolean} [password=false] Hide the inputs behind `*` when typing the answer. Default `false`. * @prop {() => (string|!Promise<string>)} [getDefault] The function which will get the default value, possibly asynchronously. * @prop {(answer: string) => void} [validation] The validation function which should throw on error. * @prop {(answer: string) => (string|!Promise<string>)} [postProcess] The transformation function for the answer. * @typedef {_reloquent.Questions} Questions A set of questions. * @typedef {!Object<string, string|!_reloquent.Question>} _reloquent.Questions A set of questions. */