-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.js
130 lines (103 loc) · 3.46 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const {isNil} = require('lodash');
const parseJson = require('parse-json');
const debug = require('debug')('semantic-release:exec');
const SemanticReleaseError = require('@semantic-release/error');
const exec = require('./lib/exec.js');
const verifyConfig = require('./lib/verify-config.js');
async function verifyConditions(pluginConfig, context) {
if (!isNil(pluginConfig.verifyConditionsCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('verifyConditionsCmd', pluginConfig);
try {
await exec('verifyConditionsCmd', pluginConfig, context);
} catch (error) {
throw new SemanticReleaseError(error.stdout, 'EVERIFYCONDITIONS');
}
}
}
async function analyzeCommits(pluginConfig, context) {
if (!isNil(pluginConfig.analyzeCommitsCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('analyzeCommitsCmd', pluginConfig);
const stdout = await exec('analyzeCommitsCmd', pluginConfig, context);
return stdout || undefined;
}
}
async function verifyRelease(pluginConfig, context) {
if (!isNil(pluginConfig.verifyReleaseCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('verifyReleaseCmd', pluginConfig);
try {
await exec('verifyReleaseCmd', pluginConfig, context);
} catch (error) {
throw new SemanticReleaseError(error.stdout, 'EVERIFYRELEASE');
}
}
}
async function generateNotes(pluginConfig, context) {
if (!isNil(pluginConfig.generateNotesCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('generateNotesCmd', pluginConfig);
const stdout = await exec('generateNotesCmd', pluginConfig, context);
return stdout;
}
}
async function prepare(pluginConfig, context) {
if (!isNil(pluginConfig.prepareCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('prepareCmd', pluginConfig);
await exec('prepareCmd', pluginConfig, context);
}
}
async function publish(pluginConfig, context) {
if (!isNil(pluginConfig.publishCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('publishCmd', pluginConfig);
const stdout = await exec('publishCmd', pluginConfig, context);
try {
return stdout ? parseJson(stdout) : undefined;
} catch (error) {
debug(stdout);
debug(error);
debug(
`The command ${
pluginConfig.publishCmd || pluginConfig.cmd
} wrote invalid JSON to stdout. The stdout content will be ignored.`
);
}
return undefined;
}
return false;
}
async function addChannel(pluginConfig, context) {
if (!isNil(pluginConfig.addChannelCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('addChannelCmd', pluginConfig);
const stdout = await exec('addChannelCmd', pluginConfig, context);
try {
return stdout ? parseJson(stdout) : undefined;
} catch (error) {
debug(stdout);
debug(error);
debug(`The command ${pluginConfig.cmd} wrote invalid JSON to stdout. The stdout content will be ignored.`);
return undefined;
}
}
return false;
}
async function success(pluginConfig, context) {
if (!isNil(pluginConfig.successCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('successCmd', pluginConfig);
await exec('successCmd', pluginConfig, context);
}
}
async function fail(pluginConfig, context) {
if (!isNil(pluginConfig.failCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig('failCmd', pluginConfig);
await exec('failCmd', pluginConfig, context);
}
}
module.exports = {
verifyConditions,
analyzeCommits,
verifyRelease,
generateNotes,
prepare,
publish,
addChannel,
success,
fail,
};