You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make sure you have [npx](https://www.npmjs.com/package/npx) installed (`npx` is shipped by default since npm `5.2.0`)
6
6
7
-
Run the following command at the root of your project and answer questions.
7
+
Run the following command at the root of your project and answer questions.`gitmoji-changelog` uses a [preset system](/PRESETS.md) to handle different type of project. The preset used by default is the Node.js one that look for project's information in the `package.json` file.
8
8
9
9
with npx:
10
10
```sh
@@ -19,6 +19,26 @@ cd my-project
19
19
gitmoji-changelog
20
20
```
21
21
22
+
It exists a generic preset that works for every kind of project. It looks for information in a `.gitmoji-changelogrc` file at the root of your project. This file must contain three mandatory properties: `name`, `description` and `version`.
23
+
24
+
.gitmoji-changelogrc:
25
+
```json
26
+
{
27
+
"project": {
28
+
"name": "gitmoji-changelog",
29
+
"description": "A changelog generator for gitmoji 😜",
30
+
"version": "2.0.1"
31
+
}
32
+
}
33
+
```
34
+
35
+
You can change the preset used by `gitmoji-changelog` with the preset option.
36
+
37
+
```sh
38
+
npx gitmoji-changelog --preset generic
39
+
```
40
+
41
+
22
42
### Available commands
23
43
24
44
```sh
@@ -48,7 +68,7 @@ The first command listed above is the idiomatic usage of `gitmoji-changelog` (re
48
68
49
69
**Here an example output:**[CHANGELOG.md](https://github.com/frinyvonnick/gitmoji-changelog/blob/master/CHANGELOG.md)
50
70
51
-
## How it works
71
+
## 📚 How it works
52
72
53
73
### Behavior
54
74
@@ -78,15 +98,119 @@ Here the recommended workflow to generate your changelog file using `gitmoji-cha
78
98
79
99
_This workflow is related to the `node` preset but can be adapted to your own technology._
80
100
81
-
## Presets
101
+
## ⚙️ Presets
82
102
83
103
`gitmoji-changelog` use presets to get project metadata useful for its smooth operation. Here is the list of available presets:
84
104
85
105
- node (default preset)
86
106
- generic
87
107
- maven
88
108
89
-
Here is the [documentation](/PRESETS.md) about presets (how they works and how to create a new one).
109
+
Didn't see the preset you need in the list? Consider adding it. Presets are stored in a [presets](packages/gitmoji-changelog-cli/src/presets) folder in the `cli` package.
110
+
111
+
### Existing presets
112
+
113
+
#### Node
114
+
115
+
The node preset looks for a `package.json` file.
116
+
117
+
```json
118
+
{
119
+
"name": "project-name",
120
+
"version": "0.0.1",
121
+
"description": "Some description",
122
+
}
123
+
```
124
+
125
+
#### Generic
126
+
127
+
The generic preset looks a `gitmoji-changelogrc` file.
128
+
129
+
```json
130
+
{
131
+
"project": {
132
+
"name": "yvonnickfrin.dev",
133
+
"description": "My blog",
134
+
"version": "1.1.0"
135
+
}
136
+
}
137
+
```
138
+
139
+
It must contain all mandatory properties in a `project` property. The `gitmoji-changelogrc` file can contain other configuration properties like a custom commit categorization.
140
+
141
+
#### Maven
142
+
143
+
The maven preset looks for 4 properties in you `pom.xml`:
144
+
145
+
- groupid
146
+
- artifactid
147
+
- version
148
+
- description
149
+
150
+
### Add a preset
151
+
152
+
A preset need to export a function. When called this function must return three mandatory information about the project in which the cli has been called. The name of the project, a short description of it and its current version.
153
+
154
+
Let's dissect the `node` preset to see how it works. First of all the module must export a function. In case something went wrong return `null`. The cli will tell the user a problem occurred.
155
+
156
+
```js
157
+
module.exports= () => {
158
+
returnnull
159
+
}
160
+
```
161
+
162
+
There is a package called `read-pkg-up` to get the first `package.json` in the parent folder structure. It returns its content as a JavaScript object. If we can't find a `package.json` or it is empty we return `null`.
163
+
164
+
```js
165
+
constreadPkgUp=require('read-pkg-up')
166
+
167
+
module.exports=async () => {
168
+
try {
169
+
constpackageInfo=awaitreadPkgUp()
170
+
171
+
if (!packageInfo.pkg) {
172
+
throwError('Empty package.json')
173
+
}
174
+
} catch (e) {
175
+
returnnull
176
+
}
177
+
}
178
+
```
179
+
180
+
If everything went fine we return the three mandatory information (name, description, version).
181
+
182
+
```js
183
+
constreadPkgUp=require('read-pkg-up')
184
+
185
+
module.exports=async () => {
186
+
try {
187
+
constpackageInfo=awaitreadPkgUp()
188
+
189
+
if (!packageInfo.pkg) {
190
+
throwError('Empty package.json')
191
+
}
192
+
193
+
return {
194
+
name:packageInfo.pkg.name,
195
+
description:packageInfo.pkg.description,
196
+
version:packageInfo.pkg.version,
197
+
}
198
+
} catch (e) {
199
+
returnnull
200
+
}
201
+
}
202
+
```
203
+
204
+
That's it. Feel free to open an issue to ask for a new preset or open a pull request to add one.
205
+
206
+
All preset needs at least 3 pieces of informations to work:
0 commit comments