@@ -26,6 +26,8 @@ export interface ScaffoldOptions {
26
26
theme : ScaffoldThemeType
27
27
useTs : boolean
28
28
injectNpmScripts : boolean
29
+ addNpmScriptsPrefix ?: boolean
30
+ npmScriptsPrefix ?: string
29
31
}
30
32
31
33
const getPackageManger = ( ) => {
@@ -36,7 +38,7 @@ const getPackageManger = () => {
36
38
export async function init ( root : string | undefined ) {
37
39
intro ( bold ( cyan ( 'Welcome to VitePress!' ) ) )
38
40
39
- const options : ScaffoldOptions = await group (
41
+ const options : ScaffoldOptions = ( await group (
40
42
{
41
43
root : async ( ) => {
42
44
if ( root ) return root
@@ -94,15 +96,33 @@ export async function init(root: string | undefined) {
94
96
injectNpmScripts : ( ) =>
95
97
confirm ( {
96
98
message : 'Add VitePress npm scripts to package.json?'
99
+ } ) ,
100
+
101
+ addNpmScriptsPrefix : ( { results } ) => {
102
+ if ( ! results . injectNpmScripts ) return Promise . resolve ( false )
103
+
104
+ return confirm ( {
105
+ message : 'Add a prefix for VitePress npm scripts?' ,
106
+ initialValue : true
107
+ } )
108
+ } ,
109
+
110
+ npmScriptsPrefix : ( { results } ) => {
111
+ if ( ! results . addNpmScriptsPrefix ) return Promise . resolve ( 'docs' )
112
+
113
+ return text ( {
114
+ message : 'Prefix for VitePress npm scripts:' ,
115
+ placeholder : 'docs'
97
116
} )
117
+ }
98
118
} ,
99
119
{
100
120
onCancel : ( ) => {
101
121
cancel ( 'Cancelled.' )
102
122
process . exit ( 0 )
103
123
}
104
124
}
105
- )
125
+ ) ) as ScaffoldOptions
106
126
107
127
outro ( scaffold ( options ) )
108
128
}
@@ -113,7 +133,9 @@ export function scaffold({
113
133
description = 'A VitePress Site' ,
114
134
theme,
115
135
useTs,
116
- injectNpmScripts
136
+ injectNpmScripts,
137
+ addNpmScriptsPrefix = true ,
138
+ npmScriptsPrefix = 'docs'
117
139
} : ScaffoldOptions ) : string {
118
140
const resolvedRoot = path . resolve ( root )
119
141
const templateDir = path . resolve (
@@ -201,15 +223,18 @@ export function scaffold({
201
223
const tip = tips . length ? yellow ( [ `\n\nTips:` , ...tips ] . join ( '\n- ' ) ) : ``
202
224
203
225
if ( injectNpmScripts ) {
204
- const scripts = {
205
- 'docs:dev' : `vitepress dev${ dir } ` ,
206
- 'docs:build' : `vitepress build${ dir } ` ,
207
- 'docs:preview' : `vitepress preview${ dir } `
208
- }
226
+ const scripts : Record < string , string > = { }
227
+
228
+ const prefix = addNpmScriptsPrefix ? `${ npmScriptsPrefix } :` : ''
229
+
230
+ scripts [ `${ prefix } dev` ] = `vitepress dev${ dir } `
231
+ scripts [ `${ prefix } build` ] = `vitepress build${ dir } `
232
+ scripts [ `${ prefix } preview` ] = `vitepress preview${ dir } `
233
+
209
234
Object . assign ( userPkg . scripts || ( userPkg . scripts = { } ) , scripts )
210
235
fs . writeFileSync ( pkgPath , JSON . stringify ( userPkg , null , 2 ) )
211
236
return `Done! Now run ${ cyan (
212
- `${ getPackageManger ( ) } run docs: dev`
237
+ `${ getPackageManger ( ) } run ${ prefix } dev`
213
238
) } and start writing.${ tip } `
214
239
} else {
215
240
const pm = getPackageManger ( )
0 commit comments