Skip to content

Commit 92bc1fa

Browse files
committed
feat: add output structure
1 parent 66dfeca commit 92bc1fa

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export const config: DtsGenerationConfig = await loadConfig({
1515
keepComments: true,
1616
clean: true,
1717
tsconfigPath: './tsconfig.json',
18+
outputStructure: 'mirror',
1819
},
1920
})

src/generate.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi
5252
if (fileDeclarations) {
5353
const relativePath = relative(options?.root ?? './src', file)
5454
const parsedPath = parse(relativePath)
55-
const outputPath = join(options?.outdir ?? './dist', parsedPath.dir, `${parsedPath.name}.d.ts`)
55+
// Use string option for outputStructure: 'mirror' | 'flat'
56+
const outputStructure = options?.outputStructure ?? 'mirror'
57+
const outputPath = outputStructure === 'mirror'
58+
? join(options?.outdir ?? './dist', parsedPath.dir, `${parsedPath.name}.d.ts`)
59+
: join(options?.outdir ?? './dist', `${parsedPath.name}.d.ts`)
5660

5761
await mkdir(dirname(outputPath), { recursive: true }) // Ensure the directory exists
5862
await writeToFile(outputPath, fileDeclarations) // Write the declarations without additional formatting

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export interface DtsGenerationConfig {
1212
clean: boolean
1313
tsconfigPath: string
1414
verbose: boolean | string[]
15+
/**
16+
* Output structure: 'mirror' to mirror src folders, 'flat' for flat output
17+
*/
18+
outputStructure?: 'mirror' | 'flat'
1519
}
1620

1721
/**

test/dts.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('dts-generation', () => {
1818
outdir: generatedDir,
1919
clean: false,
2020
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
21+
outputStructure: 'flat',
2122
}
2223

2324
await generate(config)
@@ -39,6 +40,7 @@ describe('dts-generation', () => {
3940
outdir: generatedDir,
4041
clean: false,
4142
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
43+
outputStructure: 'flat',
4244
}
4345

4446
await generate(config)
@@ -60,6 +62,7 @@ describe('dts-generation', () => {
6062
outdir: generatedDir,
6163
clean: false,
6264
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
65+
outputStructure: 'flat',
6366
}
6467

6568
await generate(config)
@@ -81,6 +84,7 @@ describe('dts-generation', () => {
8184
outdir: generatedDir,
8285
clean: false,
8386
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
87+
outputStructure: 'flat'
8488
}
8589

8690
await generate(config)
@@ -102,6 +106,7 @@ describe('dts-generation', () => {
102106
outdir: generatedDir,
103107
clean: false,
104108
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
109+
outputStructure: 'flat'
105110
}
106111

107112
await generate(config)
@@ -123,6 +128,7 @@ describe('dts-generation', () => {
123128
outdir: generatedDir,
124129
clean: false,
125130
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
131+
outputStructure: 'flat'
126132
}
127133

128134
await generate(config)
@@ -144,6 +150,7 @@ describe('dts-generation', () => {
144150
outdir: generatedDir,
145151
clean: false,
146152
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
153+
outputStructure: 'flat'
147154
}
148155

149156
await generate(config)
@@ -165,6 +172,7 @@ describe('dts-generation', () => {
165172
outdir: generatedDir,
166173
clean: false,
167174
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
175+
outputStructure: 'flat'
168176
}
169177

170178
await generate(config)
@@ -186,6 +194,7 @@ describe('dts-generation', () => {
186194
outdir: generatedDir,
187195
clean: false,
188196
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
197+
outputStructure: 'flat'
189198
}
190199

191200
await generate(config)
@@ -207,6 +216,7 @@ describe('dts-generation', () => {
207216
outdir: generatedDir,
208217
clean: false,
209218
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
219+
outputStructure: 'flat'
210220
}
211221

212222
await generate(config)
@@ -228,6 +238,7 @@ describe('dts-generation', () => {
228238
outdir: generatedDir,
229239
clean: false,
230240
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
241+
outputStructure: 'flat'
231242
}
232243

233244
await generate(config)
@@ -249,6 +260,7 @@ describe('dts-generation', () => {
249260
outdir: generatedDir,
250261
clean: false,
251262
tsconfigPath: join(__dirname, '..', 'tsconfig.json'),
263+
outputStructure: 'flat'
252264
}
253265

254266
await generate(config)

0 commit comments

Comments
 (0)