@@ -21,6 +21,7 @@ export enum ScaffoldThemeType {
21
21
22
22
export interface ScaffoldOptions {
23
23
root : string
24
+ srcDir : string
24
25
title ?: string
25
26
description ?: string
26
27
theme : ScaffoldThemeType
@@ -53,6 +54,13 @@ export async function init(root: string | undefined) {
53
54
} )
54
55
} ,
55
56
57
+ srcDir : async ( ) => {
58
+ return text ( {
59
+ message : 'Where should VitePress look for your markdown files?' ,
60
+ initialValue : './'
61
+ } )
62
+ } ,
63
+
56
64
title : ( ) =>
57
65
text ( {
58
66
message : 'Site title:' ,
@@ -129,6 +137,7 @@ export async function init(root: string | undefined) {
129
137
130
138
export function scaffold ( {
131
139
root = './' ,
140
+ srcDir = './' ,
132
141
title = 'My Awesome Project' ,
133
142
description = 'A VitePress Site' ,
134
143
theme,
@@ -138,12 +147,14 @@ export function scaffold({
138
147
npmScriptsPrefix = 'docs'
139
148
} : ScaffoldOptions ) : string {
140
149
const resolvedRoot = path . resolve ( root )
150
+ const resolvedSrcDir = path . resolve ( root , srcDir )
141
151
const templateDir = path . resolve (
142
152
path . dirname ( fileURLToPath ( import . meta. url ) ) ,
143
153
'../../template'
144
154
)
145
155
146
156
const data = {
157
+ srcDir : srcDir === './' ? undefined : JSON . stringify ( srcDir ) , // omit if default
147
158
title : JSON . stringify ( title ) ,
148
159
description : JSON . stringify ( description ) ,
149
160
useTs,
@@ -162,14 +173,20 @@ export function scaffold({
162
173
const renderFile = ( file : string ) => {
163
174
const filePath = path . resolve ( templateDir , file )
164
175
let targetPath = path . resolve ( resolvedRoot , file )
176
+
165
177
if ( useMjs && file === '.vitepress/config.js' ) {
166
178
targetPath = targetPath . replace ( / \. j s $ / , '.mjs' )
167
179
}
168
180
if ( useTs ) {
169
181
targetPath = targetPath . replace ( / \. ( m ? ) j s $ / , '.$1ts' )
170
182
}
171
- const src = fs . readFileSync ( filePath , 'utf-8' )
172
- const compiled = template ( src ) ( data )
183
+ if ( file . endsWith ( '.md' ) ) {
184
+ targetPath = path . resolve ( resolvedSrcDir , file )
185
+ }
186
+
187
+ const content = fs . readFileSync ( filePath , 'utf-8' )
188
+ const compiled = template ( content ) ( data )
189
+
173
190
fs . outputFileSync ( targetPath , compiled )
174
191
}
175
192
0 commit comments