changelog-tool 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- package/changelog.md +13 -0
- package/cli.mjs +18 -4
- package/package.json +1 -1
- package/readme.md +6 -0
- package/util.mjs +43 -0
package/changelog.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
0.7.1 (2023-02-14)
|
5
|
+
------------------
|
6
|
+
|
7
|
+
* Bug: forgot to commit the release
|
8
|
+
|
9
|
+
|
10
|
+
0.7.0 (2023-02-14)
|
11
|
+
------------------
|
12
|
+
|
13
|
+
* The "release" command now automatically commits and and creates a git tag,
|
14
|
+
much like `npm version`
|
15
|
+
|
16
|
+
|
4
17
|
0.6.0 (2023-02-14)
|
5
18
|
------------------
|
6
19
|
|
package/cli.mjs
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import { parseArgs } from 'node:util';
|
4
4
|
import * as fs from 'node:fs/promises';
|
5
5
|
import * as url from 'node:url';
|
6
|
-
import { readPackageVersion, exists, calculateNextVersion } from './util.mjs';
|
6
|
+
import { readPackageVersion, exists, calculateNextVersion, isGit, isGitClean, runCommand } from './util.mjs';
|
7
7
|
import { Changelog, VersionLog, LogItem } from './changelog.mjs';
|
8
8
|
import { parseFile } from './parse.mjs';
|
9
9
|
import { execSync } from 'node:child_process';
|
@@ -236,13 +236,27 @@ async function release() {
|
|
236
236
|
}
|
237
237
|
lastVersion.date = new Date().toISOString().substr(0,10);
|
238
238
|
console.log(`Releasing ${lastVersion.version}`);
|
239
|
+
|
240
|
+
const useGit = await isGit();
|
241
|
+
|
242
|
+
if (useGit) {
|
243
|
+
if (!await isGitClean()) {
|
244
|
+
throw new Error('Current git working directory is not clean. Please commit your changes first');
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
239
248
|
await fs.writeFile(filename, changelog.toString());
|
240
249
|
console.log(`${changelog.versions.length} changelogs saved to ${filename}`);
|
241
250
|
|
242
251
|
if (await exists('package.json')) {
|
243
|
-
|
244
|
-
|
245
|
-
|
252
|
+
runCommand(
|
253
|
+
`npm version "${lastVersion.version}" --no-git-tag-version`
|
254
|
+
);
|
255
|
+
}
|
256
|
+
if (useGit) {
|
257
|
+
runCommand(`git add --all`);
|
258
|
+
runCommand(`git commit -m "Releasing ${lastVersion.version}"`);
|
259
|
+
runCommand(`git tag v${lastVersion.version}`);
|
246
260
|
}
|
247
261
|
|
248
262
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -88,3 +88,9 @@ npm version [version] --no-git-tag-version
|
|
88
88
|
|
89
89
|
This command adjust the `version` field in `package.json` to match the latest
|
90
90
|
changelog version.
|
91
|
+
|
92
|
+
If the tool detects if this is a git directory, it will also:
|
93
|
+
|
94
|
+
* Ensure that the working directory is clean.
|
95
|
+
* Commit the changes.
|
96
|
+
* Create a tag with `git tag v[version]`.
|
package/util.mjs
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
// @ts-check
|
2
|
+
import { execSync } from 'node:child_process';
|
2
3
|
import * as fs from 'node:fs/promises';
|
4
|
+
import * as path from 'node:path';
|
3
5
|
|
4
6
|
/**
|
5
7
|
* Checks if a file exists
|
@@ -108,3 +110,44 @@ export function calculateNextVersion(prevVersion, changeType = 'patch') {
|
|
108
110
|
return parts.join('.');
|
109
111
|
|
110
112
|
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Returns true if we're in a git-powered directory
|
116
|
+
*
|
117
|
+
* @returns {Promise<boolean>}
|
118
|
+
*/
|
119
|
+
export async function isGit() {
|
120
|
+
|
121
|
+
let currentPath = process.cwd();
|
122
|
+
while(currentPath!=='/') {
|
123
|
+
if (await exists(path.join(currentPath,'.git'))) {
|
124
|
+
return true;
|
125
|
+
}
|
126
|
+
currentPath = path.dirname(currentPath);
|
127
|
+
}
|
128
|
+
return false;
|
129
|
+
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* @param {string} command
|
134
|
+
* @returns {string}
|
135
|
+
*/
|
136
|
+
export function runCommand(command) {
|
137
|
+
|
138
|
+
process.stderr.write(command + '\n');
|
139
|
+
return execSync(command).toString('utf-8');
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Returns true if the current working directory is clean.
|
145
|
+
*
|
146
|
+
* @returns {boolean}
|
147
|
+
*/
|
148
|
+
export function isGitClean() {
|
149
|
+
|
150
|
+
const result = execSync('git status --porcelain=v1').toString('utf-8');
|
151
|
+
return result.trim().length === 0;
|
152
|
+
|
153
|
+
}
|