codekingpro/portable-devtools
114k
1// get all the paths that are (or might be) installed for a given pkg
2// There's no guarantee that all of these will be installed, but if they
3// are present, then we can assume that they're associated.
4const binTarget = require('./bin-target.js')
5const manTarget = require('./man-target.js')
6const { resolve, basename, extname } = require('path')
7const isWindows = require('./is-windows.js')
8module.exports = ({ path, pkg, global, top }) => {
9 if (top && !global) {
10 return []
11 }
12
13 const binSet = []
14 const binTarg = binTarget({ path, top })
15 if (pkg.bin) {
16 for (const bin of Object.keys(pkg.bin)) {
17 const b = resolve(binTarg, bin)
18 binSet.push(b)
19 if (isWindows) {
20 binSet.push(b + '.cmd')
21 binSet.push(b + '.ps1')
22 }
23 }
24 }
25
26 const manTarg = manTarget({ path, top })
27 const manSet = []
28 if (manTarg && pkg.man && Array.isArray(pkg.man) && pkg.man.length) {
29 for (const man of pkg.man) {
30 if (!/.\.[0-9]+(\.gz)?$/.test(man)) {
31 return binSet
32 }
33
34 const section = extname(basename(man, '.gz')).slice(1)
35 const base = basename(man)
36
37 manSet.push(resolve(manTarg, 'man' + section, base))
38 }
39 }
40
41 return manSet.length ? [...binSet, ...manSet] : binSet
42}
43 