Skip to content

Commit

Permalink
Update docs template
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUltDev committed Apr 30, 2024
1 parent 792e1d4 commit 50144c6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ APP_DISPLAY_NAME: EXO
STORE_VERSION: 1.0

# Design
FONT_ID: inter
FONT_NAME: Inter
FONT_WEIGHTS: 400,500

Expand Down
20 changes: 4 additions & 16 deletions design/components/layout/card/Card.docs.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
:::import:::
import {Button} from 'vocs/components';
:::header:::

# :::name:::

> :::desc:::
:::example
:::demo

<Card
header="Test"
Expand All @@ -14,16 +9,9 @@ import {Button} from 'vocs/components';

:::

```tsx twoslash
:::twobase:::
// @log: ↓ Import the component
:::import:::

// @log: ↓ Try the example
:::example:::
```
:::usage:::

<Button href=":::storybook:::">Storybook</Button>
:::storybook:::

## Props

Expand Down
2 changes: 2 additions & 0 deletions locales.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** Supported languages **/

export type Locales = keyof typeof locales;

export const sourceLocale: Locales = 'en';
Expand Down
2 changes: 2 additions & 0 deletions toolkit/config/locales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// THIS FILE IS AUTO-GENERATED. DO NOT EDIT THIS FILE DIRECTLY.
// EDIT THE "locales.ts" FILE IN THE ROOT INSTEAD.

/** Supported languages **/

export type Locales = keyof typeof locales;

export const sourceLocale: Locales = 'en';
Expand Down
39 changes: 31 additions & 8 deletions toolkit/vocs/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,43 @@ async function processComponents(files: string[], paths: string[]) {
const {name, base} = getPartsFromDocPath(path);
const component = await readFile(`${input}/${base}/${name}.tsx`, 'utf8');
const [doc] = parseDocs(component);
const componentName = doc.displayName || '';
let mdx = await readFile(`${input}/${base}/${name}.docs.mdx`, 'utf8');
mdx = mdx.replace(/:::name:::/g, doc.displayName || '');
mdx = mdx.replace(/:::desc:::/g, doc.description || '');
mdx = mdx.replace(/:::header:::/g, `\n# ${componentName}\n\n> ${doc.description}`);
mdx = mdx.replace(/:::props:::/g, getPropsTable(doc.props));
mdx = mdx.replace(/:::import:::/g, `import {${doc.displayName}} from 'design';`);
mdx = mdx.replace(/:::twobase:::/g, `import React from 'react';\n// ---cut---`);
mdx = mdx.replace(/:::storybook:::/g, `${config.LINK_STORYBOOK}/?path=/docs/components-${base.replace('/', '-')}`);
const example = mdx.match(/:::example(.*?):::/s)?.[1];
if (example) mdx = mdx.replace(/:::example(.*?):::/gs, example.trim());
mdx = mdx.replace(/:::storybook:::/g, `<SB href="${config.LINK_STORYBOOK}/?path=/docs/components-${base.replace('/', '-')}">Storybook</SB>`);
const demo = mdx.match(/:::demo(.*?):::/s)?.[1];
const imports = mdx.match(/:::imports(.*?):::/s)?.[1];
if (demo) mdx = mdx.replace(/:::demo(.*?):::/gs, demo.trim());
if (imports) mdx = mdx.replace(/:::imports(.*?):::/gs, imports.trim());
mdx = mdx.replace(/:::usage:::/g, getCodeBlock(componentName, imports, demo));
const final = getDefaultImports(componentName) + '\n' + mdx;
await ensureDir([output, ...base.split('/')].slice(0, -1).join('/'));
await writeFile(`${output}/${base}.mdx`, mdx, 'utf8');
await writeFile(`${output}/${base}.mdx`, final, 'utf8');
});
}

function getDefaultImports(componentName: string) {
return [
`import {Button as SB} from 'vocs/components';`,
`import {${componentName}} from 'design';`,
].join('\n');
}

function getCodeBlock(componentName: string, imports?: string, demo?: string) {
return [
'```tsx twoslash',
'import React from \'react\';',
'// ---cut---',
'// @log: ↓ Import the component',
`import {${componentName}} from \'design\';`,
imports ? imports?.trim() + '\n' : '',
'// @log: ↓ Try the example',
demo?.trim(),
'```',
].join('\n');
}

function getPropsTable(props?: Record<string, PropDescriptor>) {
if (!props) return '';
const table = [
Expand Down

0 comments on commit 50144c6

Please sign in to comment.