Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Created August 4, 2018 06:56
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 SgtPooki/fe1f9d59eeb9c2dcf39064541ba51e05 to your computer and use it in GitHub Desktop.
Save SgtPooki/fe1f9d59eeb9c2dcf39064541ba51e05 to your computer and use it in GitHub Desktop.
Find names and versions of root modules and typings in your project. This checks all package.json files (at the root level of the directories) and outputs the name and version found in the relevant package.json file
const glob = require('glob');
const globPromise = (string) => new Promise((resolve, reject) => {
glob(string, (error, result) => {
if (error) {
reject(error);
}
resolve(result);
});
});
const getNamesAndVersions = (file) => {
const json = require(`./${file}`);
return `${json.name}@${json.version}`;
};
const modules = globPromise('./node_modules/*/package.json');
const types = globPromise('./node_modules/@types/*/package.json');
Promise.all([modules, types]).then((a) => {
const versions = [...a[0], ...a[1]].map(getNamesAndVersions);
console.log(versions.join('\n'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment