This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
68 lines (51 loc) · 1.45 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
/* eslint require-atomic-updates: off */
const AggregateError = require('aggregate-error');
const getPkg = require('./lib/get-pkg.js');
const verifyApm = require('./lib/verify.js');
const prepareApm = require('./lib/prepare.js');
const publishApm = require('./lib/publish.js');
let verified;
let prepared;
async function verifyConditions(pluginConfig, context) {
const errors = await verifyApm(pluginConfig, context);
try {
await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
}
if (errors.length > 0) {
throw new AggregateError(errors);
}
verified = true;
}
async function prepare(pluginConfig, context) {
const errors = verified ? [] : await verifyApm(pluginConfig, context);
try {
await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
}
if (errors.length > 0) {
throw new AggregateError(errors);
}
await prepareApm(pluginConfig, context);
prepared = true;
}
async function publish(pluginConfig, context) {
let pkg;
const errors = verified ? [] : await verifyApm(pluginConfig, context);
try {
pkg = await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
}
if (errors.length > 0) {
throw new AggregateError(errors);
}
if (!prepared) {
await prepareApm(pluginConfig, context);
prepared = true;
}
return publishApm(pluginConfig, pkg, context);
}
module.exports = {verifyConditions, prepare, publish};