Skip to content

Commit 7b9ee2d

Browse files
committed
add --out-dir option for auto generating out files
1 parent e2045fc commit 7b9ee2d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/bin/dts-bundle-generator.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface ParsedArgs extends yargs.Arguments {
4747
'export-referenced-types': boolean;
4848

4949
'out-file': string | undefined;
50+
'out-dir': string | undefined;
5051
'umd-module-name': string | undefined;
5152
project: string | undefined;
5253
config: string | undefined;
@@ -71,6 +72,11 @@ function parseArgs(): ParsedArgs {
7172
type: 'string',
7273
description: 'File name of generated d.ts',
7374
})
75+
.option('out-dir', {
76+
type: 'string',
77+
description: 'Output directory for genereated d.ts files.\n' +
78+
'For when specifying multiple entries',
79+
})
7480
.option('verbose', {
7581
type: 'boolean',
7682
default: false,
@@ -199,9 +205,23 @@ function main(): void {
199205

200206
bundlerConfig = {
201207
entries: args._.map<ConfigEntryPoint>((entryPath: string | number) => {
208+
let outFile;
209+
210+
if (args['out-dir']) {
211+
const { dir, name } = path.parse(String(entryPath));
212+
213+
if (args.project) {
214+
outFile = path.join(args['out-dir'], path.relative(path.dirname(args.project), dir), name + '.d.ts');
215+
} else {
216+
outFile = path.join(args['out-dir'], dir, name + '.d.ts');
217+
}
218+
} else {
219+
outFile = args['out-file'];
220+
}
221+
202222
return {
203223
filePath: String(entryPath),
204-
outFile: args['out-file'],
224+
outFile,
205225
noCheck: args['no-check'],
206226
libraries: {
207227
allowedTypesLibraries: args['external-types'],

0 commit comments

Comments
 (0)