Skip to content

Commit

Permalink
docs: removing generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Sep 3, 2024
1 parent 33f04c7 commit acd0ef4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2,574 deletions.
2 changes: 2 additions & 0 deletions www/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ sdk-doc.json

# generated docs
src/content/docs/docs/component/
src/content/docs/docs/reference/
!src/content/docs/docs/reference/sdk.mdx
168 changes: 83 additions & 85 deletions www/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ async function generateExamplesDocs() {
renderTdComment(module.children![0].comment?.summary!),
...renderRunFunction(module),
``,
`View the [full example](${config.github}/tree/dev/examples/${
module.name.split("/")[0]
`View the [full example](${config.github}/tree/dev/examples/${module.name.split("/")[0]
}).`,
``,
];
Expand Down Expand Up @@ -416,6 +415,9 @@ async function generateDnsDoc(module: TypeDoc.DeclarationReflection) {
vercel: "Vercel",
}[dnsProvider] || dnsProvider;

const dir = path.dirname(outputFilePath);
fs.mkdirSync(dir, { recursive: true });

fs.writeFileSync(
outputFilePath,
[
Expand Down Expand Up @@ -456,6 +458,9 @@ async function generateLinkableDoc(module: TypeDoc.DeclarationReflection) {
},
}[module.name]!;

const dir = path.dirname(outputFilePath);
fs.mkdirSync(dir, { recursive: true });

fs.writeFileSync(
outputFilePath,
[
Expand Down Expand Up @@ -497,6 +502,9 @@ async function generateComponentDoc(
`${component.name.split("/").slice(1).join("/")}.mdx`
);

const dir = path.dirname(outputFilePath);
fs.mkdirSync(dir, { recursive: true });

fs.writeFileSync(
outputFilePath,
[
Expand Down Expand Up @@ -524,23 +532,23 @@ async function generateComponentDoc(
: []),
...(sdk
? renderFunctions(
sdk,
useModuleFunctions(sdk),
sdk.name === "realtime" ? { prefix: sdk.name } : undefined
)
sdk,
useModuleFunctions(sdk),
sdk.name === "realtime" ? { prefix: sdk.name } : undefined
)
: []),
...(sdk ? renderInterfacesAtH3Level(sdk) : []),
];
return lines.length
? [
``,
`## SDK`,
``,
`Use the [SDK](/docs/reference/sdk/) in your runtime to interact with your infrastructure.`,
``,
`---`,
...lines,
]
``,
`## SDK`,
``,
`Use the [SDK](/docs/reference/sdk/) in your runtime to interact with your infrastructure.`,
``,
`---`,
...lines,
]
: [];
})(),
renderMethods(component),
Expand Down Expand Up @@ -688,8 +696,8 @@ function renderType(
function renderArrayType(type: TypeDoc.ArrayType) {
return type.elementType.type === "union"
? `<code class="symbol">(</code>${renderSomeType(
type.elementType
)}<code class="symbol">)[]</code>`
type.elementType
)}<code class="symbol">)[]</code>`
: `${renderSomeType(type.elementType)}<code class="symbol">[]</code>`;
}
function renderTypescriptType(type: TypeDoc.ReferenceType) {
Expand Down Expand Up @@ -759,9 +767,8 @@ function renderType(
}
// types in the same doc (links to an interface)
if (useModuleInterfaces(module).find((i) => i.name === type.name)) {
return `[<code class="type">${
type.name
}</code>](#${type.name.toLowerCase()})`;
return `[<code class="type">${type.name
}</code>](#${type.name.toLowerCase()})`;
}
// types in different doc
const externalModule = {
Expand Down Expand Up @@ -815,9 +822,8 @@ function renderType(
function renderSstSdkType(type: TypeDoc.ReferenceType) {
// types in the same doc (links to an interface)
if (useModuleInterfaces(module).find((i) => i.name === type.name)) {
return `[<code class="type">${
type.name
}</code>](#${type.name.toLowerCase()})`;
return `[<code class="type">${type.name
}</code>](#${type.name.toLowerCase()})`;
} else if (type.name === "T") {
return `<code class="primitive">string</code>`;
}
Expand Down Expand Up @@ -897,9 +903,8 @@ function renderType(
console.error(type);
throw new Error(`Unsupported @pulumi provider input type`);
}
return `[<code class="type">${
type.name
}</code>](https://www.pulumi.com/registry/packages/${provider}/api-docs/${link}/#${type.name.toLowerCase()})`;
return `[<code class="type">${type.name
}</code>](https://www.pulumi.com/registry/packages/${provider}/api-docs/${link}/#${type.name.toLowerCase()})`;
} else if (cls.startsWith("types/")) {
console.error(type);
throw new Error(`Unsupported @pulumi provider class type`);
Expand Down Expand Up @@ -1035,8 +1040,7 @@ function renderVariables(module: TypeDoc.DeclarationReflection) {
// nested props (ie. `.nodes`)
...useNestedTypes(v.type!, v.name).flatMap(
({ depth, prefix, subType }) => [
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${
depth === 0 ? "h4" : "h5"
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(subType)}</NestedTitle>`,
`<Segment>`,
`<Section type="parameters">`,
Expand Down Expand Up @@ -1073,7 +1077,7 @@ function renderFunctions(
`<Section type="signature">`,
"```ts",
(opts?.prefix ? `${opts.prefix}.` : "") +
renderSignature(f.signatures![0]),
renderSignature(f.signatures![0]),
"```",
`</Section>`
);
Expand Down Expand Up @@ -1211,7 +1215,7 @@ function renderMethod(
`<Section type="signature">`,
"```ts",
(method.flags.isStatic ? `${useClassName(module)}.` : "") +
renderSignature(method.signatures![0]),
renderSignature(method.signatures![0]),
"```",
`</Section>`
);
Expand Down Expand Up @@ -1266,16 +1270,14 @@ function renderProperties(module: TypeDoc.DeclarationReflection) {
// nested props (ie. `.nodes`)
...useNestedTypes(g.getSignature!.type!, g.name).flatMap(
({ depth, prefix, subType }) => [
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${
depth === 0 ? "h4" : "h5"
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(subType)}</NestedTitle>`,
`<Segment>`,
`<Section type="parameters">`,
`<InlineSection>`,
`**Type** ${
subType.kind === TypeDoc.ReflectionKind.Property
? renderType(module, subType.type!)
: renderType(module, subType.getSignature!.type!)
`**Type** ${subType.kind === TypeDoc.ReflectionKind.Property
? renderType(module, subType.type!)
: renderType(module, subType.getSignature!.type!)
}`,
`</InlineSection>`,
`</Section>`,
Expand Down Expand Up @@ -1341,7 +1343,7 @@ function renderLinks(module: TypeDoc.DeclarationReflection) {
linkType = link.type;
linkType.types = linkType.types.map((t) =>
t.type === "reference" &&
(t.name === "Output" || t.name === "OutputInstance")
(t.name === "Output" || t.name === "OutputInstance")
? t.typeArguments![0]
: t
);
Expand Down Expand Up @@ -1461,45 +1463,42 @@ function renderInterfacesAtH2Level(
({ depth, prefix, subType }) => {
return subType.kind === TypeDoc.ReflectionKind.Method
? renderMethod(module, subType, {
methodTitle: `<NestedTitle id="${useLinkHashes(module).get(
subType
)}" Tag="${
depth === 0 ? "h4" : "h5"
methodTitle: `<NestedTitle id="${useLinkHashes(module).get(
subType
)}" Tag="${depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(
subType
)}</NestedTitle>`,
parametersTitle: `**Parameters**`,
})
parametersTitle: `**Parameters**`,
})
: [
`<NestedTitle id="${useLinkHashes(module).get(
subType
)}" Tag="${
depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(
subType
)}</NestedTitle>`,
`<Segment>`,
`<Section type="parameters">`,
`<InlineSection>`,
`**Type** ${renderType(module, subType.type!)}`,
`</InlineSection>`,
`</Section>`,
...renderDefaultTag(module, subType),
...renderDescription(subType),
``,
...renderExamples(subType),
`</Segment>`,
];
`<NestedTitle id="${useLinkHashes(module).get(
subType
)}" Tag="${depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(
subType
)}</NestedTitle>`,
`<Segment>`,
`<Section type="parameters">`,
`<InlineSection>`,
`**Type** ${renderType(module, subType.type!)}`,
`</InlineSection>`,
`</Section>`,
...renderDefaultTag(module, subType),
...renderDescription(subType),
``,
...renderExamples(subType),
`</Segment>`,
];
}
)
);
} else if (prop.kind === TypeDoc.ReflectionKind.Method) {
console.debug(` - interface method ${prop.name}`);
lines.push(
...renderMethod(module, prop, {
methodTitle: `### ${
prop.flags.isStatic ? "static " : ""
}${renderName(prop)}`,
methodTitle: `### ${prop.flags.isStatic ? "static " : ""
}${renderName(prop)}`,
parametersTitle: `#### Parameters`,
})
);
Expand Down Expand Up @@ -1538,8 +1537,7 @@ function renderInterfacesAtH3Level(module: TypeDoc.DeclarationReflection) {
// nested props (ie. `.domain`, `.transform`)
...useNestedTypes(int.type!, int.name).flatMap(
({ depth, prefix, subType }) => [
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${
depth === 0 ? "h4" : "h5"
`<NestedTitle id="${useLinkHashes(module).get(subType)}" Tag="${depth === 0 ? "h4" : "h5"
}" parent="${prefix}.">${renderName(subType)}</NestedTitle>`,
`<Segment>`,
`<Section type="parameters">`,
Expand Down Expand Up @@ -1592,11 +1590,11 @@ function renderDescription(
const str = renderTdComment(prop.comment?.summary);
return opts?.indent
? [
str
.split("\n")
.map((line) => ` ${line}`)
.join("\n"),
]
str
.split("\n")
.map((line) => ` ${line}`)
.join("\n"),
]
: [str];
}

Expand All @@ -1615,12 +1613,12 @@ function renderDefaultTag(
// Otherwise render it as a comment ie. No domains configured
defaultTag.content.length === 1 && defaultTag.content[0].kind === "code"
? `**Default** ${renderType(module, {
type: "intrinsic",
name: defaultTag.content[0].text
.replace(/`/g, "")
.replace(/{/g, "&lcub;")
.replace(/}/g, "&rcub;"),
} as TypeDoc.SomeType)}`
type: "intrinsic",
name: defaultTag.content[0].text
.replace(/`/g, "")
.replace(/{/g, "&lcub;")
.replace(/}/g, "&rcub;"),
} as TypeDoc.SomeType)}`
: `**Default** ${renderTdComment(defaultTag.content)}`,
`</InlineSection>`,
];
Expand Down Expand Up @@ -1825,10 +1823,10 @@ function useNestedTypes(
: []),
...(subType.kind === TypeDoc.ReflectionKind.Accessor
? useNestedTypes(
subType.getSignature?.type!,
`${prefix}.${subType.name}`,
depth + 1
)
subType.getSignature?.type!,
`${prefix}.${subType.name}`,
depth + 1
)
: []),
]);

Expand All @@ -1841,7 +1839,7 @@ function useNestedTypes(

function configureLogger() {
if (process.env.DEBUG) return;
console.debug = () => {};
console.debug = () => { };
}

function patchCode() {
Expand Down Expand Up @@ -1890,9 +1888,9 @@ function patchCode() {
/include\?\: \{[^}]*\}/,
`include?: (AwsPermission | CloudflareBinding)`
) +
"\ntype Constructor = {};\n" +
"\ntype AwsPermission = {};\n" +
"\ntype CloudflareBinding = {};\n"
"\ntype Constructor = {};\n" +
"\ntype AwsPermission = {};\n" +
"\ntype CloudflareBinding = {};\n"
);
}

Expand Down
Loading

0 comments on commit acd0ef4

Please sign in to comment.