@@ -54,6 +54,7 @@ type Config = {
5454 globalVariableName : string
5555 targetDirName : string
5656 targetDirPath : string
57+ mainPackageDirName : string
5758 templateDirPath : string
5859 githubPath : string
5960 githubUrl : string
@@ -104,6 +105,13 @@ async function init() {
104105 }
105106 }
106107
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+
107115 const githubPath = await textPrompt ( 'GitHub path, e.g. skirtles-code/test-project (optional)' )
108116
109117 if ( githubPath && ! / ^ [ \w - ] + \/ [ \w - ] + $ / . test ( githubPath ) ) {
@@ -134,6 +142,7 @@ async function init() {
134142 globalVariableName,
135143 targetDirName,
136144 targetDirPath,
145+ mainPackageDirName,
137146 templateDirPath,
138147 githubPath,
139148 githubUrl,
@@ -172,7 +181,7 @@ async function init() {
172181
173182 console . log ( 'pnpm install' )
174183 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` )
176185}
177186
178187function copyTemplate ( templateName : string , config : Config ) {
@@ -199,7 +208,7 @@ function copyFiles(templateFile: string, config: Config) {
199208 const stats = fs . statSync ( templatePath )
200209 const basename = path . basename ( templatePath )
201210
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 ) )
203212
204213 if ( stats . isDirectory ( ) ) {
205214 if ( basename === 'node_modules' ) {
@@ -226,7 +235,7 @@ function copyFiles(templateFile: string, config: Config) {
226235 } else if ( [ 'package.json' , 'vite.config.mts' , 'config.mts' , 'index.md' , 'introduction.md' , 'App.vue' ] . includes ( filename ) ) {
227236 const template = fs . readFileSync ( templatePath , 'utf-8' )
228237 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 )
230239 . replace ( new RegExp ( `@(${ Object . keys ( config ) . join ( '|' ) } )@` , 'g' ) , ( all , setting ) => config [ setting ] ?? all )
231240
232241 fs . writeFileSync ( targetPath , content )
0 commit comments