changelog-tool 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +17 -0
- package/changelog.mjs +6 -13
- package/cli.mjs +55 -14
- package/package.json +1 -1
- package/readme.md +28 -8
- package/util.mjs +35 -1
package/changelog.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
0.5.0 (2023-02-12)
|
5
|
+
------------------
|
6
|
+
|
7
|
+
* Support changing the version to the next major/minor using the `--major` and
|
8
|
+
`--minor` arguments.
|
9
|
+
* The `add` command now uses the -m argument instead of a positional for the
|
10
|
+
message.
|
11
|
+
* bla
|
12
|
+
* bla
|
13
|
+
|
14
|
+
|
15
|
+
0.4.1 (2023-02-12)
|
16
|
+
------------------
|
17
|
+
|
18
|
+
* Make sure that the binary is executable
|
19
|
+
|
20
|
+
|
4
21
|
0.4.0 (2023-02-12)
|
5
22
|
------------------
|
6
23
|
|
package/changelog.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { wrap } from './util.mjs';
|
1
|
+
import { calculateNextVersion, wrap } from './util.mjs';
|
2
2
|
|
3
3
|
// @ts-check
|
4
4
|
export class Changelog {
|
@@ -38,21 +38,14 @@ export class Changelog {
|
|
38
38
|
* Adds a new version to the log. Version string is automatically increased
|
39
39
|
* from the previous one
|
40
40
|
*
|
41
|
+
* @params {'patch'|'minor'|'major'} changeType
|
41
42
|
* @returns {VersionLog}
|
42
43
|
*/
|
43
|
-
newVersion() {
|
44
|
+
newVersion(changeType = 'patch') {
|
44
45
|
|
45
|
-
const
|
46
|
-
const
|
47
|
-
|
48
|
-
throw new Error(`Could not automatically determine the next version string after "${lastVersionStr}"`);
|
49
|
-
}
|
50
|
-
const newVersionStr = [
|
51
|
-
...lastVersionParts.slice(0, -1),
|
52
|
-
// @ts-ignore-error 'Possibly udefined', but we know it isnt
|
53
|
-
parseInt(lastVersionParts.at(-1)) + 1
|
54
|
-
].join('.');
|
55
|
-
const versionLog = new VersionLog(newVersionStr);
|
46
|
+
const lastVersion = this.versions[0].version;
|
47
|
+
const newVersion = calculateNextVersion(lastVersion);
|
48
|
+
const versionLog = new VersionLog(newVersion);
|
56
49
|
|
57
50
|
return this.add(versionLog);
|
58
51
|
|
package/cli.mjs
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
#!/usr/bin/env node
|
1
2
|
// @ts-check
|
2
3
|
import { parseArgs } from 'node:util';
|
3
4
|
import * as fs from 'node:fs/promises';
|
4
5
|
import * as url from 'node:url';
|
5
|
-
import { readPackageVersion, exists } from './util.mjs';
|
6
|
+
import { readPackageVersion, exists, calculateNextVersion } from './util.mjs';
|
6
7
|
import { Changelog, VersionLog, LogItem } from './changelog.mjs';
|
7
8
|
import { parseFile } from './parse.mjs';
|
8
9
|
|
@@ -30,6 +31,23 @@ async function main() {
|
|
30
31
|
default: false,
|
31
32
|
description: 'Show all versions',
|
32
33
|
},
|
34
|
+
message: {
|
35
|
+
type: 'string',
|
36
|
+
description: 'Changelog message',
|
37
|
+
short: 'm'
|
38
|
+
},
|
39
|
+
patch: {
|
40
|
+
type: 'boolean',
|
41
|
+
description: 'Indicates that the current change is a patch-level change.',
|
42
|
+
},
|
43
|
+
minor: {
|
44
|
+
type: 'boolean',
|
45
|
+
description: 'Indicates that the current change is a minor change.',
|
46
|
+
},
|
47
|
+
major: {
|
48
|
+
type: 'boolean',
|
49
|
+
description: 'Indicates that the current change is a major change.',
|
50
|
+
},
|
33
51
|
},
|
34
52
|
allowPositionals: true,
|
35
53
|
});
|
@@ -51,10 +69,21 @@ async function main() {
|
|
51
69
|
await init();
|
52
70
|
break;
|
53
71
|
case 'add' :
|
54
|
-
|
55
|
-
|
72
|
+
/** @type {'major' | 'minor' | 'patch'} */
|
73
|
+
let changeType = 'patch';
|
74
|
+
if (values.minor) {
|
75
|
+
changeType = 'minor';
|
76
|
+
}
|
77
|
+
if (values.major) {
|
78
|
+
changeType = 'major';
|
79
|
+
}
|
80
|
+
if (!values.message) {
|
81
|
+
throw new Error('The "-m" or "-message" argument is required');
|
56
82
|
}
|
57
|
-
await add(
|
83
|
+
await add({
|
84
|
+
message: values.message,
|
85
|
+
changeType,
|
86
|
+
});
|
58
87
|
break;
|
59
88
|
case 'release' :
|
60
89
|
await release();
|
@@ -91,13 +120,13 @@ Manipulate your changelog file
|
|
91
120
|
|
92
121
|
Usage:
|
93
122
|
|
94
|
-
changelog init
|
95
|
-
changelog add [message]
|
96
|
-
changelog release
|
97
|
-
changelog show
|
98
|
-
changelog show [version]
|
99
|
-
changelog list
|
100
|
-
changelog format
|
123
|
+
changelog init - Create a new, empty changelog.
|
124
|
+
changelog add -m [message] - Adds a new line to the changelog.
|
125
|
+
changelog release - Marks the current changelog as released.
|
126
|
+
changelog show - Show the last changelog.
|
127
|
+
changelog show [version] - Show the changelog of a specific version.
|
128
|
+
changelog list - List all versions in the changelog.
|
129
|
+
changelog format - Reformats the changelog in the standard format.
|
101
130
|
|
102
131
|
The logs this tool uses follows a specific markdown format. Currently it will
|
103
132
|
only look for a file named 'changelog.md' in the current directory.
|
@@ -169,16 +198,28 @@ async function format() {
|
|
169
198
|
}
|
170
199
|
|
171
200
|
/**
|
172
|
-
* @param {
|
201
|
+
* @param {Object} options
|
202
|
+
* @param {string} options.message
|
203
|
+
* @param {'patch'|'major'|'minor'} options.changeType
|
173
204
|
*/
|
174
|
-
async function add(message) {
|
205
|
+
async function add({message, changeType}) {
|
175
206
|
const changelog = await parseChangelog();
|
176
207
|
|
177
208
|
let lastVersion = changelog.versions[0];
|
178
209
|
if (lastVersion.date) {
|
179
|
-
lastVersion = changelog.newVersion();
|
210
|
+
lastVersion = changelog.newVersion(changeType);
|
180
211
|
console.log('Creating new version: %s', lastVersion.version);
|
212
|
+
} else {
|
213
|
+
if (changeType === 'minor' || changeType === 'major') {
|
214
|
+
const previousVersion = changelog.versions[1];
|
215
|
+
const updatedVersionStr = calculateNextVersion(previousVersion.version, changeType);
|
216
|
+
if (updatedVersionStr !== lastVersion.version) {
|
217
|
+
console.log('Updating unreleased version from %s to %s', lastVersion.version, updatedVersionStr);
|
218
|
+
lastVersion.version = updatedVersionStr;
|
219
|
+
}
|
220
|
+
}
|
181
221
|
}
|
222
|
+
|
182
223
|
lastVersion.add(message);
|
183
224
|
|
184
225
|
await fs.writeFile(filename, changelog.toString());
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -36,13 +36,33 @@ To tool can be used programmatically and with the CLI. The CLI has the
|
|
36
36
|
following commands:
|
37
37
|
|
38
38
|
```
|
39
|
-
npx changelog init
|
40
|
-
npx changelog add [message]
|
41
|
-
npx changelog release
|
42
|
-
npx changelog show
|
43
|
-
npx changelog show [version]
|
44
|
-
npx changelog list
|
45
|
-
npx changelog format
|
39
|
+
npx changelog init - Create a new, empty npx changelog.
|
40
|
+
npx changelog add -m [message] - Adds a new line to the npx changelog.
|
41
|
+
npx changelog release - Marks the current npx changelog as released.
|
42
|
+
npx changelog show - Show the last npx changelog.
|
43
|
+
npx changelog show [version] - Show the npx changelog of a specific version.
|
44
|
+
npx changelog list - List all versions in the npx changelog.
|
45
|
+
npx changelog format - Reformats the npx changelog in the standard format.
|
46
46
|
```
|
47
47
|
|
48
|
-
|
48
|
+
### Invoking add
|
49
|
+
|
50
|
+
Easiest is to just run:
|
51
|
+
|
52
|
+
```
|
53
|
+
npx changelog add -m "Bug fix"
|
54
|
+
```
|
55
|
+
|
56
|
+
This will automatically add a line to the latest unreleased version. If there
|
57
|
+
is no unreleased version, it will create a new patch version.
|
58
|
+
|
59
|
+
If the change should cause a minor or major version bump, you can specify the
|
60
|
+
these options too:
|
61
|
+
|
62
|
+
```
|
63
|
+
npx changelog add --minor -m "New feature"
|
64
|
+
npx changelog add --major -m "Backwards compatibility break"
|
65
|
+
```
|
66
|
+
|
67
|
+
These settings will automatically adjust the version string of the most recent
|
68
|
+
unreleased version.
|
package/util.mjs
CHANGED
@@ -62,7 +62,7 @@ export function wrap(input, secondLineOffset = 0, lineLength = 79) {
|
|
62
62
|
}
|
63
63
|
|
64
64
|
const maxLength = lines.length > 1 ? lineLength - secondLineOffset : lineLength;
|
65
|
-
|
65
|
+
|
66
66
|
const potentialNewLine = [lines.at(-1),word].join(' ');
|
67
67
|
if (potentialNewLine.length>maxLength) {
|
68
68
|
lines.push(word);
|
@@ -74,3 +74,37 @@ export function wrap(input, secondLineOffset = 0, lineLength = 79) {
|
|
74
74
|
return lines.join('\n' + ' '.repeat(secondLineOffset));
|
75
75
|
|
76
76
|
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @param {string} prevVersion
|
80
|
+
* @param {'patch'|'minor'|'major'} changeType
|
81
|
+
* @returns {string}
|
82
|
+
*/
|
83
|
+
export function calculateNextVersion(prevVersion, changeType = 'patch') {
|
84
|
+
|
85
|
+
// This function only currently understands 1 format, but this may change
|
86
|
+
// in the future.
|
87
|
+
if (!prevVersion.match(/^[0-9]+\.[0-9]+\.[0-9]+$/)) {
|
88
|
+
throw new Error(`Could not automatically determine the next ${changeType} version from ${prevVersion}. You might want to request a new feature to support this`);
|
89
|
+
}
|
90
|
+
|
91
|
+
const parts = prevVersion.split('.').map( part => +part);
|
92
|
+
|
93
|
+
switch(changeType) {
|
94
|
+
case 'major' :
|
95
|
+
parts[0]++;
|
96
|
+
parts[1]=0;
|
97
|
+
parts[2]=0;
|
98
|
+
break;
|
99
|
+
case 'minor' :
|
100
|
+
parts[1]++;
|
101
|
+
parts[2]=0;
|
102
|
+
break;
|
103
|
+
case 'patch' :
|
104
|
+
parts[2]++;
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
|
108
|
+
return parts.join('.');
|
109
|
+
|
110
|
+
}
|