From 025ff736fda66e3b61fe87f9d79acddd81cbc580 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Mon, 8 Apr 2024 18:03:33 +0800 Subject: [PATCH] refactor(script): compare only to the middle version when checking version --- scripts/checkPackageVersion.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/checkPackageVersion.js b/scripts/checkPackageVersion.js index 27ae4e7f8..a3d30a12e 100644 --- a/scripts/checkPackageVersion.js +++ b/scripts/checkPackageVersion.js @@ -2,9 +2,15 @@ const packageJSON = require('../package.json') const axios = require('axios') const baseURL = process.env.HOST_URL || 'http://localhost:18083' -const packageVersion = packageJSON.version +const rawPackageVersion = packageJSON.version -const emqxVersionRegex = /^[ev](\d+\.\d+\.\d+)/ +const packageVersionRegex = /^(\d+\.\d+)/ +const matchPackageVersion = (packageVersion) => { + const matchRet = packageVersion.match(packageVersionRegex) + return matchRet ? matchRet[1] : '' +} + +const emqxVersionRegex = /^[ev](\d+\.\d+)/ const matchEmqxVersion = (emqxVersion) => { const matchRet = emqxVersion.match(emqxVersionRegex) return matchRet ? matchRet[1] : '' @@ -13,6 +19,7 @@ const matchEmqxVersion = (emqxVersion) => { const check = async () => { const { data } = await axios.get(`${baseURL}/api/v5/status`, { params: { format: 'json' } }) const { rel_vsn } = data + const packageVersion = matchPackageVersion(rawPackageVersion) const emqxVersion = matchEmqxVersion(rel_vsn) if (emqxVersion !== packageVersion) { console.log('EMQX Version:', emqxVersion)