From cc07df24d497682e007dc3cfda7ee51a621e0607 Mon Sep 17 00:00:00 2001 From: Lars Trieloff Date: Tue, 10 Dec 2019 10:52:45 +0000 Subject: [PATCH] feat(markdown): generate additional detail --- cli.js | 5 ++++- lib/markdownBuilder.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index 70fea4c3..e326155b 100755 --- a/cli.js +++ b/cli.js @@ -116,7 +116,9 @@ const { argv } = yargs .coerce('i', i => nodepath.resolve(i)) .alias('p', 'properties') - .describe('p', 'A comma separated list with custom properties which should be also in the description of an element.') + .array('p') + .describe('p', 'name of a custom property which should be also in the description of an element (may be used multiple times)') + .default('p', []) .alias('h', 'header') .describe('h', 'if the value is false the header will be skipped') .default('h', true); @@ -188,6 +190,7 @@ readdirp.promise(schemaPath, { root: schemaPath, fileFilter: `*.${schemaExtensio build({ header: argv.h, links: docs, + includeproperties: argv.p }), diff --git a/lib/markdownBuilder.js b/lib/markdownBuilder.js index 1ec6e98a..2942fe97 100644 --- a/lib/markdownBuilder.js +++ b/lib/markdownBuilder.js @@ -21,7 +21,7 @@ const { gentitle } = require('./formattingTools'); const { basename } = require('path'); const ghslugger = require('github-slugger'); -function build({ header, links = {} }) { +function build({ header, links = {}, includeproperties = [] } = {}) { const headerprops = [ { name: 'type', @@ -250,6 +250,27 @@ function build({ header, links = {} }) { return retval; } + function makenullablefact(definition) { + const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type]; + // filter out types that are null + const realtypes = alltypes.filter(type => type!=='null'); + // can the type be `null` + const nullable = alltypes.filter(type => type === 'null').length > 0; + + if (nullable) { + return listItem(paragraph(text(i18n`can be null`))); + } else { + return listItem(paragraph(text(i18n`cannot be null`))); + } + } + + function makedefinedinfact(definition) { + return listItem(paragraph([ + text(i18n`defined in: `), + link(`${definition[s.slug]}.md`, definition[s.id] + '#' + definition[s.pointer], text(definition[s.titles][0] || i18n`Untitled schema`)) + ])); + } + function makefactlist(name, definition, required = []) { const children = []; @@ -261,6 +282,17 @@ function build({ header, links = {} }) { } children.push(maketypefact(definition)); + children.push(makenullablefact(definition)); + children.push(makedefinedinfact(definition)); + + const additionalfacts = includeproperties.map(propname => { + if (definition[propname]) { + return listItem(text(propname + ': ' + String(definition[propname]))); + } + return undefined; + }).filter(item => item != undefined); + + children.push(...additionalfacts); return list('unordered', children); }