roc
Version:
Build modern web applications easily
152 lines (130 loc) • 5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.generateMarkdownDocumentation = generateMarkdownDocumentation;
exports.generateTextDocumentation = generateTextDocumentation;
var _lodash = require('lodash');
var _buildDocumentationObject = require('../documentation/build-documentation-object');
var _buildDocumentationObject2 = _interopRequireDefault(_buildDocumentationObject);
var _generateTable = require('../documentation/generate-table');
var _generateTable2 = _interopRequireDefault(_generateTable);
var _helpers = require('../documentation/helpers');
var _style = require('../helpers/style');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Generates markdown documentation for the provided configuration object.
*
* @param {string} name - The name of the one generation the documentation.
* @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(name, _ref, _ref2) {
let settings = _ref.settings;
let meta = _ref2.settings;
let filter = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3];
const documentationObject = (0, _buildDocumentationObject.sortOnProperty)('name', (0, _buildDocumentationObject2.default)(settings, meta, filter));
const header = {
name: {
name: 'Name'
},
description: {
name: 'Description',
renderer: input => (0, _lodash.escape)(input)
},
path: {
name: 'Path'
},
cli: {
name: 'CLI option'
},
defaultValue: {
name: 'Default',
renderer: input => input !== undefined && `\`${ (0, _helpers.getDefaultValue)(input) }\``
},
type: {
name: 'Type',
renderer: input => input && `\`${ input }\``
},
required: {
name: 'Required',
renderer: input => {
if (input === true) {
return 'Yes';
}
return 'No';
}
}
};
const text = (0, _generateTable2.default)(documentationObject, header, {
groupTitleWrapper: (title, level) => (0, _helpers.pad)(level + 2, '#') + ' ' + title.charAt(0).toUpperCase() + title.slice(1)
});
if (text.length === 0) {
return 'No settings available.';
}
return '# Settings for `' + name + '`' + '\n\n' + text;
}
/**
* 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) {
let settings = _ref3.settings;
let meta = _ref4.settings;
let filter = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
const documentationObject = (0, _buildDocumentationObject.sortOnProperty)('name', (0, _buildDocumentationObject2.default)(settings, meta, filter));
const header = {
description: {
name: 'Description',
renderer: input => {
if (input && input.length > 100) {
return input.substr(0, 100) + '…';
}
if (input) {
return input;
}
}
},
path: {
name: 'Path'
},
defaultValue: {
name: 'Default',
renderer: input => {
const defaultValue = (0, _helpers.getDefaultValue)(input);
if (!defaultValue || input === null) {
return (0, _style.warning)('No default value');
}
return defaultValue;
}
},
cli: {
name: 'CLI option'
},
required: {
name: 'Required',
renderer: input => {
if (input === true) {
return (0, _style.ok)('Yes');
}
return (0, _style.error)('No');
}
}
};
const text = (0, _generateTable2.default)(documentationObject, header, {
groupTitleWrapper: (name, level, parentNames) => parentNames.concat(name).join(' > ')
});
if (text.length === 0) {
return 'No settings available.';
}
return text;
}
//# sourceMappingURL=index.js.map