Skip to content

Commit 48664be

Browse files
committed
feat: allow customizing the baseName for the barrel file and other generator keys
1 parent 04f8842 commit 48664be

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/index_generator/source.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,14 @@ export class IndexGeneratorSource {
160160
#createBarrelFileKeyGenerator(config: IndexGeneratorSourceConfig) {
161161
return function (key: string) {
162162
const paths = key.split('/')
163-
const baseName = new StringBuilder(paths.pop()!)
164-
.removeSuffix(config.removeSuffix ?? '')
165-
.pascalCase()
166-
.toString()
167-
return [...paths.map((p) => string.camelCase(p)), baseName].join('/')
163+
let baseName = new StringBuilder(paths.pop()!)
164+
if (config.computeBaseName) {
165+
baseName = config.computeBaseName(baseName)
166+
} else {
167+
baseName = baseName.removeSuffix(config.removeSuffix ?? '').pascalCase()
168+
}
169+
170+
return [...paths.map((p) => string.camelCase(p)), baseName.toString()].join('/')
168171
}
169172
}
170173

src/types/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import type { Logger } from '@poppinss/cliui'
1111
import { type Prettify } from '@poppinss/utils/types'
12+
import type StringBuilder from '@poppinss/utils/string_builder'
1213

1314
import { type AllHooks } from './hooks.ts'
1415
import { type FileBuffer } from '../file_buffer.ts'
@@ -47,6 +48,7 @@ export type IndexGeneratorSourceConfig = (
4748
) => void
4849
}
4950
) & {
51+
computeBaseName?: (baseName: StringBuilder) => StringBuilder
5052
source: string
5153
output: string
5254
glob?: string[]

0 commit comments

Comments
 (0)