-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.js
59 lines (47 loc) · 1.42 KB
/
uninstall.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
const path = require('path')
const fs = require('fs')
const AutoLaunch = require('easy-auto-launch')
const pkill = require('./pkill')
async function uninstall() {
console.log('👀 detect platform:', process.platform)
if (process.platform !== 'win32' && process.platform !== 'linux') {
console.error('❌ os system is not supported:', process.platform)
process.exit(1)
}
const homedir = require('os').homedir()
const folder = path.join(homedir, '.dev-dns')
let execPath = process.execPath
if (
execPath.endsWith('nodejs')
|| execPath.endsWith('node')
|| execPath.endsWith('nodejs.exe')
|| execPath.endsWith('node.exe')
) {
if (process.platform === 'win32') {
execPath = './dist/dev-dns-win.exe'
} else if (process.platform === 'linux') {
execPath = './dist/dev-dns-linux'
}
}
const exe = path.basename(execPath)
const appName = path.basename(exe, path.extname(exe))
const targetExec = path.join(folder, exe)
console.log('🗑️ kill process:', exe)
await pkill.pkill({ exe })
console.log('📂 remove folder:', folder)
if (fs.existsSync(folder)) {
fs.rmSync(folder, { recursive: true })
}
console.log('🚗 remove autostart...')
const autoLaunch = new AutoLaunch({
name: appName,
path: targetExec,
})
const enabled = await autoLaunch.isEnabled()
if (enabled) {
await autoLaunch.disable()
}
}
module.exports = {
uninstall,
}