Skip to content

Commit

Permalink
✨ feat(monorepo-1): 初步实现首页移动配置。
Browse files Browse the repository at this point in the history
  • Loading branch information
ruan-cat committed Nov 30, 2024
1 parent 8e283c4 commit 8188d1e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions tests/monorepo-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 忽略掉会被自动移动的文件
./docs/index.md
File renamed without changes.
15 changes: 15 additions & 0 deletions tests/monorepo-1/src/configs/vip/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vitepress";
import { generateSidebar } from "vitepress-sidebar";

import { moveMdAsHomePage } from "../../../tools/move-md-as-home-page.ts";

moveMdAsHomePage("./src/configs/vip/.vitepress/index.md", "./docs");

const name = "vip";

// https://vitepress.dev/reference/site-config
Expand All @@ -14,6 +20,15 @@ export default defineConfig({
outDir: `../../../dist/${name}`,
cacheDir: `../../../.cache/${name}`,

vite: {
resolve: {
alias: {
// 警告 目前该配置无意义 无效
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
},

themeConfig: {
i18nRouting: true,

Expand Down
15 changes: 4 additions & 11 deletions tests/monorepo-1/src/tools/move-md-as-home-page.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { existsSync, copyFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { resolve } from "node:path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

function moveMdAsHomePage(targetSrcDir: string) {
const indexPath = resolve(__dirname, "index.md");
export function moveMdAsHomePage(targetMd: string, targetSrcDir: string) {
const indexPath = resolve(process.cwd(), targetMd);
const targetPath = resolve(process.cwd(), targetSrcDir, "index.md");

if (!existsSync(indexPath)) {
console.log(`未发现期望的 ${__dirname}/index.md 首页文件,无法移动文件。`);
console.log(`未发现期望的 ${targetMd} 首页文件,无法移动文件。`);
return;
}

copyFileSync(indexPath, targetPath);
console.log(`文件已复制到 ${targetPath}`);
}

// 示例调用
moveMdAsHomePage("./docs");
21 changes: 21 additions & 0 deletions tests/monorepo-1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{
"path": "../../tsconfig.md.json"
}
],
"compilerOptions": {
"paths": {
// 警告 目前该配置无意义 无效
"@/*": [
"./src/*"
]
}
},
"include": [
"./src/**/*.ts",
"./src/**/.vitepress/**/*.ts",
"./src/**/.vitepress/**/*.mts",
]
}

0 comments on commit 8188d1e

Please sign in to comment.