Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ only really useful as a `prepare-commit-msg` or `commit-msg` hook.
When to use what hook?

* `prepare-commit-msg`: use this if you do not use **Devmnojis** `--lint` option and want to use it with something like [commitlint](https://commitlint.js.org/) instead.
* `commit-msg`: use this hook if you also want to use **Devmoji** for linting
* `commit-msg`: use this hook if you also want to use **Devmoji** for linting

Configuration using [Husky](https://typicode.github.io/husky/)

Expand All @@ -168,8 +168,8 @@ Configuration using [Yorkie](https://www.npmjs.com/package/yorkie)
// package.json
{
"gitHooks": {
"prepare-commit-msg": "devmoji -e --lint"
}
"prepare-commit-msg": "devmoji -e --lint"
}
}
```

Expand Down Expand Up @@ -208,15 +208,15 @@ To get a list of all available **Devmoji**, run with `--list`. (see also

## :gear: Configuration

`devmoji` uses the config file as specified with the `--config` option, or looks
for `devmoji.config.js` in the following paths:
`devmoji` uses the config file as specified with the `--config` option, otherwise it looks
for `devmoji.config.js` or `devmoji.config.ts` in the following paths:

- current directory
- parent directory that contains a `package.json` file
- parent directory that is a `git` repository
- home directory

### Example Config File
### Example of a JavaScript Config File

```js
module.exports = {
Expand Down Expand Up @@ -247,6 +247,37 @@ module.exports = {
}
```

### Example of a TypeScript Config File

```typescript
export default {
// extra types used in commit messages
types: ["lint"],
// custom devmoji
devmoji: [
// use :boom: instead of :sparkles: for the type 'feat'
{ code: "feat", emoji: "boom" },
// add a custom devmoji
{
code: "fail",
emoji: "poop",
description: "something bad happened",
},
// add a new devmoji based on an existing gitmoji. description will be taken from the gitmoji
{
code: "css",
gitmoji: "art",
},
// the emoji from the gitmoji can be overriden as well
{
code: "config",
gitmoji: "wrench",
emoji: "gear",
},
],
}
```

### Default Devmoji Reference

| Emoji | Devmoji Code | Description |
Expand Down
16 changes: 16 additions & 0 deletions __tests__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ test("load config", async () => {
expect(config.pack.get("fuckup")?.emoji).toBe("poop")
})

test("load typescript from config file", async () => {
const config = await Config.load("__tests__/ignore.devmoji.config.ts")
expect(config.pack.get("feat")?.emoji).toBe("poop")
expect(config.pack.get("fuckup")?.emoji).toBe("poop")
})

test("missing prop code", () => {
expect(() => {
const config = { devmoji: [{ foo: 1 }] } as unknown as ConfigOptions
Expand Down Expand Up @@ -56,3 +62,13 @@ test("no default config file", async () => {
expect(error).toMatch(/missing.*/)
}
})

test("config file does not exist", async () => {
const configFile = "__tests__/fake.devmoji.config.js"
try {
await Config.load(configFile, "/")
} catch (error) {
// eslint-disable-next-line jest/no-try-expect, jest/no-conditional-expect
expect(error).toMatch(`Config file not found ${configFile}`)
}
})
10 changes: 10 additions & 0 deletions __tests__/ignore.devmoji.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
devmoji: [
{
code: "fuckup",
emoji: "poop",
description: "something got messed up pretty bad",
},
{ code: "feat", emoji: "poop" },
],
}
1 change: 1 addition & 0 deletions src/config-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type TDevmoji = {
}

export interface ConfigOptions {
default?: ConfigOptions
types: string[]
devmoji: TDevmoji[]
}
12 changes: 9 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Config {
constructor(options?: ConfigOptions) {
this._load(defaults)
if (options) {
if (options.default) options = { ...options.default }
if (!options.types) options.types = []
if (!options.devmoji) options.devmoji = []
this.validate(options)
Expand Down Expand Up @@ -71,9 +72,14 @@ export class Config {
]
for (const p of searchPaths) {
if (p) {
const file = path.resolve(p, "./devmoji.config.js")
if (fs.existsSync(file)) {
configFile = file
const javascriptConfigFile = path.resolve(p, "./devmoji.config.js")
if (fs.existsSync(javascriptConfigFile)) {
configFile = javascriptConfigFile
break
}
const typescriptConfigFile = path.resolve(p, "./devmoji.config.ts")
if (fs.existsSync(typescriptConfigFile)) {
configFile = typescriptConfigFile
break
}
}
Expand Down