Skip to content

Instantly share code, notes, and snippets.

@danielo515
Created July 12, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielo515/6cff10095dfdbd2811a98b4d20eb2189 to your computer and use it in GitHub Desktop.
Save danielo515/6cff10095dfdbd2811a98b4d20eb2189 to your computer and use it in GitHub Desktop.
List all packages under a lerna repository
'use strict';
const Fs = require('fs');
const ReadDir = Fs.readdirSync;
const Stat = Fs.statSync;
module.exports = (basePath) => {
const getAllPackages = () => ReadDir(basePath)
.map((d) => `${basePath}/${d}`)
.filter((d) => Stat(d).isDirectory())
.map((d) => ReadDir(d).filter((i) => (/package\.json/i).test(i)).map((x) => `${d}/${x}`))
.reduce( (all,p) => p.concat(all),[]);
return getAllPackages().map( (p) => ({ [require(p).name] : require(p).version }));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment