Skip to content

Commit

Permalink
feat: publish types (#58)
Browse files Browse the repository at this point in the history
* feat: publish types

* feat: export types at index.ts
  • Loading branch information
tyankatsu0105 authored Aug 2, 2020
1 parent 5651220 commit f647f74
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 51 deletions.
19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,13 @@ module.exports = {

If you love to develop with types, you can use that with `JSDocs`.

```shell
npm install -D @types/inquirer git-repo-info
```

```js
/**
* @typedef {{questionType1: string; questionType2: string}} Answers
*/

/** @type import('cz-format-extension').Config<Answers> */
module.exports = {
/**
* @param {{inquirer: import('inquirer').Inquirer, gitInfo: import('git-repo-info').GitRepoInfo}}
* @returns {import('inquirer').QuestionCollection}
*/
questions({inquirer, gitInfo}) {
return [
{
Expand All @@ -92,12 +89,6 @@ module.exports = {
},
]
},
/**
* @typedef {{questionType1: string; questionType2: string}} Answers
*
* @param {{answers: Answers, gitInfo: import('git-repo-info').GitRepoInfo}}
* @returns {string}
*/
commitMessage({answers, gitInfo}) {
return `${answers.questionType1}${answers.questionType2}`
}
Expand Down
5 changes: 1 addition & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
Expand All @@ -36,13 +37,13 @@
"typecheck": "tsc --project ./tsconfig.build.json --noEmit"
},
"dependencies": {
"@types/inquirer": "^7.3.0",
"cosmiconfig": "^6.0.0",
"git-repo-info": "^2.1.1",
"inquirer": "^7.3.3",
"tslib": "2.0.0"
},
"devDependencies": {
"@types/inquirer": "^7.3.0",
"@types/node": "^14.0.27",
"@typescript-eslint/eslint-plugin": "3.7.1",
"@typescript-eslint/parser": "3.7.1",
Expand Down
10 changes: 2 additions & 8 deletions src/engine.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { QuestionCollection } from "inquirer";
import { initialize } from "./util";
import * as inquirer from "inquirer";
import getRepoInfo from "git-repo-info";

type CZ = {
prompt: <T>(questions: QuestionCollection<T>) => Promise<T>;
};

type Commit = (commitMessage: string) => void;
import { initialize } from "./util";
import { CZ, Commit } from "./types";

export const engine = () => {
const { config } = initialize();
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { engine } from "./engine";

export = engine();
export * from "./types";
export default engine();
22 changes: 22 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Inquirer, QuestionCollection } from "inquirer";
import { GitRepoInfo } from "git-repo-info";

export type CZ = Inquirer;
export type Commit = (commitMessage: string) => void;

export type Config<T> = {
questions: ({
inquirer,
gitInfo,
}: {
inquirer: Inquirer;
gitInfo: GitRepoInfo;
}) => QuestionCollection;
commitMessage: ({
answers,
gitInfo,
}: {
answers: T;
gitInfo: GitRepoInfo;
}) => string;
};
24 changes: 3 additions & 21 deletions src/util/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
import * as Cosmiconfig from "cosmiconfig";
import * as Const from "./const";
import { QuestionCollection, Answers, Inquirer } from "inquirer";
import { GitRepoInfo } from "git-repo-info";
import { Config } from "../types";

const explorer = Cosmiconfig.cosmiconfigSync(Const.MODULE_NAME);

type Config = {
questions: ({
inquirer,
gitInfo,
}: {
inquirer: Inquirer;
gitInfo: GitRepoInfo;
}) => QuestionCollection;
commitMessage: ({
answers,
gitInfo,
}: {
answers: Answers;
gitInfo: GitRepoInfo;
}) => string;
};

type Initialize = {
config: Partial<Config>;
config: Partial<Config<unknown>>;
};

export const initialize = (): Initialize => {
Expand All @@ -32,6 +14,6 @@ export const initialize = (): Initialize => {
if (result === null) throw new Error("Could not find config file.");

return {
config: result.config as Config,
config: result.config as Config<unknown>,
};
};
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"removeComments": true
"removeComments": true,
"declaration": true
}
}

0 comments on commit f647f74

Please sign in to comment.