-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbin.js
32 lines (30 loc) · 919 Bytes
/
bin.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
const fs = require('fs-extra')
const path = require('path')
const nm = require('../../utils/nm')
const bin = (key, target) => {
const pkgJSON = require(path.join(target, 'package.json'))
if (!pkgJSON.bin) return
fs.ensureDirSync(path.join(nm, '.bin'))
if (typeof pkgJSON.bin === 'string') {
try {
fs.unlinkSync(path.join(nm, '.bin', key))
} catch (e) {}
fs.symlinkSync(
path.join(target, pkgJSON.bin),
path.join(nm, '.bin', key)
)
fs.chmodSync(path.join(target, pkgJSON.bin), '0755')
} else if (typeof pkgJSON.bin === 'object') {
Object.keys(pkgJSON.bin).forEach((cmd) => {
try {
fs.unlinkSync(path.join(nm, '.bin', cmd))
} catch (e) {}
fs.symlinkSync(
path.join(target, pkgJSON.bin[cmd]),
path.join(nm, '.bin', cmd)
)
fs.chmodSync(path.join(target, pkgJSON.bin[cmd]), '0755')
})
}
}
module.exports = bin