UNPKG

roc

Version:

Build modern web applications easily

141 lines (121 loc) 4.71 kB
'use strict'; exports.__esModule = true; exports.generateMarkdownDocumentation = generateMarkdownDocumentation; exports.generateTextDocumentation = generateTextDocumentation; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } require('source-map-support/register'); var _lodash = require('lodash'); var _documentationBuildDocumentationObject = require('../documentation/build-documentation-object'); var _documentationBuildDocumentationObject2 = _interopRequireDefault(_documentationBuildDocumentationObject); var _documentationGenerateTable = require('../documentation/generate-table'); var _documentationGenerateTable2 = _interopRequireDefault(_documentationGenerateTable); var _documentationHelpers = require('../documentation/helpers'); var _helpersStyle = require('../helpers/style'); /** * Generates markdown documentation for the provided configuration object. * * @param {rocConfig} config - The configuration object to generate documentation for. * @param {rocMetaConfig} metaConfig - The meta configuration object that has information about the config object. * @param {string[]} [filter=[]] - The groups that should be includes, by default all will be used. * * @returns {string} - A markdown table as a string. */ function generateMarkdownDocumentation(_ref, _ref2) { var settings = _ref.settings; var meta = _ref2.settings; var filter = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; var documentationObject = _documentationBuildDocumentationObject2['default'](settings, meta, filter); var header = { name: { name: 'Name' }, description: { name: 'Description', renderer: function renderer(input) { return _lodash.escape(input); } }, path: { name: 'Path' }, cli: { name: 'CLI Flag' }, defaultValue: { name: 'Default', renderer: function renderer(input) { return input && '`' + _documentationHelpers.getDefaultValue(input) + '`'; } }, type: { name: 'Type', renderer: function renderer(input) { return input && '`' + input + '`'; } }, required: { name: 'Required', renderer: function renderer(input) { if (input === true) { return 'Yes'; } return 'No'; } } }; return _documentationGenerateTable2['default'](documentationObject, header, { groupTitleWrapper: function groupTitleWrapper(name, level) { return _documentationHelpers.pad(level + 1, '#') + ' ' + name.charAt(0).toUpperCase() + name.slice(1); } }); } /** * Generates plain text documentation for the provided configuration object. * * @param {rocConfig} config - The configuration object to generate documentation for. * @param {rocMetaConfig} metaConfig - The meta configuration object that has information about the config object. * @param {string[]} [filter=[]] - The groups that should be includes, by default all will be used. * * @returns {string} - A table as a string. */ function generateTextDocumentation(_ref3, _ref4) { var settings = _ref3.settings; var meta = _ref4.settings; var filter = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; var documentationObject = _documentationBuildDocumentationObject2['default'](settings, meta, filter); var header = { description: { name: 'Description', renderer: function renderer(input) { return input && input.substr(0, 100) + '…'; } }, path: { name: 'Path' }, defaultValue: { name: 'Default', renderer: function renderer(input) { input = _documentationHelpers.getDefaultValue(input); if (!input) { return _helpersStyle.warning('No default value'); } return input; } }, cli: { name: 'CLI Flag' }, required: { name: 'Required', renderer: function renderer(input) { if (input === true) { return _helpersStyle.ok('Yes'); } return _helpersStyle.error('No'); } } }; return _documentationGenerateTable2['default'](documentationObject, header); } //# sourceMappingURL=index.js.map