Skip to content

Commit 2cd7dc6

Browse files
Add types
Related-to unifiedjs/unified-engine#46. Closes GH-23. Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent f074ac9 commit 2cd7dc6

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
},
1919
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2020
"contributors": [
21-
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
21+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
22+
"Christian Murphy <christian.murphy.42@gmail.com"
2223
],
2324
"files": [
2425
"index.js",
26+
"types/index.d.ts",
2527
"lib/"
2628
],
29+
"types": "types/index.d.ts",
2730
"dependencies": {
2831
"camelcase": "^5.0.0",
2932
"chalk": "^3.0.0",
@@ -36,10 +39,12 @@
3639
},
3740
"devDependencies": {
3841
"bail": "^1.0.0",
42+
"dtslint": "^3.0.0",
3943
"execa": "^4.0.0",
4044
"figures": "^3.0.0",
4145
"nyc": "^15.0.0",
4246
"prettier": "^2.0.0",
47+
"remark": "^11.0.0",
4348
"remark-cli": "^7.0.0",
4449
"remark-preset-wooorm": "^6.0.0",
4550
"strip-ansi": "^6.0.0",
@@ -50,10 +55,11 @@
5055
"xo": "^0.28.0"
5156
},
5257
"scripts": {
53-
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
58+
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix --ignore types",
5459
"test-api": "node test",
5560
"test-coverage": "nyc --reporter lcov tape test/index.js",
56-
"test": "npm run format && npm run test-coverage"
61+
"test-types": "dtslint types",
62+
"test": "npm run format && npm run test-coverage && npm run test-types"
5763
},
5864
"prettier": {
5965
"tabWidth": 2,

types/index.d.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// TypeScript Version: 3.0
2+
3+
import {Options as EngineOptions} from 'unified-engine'
4+
5+
type RequiredEngineOptions = Required<
6+
Pick<
7+
EngineOptions,
8+
| 'extensions'
9+
| 'ignoreName'
10+
| 'packageField'
11+
| 'pluginPrefix'
12+
| 'processor'
13+
| 'rcName'
14+
>
15+
>
16+
17+
declare namespace unifiedArgs {
18+
interface Options extends RequiredEngineOptions {
19+
/**
20+
* Name of executable
21+
*/
22+
name: string
23+
24+
/**
25+
* Description of executable
26+
*/
27+
description: string
28+
29+
/**
30+
* Version of executable
31+
*/
32+
version: string
33+
}
34+
}
35+
36+
/**
37+
* Create a CLI for a unified processor
38+
*/
39+
declare function unifiedArgs(options: unifiedArgs.Options): void
40+
41+
export = unifiedArgs

types/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2015"],
4+
"strict": true,
5+
"baseUrl": ".",
6+
"paths": {
7+
"unified-args": ["index.d.ts"]
8+
}
9+
}
10+
}

types/tslint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"semicolon": false,
5+
"whitespace": false
6+
}
7+
}

types/unified-args-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as start from 'unified-args'
2+
import * as remark from 'remark'
3+
4+
start({
5+
processor: remark(),
6+
name: 'remark',
7+
description: 'description',
8+
version: '1.0.0',
9+
pluginPrefix: 'remark',
10+
extensions: ['md'],
11+
packageField: 'remarkConfig',
12+
rcName: '.remarkrc',
13+
ignoreName: '.remarkignore'
14+
})
15+
16+
// $ExpectError
17+
start({})
18+
19+
// $ExpectError
20+
start({
21+
name: 'remark',
22+
description: 'description',
23+
version: '1.0.0'
24+
})

0 commit comments

Comments
 (0)