check for mahor version for updates

This commit is contained in:
cupcakearmy 2021-04-15 00:57:15 +02:00
parent 805bed7db1
commit 190eca6f6e
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 22 additions and 13 deletions

View File

@ -17,12 +17,14 @@
"typescript": "^3.9" "typescript": "^3.9"
}, },
"dependencies": { "dependencies": {
"@types/semver": "^7.3.4",
"axios": "^0.19", "axios": "^0.19",
"clitastic": "^0.1.2", "clitastic": "^0.1.2",
"colors": "^1", "colors": "^1",
"commander": "^6.2", "commander": "^6.2",
"cron-parser": "2.x.x", "cron-parser": "2.x.x",
"js-yaml": "3.x.x", "js-yaml": "3.x.x",
"semver": "^7.3.5",
"uhrwerk": "1.x.x" "uhrwerk": "1.x.x"
} }
} }

View File

@ -2,6 +2,7 @@ import { chmodSync } from 'fs'
import axios from 'axios' import axios from 'axios'
import { Writer } from 'clitastic' import { Writer } from 'clitastic'
import semver from 'semver'
import { INSTALL_DIR, VERSION } from '..' import { INSTALL_DIR, VERSION } from '..'
import { checkIfResticIsAvailable, downloadFile, exec } from '../utils' import { checkIfResticIsAvailable, downloadFile, exec } from '../utils'
@ -18,6 +19,11 @@ export async function upgrade() {
responseType: 'json', responseType: 'json',
}) })
const latest = semver.coerce(json.tag_name)
const current = semver.coerce(VERSION)
if (!latest || !current) throw new Error('Could not parse versions numbers.')
if (semver.gt(latest, current) && semver.major(latest) === semver.major(current)) {
// Update to compatible
if (json.tag_name != VERSION) { if (json.tag_name != VERSION) {
const platformMap: { [key: string]: string } = { const platformMap: { [key: string]: string } = {
darwin: 'macos', darwin: 'macos',
@ -32,6 +38,7 @@ export async function upgrade() {
chmodSync(to, 0o755) chmodSync(to, 0o755)
} }
}
w.done('All up to date! 🚀') w.done('All up to date! 🚀')
} }

View File

@ -17,7 +17,7 @@ import install from './handlers/install'
import { uninstall } from './handlers/uninstall' import { uninstall } from './handlers/uninstall'
import { upgrade } from './handlers/upgrade' import { upgrade } from './handlers/upgrade'
export const VERSION = '0.27' export const VERSION = '0.28'
export const INSTALL_DIR = '/usr/local/bin' export const INSTALL_DIR = '/usr/local/bin'
let requireConfig: boolean = true let requireConfig: boolean = true