From 91379e7a18bbfa2f903f61a1bc04a4350212fbbe Mon Sep 17 00:00:00 2001 From: Ayush Jain Date: Mon, 6 Jul 2020 15:18:17 +0530 Subject: [PATCH 1/3] Fix tokenization and add platform and default tags --- website/scripts/sync-api-docs/generateMarkdown.js | 7 +++++-- .../scripts/sync-api-docs/preprocessGeneratedApiDocs.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/website/scripts/sync-api-docs/generateMarkdown.js b/website/scripts/sync-api-docs/generateMarkdown.js index 4b16464b307..90632fb68e6 100644 --- a/website/scripts/sync-api-docs/generateMarkdown.js +++ b/website/scripts/sync-api-docs/generateMarkdown.js @@ -58,8 +58,8 @@ function generateProp(propName, prop) { { Type: prop.flowType ? maybeLinkifyType(prop.flowType) : '', Required: prop.required ? 'Yes' : 'No', - ...(prop.rnTags && prop.rnTags.platform - ? {Platform: formatPlatformName(prop.rnTags.platform)} + ...(prop.rnTags && prop.rnTags.default + ? {Default: prop.rnTags.default} : {}), }, ]); @@ -68,6 +68,9 @@ function generateProp(propName, prop) { '### `' + propName + '`' + + (prop.rnTags && prop.rnTags.platform + ? formatPlatformName(prop.rnTags.platform) + : '') + '\n' + '\n' + (prop.description ? prop.description + '\n\n' : '') + diff --git a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js index 3732e45fa0e..d2ce4ee44d7 100644 --- a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js +++ b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js @@ -29,15 +29,23 @@ function joinDescriptionAndExamples(tokenized) { function preprocessTagsInDescription(obj) { if (obj && obj.description) { + obj.description = obj.description.split(' ').join(''); const descriptionTokenized = tokenizeComment(obj.description); obj.description = joinDescriptionAndExamples(descriptionTokenized); obj.rnTags = {}; const platformTag = descriptionTokenized.tags.find( ({key}) => key === 'platform' ); + const defaultTag = descriptionTokenized.tags.find( + ({key}) => key === 'default' + ); + if (platformTag) { obj.rnTags.platform = platformTag.value; } + if (defaultTag) { + obj.rnTags.default = defaultTag.value; + } } } From cafe328abe7885a3d0922423434f21924a946c89 Mon Sep 17 00:00:00 2001 From: Ayush Jain Date: Mon, 6 Jul 2020 19:55:41 +0530 Subject: [PATCH 2/3] Fix multiple types format --- .../scripts/sync-api-docs/generateMarkdown.js | 27 ++++++++++++++++++- .../preprocessGeneratedApiDocs.js | 16 +++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/website/scripts/sync-api-docs/generateMarkdown.js b/website/scripts/sync-api-docs/generateMarkdown.js index 90632fb68e6..4021f484f93 100644 --- a/website/scripts/sync-api-docs/generateMarkdown.js +++ b/website/scripts/sync-api-docs/generateMarkdown.js @@ -54,9 +54,34 @@ function stringToInlineCodeForTable(str) { // Formats information about a prop function generateProp(propName, prop) { + let tableRows = ''; + + if (prop.rnTags && prop.rnTags.type) { + if (prop.rnTags.type.length) { + prop.rnTags.type.forEach(tag => { + const isMatch = tag.match(/{@platform [a-z]*}/); + if (isMatch) { + const platform = isMatch[0].match(/ [a-z]*/); + tag = tag.replace(/{@platform [a-z]*}/g, ''); + tag = + tag + + '
' + + platform[0].trim() + + '
'; + } + tableRows = tableRows + tag + '
'; + }); + tableRows = tableRows.replace(/$/, ''); + } else { + tableRows = prop.rnTags.type.join('
'); + } + } else tableRows = prop.flowType ? maybeLinkifyType(prop.flowType) : ''; + const infoTable = generateTable([ { - Type: prop.flowType ? maybeLinkifyType(prop.flowType) : '', + Type: tableRows, Required: prop.required ? 'Yes' : 'No', ...(prop.rnTags && prop.rnTags.default ? {Default: prop.rnTags.default} diff --git a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js index d2ce4ee44d7..fc38cbe5c64 100644 --- a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js +++ b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js @@ -30,7 +30,9 @@ function joinDescriptionAndExamples(tokenized) { function preprocessTagsInDescription(obj) { if (obj && obj.description) { obj.description = obj.description.split(' ').join(''); + // console.log("preprocessTagsInDescription -> obj.description", obj.description) const descriptionTokenized = tokenizeComment(obj.description); + // console.log("preprocessTagsInDescription -> obj.description", descriptionTokenized) obj.description = joinDescriptionAndExamples(descriptionTokenized); obj.rnTags = {}; const platformTag = descriptionTokenized.tags.find( @@ -40,12 +42,26 @@ function preprocessTagsInDescription(obj) { ({key}) => key === 'default' ); + let typeTag = descriptionTokenized.tags.filter(tag => { + return tag.key === 'type'; + }); + // let typeTag = descriptionTokenized.tags.find( + // ({key}) => key === 'type' + // ); + // console.log("preprocessTagsInDescription -> typeTag", typeTag) + if (platformTag) { obj.rnTags.platform = platformTag.value; } if (defaultTag) { obj.rnTags.default = defaultTag.value; } + if (typeTag.length) { + obj.rnTags.type = []; + typeTag.forEach(tag => { + obj.rnTags.type.push(tag.value); + }); + } } } From 9b3be037fcb5f16ae2ff5ee5c4ce9da90dec17aa Mon Sep 17 00:00:00 2001 From: Ayush Jain Date: Wed, 8 Jul 2020 20:08:03 +0530 Subject: [PATCH 3/3] Remove extra code --- .../sync-api-docs/preprocessGeneratedApiDocs.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js index fc38cbe5c64..fa2c7ae93a9 100644 --- a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js +++ b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js @@ -30,10 +30,9 @@ function joinDescriptionAndExamples(tokenized) { function preprocessTagsInDescription(obj) { if (obj && obj.description) { obj.description = obj.description.split(' ').join(''); - // console.log("preprocessTagsInDescription -> obj.description", obj.description) const descriptionTokenized = tokenizeComment(obj.description); - // console.log("preprocessTagsInDescription -> obj.description", descriptionTokenized) obj.description = joinDescriptionAndExamples(descriptionTokenized); + obj.rnTags = {}; const platformTag = descriptionTokenized.tags.find( ({key}) => key === 'platform' @@ -41,14 +40,9 @@ function preprocessTagsInDescription(obj) { const defaultTag = descriptionTokenized.tags.find( ({key}) => key === 'default' ); - - let typeTag = descriptionTokenized.tags.filter(tag => { + const typeTag = descriptionTokenized.tags.filter(tag => { return tag.key === 'type'; }); - // let typeTag = descriptionTokenized.tags.find( - // ({key}) => key === 'type' - // ); - // console.log("preprocessTagsInDescription -> typeTag", typeTag) if (platformTag) { obj.rnTags.platform = platformTag.value;