@vendure-io/docs-generator 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +8 -6
- package/dist/index.js +74 -76
- package/dist/renderer.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("node:path"),D=require("node:fs"),c=require("typescript"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("node:path"),D=require("node:fs"),c=require("typescript"),N=require("klaw-sync"),$=require("fs-extra");function P(d){return`---
|
|
2
2
|
title: "${k(d.replace(/-/g," "))}"
|
|
3
3
|
generated: true
|
|
4
4
|
---
|
|
5
|
-
`}function k(d){return d.split(" ").map(e=>e.length?e[0].toLocaleUpperCase()+e.slice(1):e).join(" ")}function b(d){return d==null?d:d.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9-_/]/g," ").replace(/\s+/g,"-").toLowerCase()}function
|
|
5
|
+
`}function k(d){return d.split(" ").map(e=>e.length?e[0].toLocaleUpperCase()+e.slice(1):e).join(" ")}function b(d){return d==null?d:d.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9-_/]/g," ").replace(/\s+/g,"-").toLowerCase()}function v(d){if(D.existsSync(d))try{let e=0;const n=N(d,{nodir:!0});for(const i of n){const t=D.readFileSync(i.path,"utf-8");z(t)&&(D.unlinkSync(i.path),e++)}e&&console.log(`Deleted ${e} generated docs from ${d}`)}catch(e){throw console.error("Could not delete generated docs!"),console.error(e),e}}function z(d){return/generated: true\n---\n/.test(d)}function j(d,e,n=[]){return d.flatMap(i=>N(T.join(e,i),{nodir:!0,filter:t=>{const r=T.extname(t.path);if(r===".ts"||r===".tsx"){for(const s of n)if(s.test(t.path))return!1;return!0}return!1},traverseAll:!0})).map(i=>i.path)}function G(d){return d!=null}class L{constructor(e){this.options=e}atTokenPlaceholder="__EscapedAtToken__";commentBlockEndTokenPlaceholder="__EscapedCommentBlockEndToken__";parse(e){const n=e.map(r=>c.createSourceFile(r,this.replaceEscapedTokens(D.readFileSync(r).toString()),c.ScriptTarget.ES2015,!0)),t=this.getStatementsWithSourceLocation(n).map(r=>this.parseDeclaration(r.statement,r.sourceFile,r.sourceLine)).filter(G).reduce((r,s)=>{const a=s.page||s.title,p=r.get(a);if(p)p.declarations.push(s);else{const g=b(a),u=s.category.split("/").pop(),o=g===u?"index":g;r.set(a,{title:a,category:s.category.split("/"),declarations:[s],fileName:o})}return r},new Map);return Array.from(t.values())}getStatementsWithSourceLocation(e){return e.reduce((n,i)=>{const t=i.statements.map(r=>{const s=T.relative(this.options.repoRoot,i.fileName).replace(/\\/g,"/"),a=i.getLineAndCharacterOfPosition(r.getStart()).line+1;return{statement:r,sourceFile:s,sourceLine:a}});return n.push(...t),n},[])}parseDeclaration(e,n,i){if(!this.isValidDeclaration(e))return;const t=this.getDocsCategory(e);if(t===void 0)return;let r;c.isVariableStatement(e)?r=e.declarationList.declarations[0].name.getText():r=e.name?e.name.getText():"anonymous";const s=this.getDeclarationFullText(e),a=this.getDeclarationWeight(e),p=this.getDeclarationDescription(e),g=this.getDocsPage(e),u=this.getSince(e),o=this.getExperimental(e),l={packageName:this.getPackageName(n),sourceFile:n,sourceLine:i,fullText:s,title:r,weight:a,category:t,description:p,page:g,since:u,experimental:o};if(c.isInterfaceDeclaration(e))return{...l,kind:"interface",extendsClause:this.getHeritageClause(e,c.SyntaxKind.ExtendsKeyword),members:this.parseMembers(e.members)};if(c.isTypeAliasDeclaration(e))return{...l,typeText:e.type.getText(),kind:"typeAlias",members:c.isTypeLiteralNode(e.type)?this.parseMembers(e.type.members):void 0};if(c.isClassDeclaration(e))return{...l,kind:"class",members:this.parseMembers(e.members),extendsClause:this.getHeritageClause(e,c.SyntaxKind.ExtendsKeyword),implementsClause:this.getHeritageClause(e,c.SyntaxKind.ImplementsKeyword)};if(c.isEnumDeclaration(e))return{...l,kind:"enum",members:this.parseMembers(e.members)};if(c.isFunctionDeclaration(e)){const x=e.parameters.map(y=>{let f=y.name.getText();return f.startsWith("{")&&f.endsWith("}")&&l.sourceFile.endsWith(".tsx")&&(f="props"),{name:f,type:y.type?y.type.getText():"",optional:!!y.questionToken,initializer:y.initializer?.getText()}});return{...l,kind:"function",parameters:x,typeText:e.type?.getText()}}else if(c.isVariableStatement(e))return{...l,kind:"variable"}}getHeritageClause(e,n){const{heritageClauses:i}=e;if(!i)return;const t=i.find(r=>r.token===n);if(t)return{text:t.getText(),types:t.types.map(r=>r.getText())}}getDeclarationFullText(e){let n;c.isVariableStatement(e)?n=e.declarationList.declarations[0].name.getText():n=e.name?e.name.getText():"anonymous";let i="";return!c.isEnumDeclaration(e)&&!c.isVariableStatement(e)&&e.typeParameters&&(i=`<${e.typeParameters.map(t=>t.getText()).join(", ")}>`),n+i}getPackageName(e){const n=e.match(/(?:^|\/)packages\/([^/]+)\//);return n?`${this.options.packagePrefix}/${n[1]}`:""}parseMembers(e){const n=[],i=t=>"modifiers"in t&&Array.isArray(t.modifiers);for(const t of e){const r=i(t)?t.modifiers.map(a=>a.getText()):[];if(!r.includes("private")&&(c.isPropertySignature(t)||c.isMethodSignature(t)||c.isPropertyDeclaration(t)||c.isMethodDeclaration(t)||c.isConstructorDeclaration(t)||c.isEnumMember(t)||c.isGetAccessorDeclaration(t)||c.isIndexSignatureDeclaration(t))){const a=t.name?t.name.getText():c.isIndexSignatureDeclaration(t)?"[index]":"constructor";let p="",g="",u="",o=[],m="",l=!1,x,y=!1;if(c.isConstructorDeclaration(t)?m="constructor":c.isMethodDeclaration(t)?m=t.name.getText():c.isGetAccessorDeclaration(t)?m=`${t.name.getText()}: ${t.type?t.type.getText():"void"}`:m=t.getText(),this.parseTags(t,{description:h=>p+=h||"",example:h=>p+=this.formatExampleCode(h),default:h=>u=h||"",internal:h=>l=!0,since:h=>x=h||void 0,experimental:h=>y=h!=null}),l)continue;!c.isEnumMember(t)&&t.type&&(g=t.type.getText());const f={fullText:m,name:a,description:this.restoreTokens(p),type:g.replace(/`/g,"\\`"),modifiers:r,since:x,experimental:y};c.isMethodSignature(t)||c.isMethodDeclaration(t)||c.isConstructorDeclaration(t)?(o=t.parameters.map(h=>({name:h.name.getText(),type:h.type?h.type.getText():"",optional:!!h.questionToken,initializer:h.initializer?.getText()})),n.push({...f,kind:"method",parameters:o})):n.push({...f,kind:"property",defaultValue:u})}}return n}tagCommentText(e){return e.comment?typeof e.comment=="string"?e.comment:e.comment.map(n=>n.kind===c.SyntaxKind.JSDocText?n.text:n.getText()).join(""):""}getDeclarationWeight(e){let n=10;return this.parseTags(e,{docsWeight:i=>n=Number.parseInt(i||"10",10)}),n}getDocsPage(e){let n;return this.parseTags(e,{docsPage:i=>n=i}),n}getSince(e){let n;return this.parseTags(e,{since:i=>n=i}),n}getExperimental(e){let n=!1;return this.parseTags(e,{experimental:i=>n=i!=null}),n}getDeclarationDescription(e){let n="";return this.parseTags(e,{description:i=>n+=i,example:i=>n+=this.formatExampleCode(i)}),this.restoreTokens(n)}getDocsCategory(e){let n;return this.parseTags(e,{docsCategory:i=>n=i||""}),b(n)}isValidDeclaration(e){return c.isInterfaceDeclaration(e)||c.isTypeAliasDeclaration(e)||c.isClassDeclaration(e)||c.isEnumDeclaration(e)||c.isFunctionDeclaration(e)||c.isVariableStatement(e)}parseTags(e,n){const i=c.getJSDocTags(e);for(const t of i){const r=t.tagName.text;n[r]&&n[r](this.tagCommentText(t))}}formatExampleCode(e=""){return`
|
|
6
6
|
|
|
7
7
|
*Example*
|
|
8
8
|
|
|
9
|
-
${e.replace(/\r/g,"")}`}replaceEscapedTokens(e){return e.replace(/\\@/g,this.atTokenPlaceholder).replace(/\\\/\*/g,this.commentBlockEndTokenPlaceholder)}restoreTokens(e){return e.replace(new RegExp(this.atTokenPlaceholder,"g"),"@").replace(new RegExp(this.commentBlockEndTokenPlaceholder,"g"),"/*")}}function
|
|
10
|
-
|
|
9
|
+
${e.replace(/\r/g,"")}`}replaceEscapedTokens(e){return e.replace(/\\@/g,this.atTokenPlaceholder).replace(/\\\/\*/g,this.commentBlockEndTokenPlaceholder)}restoreTokens(e){return e.replace(new RegExp(this.atTokenPlaceholder,"g"),"@").replace(new RegExp(this.commentBlockEndTokenPlaceholder,"g"),"/*")}}function V(d){throw new Error(`Expected never, got ${typeof d}`)}const S=" ";function w(d){return d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}class I{render(e,n,i,t){let r=0;$.existsSync(i)||$.ensureDirSync(i);const s=i.indexOf("/reference/"),a=s!==-1?i.slice(s+11):"",p=new Map,g=new Set;for(const u of e){u.category.length>0&&g.add(u.category[0]);for(let o=0;o<u.category.length-1;o++){const m=u.category.slice(0,o+1).join("/"),l=u.category[o+1];p.has(m)||p.set(m,new Set),p.get(m).add(l)}}for(const u of e){let o="";o+=P(u.title);const m=[...u.declarations].sort((f,h)=>f.weight-h.weight),l=m.length>1;for(const f of m)switch(l&&(o+=`## ${f.title}
|
|
10
|
+
|
|
11
|
+
`),f.kind){case"interface":o+=this.renderInterfaceOrClass(f,t,n);break;case"typeAlias":o+=this.renderTypeAlias(f,t,n);break;case"class":o+=this.renderInterfaceOrClass(f,t,n);break;case"enum":o+=this.renderEnum(f,t,n);break;case"function":o+=this.renderFunction(f,t,n);break;case"variable":o+=this.renderVariable(f,t,n);break;default:V(f)}const x=T.join(i,...u.category);$.existsSync(x)||$.mkdirsSync(x);const y=[];for(const f of u.category){y.push(f);const h=y.join("/"),C=p.get(h),E=new Set;if(C&&C.size>0)for(const A of C){const R=a?`${a}/`:"";E.add(`/reference/${R}${h}/${A}`)}const M=T.join(i,...y,"index.mdx");this.writeIndexFileIfNeeded(M,f,E)==="created"&&r++}$.writeFileSync(T.join(x,`${u.fileName}.mdx`),o),r++}if(a&&g.size>0){const u=new Set;for(const x of g)u.add(`/reference/${a}/${x}`);const o=k(a.replace(/-/g," ")),m=T.join(i,"index.mdx");this.writeIndexFileIfNeeded(m,o,u)==="created"&&r++}return r}writeIndexFileIfNeeded(e,n,i){const t=$.existsSync(e),r=t?$.readFileSync(e).toString():"";if(r.includes("isDefaultIndex: false"))return null;const a=r.includes("generated: true"),p=new Set;if(t&&a){const o=/<LinkCard href="([^"]+)"/g;let m;for(;(m=o.exec(r))!==null;)p.add(m[1])}const g=new Set([...p,...i]),u=i.size>0&&[...i].some(o=>!p.has(o));if(!t||u){let o=P(n);if(g.size>0){o+=`
|
|
12
|
+
`;const m=Array.from(g).sort((l,x)=>l.localeCompare(x));for(const l of m){const x=l.split("/").pop()||"",y=k(x.replace(/-/g," "));o+=`<LinkCard href="${l}" title="${y}" />
|
|
11
13
|
`}}return $.writeFileSync(e,o),t?"updated":"created"}return null}renderInterfaceOrClass(e,n,i){const{description:t}=e;let r="";return r+=this.renderGenerationInfoShortcode(e),r+=`${this.renderDescription(t,n,i)}
|
|
12
14
|
|
|
13
15
|
`,r+=e.kind==="interface"?this.renderInterfaceSignature(e):this.renderClassSignature(e),e.extendsClause&&(r+="* Extends: ",r+=`${this.renderHeritageClause(e.extendsClause,n,i)}
|
|
@@ -57,7 +59,7 @@ ${e.replace(/\r/g,"")}`}replaceEscapedTokens(e){return e.replace(/\\@/g,this.atT
|
|
|
57
59
|
|
|
58
60
|
`,t+=`<MemberInfo kind="parameter" type={\`${s}\`} />
|
|
59
61
|
|
|
60
|
-
`}return t}renderMembers(e,n,i){const{members:t,title:r}=e;let s="";for(const a of t||[]){let p="",g="",u="",o="";
|
|
62
|
+
`}return t}renderMembers(e,n,i){const{members:t,title:r}=e;let s="";for(const a of t||[]){if(a.kind==="method"&&a.fullText==="constructor")continue;let p="",g="",u="",o="";a.kind==="property"?(o=this.renderType(a.type,n,i),p=a.defaultValue?`default={\`${this.renderType(a.defaultValue,n,i)}\`} `:""):o=`(${a.parameters.map(l=>this.renderParameter(l,this.renderType(l.type,n,i))).join(", ")}) => ${this.renderType(a.type,n,i)}`,a.since&&(g=`since="${a.since}" `),a.experimental&&(u='experimental="true"'),s+=`
|
|
61
63
|
### ${a.name}
|
|
62
64
|
|
|
63
65
|
`,s+=`<MemberInfo kind="${a.kind}" type={\`${o}\`} ${p} ${g}${u} />
|
|
@@ -66,4 +68,4 @@ ${e.replace(/\r/g,"")}`}replaceEscapedTokens(e){return e.replace(/\\@/g,this.atT
|
|
|
66
68
|
|
|
67
69
|
`}renderParameter(e,n){return`${e.name}${e.optional?"?":""}: ${n}${e.initializer?` = ${e.initializer}`:""}`}renderGenerationInfoShortcode(e){const n=e.sourceFile.replace(/^\.\.\//,"");let i="";e.since&&(i=` since="${e.since}"`);let t="";return e.experimental&&(t=' experimental="true"'),`<GenerationInfo sourceFile="${n}" sourceLine="${e.sourceLine}" packageName="${e.packageName}"${i}${t} />
|
|
68
70
|
|
|
69
|
-
`}resolveTypeLinks(e,n,i){const r=[...n.entries()].sort((p,g)=>g[0].length-p[0].length).map(([p,g])=>[p,g,
|
|
71
|
+
`}resolveTypeLinks(e,n,i){const r=[...n.entries()].sort((p,g)=>g[0].length-p[0].length).map(([p,g])=>[p,g,w(p)]);let s="",a=e;for(;a.length>0;){let p=!1;for(const[g,u,o]of r){const m=new RegExp(`^(${o})\\b`),l=a.match(m);if(l){const x=u.replace(/\/_index$/,"");s+=i.onMatch(g,x),a=a.slice(l[0].length),p=!0;break}}if(!p){let g=a.length;for(const[,,o]of r){const m=new RegExp(`\\b(${o})\\b`),l=a.match(m);l?.index!==void 0&&l.index>0&&l.index<g&&(g=l.index)}const u=a.slice(0,g);s+=i.onNonMatch(u),a=a.slice(g)}}return s}prepareTypeText(e){return e.trim().replace(/[\u00A0-\u9999&]/gim,n=>`&#${n.charCodeAt(0)};`).replace(/\n/g," ")}renderType(e,n,i){return this.resolveTypeLinks(this.prepareTypeText(e),n,{onMatch:(t,r)=>`<a href='${i}/${r}'>${t}</a>`,onNonMatch:t=>t})}renderHeritageType(e,n,i){return this.resolveTypeLinks(this.prepareTypeText(e),n,{onMatch:(t,r)=>`[\`${t}\`](${i}/${r})`,onNonMatch:t=>t.includes("<")||t.includes(">")?`\`${t}\``:t})}renderDescription(e,n,i){for(const[t,r]of n){const s=new RegExp(`{@link\\s*${w(t)}}`,"g");e=e.replace(s,`[${t}](${i}/${r})`)}return e=e.replace(/\{@link\s*(\S+)\}/g,"`$1`"),e}}function W(d,e){const n=Date.now(),i=e.docsUrl??"",t=new Map;if(!e.isWatchMode)for(const{outputPath:r}of d)v(F(e.outputRoot,r));for(const{outputPath:r,sourceDirs:s,exclude:a}of d){const p=j(s,e.repoRoot,a),u=new L({packagePrefix:e.packagePrefix,repoRoot:e.repoRoot}).parse(p);for(const m of u){const{category:l,fileName:x,declarations:y}=m;for(const f of y){const h=`reference/${r?`${r}/`:""}${l?`${l.map(C=>b(C)).join("/")}/`:""}${x==="index"?"":x}#${_(f.title)}`;t.set(f.title,h)}}const o=new I().render(u,i,F(e.outputRoot,r),t);o&&console.log(`Generated ${o} typescript api docs for "${r||"root"}" in ${Date.now()-n}ms`)}}function _(d){return d.replace(/\s/g,"").toLowerCase()}function F(d,e){return T.join(d,e)}exports.TypescriptDocsParser=L;exports.TypescriptDocsRenderer=I;exports.deleteGeneratedDocs=v;exports.generateFrontMatter=P;exports.generateTypescriptDocs=W;exports.getSourceFilePaths=j;exports.normalizeForUrlPart=b;exports.titleCase=k;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import T from "node:path";
|
|
2
2
|
import D from "node:fs";
|
|
3
|
-
import c, { SyntaxKind as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function
|
|
3
|
+
import c, { SyntaxKind as I } from "typescript";
|
|
4
|
+
import N from "klaw-sync";
|
|
5
|
+
import $ from "fs-extra";
|
|
6
|
+
function E(d) {
|
|
7
7
|
return `---
|
|
8
8
|
title: "${k(d.replace(/-/g, " "))}"
|
|
9
9
|
generated: true
|
|
@@ -16,11 +16,11 @@ function k(d) {
|
|
|
16
16
|
function b(d) {
|
|
17
17
|
return d == null ? d : d.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9-_/]/g, " ").replace(/\s+/g, "-").toLowerCase();
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function M(d) {
|
|
20
20
|
if (D.existsSync(d))
|
|
21
21
|
try {
|
|
22
22
|
let e = 0;
|
|
23
|
-
const n =
|
|
23
|
+
const n = N(d, { nodir: !0 });
|
|
24
24
|
for (const i of n) {
|
|
25
25
|
const t = D.readFileSync(i.path, "utf-8");
|
|
26
26
|
A(t) && (D.unlinkSync(i.path), e++);
|
|
@@ -33,9 +33,9 @@ function I(d) {
|
|
|
33
33
|
function A(d) {
|
|
34
34
|
return /generated: true\n---\n/.test(d);
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function R(d, e, n = []) {
|
|
37
37
|
return d.flatMap(
|
|
38
|
-
(i) =>
|
|
38
|
+
(i) => N(T.join(e, i), {
|
|
39
39
|
nodir: !0,
|
|
40
40
|
filter: (t) => {
|
|
41
41
|
const r = T.extname(t.path);
|
|
@@ -51,10 +51,10 @@ function M(d, e, n = []) {
|
|
|
51
51
|
})
|
|
52
52
|
).map((i) => i.path);
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function z(d) {
|
|
55
55
|
return d != null;
|
|
56
56
|
}
|
|
57
|
-
class
|
|
57
|
+
class G {
|
|
58
58
|
constructor(e) {
|
|
59
59
|
this.options = e;
|
|
60
60
|
}
|
|
@@ -74,7 +74,7 @@ class z {
|
|
|
74
74
|
r.statement,
|
|
75
75
|
r.sourceFile,
|
|
76
76
|
r.sourceLine
|
|
77
|
-
)).filter(
|
|
77
|
+
)).filter(z).reduce((r, s) => {
|
|
78
78
|
const a = s.page || s.title, p = r.get(a);
|
|
79
79
|
if (p)
|
|
80
80
|
p.declarations.push(s);
|
|
@@ -160,13 +160,13 @@ class z {
|
|
|
160
160
|
members: this.parseMembers(e.members)
|
|
161
161
|
};
|
|
162
162
|
if (c.isFunctionDeclaration(e)) {
|
|
163
|
-
const x = e.parameters.map((
|
|
164
|
-
let
|
|
165
|
-
return
|
|
166
|
-
name:
|
|
167
|
-
type:
|
|
168
|
-
optional: !!
|
|
169
|
-
initializer:
|
|
163
|
+
const x = e.parameters.map((y) => {
|
|
164
|
+
let f = y.name.getText();
|
|
165
|
+
return f.startsWith("{") && f.endsWith("}") && l.sourceFile.endsWith(".tsx") && (f = "props"), {
|
|
166
|
+
name: f,
|
|
167
|
+
type: y.type ? y.type.getText() : "",
|
|
168
|
+
optional: !!y.questionToken,
|
|
169
|
+
initializer: y.initializer?.getText()
|
|
170
170
|
};
|
|
171
171
|
});
|
|
172
172
|
return {
|
|
@@ -217,25 +217,25 @@ class z {
|
|
|
217
217
|
const r = i(t) ? t.modifiers.map((a) => a.getText()) : [];
|
|
218
218
|
if (!r.includes("private") && (c.isPropertySignature(t) || c.isMethodSignature(t) || c.isPropertyDeclaration(t) || c.isMethodDeclaration(t) || c.isConstructorDeclaration(t) || c.isEnumMember(t) || c.isGetAccessorDeclaration(t) || c.isIndexSignatureDeclaration(t))) {
|
|
219
219
|
const a = t.name ? t.name.getText() : c.isIndexSignatureDeclaration(t) ? "[index]" : "constructor";
|
|
220
|
-
let p = "", g = "", u = "", o = [], m = "", l = !1, x,
|
|
220
|
+
let p = "", g = "", u = "", o = [], m = "", l = !1, x, y = !1;
|
|
221
221
|
if (c.isConstructorDeclaration(t) ? m = "constructor" : c.isMethodDeclaration(t) ? m = t.name.getText() : c.isGetAccessorDeclaration(t) ? m = `${t.name.getText()}: ${t.type ? t.type.getText() : "void"}` : m = t.getText(), this.parseTags(t, {
|
|
222
222
|
description: (h) => p += h || "",
|
|
223
223
|
example: (h) => p += this.formatExampleCode(h),
|
|
224
224
|
default: (h) => u = h || "",
|
|
225
225
|
internal: (h) => l = !0,
|
|
226
226
|
since: (h) => x = h || void 0,
|
|
227
|
-
experimental: (h) =>
|
|
227
|
+
experimental: (h) => y = h != null
|
|
228
228
|
}), l)
|
|
229
229
|
continue;
|
|
230
230
|
!c.isEnumMember(t) && t.type && (g = t.type.getText());
|
|
231
|
-
const
|
|
231
|
+
const f = {
|
|
232
232
|
fullText: m,
|
|
233
233
|
name: a,
|
|
234
234
|
description: this.restoreTokens(p),
|
|
235
235
|
type: g.replace(/`/g, "\\`"),
|
|
236
236
|
modifiers: r,
|
|
237
237
|
since: x,
|
|
238
|
-
experimental:
|
|
238
|
+
experimental: y
|
|
239
239
|
};
|
|
240
240
|
c.isMethodSignature(t) || c.isMethodDeclaration(t) || c.isConstructorDeclaration(t) ? (o = t.parameters.map((h) => ({
|
|
241
241
|
name: h.name.getText(),
|
|
@@ -243,11 +243,11 @@ class z {
|
|
|
243
243
|
optional: !!h.questionToken,
|
|
244
244
|
initializer: h.initializer?.getText()
|
|
245
245
|
})), n.push({
|
|
246
|
-
|
|
246
|
+
...f,
|
|
247
247
|
kind: "method",
|
|
248
248
|
parameters: o
|
|
249
249
|
})) : n.push({
|
|
250
|
-
|
|
250
|
+
...f,
|
|
251
251
|
kind: "property",
|
|
252
252
|
defaultValue: u
|
|
253
253
|
});
|
|
@@ -256,7 +256,7 @@ class z {
|
|
|
256
256
|
return n;
|
|
257
257
|
}
|
|
258
258
|
tagCommentText(e) {
|
|
259
|
-
return e.comment ? typeof e.comment == "string" ? e.comment : e.comment.map((n) => n.kind ===
|
|
259
|
+
return e.comment ? typeof e.comment == "string" ? e.comment : e.comment.map((n) => n.kind === I.JSDocText ? n.text : n.getText()).join("") : "";
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* Reads the @docsWeight JSDoc tag from the interface.
|
|
@@ -356,17 +356,17 @@ ${e.replace(/\r/g, "")}`;
|
|
|
356
356
|
return e.replace(new RegExp(this.atTokenPlaceholder, "g"), "@").replace(new RegExp(this.commentBlockEndTokenPlaceholder, "g"), "/*");
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
-
function
|
|
359
|
+
function V(d) {
|
|
360
360
|
throw new Error(`Expected never, got ${typeof d}`);
|
|
361
361
|
}
|
|
362
362
|
const S = " ";
|
|
363
|
-
function
|
|
363
|
+
function w(d) {
|
|
364
364
|
return d.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
365
365
|
}
|
|
366
|
-
class
|
|
366
|
+
class W {
|
|
367
367
|
render(e, n, i, t) {
|
|
368
368
|
let r = 0;
|
|
369
|
-
|
|
369
|
+
$.existsSync(i) || $.ensureDirSync(i);
|
|
370
370
|
const s = i.indexOf("/reference/"), a = s !== -1 ? i.slice(s + 11) : "", p = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set();
|
|
371
371
|
for (const u of e) {
|
|
372
372
|
u.category.length > 0 && g.add(u.category[0]);
|
|
@@ -377,10 +377,12 @@ class V {
|
|
|
377
377
|
}
|
|
378
378
|
for (const u of e) {
|
|
379
379
|
let o = "";
|
|
380
|
-
o +=
|
|
381
|
-
const m = [...u.declarations].sort((f,
|
|
380
|
+
o += E(u.title);
|
|
381
|
+
const m = [...u.declarations].sort((f, h) => f.weight - h.weight), l = m.length > 1;
|
|
382
382
|
for (const f of m)
|
|
383
|
-
switch (f.
|
|
383
|
+
switch (l && (o += `## ${f.title}
|
|
384
|
+
|
|
385
|
+
`), f.kind) {
|
|
384
386
|
case "interface":
|
|
385
387
|
o += this.renderInterfaceOrClass(f, t, n);
|
|
386
388
|
break;
|
|
@@ -400,23 +402,23 @@ class V {
|
|
|
400
402
|
o += this.renderVariable(f, t, n);
|
|
401
403
|
break;
|
|
402
404
|
default:
|
|
403
|
-
|
|
405
|
+
V(f);
|
|
404
406
|
}
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
const
|
|
407
|
+
const x = T.join(i, ...u.category);
|
|
408
|
+
$.existsSync(x) || $.mkdirsSync(x);
|
|
409
|
+
const y = [];
|
|
408
410
|
for (const f of u.category) {
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
if (
|
|
412
|
-
for (const
|
|
413
|
-
const
|
|
414
|
-
|
|
411
|
+
y.push(f);
|
|
412
|
+
const h = y.join("/"), C = p.get(h), P = /* @__PURE__ */ new Set();
|
|
413
|
+
if (C && C.size > 0)
|
|
414
|
+
for (const j of C) {
|
|
415
|
+
const L = a ? `${a}/` : "";
|
|
416
|
+
P.add(`/reference/${L}${h}/${j}`);
|
|
415
417
|
}
|
|
416
|
-
const
|
|
417
|
-
this.writeIndexFileIfNeeded(
|
|
418
|
+
const v = T.join(i, ...y, "index.mdx");
|
|
419
|
+
this.writeIndexFileIfNeeded(v, f, P) === "created" && r++;
|
|
418
420
|
}
|
|
419
|
-
|
|
421
|
+
$.writeFileSync(T.join(x, `${u.fileName}.mdx`), o), r++;
|
|
420
422
|
}
|
|
421
423
|
if (a && g.size > 0) {
|
|
422
424
|
const u = /* @__PURE__ */ new Set();
|
|
@@ -432,7 +434,7 @@ class V {
|
|
|
432
434
|
* Returns 'created' if a new file was written, 'updated' if existing was changed, null if skipped.
|
|
433
435
|
*/
|
|
434
436
|
writeIndexFileIfNeeded(e, n, i) {
|
|
435
|
-
const t =
|
|
437
|
+
const t = $.existsSync(e), r = t ? $.readFileSync(e).toString() : "";
|
|
436
438
|
if (r.includes("isDefaultIndex: false"))
|
|
437
439
|
return null;
|
|
438
440
|
const a = r.includes("generated: true"), p = /* @__PURE__ */ new Set();
|
|
@@ -444,18 +446,18 @@ class V {
|
|
|
444
446
|
}
|
|
445
447
|
const g = /* @__PURE__ */ new Set([...p, ...i]), u = i.size > 0 && [...i].some((o) => !p.has(o));
|
|
446
448
|
if (!t || u) {
|
|
447
|
-
let o =
|
|
449
|
+
let o = E(n);
|
|
448
450
|
if (g.size > 0) {
|
|
449
451
|
o += `
|
|
450
452
|
`;
|
|
451
453
|
const m = Array.from(g).sort((l, x) => l.localeCompare(x));
|
|
452
454
|
for (const l of m) {
|
|
453
|
-
const x = l.split("/").pop() || "",
|
|
454
|
-
o += `<LinkCard href="${l}" title="${
|
|
455
|
+
const x = l.split("/").pop() || "", y = k(x.replace(/-/g, " "));
|
|
456
|
+
o += `<LinkCard href="${l}" title="${y}" />
|
|
455
457
|
`;
|
|
456
458
|
}
|
|
457
459
|
}
|
|
458
|
-
return
|
|
460
|
+
return $.writeFileSync(e, o), t ? "updated" : "created";
|
|
459
461
|
}
|
|
460
462
|
return null;
|
|
461
463
|
}
|
|
@@ -579,14 +581,10 @@ class V {
|
|
|
579
581
|
const { members: t, title: r } = e;
|
|
580
582
|
let s = "";
|
|
581
583
|
for (const a of t || []) {
|
|
584
|
+
if (a.kind === "method" && a.fullText === "constructor")
|
|
585
|
+
continue;
|
|
582
586
|
let p = "", g = "", u = "", o = "";
|
|
583
|
-
|
|
584
|
-
o = this.renderType(a.type, n, i), p = a.defaultValue ? `default={\`${this.renderType(a.defaultValue, n, i)}\`} ` : "";
|
|
585
|
-
else {
|
|
586
|
-
const m = a.parameters.map((l) => this.renderParameter(l, this.renderType(l.type, n, i))).join(", ");
|
|
587
|
-
a.fullText === "constructor" ? o = `(${m}) => ${r}` : o = `(${m}) => ${this.renderType(a.type, n, i)}`;
|
|
588
|
-
}
|
|
589
|
-
a.since && (g = `since="${a.since}" `), a.experimental && (u = 'experimental="true"'), s += `
|
|
587
|
+
a.kind === "property" ? (o = this.renderType(a.type, n, i), p = a.defaultValue ? `default={\`${this.renderType(a.defaultValue, n, i)}\`} ` : "") : o = `(${a.parameters.map((l) => this.renderParameter(l, this.renderType(l.type, n, i))).join(", ")}) => ${this.renderType(a.type, n, i)}`, a.since && (g = `since="${a.since}" `), a.experimental && (u = 'experimental="true"'), s += `
|
|
590
588
|
### ${a.name}
|
|
591
589
|
|
|
592
590
|
`, s += `<MemberInfo kind="${a.kind}" type={\`${o}\`} ${p} ${g}${u} />
|
|
@@ -617,7 +615,7 @@ class V {
|
|
|
617
615
|
* callback for matched vs non-matched segments.
|
|
618
616
|
*/
|
|
619
617
|
resolveTypeLinks(e, n, i) {
|
|
620
|
-
const r = [...n.entries()].sort((p, g) => g[0].length - p[0].length).map(([p, g]) => [p, g,
|
|
618
|
+
const r = [...n.entries()].sort((p, g) => g[0].length - p[0].length).map(([p, g]) => [p, g, w(p)]);
|
|
621
619
|
let s = "", a = e;
|
|
622
620
|
for (; a.length > 0; ) {
|
|
623
621
|
let p = !1;
|
|
@@ -668,33 +666,33 @@ class V {
|
|
|
668
666
|
*/
|
|
669
667
|
renderDescription(e, n, i) {
|
|
670
668
|
for (const [t, r] of n) {
|
|
671
|
-
const s = new RegExp(`{@link\\s*${
|
|
669
|
+
const s = new RegExp(`{@link\\s*${w(t)}}`, "g");
|
|
672
670
|
e = e.replace(s, `[${t}](${i}/${r})`);
|
|
673
671
|
}
|
|
674
672
|
return e = e.replace(/\{@link\s*(\S+)\}/g, "`$1`"), e;
|
|
675
673
|
}
|
|
676
674
|
}
|
|
677
|
-
function
|
|
675
|
+
function Z(d, e) {
|
|
678
676
|
const n = Date.now(), i = e.docsUrl ?? "", t = /* @__PURE__ */ new Map();
|
|
679
677
|
if (!e.isWatchMode)
|
|
680
678
|
for (const { outputPath: r } of d)
|
|
681
|
-
|
|
679
|
+
M(F(e.outputRoot, r));
|
|
682
680
|
for (const { outputPath: r, sourceDirs: s, exclude: a } of d) {
|
|
683
|
-
const p =
|
|
681
|
+
const p = R(s, e.repoRoot, a), u = new G({
|
|
684
682
|
packagePrefix: e.packagePrefix,
|
|
685
683
|
repoRoot: e.repoRoot
|
|
686
684
|
}).parse(p);
|
|
687
685
|
for (const m of u) {
|
|
688
|
-
const { category: l, fileName: x, declarations:
|
|
689
|
-
for (const
|
|
690
|
-
const h = `reference/${r ? `${r}/` : ""}${l ? `${l.map((C) => b(C)).join("/")}/` : ""}${x === "index" ? "" : x}#${
|
|
691
|
-
t.set(
|
|
686
|
+
const { category: l, fileName: x, declarations: y } = m;
|
|
687
|
+
for (const f of y) {
|
|
688
|
+
const h = `reference/${r ? `${r}/` : ""}${l ? `${l.map((C) => b(C)).join("/")}/` : ""}${x === "index" ? "" : x}#${_(f.title)}`;
|
|
689
|
+
t.set(f.title, h);
|
|
692
690
|
}
|
|
693
691
|
}
|
|
694
|
-
const o = new
|
|
692
|
+
const o = new W().render(
|
|
695
693
|
u,
|
|
696
694
|
i,
|
|
697
|
-
|
|
695
|
+
F(e.outputRoot, r),
|
|
698
696
|
t
|
|
699
697
|
);
|
|
700
698
|
o && console.log(
|
|
@@ -702,19 +700,19 @@ function J(d, e) {
|
|
|
702
700
|
);
|
|
703
701
|
}
|
|
704
702
|
}
|
|
705
|
-
function
|
|
703
|
+
function _(d) {
|
|
706
704
|
return d.replace(/\s/g, "").toLowerCase();
|
|
707
705
|
}
|
|
708
|
-
function
|
|
706
|
+
function F(d, e) {
|
|
709
707
|
return T.join(d, e);
|
|
710
708
|
}
|
|
711
709
|
export {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
710
|
+
G as TypescriptDocsParser,
|
|
711
|
+
W as TypescriptDocsRenderer,
|
|
712
|
+
M as deleteGeneratedDocs,
|
|
713
|
+
E as generateFrontMatter,
|
|
714
|
+
Z as generateTypescriptDocs,
|
|
715
|
+
R as getSourceFilePaths,
|
|
718
716
|
b as normalizeForUrlPart,
|
|
719
717
|
k as titleCase
|
|
720
718
|
};
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,QAAQ,EAOR,OAAO,EAER,MAAM,SAAS,CAAA;AAkBhB,qBAAa,sBAAsB;IACjC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,QAAQ,EAOR,OAAO,EAER,MAAM,SAAS,CAAA;AAkBhB,qBAAa,sBAAsB;IACjC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;IA2GxF;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,CAAC,sBAAsB;IA6B9B,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,UAAU;IASlB,OAAO,CAAC,cAAc;IAiBtB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,wBAAwB;IAehC,OAAO,CAAC,oBAAoB;IA+B5B,OAAO,CAAC,wBAAwB;IAgBhC,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,aAAa;IAwCrB,OAAO,CAAC,oBAAoB;IAM5B,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,6BAA6B;IAarC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA4CxB,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAS1B"}
|