🏡 index : github.com/captn3m0/which-electron.git

author Nemo <me@captnemo.in> 2021-07-15 21:36:12.0 +05:30:00
committer Nemo <me@captnemo.in> 2021-07-15 21:36:12.0 +05:30:00
commit
422cd3a254592ae7733773d87e0a61a1eb96b3ad [patch]
tree
4e3cb2bfb3cff4cd8cfd9c4710d93a2162e65f88
parent
a57a42b09225e4f645e59d8a02a3cf45cc915477
download
422cd3a254592ae7733773d87e0a61a1eb96b3ad.tar.gz

Get it working for some files



Diff

 finder.js         |  2 +-
 index.js          | 40 ++++++++++++++++++++++------------------
 package-lock.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 package.json      |  8 ++++++--
 zip.js            | 27 +++++++++++++++++++++++++++
 5 files changed, 109 insertions(+), 44 deletions(-)

diff --git a/finder.js b/finder.js
index 4f1031f..fa34b4a 100644
--- a/finder.js
+++ a/finder.js
@@ -5,7 +5,7 @@
module.exports = {
  // Finds the electron asar file, if we can
  asar: function(entries) {
    return Object.values(entries)
    return entries
      .filter((e) => {
        return (
          isDirectory(e.attributes) == false &&
diff --git a/index.js b/index.js
index efe8885..4996b45 100644
--- a/index.js
+++ a/index.js
@@ -1,36 +1,32 @@
const Seven = require("node-7z");
const path = require("path");
const osguess = require("./os");
const finder = require("./finder");
// Input file comes from process.argv[2]
const zip = require("./zip");

// Input file comes from process.argv[2]
const FILENAME = process.argv[2];
console.log(FILENAME)
const zip = Seven.list(FILENAME);
entries = [];
zip.on("data", (data) => {
  entries.push(data);
});

zip.on("end", () => {
zip.listFileContents(FILENAME, (entries)=> {
  let asar = finder.asar(entries);
  let binary = finder.binary(entries);
  let versionFiles = finder.version(entries);
  let enm = finder.findElectronPackageInsideNodeModules(entries);
  if (asar.length > 0) {
    asar.forEach((a) => {
      console.log(`${process.argv[2]}:${a}`);
    });
  }
  if (binary) {
    console.log(`${process.argv[2]}:${binary}`);
  }
  // if (asar.length > 0) {
  //   asar.forEach((a) => {
  //     console.log(`${process.argv[2]}:${a}`);
  //   });
  // }
  // if (binary) {
  //   console.log(`${process.argv[2]}:${binary}`);
  // }
  if (versionFiles.length > 0) {
    versionFiles.forEach((a) => {
      console.log(`${process.argv[2]}:${a}`);
    versionFiles.map((f) => {
      zip.readFileContents(FILENAME, f, (c)=>console.log(c))
    });
  }
  if (enm) {
    enm.forEach((a) => console.log(`${process.argv[2]}:${a}`));
  }
  // if (enm) {
  //   enm.forEach((a) => {
  //     zip.readFileContents(FILENAME, a, (c)=>console.log(c))
  //   });
  // }
});
diff --git a/package-lock.json b/package-lock.json
index b81ac90..004dcef 100644
--- a/package-lock.json
+++ a/package-lock.json
@@ -10,8 +10,9 @@
      "dependencies": {
        "asar": "^3.0.3",
        "elfinfo": "*",
        "node-7z": "^3.0.0",
        "node-stream-zip": "^1.13.6"
        "elfy": "^1.0.0",
        "macho": "^1.4.0",
        "node-7z": "^3.0.0"
      }

    },

    "node_modules/@types/glob": {
@@ -117,6 +118,24 @@
      "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.5.tgz",
      "integrity": "sha512-bjqH2cX/O33jXT/UmReo2pM7DIJREPMnarixbQ57DOOzzFaI6D2+IcwaJQaJpv0M1E9TIhPCYVxrkcityLjlqA=="
    },

    "node_modules/elfy": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/elfy/-/elfy-1.0.0.tgz",
      "integrity": "sha512-4Kp3AA94jC085IJox+qnvrZ3PudqTi4gQNvIoTZfJJ9IqkRuCoqP60vCVYlIg00c5aYusi5Wjh2bf0cHYt+6gQ==",
      "dependencies": {
        "endian-reader": "^0.3.0"
      }

    },

    "node_modules/elfy/node_modules/endian-reader": {
      "version": "0.3.0",
      "resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.3.0.tgz",
      "integrity": "sha1-hOykNrgK7Q0GOcRykTOLky7+UKA="
    },

    "node_modules/endian-reader": {
      "version": "0.1.0",
      "resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.1.0.tgz",
      "integrity": "sha1-7tYexWSqX2KFJI82JF4siRVtlKw="
    },

    "node_modules/fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -179,6 +198,14 @@
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/lodash.negate/-/lodash.negate-3.0.2.tgz",
      "integrity": "sha1-nIl7C/YQAZ4LQ7j/Pwr+89e2bzQ="
    },

    "node_modules/macho": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/macho/-/macho-1.4.0.tgz",
      "integrity": "sha512-PT3YMEKYogCeVYEA2bCFRZASNyn/JaOhjq6eV8SzBQ3RFia7XU8ASQCgGx+f3RnJFHT+xavLP+Qds48jQb0J5Q==",
      "dependencies": {
        "endian-reader": "^0.1.0"
      }

    },

    "node_modules/minimatch": {
      "version": "3.0.4",
@@ -211,18 +238,6 @@
      },

      "engines": {
        "node": ">=10"
      }

    },

    "node_modules/node-stream-zip": {
      "version": "1.13.6",
      "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.13.6.tgz",
      "integrity": "sha512-c7tRSVkLNOHvasWgmZ2d86cDgTWEygnkuuHNOY9c0mR3yLZtQTTrGvMaJ/fPs6+LOJn3240y30l5sjLaXFtcvw==",
      "engines": {
        "node": ">=0.10.0"
      },

      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/antelle"
      }

    },

    "node_modules/normalize-path": {
@@ -339,9 +354,29 @@
          "version": "14.17.5",
          "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.5.tgz",
          "integrity": "sha512-bjqH2cX/O33jXT/UmReo2pM7DIJREPMnarixbQ57DOOzzFaI6D2+IcwaJQaJpv0M1E9TIhPCYVxrkcityLjlqA=="
        }

      }

    },

    "elfy": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/elfy/-/elfy-1.0.0.tgz",
      "integrity": "sha512-4Kp3AA94jC085IJox+qnvrZ3PudqTi4gQNvIoTZfJJ9IqkRuCoqP60vCVYlIg00c5aYusi5Wjh2bf0cHYt+6gQ==",
      "requires": {
        "endian-reader": "^0.3.0"
      },

      "dependencies": {
        "endian-reader": {
          "version": "0.3.0",
          "resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.3.0.tgz",
          "integrity": "sha1-hOykNrgK7Q0GOcRykTOLky7+UKA="
        }

      }

    },

    "endian-reader": {
      "version": "0.1.0",
      "resolved": "https://registry.npmjs.org/endian-reader/-/endian-reader-0.1.0.tgz",
      "integrity": "sha1-7tYexWSqX2KFJI82JF4siRVtlKw="
    },

    "fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -398,6 +433,14 @@
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/lodash.negate/-/lodash.negate-3.0.2.tgz",
      "integrity": "sha1-nIl7C/YQAZ4LQ7j/Pwr+89e2bzQ="
    },

    "macho": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/macho/-/macho-1.4.0.tgz",
      "integrity": "sha512-PT3YMEKYogCeVYEA2bCFRZASNyn/JaOhjq6eV8SzBQ3RFia7XU8ASQCgGx+f3RnJFHT+xavLP+Qds48jQb0J5Q==",
      "requires": {
        "endian-reader": "^0.1.0"
      }

    },

    "minimatch": {
      "version": "3.0.4",
@@ -425,11 +468,6 @@
        "lodash.negate": "^3.0.2",
        "normalize-path": "^3.0.0"
      }

    },

    "node-stream-zip": {
      "version": "1.13.6",
      "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.13.6.tgz",
      "integrity": "sha512-c7tRSVkLNOHvasWgmZ2d86cDgTWEygnkuuHNOY9c0mR3yLZtQTTrGvMaJ/fPs6+LOJn3240y30l5sjLaXFtcvw=="
    },

    "normalize-path": {
      "version": "3.0.0",
diff --git a/package.json b/package.json
index d8397d3..c675f8a 100644
--- a/package.json
+++ a/package.json
@@ -1,8 +1,11 @@
{
  "name": "which-electron",
  "version": "1.0.0",
  "description": "Guess which electron version is bundled in an application",
  "main": "index.js",
  "bin": {
    "which-electron": "index.js"
  },

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

@@ -26,7 +29,8 @@
  "dependencies": {
    "asar": "^3.0.3",
    "elfinfo": "*",
    "node-7z": "^3.0.0",
    "node-stream-zip": "^1.13.6"
    "elfy": "^1.0.0",
    "macho": "^1.4.0",
    "node-7z": "^3.0.0"
  }

}

diff --git a/zip.js b/zip.js
new file mode 100644
index 0000000..117b850 100644
--- /dev/null
+++ a/zip.js
@@ -1,0 +1,27 @@
const Seven = require("node-7z");
const path = require("path");
const fs = require("fs");

module.exports = {
  readFileContents: function(archive, filepath, cb) {
    // TODO: Create a new temp directory
    let stream = Seven.extract(archive, "/tmp", {
      recursive: true,
      $cherryPick: filepath,
    });
    let fn = path.basename(filepath);
    stream.on("end", ()=>{
      cb(fs.readFileSync(`/tmp/${fn}`, {encoding: 'utf8'}))
    });
  },
  listFileContents: function(archive, cb) {
    let zip = Seven.list(archive);
    let entries = [];
    zip.on("data", (data) => {
      entries.push(data);
    });
    zip.on("end", () => {
      cb(entries);
    });
  },
};