Skip to content

Commit

Permalink
feat: create package
Browse files Browse the repository at this point in the history
  • Loading branch information
tyankatsu0105 committed Aug 1, 2020
1 parent 57d4c08 commit 79132e5
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 19 deletions.
69 changes: 61 additions & 8 deletions .czferc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,73 @@
const prefix = [
{
name: "feat: A new feature",
value: "feat"
},
{
name: "fix: A bug fix",
value: "fix"
},
{
name: "docs: Documentation only changes",
value: "docs"
},
{
name: "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",
value: "style"
},
{
name: "refactor: A code change that neither fixes a bug nor adds a feature",
value: "refactor"
},
{
name: "perf: A code change that improves performance",
value: "perf"
},
{
name: "test: Adding missing tests or correcting existing tests",
value: "test"
},
{
name: "build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)",
value: "build"
},
{
name: "ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)",
value: "ci"
},
{
name: "chore: Other changes that don't modify src or test files",
value: "chore"
},
{
name: "revert: Reverts a previous commit",
value: "revert"
},
]

module.exports = {
/**
* @param {import('inquirer').Inquirer} inquirer
* @returns {import('inquirer').QuestionCollection}
*/
questions(inquirer) {
return [
{
type: "list",
name: "prefix",
message: "Select prefix",
choices: [
{
name: 'aaaaaaaaaaaaa',
value: 'value',
}
]
choices: prefix
},
],
]

},
/**
* @typedef {{questionType1: string; questionType2: string}} Answers
*
* @param {Answers} answers
* @returns {string}
*/
commitMessage(answers) {
return answers.prefix
return `${answers.questionType1}${answers.questionType2}`
}
}
76 changes: 72 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

Extensible [Commitizen](https://github.com/commitizen/cz-cli)'s format

This package is extension commit message format when use

## Usage

```
Expand All @@ -29,8 +27,78 @@ Make `.czrc` or add `config` fields into package.json
```json
{
"config": {
"commitizen": {
"path": "cz-format-extension"
"commitizen": {
"path": "cz-format-extension"
}
}
}
```

### Create Config file

Make `.czferc.js`

```js
module.exports = {
questions(inquirer) {
return [
{...},
{...},
]
},
commitMessage(answers) {
return ...
}
}
```

- questions
- params
- ([inquirer](https://github.com/SBoudrias/Inquirer.js))
- return
- [Question Object](https://github.com/SBoudrias/Inquirer.js#question)
- commitMessage
- params
- [answers](https://github.com/SBoudrias/Inquirer.js#answers)
- return
- string

#### Tips: Configuration settings with types

If you love to develop with types, you can use that with `JSDoc`.
You should install `@types/inquirer`.

```shell
npm install -D @types/inquirer
```

```js
module.exports = {
/**
* @param {import('inquirer').Inquirer} inquirer
* @returns {import('inquirer').QuestionCollection}
*/
questions(inquirer) {
return [
{
type: "list",
name: "questionType1",
message: "Select answer",
choices: [
{...},
{...}
]
},
]
},
/**
* @typedef {{questionType1: string; questionType2: string}} Answers
*
* @param {Answers} answers
* @returns {string}
*/
commitMessage(answers) {
return `${answers.questionType1}${answers.questionType2}`
}
}
```
Expand Down
9 changes: 2 additions & 7 deletions src/util/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ import { QuestionCollection, Answers, Inquirer } from "inquirer";

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

type Search = NonNullable<
ReturnType<ReturnType<typeof Cosmiconfig.cosmiconfigSync>["search"]>
>;

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

type Initialize = Pick<Search, "filepath"> & {
type Initialize = {
config: Partial<Config>;
};

export const initialize = (): Initialize => {
const result = explorer.search();

if (result === null) throw new Error("Can not find config file.");
if (result === null) throw new Error("Could not find config file.");

return {
config: result.config as Config,
filepath: result.filepath,
};
};

0 comments on commit 79132e5

Please sign in to comment.