-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathremove-old-electron-apps.js
60 lines (45 loc) · 1.58 KB
/
remove-old-electron-apps.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
#!/usr/bin/env node
const fs = require('fs').promises
const semver = require('semver')
const findOldElectronApps = require('../lib/old-electron-apps')
const OLD_ELECTRON_VERSION = '6.0.0'
/* Links can break at any time and it's outside of the repo's control,
so it doesn't make sense to run this script as part of CI. Instead,
this should be run periodically as part of a separate process. */
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
})
const numberArgs = process.argv.filter((v) => /^\d+$/.test(v))
const possibleStart =
numberArgs.length > 0 ? parseInt(numberArgs[0], 10) : undefined
const possibleEnd =
numberArgs.length > 0 ? parseInt(numberArgs[1], 10) : undefined
console.log(
`Checking apps ${possibleStart || 0} through ${
possibleEnd || 'infinity'
} for old electron apps`
)
async function main() {
const oldArrays = (
await findOldElectronApps(possibleStart, possibleEnd)
).filter((old) => {
if (old.result === undefined) return false
try {
return semver.lt(old.result, OLD_ELECTRON_VERSION)
} catch (err) {
return false
}
})
console.log(`Will disable ${oldArrays.length} entries`)
for (const old of oldArrays) {
let data = await fs.readFile(old.entry.fullPath, { encoding: 'utf-8' })
if (!data.endsWith('\n')) {
data += `\n`
}
data += `disabled: true # Old Electron version: v${old.result}\n`
await fs.writeFile(old.entry.fullPath, data, { encoding: 'utf-8' })
console.log(data)
console.log(`\n---\n`)
}
}
main()