Created
October 18, 2016 15:11
-
-
Save DanielZlotin/4199f3dd85d1b952117ea260a99fdb72 to your computer and use it in GitHub Desktop.
puts all executables from node_modules into .bin, as npm usually does
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cp = require('child_process'); | |
const _ = require('lodash'); | |
const p = require('path'); | |
const fs = require('fs'); | |
const nodeModules = p.join(process.cwd(), 'node_modules'); | |
const bin = p.join(nodeModules, '.bin'); | |
cp.execSync(`mkdir ${bin} || true`); | |
const result = _.split(String(cp.execSync(`find ${nodeModules} -type f -name 'package.json'`)), '\n'); | |
_.forEach(result, (f) => { | |
if (!fs.existsSync(f)) { | |
return; | |
} | |
const pgk = JSON.parse(fs.readFileSync(f)); | |
_.forEach(pgk.bin, (pth, name) => { | |
if (!_.isString(name)) { | |
return; | |
} | |
const src = p.join(bin, name); | |
const dst = p.resolve(p.dirname(f), pth); | |
if (!fs.existsSync(src)) { | |
cp.execSync(`ln -s ${dst} ${src} || true`, {stdio: [0, 1, 'ignore']}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment