Skip to content

Instantly share code, notes, and snippets.

@jwulf
Created March 20, 2017 12:22
Show Gist options
  • Save jwulf/07406d311eb0ed7b46943a3c11fb2606 to your computer and use it in GitHub Desktop.
Save jwulf/07406d311eb0ed7b46943a3c11fb2606 to your computer and use it in GitHub Desktop.
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}",`);
}
@jwulf
Copy link
Author

jwulf commented Mar 20, 2017

This is a script to create the package.json dependencies section from an existing project. If you have packages installed but not tracked in package.json, this will generate that section for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment