-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (61 loc) · 2.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
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
const verifyWHMCS = require('./lib/verify')
const publishWHMCS = require('./lib/publish')
const deleteVersion = require('./lib/delete-marketplace-version')
const setCompatibleVersions = require('./lib/set-compatible-versions')
const githubReleases = require('./lib/get-github-releases.js')
const marketplaceVersions = require('./lib/scrape-marketplace-versions.js')
let verified
/**
* Called by semantic-release during the verify step
* @param {*} pluginConfig The semantic-release plugin config
* @param {*} context The context provided by semantic-release
*/
async function verifyConditions (pluginConfig, context) {
if (!verified) {
await verifyWHMCS(pluginConfig, context)
verified = true
}
}
/**
* Called by semantic-release during the publish step
* @param {*} pluginConfig The semantic-release plugin config
* @param {*} context The context provided by semantic-release
*/
async function publish (pluginConfig, context) {
await verifyConditions(pluginConfig, context)
return publishWHMCS(pluginConfig, context)
}
async function syncVersions (pluginConfig, context) {
await verifyConditions(pluginConfig, context)
const releases = await githubReleases(pluginConfig, context)
if (releases && releases.length) {
const versions = await marketplaceVersions(pluginConfig, context)
for (const release of releases) {
if (!versions.includes(release.name.substring(1))) {
context.nextRelease = {
version: release.name.substring(1),
notes: release.body,
releaseDate: release.published_at
}
console.log(`Adding missing version ${context.nextRelease.version}`)
await publish(pluginConfig, context)
}
}
}
}
async function delVersion (pluginConfig, context) {
await verifyConditions(pluginConfig, context)
await deleteVersion(pluginConfig, context)
}
async function updateCompatibility (pluginConfig, context) {
await verifyConditions(pluginConfig, context)
await setCompatibleVersions(pluginConfig, context)
}
module.exports = {
publish,
syncVersions,
delVersion,
githubReleases,
marketplaceVersions,
updateCompatibility
}