Skip to content

Instantly share code, notes, and snippets.

@knnhcn
Created January 16, 2018 20:45
Show Gist options
  • Select an option

  • Save knnhcn/f923f379253b9b1ea68d037d33ccea58 to your computer and use it in GitHub Desktop.

Select an option

Save knnhcn/f923f379253b9b1ea68d037d33ccea58 to your computer and use it in GitHub Desktop.

Revisions

  1. knnhcn renamed this gist Jan 16, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. knnhcn created this gist Jan 16, 2018.
    51 changes: 51 additions & 0 deletions checkVersions.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    var fs = require("fs");
    var path = "./node_modules";
    var outPutFileName = "output.txt";

    fs.writeFile(outPutFileName, "", function(err) {
    if(err) {
    throw err;
    }
    })

    function getFiles (dir, files_){

    files_ = files_ || [];

    var files = fs.readdirSync(dir);

    for (let i in files) {

    var name = dir + '/' + files[i];

    if (fs.statSync(name).isDirectory()){
    getFiles(name, files_);
    } else {
    files_.push(name);
    }
    }

    return files_;
    }

    var files = getFiles(path);

    for(let i = 0; i<files.length; ++i) {

    if (files[i].indexOf("package.json") > 0 ) {

    var currentFile = fs.readFileSync(files[i], "UTF-8");

    try {
    var json = JSON.parse(currentFile);

    console.log(json._requested.raw);

    fs.appendFile(outPutFileName, json._requested.raw + `\n`);

    } catch (error) {
    }

    }

    }