Skip to content

Commit 932b89b

Browse files
Release v0.0.2 (#1)
* Fixes: - Hotfix for baseDir read from config. - Hotfix for out file from configuration name. - checkGeneratedArguments moved to before baseUrl check. * Update README.md * Removed dots from CLI options descriptions. * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update package.json
1 parent 08cd719 commit 932b89b

File tree

6 files changed

+90
-22
lines changed

6 files changed

+90
-22
lines changed

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
# dts-bundle-appends
2-
Appends cutom .d.ts files into bundled d.ts file.
1+
# dts-bundle-appends
2+
[![NPM version](http://img.shields.io/npm/v/dts-bundle-appends.svg)](https://www.npmjs.com/package/dts-bundle-appends) [![dependencies Status](https://david-dm.org/quatrocode/dts-bundle-appends/status.svg)](https://david-dm.org/quatrocode/dts-bundle-appends) [![devDependencies Status](https://david-dm.org/quatrocode/dts-bundle-appends/dev-status.svg)](https://david-dm.org/quatrocode/dts-bundle-appends?type=dev)
3+
4+
Appends custom `d.ts` files into one `d.ts` file bundled by [dts-bundle](https://github.com/TypeStrong/dts-bundle).
5+
6+
## Usage
7+
1) Install from npm:
8+
```cmd
9+
npm install dts-bundle-appends
10+
```
11+
2) Run `dts-bundle`.
12+
13+
3) After `d.ts` file bundled, run `dts-bundle-appends`.
14+
15+
## Requirements
16+
[NodeJS](https://nodejs.org/): >= 6.0.0
17+
18+
## Configuration
19+
Default configuration are taken from a `dts-bundle.json` file.
20+
21+
Also, you can specify a custom config file (see [#command-line](#command-line)).
22+
23+
### Configuration options
24+
| Argument | Type | Description |
25+
|--------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
26+
| appends | `string | Array<string>` | Specifies a list of glob patterns that match `d.ts` files to be appended in bundled `d.ts` file. Read more about [globs](https://github.com/isaacs/node-glob#glob-primer). |
27+
28+
*All other configuration options available from `dts-bundle` (read more [TypeStrong/dts-bundle#options](https://github.com/TypeStrong/dts-bundle#options)).
29+
30+
31+
### Configuration example
32+
```json
33+
{
34+
"name": "module-name",
35+
"main": "dist/main.d.ts",
36+
"out": "module-name.d.ts",
37+
"baseDir": "dist",
38+
"appends": [
39+
"src/global.d.ts"
40+
]
41+
}
42+
```
43+
44+
## Command line
45+
```cmd
46+
Usage: dts-bundle-appends [options]
47+
48+
Options:
49+
--help Show help [boolean]
50+
--version Show version number [boolean]
51+
--appends Appends files to global [string]
52+
--out dts-bundle bundled out file [string]
53+
--configJson dts-bundle configuration file [string] [default: "dts-bundle.json"]
54+
--baseDir dts-bundle base directory [string]
55+
```
56+
57+
## License
58+
[GPL-3.0](LICENSE)

dist/arguments.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ exports.default = yargs
77
return `Current version: ${require('../package.json').version}`;
88
})
99
.option('appends', {
10-
describe: 'Appends files to global.',
10+
describe: 'Appends files to global',
1111
type: "string"
1212
})
1313
.option("out", {
14-
describe: "dts-bundle bundled out file.",
14+
describe: "dts-bundle bundled out file",
1515
type: "string"
1616
})
1717
.option("configJson", {
18-
describe: "dts-bundle configuration file.",
18+
describe: "dts-bundle configuration file",
1919
default: "dts-bundle.json",
2020
type: "string"
2121
})
2222
.option("baseDir", {
23-
describe: "dts-bundle base directory.",
23+
describe: "dts-bundle base directory",
2424
type: "string"
2525
})
2626
.usage('Usage: dts-bundle-appends [options]')

dist/cli.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ class Cli {
2121
let argvCheck = yield this.checkArguments(argv);
2222
if (argvCheck.valid) {
2323
let appends, out, baseDir;
24-
if (argv.appends != null && argv.out != null && argv.out.length > 0) {
24+
if (argv.appends != null && argv.out != null && argv.out.length > 0 && argv.baseDir != null && argv.baseDir.length > 0) {
2525
out = argv.out;
2626
appends = argv.appends;
2727
baseDir = argv.baseDir || undefined;
2828
}
2929
else {
3030
let dtsConfig = yield this.readDtsBundleConfig(argv.configJson);
31-
out = argv.out || dtsConfig.out || dtsConfig.name;
31+
out = argv.out || dtsConfig.out || this.addDTsExtension(dtsConfig.name);
3232
appends = argv.appends || dtsConfig.appends;
3333
baseDir = argv.baseDir || dtsConfig.baseDir || undefined;
3434
}
35-
if (baseDir !== undefined) {
36-
out = path.join(baseDir, out);
37-
}
3835
if (this.checkGeneratedArguments(appends, out)) {
36+
if (baseDir !== undefined) {
37+
out = path.join(baseDir, out);
38+
}
3939
new appends_1.default(appends, out);
4040
}
4141
}
@@ -44,6 +44,12 @@ class Cli {
4444
}
4545
});
4646
}
47+
addDTsExtension(name) {
48+
if (name != null) {
49+
return `${name}.d.ts`;
50+
}
51+
return undefined;
52+
}
4753
checkGeneratedArguments(appends, out) {
4854
if (appends == null) {
4955
this.throwError("[ERROR] Appends files list not specified");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dts-bundle-appends",
33
"version": "0.0.1",
4-
"description": "Appends custom definitions into bundled d.ts file.",
4+
"description": "Appends custom d.ts files into d.ts file bundle by dts-bundle.",
55
"keywrods": [
66
"dts-bundle",
77
"typescript",

src/arguments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ export default yargs
1313
return `Current version: ${require('../package.json').version}`;
1414
})
1515
.option('appends', {
16-
describe: 'Appends files to global.',
16+
describe: 'Appends files to global',
1717
type: "string"
1818
})
1919
.option("out", {
20-
describe: "dts-bundle bundled out file.",
20+
describe: "dts-bundle bundled out file",
2121
type: "string"
2222
})
2323
.option("configJson", {
24-
describe: "dts-bundle configuration file.",
24+
describe: "dts-bundle configuration file",
2525
default: "dts-bundle.json",
2626
type: "string"
2727
})
2828
.option("baseDir", {
29-
describe: "dts-bundle base directory.",
29+
describe: "dts-bundle base directory",
3030
type: "string"
3131
})
3232
.usage('Usage: dts-bundle-appends [options]')

src/cli.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,35 @@ class Cli {
4141
let appends: string | Array<string>,
4242
out: string,
4343
baseDir: string;
44-
if (argv.appends != null && argv.out != null && argv.out.length > 0) {
44+
if (argv.appends != null && argv.out != null && argv.out.length > 0 && argv.baseDir != null && argv.baseDir.length > 0) {
4545
out = argv.out;
4646
appends = argv.appends;
4747
baseDir = argv.baseDir || undefined;
4848
} else {
4949
let dtsConfig = await this.readDtsBundleConfig(argv.configJson);
50-
out = argv.out || dtsConfig.out || dtsConfig.name;
50+
out = argv.out || dtsConfig.out || this.addDTsExtension(dtsConfig.name);
5151
appends = argv.appends || dtsConfig.appends;
5252
baseDir = argv.baseDir || dtsConfig.baseDir || undefined;
5353
}
5454

55-
if (baseDir !== undefined) {
56-
out = path.join(baseDir, out);
57-
}
58-
5955
if (this.checkGeneratedArguments(appends, out)) {
56+
if (baseDir !== undefined) {
57+
out = path.join(baseDir, out);
58+
}
6059
new Appends(appends, out);
6160
}
6261
} else {
6362
this.throwError("[ERROR] " + argvCheck.errorMessage);
6463
}
6564
}
6665

66+
private addDTsExtension(name: string): string | undefined {
67+
if (name != null) {
68+
return `${name}.d.ts`;
69+
}
70+
return undefined;
71+
}
72+
6773
private checkGeneratedArguments(appends: string | Array<string>, out: string) {
6874
if (appends == null) {
6975
this.throwError("[ERROR] Appends files list not specified");

0 commit comments

Comments
 (0)