-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
34 lines (30 loc) · 979 Bytes
/
install.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
import { access } from 'fs/promises'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import grab from 'grab-github-release'
import { installLink } from 'link-bin-executable'
const exists = file => access(file).then(() => true, () => false)
const __dirname = dirname(fileURLToPath(import.meta.url))
try {
// use a locally produced executable during the build, or download it
let executable
executable = join(__dirname, 'changever')
if (process.platform === 'win32') executable += '.exe'
if (!await exists(executable)) {
let version
({ executable, version } = await grab({
repository: 'prantlf/changever',
targetDirectory: __dirname,
unpackExecutable: true
}))
console.log('downloaded and unpacked "%s" version %s', executable, version)
}
await installLink({
linkNames: ['changever'],
executable,
packageDirectory: __dirname
})
} catch (err) {
console.error(err)
process.exitCode = 1
}