Skip to content

Commit

Permalink
feat: 合并md文件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamiao committed Jul 15, 2024
1 parent 660e14d commit 683690a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion scripts/hi-docs/src/merge-docs.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Path from 'path'
import { heading, html, text } from 'mdast-builder'
import { markdownRender, outputPath, writeFileAsync, cleanCreateDir } from './utils/index.mjs'
import {
markdownRender,
outputPath,
writeFileAsync,
appendFileAsync,
cleanCreateDir,
} from './utils/index.mjs'

export async function mergeDocs(components) {
// const pkgs = components
Expand All @@ -18,6 +24,7 @@ export async function mergeDocs(components) {
markdown = mergePropsIntoReadme(markdown, info.props)
const markdownMd = mergeStoriesCodeIntoReadme(info.name, markdown, info.stories)
await writeReadmeAsync(info, markdownMd)
await appendReadmeAsync(info, markdownMd)
markdown = transformJSX(markdown)
markdown = mergeStoriesIntoReadme(info.name, markdown, info.stories)
// 写入
Expand Down Expand Up @@ -114,6 +121,11 @@ async function writeReadmeAsync(info, markdown) {
])
}

async function appendReadmeAsync(info, markdown) {
markdown = '\n\n###@###\n\n' + markdown
await Promise.all([appendFileAsync(Path.join(outputPath, 'hiui.md'), info.name, markdown)])
}

function storiesRender(name, stories) {
const markdownConfig = stories.reduce((acc, storyInfo) => {
const storyBlock = getStoryBlock(name, storyInfo)
Expand Down
4 changes: 4 additions & 0 deletions scripts/hi-docs/src/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const writeFileAsync = async (path, content) => {
await FS.writeFile(path, content)
}

export const appendFileAsync = async (path, name, content) => {
if (name !== 'hiui') await FS.appendFile(path, content)
}

export const readFileAsync = async (path, basePath) => {
if (basePath) {
path = Path.join(basePath, path)
Expand Down

0 comments on commit 683690a

Please sign in to comment.