Created
November 23, 2018 01:48
-
-
Save rming/8d495784d3574b3bf68d35e7998979aa to your computer and use it in GitHub Desktop.
collect the dependencies in ./node_modules.
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
| var fs = require("fs"); | |
| function main() { | |
| fs.readdir("./node_modules", function (err, dirs) { | |
| if (err) { | |
| console.log(err); | |
| return; | |
| } | |
| dirs.forEach(function(dir){ | |
| if (dir.indexOf(".") !== 0) { | |
| var packageJsonFile = "./node_modules/" + dir + "/package.json"; | |
| if (fs.existsSync(packageJsonFile)) { | |
| fs.readFile(packageJsonFile, function (err, data) { | |
| if (err) { | |
| console.log(err); | |
| } | |
| else { | |
| var json = JSON.parse(data); | |
| console.log('"'+json.name+'": "' + json.version + '",'); | |
| } | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment