Add md generation
This commit is contained in:
parent
fdb8ffcf2d
commit
59b01e3e88
|
@ -159,7 +159,7 @@ export interface IBlockDefinition<T> {
|
|||
icon?: string;
|
||||
getDefaultData: T;
|
||||
edit: Component<IBlockProps<T>>;
|
||||
display: Component<IBlockProps<T>>;
|
||||
view: Component<IBlockProps<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ export default defineComponent({
|
|||
const block = exampleData;
|
||||
|
||||
onMounted(async () => {
|
||||
// getBlock could be used to access the block data inside the editor
|
||||
const { getBlock } = await startSchlechtenburg(
|
||||
'#example-editor',
|
||||
{
|
||||
|
@ -39,8 +40,7 @@ export default defineComponent({
|
|||
|
||||
// This callback will be alled any time the block data gets updated
|
||||
onUpdate: (blockData) => {
|
||||
console.log('Got onUpdate', blockData);
|
||||
console.log('getBlock', getBlock());
|
||||
console.log('got update', blockData);
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
@ -18,7 +18,6 @@ export default defineComponent({
|
|||
|
||||
setup(props) {
|
||||
const docs = props.docs;
|
||||
console.log(docs);
|
||||
return () => <section class="docs component-docs">
|
||||
<header class="docs--header">
|
||||
<h2
|
||||
|
|
|
@ -3,8 +3,6 @@ import { defineComponent } from 'vue';
|
|||
import { ComponentDoc } from 'vue-docgen-api';
|
||||
import { DeclarationReflection } from 'typedoc';
|
||||
|
||||
import { getByName } from '../docs';
|
||||
import { getShortPackageName } from './package';
|
||||
import ComponentDocs from './ComponentDocs';
|
||||
import TSDocs from './TSDocs';
|
||||
|
||||
|
@ -28,7 +26,7 @@ export default defineComponent({
|
|||
}
|
||||
|
||||
const { lib, components } = docs;
|
||||
return () => <main class="package">
|
||||
return () => <div class="package">
|
||||
<h1>{lib.name}</h1>
|
||||
<p>{lib.comment}</p>
|
||||
<p>{lib.flags}</p>
|
||||
|
@ -40,6 +38,6 @@ export default defineComponent({
|
|||
|
||||
return <TSDocs docs={child}></TSDocs>
|
||||
})}
|
||||
</main>;
|
||||
</div>;
|
||||
},
|
||||
});
|
||||
|
|
84
packages/docs/lib/api/generate-api.ts
Normal file
84
packages/docs/lib/api/generate-api.ts
Normal file
|
@ -0,0 +1,84 @@
|
|||
import { DeclarationReflection } from 'typedoc';
|
||||
import { ComponentDoc } from 'vue-docgen-api';
|
||||
|
||||
import { getByName } from '../docs';
|
||||
import { getShortPackageName } from './package';
|
||||
|
||||
const getTypeParamString = (params: TypeParameterReflection[]) => `<${params.map(p => p.name).join(', ')}>`;
|
||||
|
||||
const generateComponentDoc = (docs: ComponentDoc) => `
|
||||
## ${docs.exportName}
|
||||
|
||||
<p class="docs--type">Component <code><${docs.displayName} /></code></p>
|
||||
|
||||
${docs.description}
|
||||
|
||||
### Props
|
||||
|
||||
${(docs.props || []).map(prop => `
|
||||
#### ${prop.name}
|
||||
|
||||
${prop.description}
|
||||
|
||||
${prop.type ? `Type: <code>${prop.type.name}</code>` : ''}
|
||||
|
||||
${prop.defaultValue ? `Default: <code>${prop.defaultValue.value}</code>`: null}
|
||||
</div>`).join('\n\n')}
|
||||
`;
|
||||
|
||||
const generateTSDocs = (docs: DeclarationReflection) => `
|
||||
## ${docs.name}${docs.typeParameters ? getTypeParamString(docs.typeParameters) : ''}
|
||||
|
||||
<p class="docs--type">{docs.kindString}</p>
|
||||
|
||||
${docs.comment?.shortText || ''}
|
||||
|
||||
${(docs.children || []).map((child: DeclarationReflection) => `
|
||||
\`\`\`
|
||||
${child.name}: ${child.type?.name}
|
||||
\`\`\`
|
||||
`).join('\n\n')}
|
||||
`;
|
||||
|
||||
const generateChildren = (
|
||||
children: DeclarationReflection[] = [],
|
||||
components: ComponentDoc[],
|
||||
) => children.map((child) => {
|
||||
const componentDocs = components.find((c: ComponentDoc) => c.exportName === child.name);
|
||||
if (componentDocs) {
|
||||
return generateComponentDoc(componentDocs);
|
||||
}
|
||||
|
||||
return generateTSDocs(child);
|
||||
});
|
||||
|
||||
/**
|
||||
* Generate the full markdown for a package
|
||||
*
|
||||
* Takes the package name (e.g. @schlechtenburg/core) and outputs a markdown string ready to be
|
||||
* consumed by vitepress
|
||||
*/
|
||||
export const generatePackageMd = (packageName: string) => {
|
||||
const docs = getByName(getShortPackageName(Array.isArray(packageName) ? packageName[0] : packageName));
|
||||
|
||||
if (!docs) {
|
||||
return `Could not find package docs for ${packageName}`;
|
||||
}
|
||||
|
||||
const { lib, components } = docs;
|
||||
|
||||
const markdown = `
|
||||
# ${lib.name}
|
||||
|
||||
${lib.comment}
|
||||
|
||||
${lib.flags}
|
||||
|
||||
${generateChildren(lib.children, components)}
|
||||
|
||||
`;
|
||||
|
||||
return markdown
|
||||
.trim()
|
||||
.replace(/\n\n+/, '\n\n');
|
||||
}
|
Loading…
Reference in a new issue