Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
9d61cf82
Commit
9d61cf82
authored
Jun 20, 2016
by
antoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated version comparison algorithm
更新版本对比算法
parent
e4313af5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
update.js
modules/update.js
+25
-4
No files found.
modules/update.js
View file @
9d61cf82
...
...
@@ -29,10 +29,7 @@ class Update {
let
newVersion
=
lastInfo
[
'tag_name'
];
let
curVersion
=
config
[
'package'
].
version
;
// 比对版本
if
(
parseInt
(
newVersion
.
replace
(
/
\.
/g
,
''
))
>
parseInt
(
curVersion
.
replace
(
/
\.
/g
,
''
))
)
{
if
(
this
.
CompVersion
(
curVersion
,
newVersion
))
{
this
.
logger
.
info
(
'Found a new version'
,
newVersion
);
event
.
sender
.
send
(
'notification-update'
,
{
ver
:
newVersion
,
...
...
@@ -46,6 +43,30 @@ class Update {
}
});
}
/**
* 版本比对
* @param {String} curVer 当前版本
* @param {String} newVer 新的版本
* @return {Boolean}
*/
CompVersion
(
curVer
,
newVer
)
{
// 如果版本相同
if
(
curVer
===
newVer
)
{
return
false
}
let
currVerArr
=
curVer
.
split
(
"."
);
let
promoteVerArr
=
newVer
.
split
(
"."
);
let
len
=
Math
.
max
(
currVerArr
.
length
,
promoteVerArr
.
length
);
for
(
let
i
=
0
;
i
<
len
;
i
++
)
{
let
proVal
=
~~
promoteVerArr
[
i
],
curVal
=
~~
currVerArr
[
i
];
if
(
proVal
<
curVal
)
{
return
false
;
}
else
if
(
proVal
>
curVal
)
{
return
true
;
}
}
return
false
;
}
}
module
.
exports
=
Update
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment