Created
August 4, 2018 06:56
-
-
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
This file contains hidden or 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 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