UNPKG

932 BJavaScriptView Raw
1const path = require('path')
2const fs = require('fs')
3const chalk = require('chalk')
4const glob = require('glob')
5const flatten = require('lodash/flatten')
6const mkdirp = require('mkdirp')
7
8module.exports = () => {
9 const configPath = path.join(process.env.PWD, 'lerna.json')
10
11 if (!fs.existsSync(configPath)) {
12 console.log('Error: file "lerna.json" not found')
13 console.log('Command should be run from the lerna project root.')
14 process.exit(-1)
15 }
16
17 const config = JSON.parse(fs.readFileSync(configPath))
18 const globs = config.packages.map(globStr => globStr + '/')
19 const packages = flatten(globs.map(globStr => glob.sync(globStr)))
20
21 const gnoll = path.join(process.env.PWD, 'node_modules', '.bin', 'gnoll')
22 packages.forEach(package => {
23 const bin = path.join(package, 'node_modules', '.bin')
24 const link = path.join(bin, 'gnoll')
25 if (fs.existsSync(link)) return
26 mkdirp.sync(bin)
27 fs.symlinkSync(gnoll, link)
28 })
29}