Last active
April 24, 2018 20:28
-
-
Save Nevexo/52b4d183ac978c0b6a658cffc46854ca to your computer and use it in GitHub Desktop.
Node_modules dependency Generator
This file contains 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
//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)) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A file named "yeet.json" will be created with a JSON object of all modules, feel free to paste this back into package.json.