@@ -54,6 +54,7 @@ type Config = {
54
54
globalVariableName : string
55
55
targetDirName : string
56
56
targetDirPath : string
57
+ mainPackageDirName : string
57
58
templateDirPath : string
58
59
githubPath : string
59
60
githubUrl : string
@@ -104,6 +105,13 @@ async function init() {
104
105
}
105
106
}
106
107
108
+ const mainPackageDirName = await textPrompt ( 'Main package directory' , unscopedPackageName )
109
+
110
+ if ( ! / ^ [ \w - ] + $ / . test ( mainPackageDirName ) ) {
111
+ console . log ( 'Invalid directory name: ' + mainPackageDirName )
112
+ process . exit ( 1 )
113
+ }
114
+
107
115
const githubPath = await textPrompt ( 'GitHub path, e.g. skirtles-code/test-project (optional)' )
108
116
109
117
if ( githubPath && ! / ^ [ \w - ] + \/ [ \w - ] + $ / . test ( githubPath ) ) {
@@ -134,6 +142,7 @@ async function init() {
134
142
globalVariableName,
135
143
targetDirName,
136
144
targetDirPath,
145
+ mainPackageDirName,
137
146
templateDirPath,
138
147
githubPath,
139
148
githubUrl,
@@ -172,7 +181,7 @@ async function init() {
172
181
173
182
console . log ( 'pnpm install' )
174
183
console . log ( )
175
- console . log ( `You should add a suitable license at ${ targetDirName } /packages/${ config . shortUnscopedPackageName } /LICENSE` )
184
+ console . log ( `You should add a suitable license at ${ targetDirName } /packages/${ config . mainPackageDirName } /LICENSE` )
176
185
}
177
186
178
187
function copyTemplate ( templateName : string , config : Config ) {
@@ -199,7 +208,7 @@ function copyFiles(templateFile: string, config: Config) {
199
208
const stats = fs . statSync ( templatePath )
200
209
const basename = path . basename ( templatePath )
201
210
202
- const targetPath = path . join ( config . targetDirPath , templateFile . replace ( / @ p r o j e c t N a m e @ / g, config . shortUnscopedPackageName ) )
211
+ const targetPath = path . join ( config . targetDirPath , templateFile . replace ( / @ p r o j e c t N a m e @ / g, config . mainPackageDirName ) )
203
212
204
213
if ( stats . isDirectory ( ) ) {
205
214
if ( basename === 'node_modules' ) {
@@ -226,7 +235,7 @@ function copyFiles(templateFile: string, config: Config) {
226
235
} else if ( [ 'package.json' , 'vite.config.mts' , 'config.mts' , 'index.md' , 'introduction.md' , 'App.vue' ] . includes ( filename ) ) {
227
236
const template = fs . readFileSync ( templatePath , 'utf-8' )
228
237
const content = template
229
- . replace ( / @ p r o j e c t N a m e @ / g, config . shortUnscopedPackageName )
238
+ . replace ( / @ p r o j e c t N a m e @ / g, config . mainPackageDirName )
230
239
. replace ( new RegExp ( `@(${ Object . keys ( config ) . join ( '|' ) } )@` , 'g' ) , ( all , setting ) => config [ setting ] ?? all )
231
240
232
241
fs . writeFileSync ( targetPath , content )
0 commit comments