From f647f744570a27fe635ce3e59eb6862427417a05 Mon Sep 17 00:00:00 2001 From: tyankatsu Date: Sun, 2 Aug 2020 16:02:58 +0900 Subject: [PATCH] feat: publish types (#58) * feat: publish types * feat: export types at index.ts --- README.md | 19 +++++-------------- package-lock.json | 5 +---- package.json | 3 ++- src/engine.ts | 10 ++-------- src/index.ts | 4 ++-- src/types.ts | 22 ++++++++++++++++++++++ src/util/initialize.ts | 24 +++--------------------- tsconfig.build.json | 3 ++- 8 files changed, 39 insertions(+), 51 deletions(-) create mode 100644 src/types.ts diff --git a/README.md b/README.md index ecb92c0..6eb550b 100644 --- a/README.md +++ b/README.md @@ -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 */ module.exports = { - /** - * @param {{inquirer: import('inquirer').Inquirer, gitInfo: import('git-repo-info').GitRepoInfo}} - * @returns {import('inquirer').QuestionCollection} - */ questions({inquirer, gitInfo}) { return [ { @@ -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}` } diff --git a/package-lock.json b/package-lock.json index a073337..b4079b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -342,7 +342,6 @@ "version": "7.3.0", "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-7.3.0.tgz", "integrity": "sha512-wcPs5jTrZYQBzzPlvUEzBcptzO4We2sijSvkBq8oAKRMJoH8PvrmP6QQnxLB5RScNUmRfujxA+ngxD4gk4xe7Q==", - "dev": true, "requires": { "@types/through": "*", "rxjs": "^6.4.0" @@ -369,8 +368,7 @@ "@types/node": { "version": "14.0.27", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.27.tgz", - "integrity": "sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==", - "dev": true + "integrity": "sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -387,7 +385,6 @@ "version": "0.0.30", "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", - "dev": true, "requires": { "@types/node": "*" } diff --git a/package.json b/package.json index 0aa898a..89cde72 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ } ], "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist" ], @@ -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", diff --git a/src/engine.ts b/src/engine.ts index bea7624..3e06501 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -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: (questions: QuestionCollection) => Promise; -}; - -type Commit = (commitMessage: string) => void; +import { initialize } from "./util"; +import { CZ, Commit } from "./types"; export const engine = () => { const { config } = initialize(); diff --git a/src/index.ts b/src/index.ts index 1c68d3f..ba02159 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ import { engine } from "./engine"; - -export = engine(); +export * from "./types"; +export default engine(); diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..771c7ec --- /dev/null +++ b/src/types.ts @@ -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 = { + questions: ({ + inquirer, + gitInfo, + }: { + inquirer: Inquirer; + gitInfo: GitRepoInfo; + }) => QuestionCollection; + commitMessage: ({ + answers, + gitInfo, + }: { + answers: T; + gitInfo: GitRepoInfo; + }) => string; +}; diff --git a/src/util/initialize.ts b/src/util/initialize.ts index 54c5eff..47dc8f8 100644 --- a/src/util/initialize.ts +++ b/src/util/initialize.ts @@ -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: Partial>; }; export const initialize = (): Initialize => { @@ -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, }; }; diff --git a/tsconfig.build.json b/tsconfig.build.json index 73a5878..401fe90 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "removeComments": true + "removeComments": true, + "declaration": true } } \ No newline at end of file