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

author Nemo <commits@captnemo.in> 2021-12-19 20:52:28.0 +05:30:00
committer Nemo <commits@captnemo.in> 2021-12-19 20:57:46.0 +05:30:00
commit
56fac545ce23b77aeaa6c9ca688d0e61b228873c [patch]
tree
eb0468c026ec87c1cf8d360f795d81be817dec21
parent
907c50097dbde33ac276e50b1faecd391a397b2e
download
56fac545ce23b77aeaa6c9ca688d0e61b228873c.tar.gz

new script for updating supporting packages



Diff

 .gitignore                |  3 ++-
 HACKING.md                |  4 ++++
 package.json              |  3 ++-
 _scripts/gen_versions.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index b512c09..81bcbda 100644
--- a/.gitignore
+++ a/.gitignore
@@ -1,1 +1,2 @@
node_modules
node_modules
electron-src
diff --git a/HACKING.md b/HACKING.md
index 0b72114..586ca49 100644
--- a/HACKING.md
+++ a/HACKING.md
@@ -1,5 +1,9 @@
# HACKING

## Generating Fixtures

`node _scripts/gen-fixture.js /path/to/filename.zip`

## Generating versions.json

`php _scripts/gen_versions.php`
diff --git a/package.json b/package.json
index abad38d..24a742f 100644
--- a/package.json
+++ a/package.json
@@ -7,7 +7,8 @@
    "which-electron": "src/index.js"
  },

  "scripts": {
    "test": "kuta tests/*.js"
    "test": "kuta tests/*.js",
    "release": "npm update && php _scripts/gen_versions.php && git add src/versions.json package-lock.json && git commit -m 'new release' && npm version patch"
  },

  "repository": {
    "type": "git",
diff --git a/_scripts/gen_versions.php b/_scripts/gen_versions.php
new file mode 100644
index 0000000..25ecd77 100644
--- /dev/null
+++ a/_scripts/gen_versions.php
@@ -1,0 +1,69 @@
<?php

const VERSION_EXCLUDE = ['nightly', 'beta', 'alpha'];
const SUPPORTED_MAJOR_VERSIONS = [12, 13, 14, 15, 16];

function get_versions() {
    `rm -rf electron-src`;
    `git clone https://github.com/electron/electron.git electron-src`;
    chdir("electron-src");

    $versions = [];
    foreach(explode("\n", shell_exec("git tag -l")) as $version) {
        foreach(VERSION_EXCLUDE as $needle) {
            if (stripos($version, $needle) !== false) {
                continue 2;
            }
        }
        // Atom shell was renamed to electron in this release (17th April 2015)
        if (version_compare($version, 'v0.24.0', '<')) {
            continue;
        }

        $versions[] = $version;
    }

    chdir("..");
    `rm -rf electron-src`;

    return $versions;
}

function get_major_version($version) : int {
    $r = explode('.', $version);
    return intval($r[0]);
}

function get_supported_versions($versions = []) {
    $result = [];
    $versions = array_map(function($v) {
      return substr($v, 1);
    }, $versions);

    foreach(SUPPORTED_MAJOR_VERSIONS as $major) {
        $result[$major] = '0.0.0';
    }

    foreach($versions as $version) {
        $major = get_major_version($version);
        if (in_array($major, SUPPORTED_MAJOR_VERSIONS)) {
            if (version_compare($version, $result["$major"], '>')) {
                $result["$major"] = "v$version";
            }
        }
    }

    return array_values($result);
}

function json_data() {
    $versions = get_versions();
    usort($versions, 'version_compare');
    $supported = get_supported_versions($versions);
    return [
        'supported' => $supported,
        'all' => $versions
    ];
}

file_put_contents('src/versions.json', json_encode(json_data(), JSON_PRETTY_PRINT));