@capacitor/docgen
Advanced tools
+52
-42
@@ -45,6 +45,6 @@ "use strict"; | ||
| exports.replaceMarkdownPlaceholders = replaceMarkdownPlaceholders; | ||
| const INDEX_START = `<!--DOCGEN_INDEX_START-->`; | ||
| const INDEX_END = `<!--DOCGEN_INDEX_END-->`; | ||
| const API_START = `<!--DOCGEN_API_START-->`; | ||
| const API_END = `<!--DOCGEN_API_END-->`; | ||
| const INDEX_START = `<docgen-index`; | ||
| const INDEX_END = `</docgen-index>`; | ||
| const API_START = `<docgen-api`; | ||
| const API_END = `</docgen-api>`; | ||
| const UPDATE_MSG = `<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->`; | ||
@@ -56,6 +56,7 @@ function replaceMarkdownDocsIndex(content, data) { | ||
| if (endInnerIndex > -1) { | ||
| const startInnerIndex = startOuterIndex + INDEX_START.length; | ||
| const start = content.substring(0, startInnerIndex); | ||
| const inner = content.substring(startOuterIndex + INDEX_START.length); | ||
| const startInnderIndex = startOuterIndex + INDEX_START.length + inner.indexOf('>') + 1; | ||
| const start = content.substring(0, startInnderIndex); | ||
| const end = content.substring(endInnerIndex); | ||
| return `${start}\n${markdownIndex(data)}\n${end}`; | ||
| return `${start}\n\n${markdownIndex(data)}\n\n${end}`; | ||
| } | ||
@@ -70,6 +71,7 @@ } | ||
| if (endInnerIndex > -1) { | ||
| const startInnerIndex = startOuterIndex + API_START.length; | ||
| const inner = content.substring(startOuterIndex + API_START.length); | ||
| const startInnerIndex = startOuterIndex + API_START.length + inner.indexOf('>') + 1; | ||
| const start = content.substring(0, startInnerIndex); | ||
| const end = content.substring(endInnerIndex); | ||
| return `${start}\n${UPDATE_MSG}\n${markdownApi(data)}\n${end}`; | ||
| return `${start}\n${UPDATE_MSG}\n\n${markdownApi(data)}\n\n${end}`; | ||
| } | ||
@@ -91,3 +93,3 @@ } | ||
| } | ||
| return `<div class="docgen docgen-index">\n\n${o.join('\n').trim()}\n\n</div>`; | ||
| return o.join('\n').trim(); | ||
| } | ||
@@ -122,3 +124,3 @@ function markdownApi(data) { | ||
| } | ||
| return `<div class="docgen docgen-api">\n\n${o.join('\n').trim()}\n\n</div>`; | ||
| return o.join('\n').trim(); | ||
| } | ||
@@ -141,4 +143,7 @@ function methodsTable(data, m) { | ||
| } | ||
| o.push(`**Returns:** ${cleanTypes(data, m.returns)}`); | ||
| o.push(``); | ||
| const ret = cleanTypes(data, m.returns); | ||
| if (ret.type && ret.type !== 'void' && ret.type !== 'Promise<void>') { | ||
| o.push(`**Returns:** ${ret.formatted}`); | ||
| o.push(``); | ||
| } | ||
| const since = getTagText(m.tags, 'since'); | ||
@@ -149,3 +154,3 @@ if (since) { | ||
| } | ||
| o.push(HR); | ||
| o.push(`--------------------`); | ||
| o.push(``); | ||
@@ -161,3 +166,3 @@ o.push(``); | ||
| const ty = cleanTypes(data, p.type); | ||
| t.addRow([nm, ty, p.docs]); | ||
| t.addRow([nm, ty.formatted, p.docs]); | ||
| }); | ||
@@ -168,27 +173,33 @@ t.removeEmptyColumns(); | ||
| function cleanTypes(data, c) { | ||
| if (typeof c !== 'string') { | ||
| return ''; | ||
| const rtn = { type: '', formatted: '' }; | ||
| if (typeof c === 'string') { | ||
| c = c.replace(/\n/g, ' ').trim(); | ||
| while (c.includes(' ')) { | ||
| c = c.replace(/ /g, ' '); | ||
| } | ||
| const isAsync = c.startsWith(`Promise<`) && c.endsWith(`>`); | ||
| if (isAsync) { | ||
| c = c.substring(`Promise<`.length); | ||
| c = c.substring(0, c.length - 1); | ||
| } | ||
| c = c | ||
| .split('|') | ||
| .map(c => c.trim()) | ||
| .filter(c => c !== 'undefined') | ||
| .map(c => linkType(data, c)) | ||
| .join(` | `); | ||
| if (c === '') { | ||
| return rtn; | ||
| } | ||
| if (isAsync) { | ||
| rtn.type = `Promise<${c}>`; | ||
| rtn.formatted = `Promise<${c}>`; | ||
| } | ||
| else { | ||
| rtn.type = c; | ||
| rtn.formatted = c; | ||
| } | ||
| rtn.formatted = `<code>${rtn.formatted}</code>`; | ||
| } | ||
| c = c.replace(/\n/g, ' ').trim(); | ||
| while (c.includes(' ')) { | ||
| c = c.replace(/ /g, ' '); | ||
| } | ||
| const isAsync = c.startsWith(`Promise<`) && c.endsWith(`>`); | ||
| if (isAsync) { | ||
| c = c.substring(`Promise<`.length); | ||
| c = c.substring(0, c.length - 1); | ||
| } | ||
| c = c | ||
| .split('|') | ||
| .map(c => c.trim()) | ||
| .filter(c => c !== 'undefined') | ||
| .map(c => linkType(data, c)) | ||
| .join(` | `); | ||
| if (c === '') { | ||
| return ''; | ||
| } | ||
| if (isAsync) { | ||
| c = `Promise<${c}>`; | ||
| } | ||
| return `<code>${c}</code>`; | ||
| return rtn; | ||
| } | ||
@@ -225,3 +236,3 @@ function linkType(data, s) { | ||
| `**\`${m.name}\`**`, | ||
| cleanTypes(data, m.type), | ||
| cleanTypes(data, m.type).formatted, | ||
| m.docs, | ||
@@ -259,3 +270,3 @@ defaultValue ? `<code>${defaultValue}</code>` : '', | ||
| `**\`${m.name}\`**`, | ||
| cleanTypes(data, m.value), | ||
| cleanTypes(data, m.value).formatted, | ||
| m.docs, | ||
@@ -295,2 +306,1 @@ getTagText(m.tags, 'since'), | ||
| exports.outputJson = outputJson; | ||
| const HR = `--------------------`; |
+3
-3
| { | ||
| "name": "@capacitor/docgen", | ||
| "version": "0.0.8", | ||
| "version": "0.0.9", | ||
| "description": "Docs Readme Markdown and JSON Generator for Capacitor Plugins", | ||
@@ -40,7 +40,7 @@ "keywords": [ | ||
| "@ionic/prettier-config": "^1.0.0", | ||
| "@stencil/core": "^2.0.3", | ||
| "@stencil/core": "^2.1.0-5", | ||
| "@types/github-slugger": "^1.3.0", | ||
| "@types/jest": "^26.0.14", | ||
| "@types/minimist": "^1.2.0", | ||
| "jest": "^26.4.2", | ||
| "jest": "^26.6.0", | ||
| "np": "^6.5.0", | ||
@@ -47,0 +47,0 @@ "prettier": "^2.1.2", |
+8
-6
@@ -27,4 +27,3 @@ # @capacitor/docgen | ||
| <!--DOCGEN_INDEX_START--> | ||
| <!--DOCGEN_INDEX_END--> | ||
| <docgen-index></docgen-index> | ||
@@ -37,4 +36,3 @@ ## Custom Readme Content | ||
| <!--DOCGEN_API_START--> | ||
| <!--DOCGEN_API_END--> | ||
| <docgen-api></docgen-api> | ||
@@ -48,4 +46,4 @@ ## Commit Your Readme 🚀 | ||
| - [Example Readme Output](https://github.com/ionic-team/capacitor-docgen/blob/master/src/test/README.md) | ||
| - [Example JSON Output](https://github.com/ionic-team/capacitor-docgen/blob/master/src/test/docs.json) | ||
| - [Example Readme Output](https://github.com/ionic-team/capacitor-docgen/blob/main/src/test/README.md) | ||
| - [Example JSON Output](https://github.com/ionic-team/capacitor-docgen/blob/main/src/test/docs.json) | ||
@@ -81,3 +79,7 @@ | ||
| ## API | ||
| The same API that's available to the CLI can also be imported from `@capacitor/docgen`. | ||
| ## Related | ||
@@ -84,0 +86,0 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
39194
1.44%994
1.02%85
2.41%