1
1
import path from 'path'
2
2
import chalk from 'chalk'
3
3
import globby from 'globby'
4
- import { promises as fs } from 'fs'
5
4
import { createResolver , APP_PATH } from './utils/pathResolver'
6
5
import { Resolver } from 'vite'
7
6
import { Header } from './markdown/plugins/header'
7
+ import { exists } from './utils/fs'
8
8
9
9
const debug = require ( 'debug' ) ( 'vitepress:config' )
10
10
@@ -26,6 +26,7 @@ export interface SiteConfig<ThemeConfig = any> {
26
26
site : SiteData < ThemeConfig >
27
27
configPath : string
28
28
themeDir : string
29
+ publicDir : string
29
30
outDir : string
30
31
tempDir : string
31
32
resolver : Resolver
@@ -57,20 +58,17 @@ export async function resolveConfig(
57
58
58
59
// resolve theme path
59
60
const userThemeDir = resolve ( root , 'theme' )
60
- let themeDir : string
61
- try {
62
- await fs . stat ( userThemeDir )
63
- themeDir = userThemeDir
64
- } catch ( e ) {
65
- themeDir = path . join ( __dirname , '../lib/theme-default' )
66
- }
61
+ const themeDir = ( await exists ( userThemeDir ) )
62
+ ? userThemeDir
63
+ : path . join ( __dirname , '../lib/theme-default' )
67
64
68
65
const config : SiteConfig = {
69
66
root,
70
67
site,
71
68
themeDir,
72
69
pages : await globby ( [ '**.md' ] , { cwd : root , ignore : [ 'node_modules' ] } ) ,
73
70
configPath : resolve ( root , 'config.js' ) ,
71
+ publicDir : resolve ( root , 'public' ) ,
74
72
outDir : resolve ( root , 'dist' ) ,
75
73
tempDir : path . resolve ( APP_PATH , 'temp' ) ,
76
74
resolver : createResolver ( themeDir )
@@ -82,12 +80,7 @@ export async function resolveConfig(
82
80
export async function resolveSiteData ( root : string ) : Promise < SiteData > {
83
81
// load user config
84
82
const configPath = resolve ( root , 'config.js' )
85
- let hasUserConfig = false
86
- try {
87
- await fs . stat ( configPath )
88
- hasUserConfig = true
89
- } catch ( e ) { }
90
-
83
+ const hasUserConfig = await exists ( configPath )
91
84
// always delete cache first before loading config
92
85
delete require . cache [ configPath ]
93
86
const userConfig : UserConfig = hasUserConfig ? require ( configPath ) : { }
0 commit comments