forked from ensdomains/ens-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
surgeGarbageCollect.js
executable file
·91 lines (83 loc) · 2.54 KB
/
surgeGarbageCollect.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
#!/usr/bin/env node
//const { exec, spawn, spawnSync } = require('child_process')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const whitelist = [
'apollo-upgrade-ensdev.surge.sh',
'app.avaxns.domains',
'ensdomains.surge.sh',
'ensdomains-v2.surge.sh',
'jefflau.dev',
'jefflau.surge.sh',
'impulseroutesetting.com',
'noxious-loss.surge.sh',
'manager.avaxns.domains',
'manager-beta.avaxns.domains',
'ensappdev3.surge.sh',
'silent-geese.surge.sh',
'hackathons.avaxns.domains',
'ens-hackathons-dev.surge.sh',
'ethparis.avaxns.domains',
'learn-more-ens.surge.sh',
'jefflau.net',
'ensropsten.surge.sh',
'ensdomains2.surge.sh',
'enstestregistrar.surge.sh',
'frontendmentor.surge.sh',
'animedrop.surge.sh',
'ensmanager.surge.sh',
'animedrop.com',
'djweddingphuket.com'
]
const removeSurgeDomain = domain => {
const domainToRemove = domain
console.log('domain to remove: ', domainToRemove)
if (domainToRemove.includes('app')) {
console.warn(`Not removing domain ${domainToRemove} as it contains 'app'`)
return
}
if (domainToRemove.includes('ensdomains')) {
console.warn(
`Not removing domain ${domainToRemove} as it contains 'ensdomains'`
)
return
}
if (whitelist.includes(domainToRemove)) {
console.warn(
`Not removing domain ${domainToRemove} as it is on the whitelist`
)
return
}
console.log(`Removing domain: ${domainToRemove}`)
exec(`surge teardown ${domainToRemove}`)
}
const run = async () => {
const surgeList = await exec("surge list | awk '{print $4}'")
const surgeDomains = surgeList.stdout.split(/\r?\n/)
const filterEmpty = surgeDomains.filter(x => x)
const cleanDomains = filterEmpty.map(x => x.replace('\x1B[39m', ''))
const subDomains = cleanDomains.map(x => x.split('.')[0])
const fetch = await exec('git fetch')
const branches = await exec('git branch -a')
const branchesList = branches.stdout.split(/\r?\n/).map(x => x.split('/')[2])
const filterEmptyBranches = branchesList.filter(x => x)
const trimStartBranches = filterEmptyBranches
let domainsToRemove = []
for (domain of cleanDomains) {
const result = trimStartBranches.filter(branch => {
return domain.includes(branch)
})
if (!result.length) {
domainsToRemove = [...domainsToRemove, domain]
}
}
if (!domainsToRemove.length) {
console.log('Not removing any domains')
return
}
console.log('domains to remove: ', domainsToRemove)
for (domain of domainsToRemove) {
removeSurgeDomain(domain)
}
}
run()