[client] compare versions in updater

This commit is contained in:
2019-09-30 21:42:33 +03:00
parent 1e79fcfacb
commit cfa1475cf6
6 changed files with 71 additions and 12 deletions

View File

@@ -6,10 +6,11 @@ const through = require('through2');
class Package {
constructor(platform, type, version) {
constructor(platform, type, version, versionInt) {
this.platform = platform;
this.type = type;
this.version = version;
this.versionInt = versionInt;
}
get key() {
@@ -47,9 +48,9 @@ class Package {
}
static getVersion(filename) {
const m = /(\d+)\.(\d+).(\d+)/.exec(filename);
const m = /(\d+)\.(\d+)\.(\d+)/.exec(filename);
if (m) {
return parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3]);
return [m[0], parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3])];
}
return null;
}
@@ -59,7 +60,7 @@ class Package {
const type = this.getType(filename);
const version = this.getVersion(filename);
if (platform && type && version) {
return new Package(platform, type, version);
return new Package(platform, type, version[0], version[1]);
}
return null;
}
@@ -86,11 +87,12 @@ module.exports = (name, version, publishDir, publishUrl) => function publish(cb)
const basepath = file.path.replace(file.base + path.sep, '');
const pack = Package.parseFilename(file.path);
if (pack) {
if (!packages[pack.key] || packages[pack.key].version < pack.version) {
if (!packages[pack.key] || packages[pack.key].versionInt < pack.versionInt) {
packages[pack.key] = {
platform: pack.platform,
type: pack.type,
version: pack.version,
versionInt: pack.versionInt,
path: basepath,
filename: basepath.split(path.sep).pop(),
url: `${publishUrl}/${basepath.replace(path.sep, "/")}`,