forked from epicmaxco/vuestic-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
112 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/docs/modules/page-config/blocks/change-log/transform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { readFile } from 'fs/promises'; | ||
import { defineBlockTransform } from "../../compiler/define-block-transform"; | ||
import glob from 'fast-glob' | ||
import { resolve, join } from 'pathe' | ||
|
||
const changelogs = glob(join(resolve(''), '..', 'ui/src/**/CHANGELOG.md')) | ||
|
||
export const render = async () => { | ||
const logs = await changelogs | ||
const logEnteries = await Promise.all((logs) | ||
.map(async (path) => { | ||
return [ | ||
path, | ||
await readFile(path, 'utf-8') | ||
] | ||
})) | ||
|
||
const mergedChangelog = logEnteries | ||
.reduce((acc, [path, changelog]) => { | ||
const componentName = path.match(/components\/(.*)\/CHANGELOG.md/)?.[1] | ||
|
||
const spilledByVersion = changelog.split(/# ([0-9]*\.[0-9]*\.[0-9]*)/).filter(Boolean) | ||
|
||
for (let i = 0; i < spilledByVersion.length; i += 2) { | ||
const version = spilledByVersion[i] | ||
const content = spilledByVersion[i + 1] | ||
|
||
acc[version] = acc[version] || {} | ||
|
||
if (componentName) { | ||
acc[version][componentName] = content.split('\n').filter(Boolean) | ||
} | ||
} | ||
return acc | ||
}, {} as Record<string, Record<string, string[]>>) | ||
|
||
return mergedChangelog | ||
} | ||
|
||
export default defineBlockTransform(async function (block) { | ||
if (block.type !== 'changeLog') { return } | ||
|
||
const changelog = await render() | ||
|
||
const newblock = block.replaceArgCode(0, JSON.stringify(changelog)) | ||
return newblock | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export type ChangeLog = Record<`${number}.${number}.${number}`, string[]> | ||
import { type render } from './transform' | ||
|
||
export type ChangeLog = Awaited<ReturnType<typeof render>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,6 @@ | ||
const changelogs = import.meta.glob('@/../ui/**/CHANGELOG.md', { as: 'raw' }) as Record<string, () => Promise<string>> | ||
|
||
|
||
const render = async () => { | ||
const logEnteries = await Promise.all(Object.entries(changelogs) | ||
.map(async ([path, changelog]) => { | ||
return [ | ||
path, | ||
await changelog() | ||
] | ||
})) | ||
|
||
const mergedChangelog = logEnteries | ||
.reduce((acc, [path, changelog]) => { | ||
const componentName = path.match(/components\/(.*)\/CHANGELOG.md/)?.[1] | ||
|
||
const spilledByVersion = changelog.split(/# ([0-9]*\.[0-9]*\.[0-9]*)/).filter(Boolean) | ||
|
||
for (let i = 0; i < spilledByVersion.length; i += 2) { | ||
const version = spilledByVersion[i] | ||
const content = spilledByVersion[i + 1] | ||
|
||
acc[version] = acc[version] || {} | ||
|
||
if (componentName) { | ||
acc[version][componentName] = content.split('\n').filter(Boolean) | ||
} | ||
} | ||
return acc | ||
}, {} as Record<string, Record<string, string[]>>) | ||
|
||
return [ | ||
block.component("ChangeLog", { changelog: mergedChangelog }) | ||
] | ||
} | ||
|
||
export default definePageConfig({ | ||
blocks: [ | ||
block.title('Change Log'), | ||
block.async(render()) | ||
block.changeLog(), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters