Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
Related-to unifiedjs/unified-engine#46.
Closes GH-23.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
ChristianMurphy authored Mar 30, 2020
1 parent f074ac9 commit 2cd7dc6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Christian Murphy <christian.murphy.42@gmail.com"
],
"files": [
"index.js",
"types/index.d.ts",
"lib/"
],
"types": "types/index.d.ts",
"dependencies": {
"camelcase": "^5.0.0",
"chalk": "^3.0.0",
Expand All @@ -36,10 +39,12 @@
},
"devDependencies": {
"bail": "^1.0.0",
"dtslint": "^3.0.0",
"execa": "^4.0.0",
"figures": "^3.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^11.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"strip-ansi": "^6.0.0",
Expand All @@ -50,10 +55,11 @@
"xo": "^0.28.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix --ignore types",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run format && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run format && npm run test-coverage && npm run test-types"
},
"prettier": {
"tabWidth": 2,
Expand Down
41 changes: 41 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// TypeScript Version: 3.0

import {Options as EngineOptions} from 'unified-engine'

type RequiredEngineOptions = Required<
Pick<
EngineOptions,
| 'extensions'
| 'ignoreName'
| 'packageField'
| 'pluginPrefix'
| 'processor'
| 'rcName'
>
>

declare namespace unifiedArgs {
interface Options extends RequiredEngineOptions {
/**
* Name of executable
*/
name: string

/**
* Description of executable
*/
description: string

/**
* Version of executable
*/
version: string
}
}

/**
* Create a CLI for a unified processor
*/
declare function unifiedArgs(options: unifiedArgs.Options): void

export = unifiedArgs
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"unified-args": ["index.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
}
}
24 changes: 24 additions & 0 deletions types/unified-args-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as start from 'unified-args'
import * as remark from 'remark'

start({
processor: remark(),
name: 'remark',
description: 'description',
version: '1.0.0',
pluginPrefix: 'remark',
extensions: ['md'],
packageField: 'remarkConfig',
rcName: '.remarkrc',
ignoreName: '.remarkignore'
})

// $ExpectError
start({})

// $ExpectError
start({
name: 'remark',
description: 'description',
version: '1.0.0'
})

0 comments on commit 2cd7dc6

Please sign in to comment.