-
-
Notifications
You must be signed in to change notification settings - Fork 511
/
GitRelease.js
51 lines (43 loc) 路 1.48 KB
/
GitRelease.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
42
43
44
45
46
47
48
49
50
51
import _ from 'lodash';
import { readJSON } from '../util.js';
import GitBase from './GitBase.js';
const defaultConfig = readJSON(new URL('../../config/release-it.json', import.meta.url));
class GitRelease extends GitBase {
static isEnabled(options) {
return options.release;
}
getInitialOptions(options) {
const baseOptions = super.getInitialOptions(...arguments);
const git = options.git || defaultConfig.git;
const gitOptions = _.pick(git, ['tagExclude', 'tagName', 'tagMatch', 'pushRepo', 'changelog']);
return _.defaults(baseOptions, gitOptions);
}
get token() {
const { tokenRef } = this.options;
return _.get(process.env, tokenRef, null);
}
async beforeRelease() {
const { releaseNotes: script } = this.options;
const { changelog } = this.config.getContext();
const releaseNotes = script ? await this.processReleaseNotes(script) : changelog;
this.setContext({ releaseNotes });
if (releaseNotes !== changelog) {
this.log.preview({ title: 'release notes', text: releaseNotes });
}
}
async processReleaseNotes(script) {
if (typeof script === 'function') {
const ctx = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
return script(ctx);
} else {
return this.exec(script);
}
}
afterRelease() {
const { isReleased, releaseUrl } = this.getContext();
if (isReleased) {
this.log.log(`馃敆 ${releaseUrl}`);
}
}
}
export default GitRelease;