Skip to content

Commit cb132ca

Browse files
committed
Prompt for main package directory name
1 parent b8e356e commit cb132ca

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

178187
function 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(/@projectName@/g, config.shortUnscopedPackageName))
211+
const targetPath = path.join(config.targetDirPath, templateFile.replace(/@projectName@/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(/@projectName@/g, config.shortUnscopedPackageName)
238+
.replace(/@projectName@/g, config.mainPackageDirName)
230239
.replace(new RegExp(`@(${Object.keys(config).join('|')})@`, 'g'), (all, setting) => config[setting] ?? all)
231240

232241
fs.writeFileSync(targetPath, content)

src/template/base/config/package.json.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<%_ if (config.includeDocs) { _%>
1313
"docs:dev": "pnpm run --filter ./packages/docs -r dev",
1414
<%_ } _%>
15-
"test:unit": "pnpm run --filter ./packages/<%- config.shortUnscopedPackageName %> -r test:unit",
16-
"coverage": "pnpm run --filter ./packages/<%- config.shortUnscopedPackageName %> -r coverage",
15+
"test:unit": "pnpm run --filter ./packages/<%- config.mainPackageDirName %> -r test:unit",
16+
"coverage": "pnpm run --filter ./packages/<%- config.mainPackageDirName %> -r coverage",
1717
"preinstall": "node scripts/preinstall.js",
1818
"postinstall": "simple-git-hooks"
1919
},

src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
3030
vite: {
3131
resolve: {
3232
alias: {
33-
'<%- config.scopedPackageName %>': resolve(__dirname, '../../<%- config.shortUnscopedPackageName %>/src/index.ts')
33+
'<%- config.scopedPackageName %>': resolve(__dirname, '../../<%- config.mainPackageDirName %>/src/index.ts')
3434
}
3535
},
3636

@@ -42,7 +42,7 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({
4242
fs: {
4343
allow: [
4444
'..',
45-
'../../<%- config.shortUnscopedPackageName %>/src'
45+
'../../<%- config.mainPackageDirName %>/src'
4646
]
4747
}
4848
}

0 commit comments

Comments
 (0)