-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckRemotes.js
59 lines (44 loc) · 1.71 KB
/
checkRemotes.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
const checkType = process.argv[2]
const getFormattedRemotes = (input) => {
const numberOfRemotes = input.length
const remotes = []
for(let i = 0; i < numberOfRemotes; i = i + 3) {
const [remote, url, type] = input.slice(i, i + 3)
remotes.push({
remote,
url,
type
})
}
const validRemotes = remotes.filter(remote => remote.type === '(push)').reduce((result, remote) => {
if(remote.url !== '[email protected]:PTFS-Europe/koha-plugin-template.git' &&
remote.url !== 'https://github.com/PTFS-Europe/koha-plugin-template.git') {
result.push(remote)
}
return result
}, [])
return validRemotes
}
if(checkType === 'check') {
const cliInput = process.argv.slice(3)
const validRemotes = getFormattedRemotes(cliInput)
if(validRemotes.length === 0) console.log('No valid remotes')
if(validRemotes.length === 1) return console.log(validRemotes[0].remote)
if(validRemotes.length > 1) console.log('Multiple remotes available')
}
if(checkType === 'validate') {
const response = process.argv.slice(3, 4)[0].split('-')[0]
const remoteList = process.argv.slice(4)
const validRemotes = getFormattedRemotes(remoteList).map(i => i.remote)
const checkRemoteIsValid = validRemotes.indexOf(response)
if(checkRemoteIsValid > -1) return console.log(response)
if(checkRemoteIsValid === -1) return console.log('Invalid')
}
if(checkType === 'provide') {
const cliInput = process.argv.slice(3)
const validRemotes = getFormattedRemotes(cliInput)
const remoteStrings = validRemotes.map(remote => {
return `${remote.remote}-${remote.url}`
})
console.log(...remoteStrings)
}