-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (34 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import validatePeerDependencies from 'validate-peer-dependencies';
import { Plugin } from 'release-it';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// resolving peer dependencies relative to `process.cwd()` so that the peer dependency validation still works properly through `npm link` scenarios
validatePeerDependencies(__dirname, {
resolvePeerDependenciesFrom: process.cwd(),
});
export default class GHChangelogGeneratorPlugin extends Plugin {
async init() {
this._fromReference =
(await this.getTagForHEAD()) || (await this.getFirstCommit());
}
async getTagForHEAD() {
try {
return await this.exec('git describe --tags --abbrev=0', {
options: { write: false },
});
} catch (error) {
return null;
}
}
async getFirstCommit() {
if (this._firstCommit) {
return this._firstCommit;
}
this._firstCommit = await this.exec(`git rev-list --max-parents=0 HEAD`, {
options: { write: false },
});
return this._firstCommit;
}
}