From 634bbffd46c456d99a1d1aa311ad7cc8ed1683bf Mon Sep 17 00:00:00 2001 From: darksaid98 Date: Thu, 23 Sep 2021 20:55:08 +0200 Subject: [PATCH] feat: version check on startup (#28) --- package.json | 1 + patches/github-version-checker+2.2.0.patch | 12 ++++++++++++ src/config.js | 20 ++++++++++++++++++++ yarn.lock | 15 ++++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 patches/github-version-checker+2.2.0.patch diff --git a/package.json b/package.json index 30f4b25..6dadce7 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "@citizenfx/server": "^2.0.4376-1", "connection-string-parser": "^1.0.4", + "github-version-checker": "^2.2.0", "mysql2": "^2.3.0", "postinstall-postinstall": "^2.1.0" }, diff --git a/patches/github-version-checker+2.2.0.patch b/patches/github-version-checker+2.2.0.patch new file mode 100644 index 0000000..e9af3fd --- /dev/null +++ b/patches/github-version-checker+2.2.0.patch @@ -0,0 +1,12 @@ +diff --git a/node_modules/github-version-checker/lib/check.js b/node_modules/github-version-checker/lib/check.js +index 7f00060..cf0e231 100644 +--- a/node_modules/github-version-checker/lib/check.js ++++ b/node_modules/github-version-checker/lib/check.js +@@ -88,7 +88,6 @@ const rest = (options, callback) => { + + if (found) { + const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version); +- console.log(mapped); + callback(null, mapped); + } else { + callback(null, null); diff --git a/src/config.js b/src/config.js index 5b6c8cf..361f329 100644 --- a/src/config.js +++ b/src/config.js @@ -1,4 +1,6 @@ import { ConnectionStringParser } from 'connection-string-parser'; +import versionCheck from 'github-version-checker'; +import currentVersion from '../package.json'; const connectionString = GetConvar('mysql_connection_string', ''); @@ -33,3 +35,21 @@ const isolationLevel = (() => { const resourceName = GetCurrentResourceName() || 'oxmysql'; export { config, slowQueryWarning, debug, isolationLevel, resourceName }; + +setImmediate(async () => { + const versionCheckConfig = { + repo: 'oxmysql', + owner: 'overextended', + currentVersion: currentVersion.version, + latest: true + }; + + try { + const update = await versionCheck(versionCheckConfig); + if (update) { + console.log(`^3Your version of oxmysql is outdated (v${versionCheckConfig.currentVersion})! Please update to the latest version (${update.name}) here: \nhttps://github.com/overextended/oxmysql/releases/latest`); + } + } catch (e) { + console.log(`^3Could not fetch updates for oxmysql!^0\n${e}`); + } +}); \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 44a230b..b35522b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -571,6 +571,19 @@ get-stream@^6.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== +github-graphql-client@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/github-graphql-client/-/github-graphql-client-1.0.0.tgz#d5acacc31bb9f6b77e5c502812e90c844f727bca" + integrity sha1-1ayswxu59rd+XFAoEukMhE9ye8o= + +github-version-checker@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/github-version-checker/-/github-version-checker-2.2.0.tgz#08a2b52f9ef9cd3dd05b898537750a91b73facec" + integrity sha512-Ttj/Uzg++TGfycfn5ga8BfMJ8QYB1+DhG24rtasrN8tHYWgqqrEMAQ52y2qGnPNWzSF8AUdjm6dBcoPdUhKhDQ== + dependencies: + github-graphql-client "^1.0.0" + semver "^5.5.1" + glob-parent@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" @@ -1120,7 +1133,7 @@ schema-utils@^3.0.0, schema-utils@^3.1.0, schema-utils@^3.1.1: ajv "^6.12.5" ajv-keywords "^3.5.2" -semver@^5.5.0, semver@^5.6.0: +semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==