Skip to content

Instantly share code, notes, and snippets.

@Nevexo
Last active April 24, 2018 20:28
Show Gist options
  • Save Nevexo/52b4d183ac978c0b6a658cffc46854ca to your computer and use it in GitHub Desktop.
Save Nevexo/52b4d183ac978c0b6a658cffc46854ca to your computer and use it in GitHub Desktop.
Node_modules dependency Generator
//Please note, the code in here is a bit "scratty" but it gets the work done so shush ok? It requires the file to have a package.json.
console.log("[hi doe] Hi mate dis is a script")
var dependencies = {}
var fs = require("fs")
var mnt;
function getDirectories(path) { //Credit to: Titlacauan on Stackoverflow (2014)
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
}
var dirs = getDirectories("node_modules") //array of all directories in node_modules
var loop = 0;
dirs.forEach(function(dir) {
loop++;
var file = "node_modules/" + dir + "/package.json"
console.log("[!] Package file: " + file)
mnt = require("./" + file)
console.log("[" + mnt.name + "] Processing version: " + mnt.version)
dependencies[mnt.name] = "^" + mnt.version
mnt = null
if (loop == dirs.length) {
console.log("[!] Finished.")
console.log(dependencies)
fs.writeFile("yeet.json", JSON.stringify(dependencies))
}
})
@Nevexo
Copy link
Author

Nevexo commented Apr 24, 2018

A file named "yeet.json" will be created with a JSON object of all modules, feel free to paste this back into package.json.

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