build: introduce to turborepo

This commit is contained in:
melvinchia3636
2026-06-09 23:35:34 +08:00
parent 7548c1a091
commit bdb860853c
119 changed files with 2349 additions and 2536 deletions

3
docs/plugins/mdxListCountsPlugin.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
import type { Plugin } from 'vite';
declare function mdxListCountsPlugin(): Plugin;
export default mdxListCountsPlugin;

View File

@@ -3,11 +3,14 @@ import path from 'node:path'
import type { Plugin } from 'vite'
const VIRTUAL_MODULE_ID = 'virtual:mdx-list-counts'
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID
function countListItems(mdxSource: string): number {
const listItemRegex = /^[\t ]*- /gm
const matches = mdxSource.match(listItemRegex)
return matches ? matches.length : 0
}
@@ -25,6 +28,7 @@ function mdxListCountsPlugin(): Plugin {
__dirname,
'../src/contents/04.progress/versions'
)
const counts: Record<string, number> = {}
// Read all MDX files recursively
@@ -33,13 +37,16 @@ function mdxListCountsPlugin(): Plugin {
for (const entry of entries) {
const fullPath = path.join(dir, entry.name)
const relativePath = path.join(basePath, entry.name)
if (entry.isDirectory()) {
readMdxFiles(fullPath, relativePath)
} else if (entry.name.endsWith('.mdx')) {
const content = fs.readFileSync(fullPath, 'utf-8')
const key = `../versions/${relativePath.replace(/\\/g, '/')}`
counts[key] = countListItems(content)
}
}
@@ -56,8 +63,10 @@ function mdxListCountsPlugin(): Plugin {
const module = server.moduleGraph.getModuleById(
RESOLVED_VIRTUAL_MODULE_ID
)
if (module) {
server.moduleGraph.invalidateModule(module)
return [module]
}
}