-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.js
More file actions
130 lines (102 loc) · 3.64 KB
/
index.js
File metadata and controls
130 lines (102 loc) · 3.64 KB
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
import { isNil } from "lodash-es";
import parseJson from "parse-json";
import debugFactory from "debug";
import SemanticReleaseError from "@semantic-release/error";
import exec from "./lib/exec.js";
import verifyConfig from "./lib/verify-config.js";
const debug = debugFactory("semantic-release:exec");
function execErrorMessage(error) {
return error.stdout && error.stdout.trim.length > 0
? error.stdout
: `${error.name}: ${error.message}`;
}
export async function verifyConditions(pluginConfig, context) {
if (!isNil(pluginConfig.verifyConditionsCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("verifyConditionsCmd", pluginConfig);
try {
await exec("verifyConditionsCmd", pluginConfig, context);
} catch (error) {
const message = execErrorMessage(error);
throw new SemanticReleaseError(message, "EVERIFYCONDITIONS");
}
}
}
export 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;
}
}
export async function verifyRelease(pluginConfig, context) {
if (!isNil(pluginConfig.verifyReleaseCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("verifyReleaseCmd", pluginConfig);
try {
await exec("verifyReleaseCmd", pluginConfig, context);
} catch (error) {
const message = execErrorMessage(error);
throw new SemanticReleaseError(message, "EVERIFYRELEASE");
}
}
}
export async function generateNotes(pluginConfig, context) {
if (!isNil(pluginConfig.generateNotesCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("generateNotesCmd", pluginConfig);
const stdout = await exec("generateNotesCmd", pluginConfig, context);
return stdout;
}
}
export async function prepare(pluginConfig, context) {
if (!isNil(pluginConfig.prepareCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("prepareCmd", pluginConfig);
await exec("prepareCmd", pluginConfig, context);
}
}
export 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;
}
export 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;
}
export async function success(pluginConfig, context) {
if (!isNil(pluginConfig.successCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("successCmd", pluginConfig);
await exec("successCmd", pluginConfig, context);
}
}
export async function fail(pluginConfig, context) {
if (!isNil(pluginConfig.failCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("failCmd", pluginConfig);
await exec("failCmd", pluginConfig, context);
}
}