From c61800b3419a1f1e9e95008c377f299018d17273 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 24 Feb 2025 03:00:52 +0530 Subject: [PATCH] wip --- __tests__/e2e/dynamic-routes/[id].paths.ts | 13 +++++++------ __tests__/e2e/dynamic-routes/paths.ts | 4 ++++ src/node/init/init.ts | 14 +++++++------- src/node/markdownToVue.ts | 2 +- src/node/siteConfig.ts | 4 +--- 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 __tests__/e2e/dynamic-routes/paths.ts diff --git a/__tests__/e2e/dynamic-routes/[id].paths.ts b/__tests__/e2e/dynamic-routes/[id].paths.ts index 3eca4d91..48e35261 100644 --- a/__tests__/e2e/dynamic-routes/[id].paths.ts +++ b/__tests__/e2e/dynamic-routes/[id].paths.ts @@ -1,8 +1,9 @@ +import paths from './paths' + export default { - async paths() { - return [ - { params: { id: 'foo' }, content: `# Foo` }, - { params: { id: 'bar' }, content: `# Bar` } - ] - } + async paths(watchedFiles: string[]) { + console.log('watchedFiles', watchedFiles) + return paths + }, + watch: ['**/data-loading/**/*.json'] } diff --git a/__tests__/e2e/dynamic-routes/paths.ts b/__tests__/e2e/dynamic-routes/paths.ts new file mode 100644 index 00000000..5adb0ed4 --- /dev/null +++ b/__tests__/e2e/dynamic-routes/paths.ts @@ -0,0 +1,4 @@ +export default [ + { params: { id: 'foo' }, content: `# Foo` }, + { params: { id: 'bar' }, content: `# Bar` } +] diff --git a/src/node/init/init.ts b/src/node/init/init.ts index 6ccfdf09..8a6836a1 100644 --- a/src/node/init/init.ts +++ b/src/node/init/init.ts @@ -11,7 +11,7 @@ import fs from 'fs-extra' import template from 'lodash.template' import path from 'node:path' import { fileURLToPath } from 'node:url' -import { bold, cyan, yellow } from 'picocolors' +import c from 'picocolors' import { slash } from '../shared' export enum ScaffoldThemeType { @@ -38,7 +38,7 @@ const getPackageManger = () => { } export async function init(root?: string) { - intro(bold(cyan('Welcome to VitePress!'))) + intro(c.bold(c.cyan('Welcome to VitePress!'))) const options = await group( { @@ -232,7 +232,7 @@ export function scaffold({ const gitignorePrefix = root ? `${slash(root)}/.vitepress` : '.vitepress' if (fs.existsSync('.git')) { tips.push( - `Make sure to add ${cyan(`${gitignorePrefix}/dist`)} and ${cyan(`${gitignorePrefix}/cache`)} to your ${cyan(`.gitignore`)} file.` + `Make sure to add ${c.cyan(`${gitignorePrefix}/dist`)} and ${c.cyan(`${gitignorePrefix}/cache`)} to your ${c.cyan(`.gitignore`)} file.` ) } @@ -242,11 +242,11 @@ export function scaffold({ !userPkg.devDependencies?.['vue'] ) { tips.push( - `Since you've chosen to customize the theme, you should also explicitly install ${cyan(`vue`)} as a dev dependency.` + `Since you've chosen to customize the theme, you should also explicitly install ${c.cyan(`vue`)} as a dev dependency.` ) } - const tip = tips.length ? yellow([`\n\nTips:`, ...tips].join('\n- ')) : `` + const tip = tips.length ? c.yellow([`\n\nTips:`, ...tips].join('\n- ')) : `` const dir = root ? ' ' + root : '' const pm = getPackageManger() @@ -261,8 +261,8 @@ export function scaffold({ Object.assign(userPkg.scripts || (userPkg.scripts = {}), scripts) fs.writeFileSync(pkgPath, JSON.stringify(userPkg, null, 2)) - return `Done! Now run ${cyan(`${pm} run ${prefix}dev`)} and start writing.${tip}` + return `Done! Now run ${c.cyan(`${pm} run ${prefix}dev`)} and start writing.${tip}` } else { - return `You're all set! Now run ${cyan(`${pm === 'npm' ? 'npx' : pm} vitepress dev${dir}`)} and start writing.${tip}` + return `You're all set! Now run ${c.cyan(`${pm === 'npm' ? 'npx' : pm} vitepress dev${dir}`)} and start writing.${tip}` } } diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index ced8b3b4..8212800e 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -51,7 +51,7 @@ function getResolutionCache(siteConfig: SiteConfig) { __pages = siteConfig.pages.map((p) => slash(p.replace(/\.md$/, ''))) __dynamicRoutes = new Map( - siteConfig.dynamicRoutes.routes.map((r) => [ + siteConfig.dynamicRoutes.map((r) => [ r.fullPath, slash(path.join(siteConfig.srcDir, r.route)) ]) diff --git a/src/node/siteConfig.ts b/src/node/siteConfig.ts index 47414622..49451cbe 100644 --- a/src/node/siteConfig.ts +++ b/src/node/siteConfig.ts @@ -221,9 +221,7 @@ export interface SiteConfig cacheDir: string tempDir: string pages: string[] - dynamicRoutes: { - routes: ResolvedRouteConfig[] - } + dynamicRoutes: ResolvedRouteConfig[] rewrites: { map: Record inv: Record