Created
March 20, 2017 12:22
-
-
Save jwulf/07406d311eb0ed7b46943a3c11fb2606 to your computer and use it in GitHub Desktop.
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 fs = require('fs'); | |
const package = JSON.parse(fs.readFileSync('./package.json')); | |
//console.log(package); | |
const deps = package.dependencies; | |
console.log(deps); | |
for (let i = 0; i < Object.keys(deps).length; i++) { | |
const dep = Object.keys(deps)[i]; | |
//const version = dep[pkg]; | |
const fsname = `./node_modules/${dep}/package.json`; | |
const depPackage = fs.readFileSync(fsname); | |
const depPkg = JSON.parse(depPackage); | |
const version = depPkg.version; | |
console.log(`"${dep}" : "${version}",`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a script to create the
package.json
dependencies
section from an existing project. If you have packages installed but not tracked inpackage.json
, this will generate that section for you.