-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync.js
36 lines (29 loc) · 974 Bytes
/
sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const fs = require('fs');
const github = require('./github.json');
const npm = require('./npm.json');
// curl https://registry.npmjs.org/swagger-ui-dist/latest > npm.json
// curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/ke4nec/swagger-ui-electron/releases/latest > npm.json
(async () => {
console.log(npm.version)
console.log(github.tag_name)
// console.log(github.tag_name < npm.version)
const tagNames = github.tag_name.split('.')
const versions = npm.version.split('.')
for (let i = 0; i < Math.min(tagNames.length, versions.length); i++) {
const ver1 = parseInt(tagNames[i])
const ver2 = parseInt(versions[i])
if (isNaN(ver1) || isNaN(ver2)) {
process.exit(0)
}
if (ver1 < ver2) {
try {
console.log('need update')
fs.writeFileSync('./ver.txt', npm.version)
} catch (err) {
console.error(err)
}
process.exit(0)
}
}
process.exit(1)
})()