From 190eca6f6e3e78ab9936b826268570c8223ac0da Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 15 Apr 2021 00:57:15 +0200 Subject: [PATCH 1/3] check for mahor version for updates --- package.json | 2 ++ src/handlers/upgrade.ts | 27 +++++++++++++++++---------- src/index.ts | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 880f591..dd66d3d 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,14 @@ "typescript": "^3.9" }, "dependencies": { + "@types/semver": "^7.3.4", "axios": "^0.19", "clitastic": "^0.1.2", "colors": "^1", "commander": "^6.2", "cron-parser": "2.x.x", "js-yaml": "3.x.x", + "semver": "^7.3.5", "uhrwerk": "1.x.x" } } diff --git a/src/handlers/upgrade.ts b/src/handlers/upgrade.ts index 3c6880b..3098393 100644 --- a/src/handlers/upgrade.ts +++ b/src/handlers/upgrade.ts @@ -2,6 +2,7 @@ import { chmodSync } from 'fs' import axios from 'axios' import { Writer } from 'clitastic' +import semver from 'semver' import { INSTALL_DIR, VERSION } from '..' import { checkIfResticIsAvailable, downloadFile, exec } from '../utils' @@ -18,19 +19,25 @@ export async function upgrade() { responseType: 'json', }) - if (json.tag_name != VERSION) { - const platformMap: { [key: string]: string } = { - darwin: 'macos', - } + 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) { + const platformMap: { [key: string]: string } = { + darwin: 'macos', + } - const name = `autorestic_${platformMap[process.platform] || process.platform}_${process.arch}` - const dl = json.assets.find((asset: any) => asset.name === name) + const name = `autorestic_${platformMap[process.platform] || process.platform}_${process.arch}` + const dl = json.assets.find((asset: any) => asset.name === name) - const to = INSTALL_DIR + '/autorestic' - w.replaceLn('Downloading binary... 🌎') - await downloadFile(dl.browser_download_url, to) + const to = INSTALL_DIR + '/autorestic' + w.replaceLn('Downloading binary... 🌎') + await downloadFile(dl.browser_download_url, to) - chmodSync(to, 0o755) + chmodSync(to, 0o755) + } } w.done('All up to date! 🚀') diff --git a/src/index.ts b/src/index.ts index 0936d47..7b6d003 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ import install from './handlers/install' import { uninstall } from './handlers/uninstall' import { upgrade } from './handlers/upgrade' -export const VERSION = '0.27' +export const VERSION = '0.28' export const INSTALL_DIR = '/usr/local/bin' let requireConfig: boolean = true From 7629626ae066b8bc51299645bd517c6e112fc180 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 15 Apr 2021 01:08:56 +0200 Subject: [PATCH 2/3] comment on major version --- src/handlers/upgrade.ts | 8 +++++--- src/index.ts | 2 +- yarn.lock | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/handlers/upgrade.ts b/src/handlers/upgrade.ts index 3098393..675f8ca 100644 --- a/src/handlers/upgrade.ts +++ b/src/handlers/upgrade.ts @@ -22,9 +22,9 @@ export async function upgrade() { 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 (semver.gt(latest, current)) { + if (semver.major(latest) === semver.major(current)) { + // Update to compatible const platformMap: { [key: string]: string } = { darwin: 'macos', } @@ -37,6 +37,8 @@ export async function upgrade() { await downloadFile(dl.browser_download_url, to) chmodSync(to, 0o755) + } else { + w.appendLn('Newer major version available, will not install automatically.') } } diff --git a/src/index.ts b/src/index.ts index 7b6d003..8077f0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ import install from './handlers/install' import { uninstall } from './handlers/uninstall' import { upgrade } from './handlers/upgrade' -export const VERSION = '0.28' +export const VERSION = '0.29' export const INSTALL_DIR = '/usr/local/bin' let requireConfig: boolean = true diff --git a/yarn.lock b/yarn.lock index 9cbdc22..2372523 100644 --- a/yarn.lock +++ b/yarn.lock @@ -56,6 +56,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.10.tgz#5958a82e41863cfc71f2307b3748e3491ba03785" integrity sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ== +"@types/semver@^7.3.4": + version "7.3.4" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb" + integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ== + "@types/strip-bom@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/strip-bom/-/strip-bom-3.0.0.tgz#14a8ec3956c2e81edb7520790aecf21c290aebd2" @@ -789,6 +794,13 @@ loud-rejection@^1.0.0: currently-unhandled "^0.4.1" signal-exit "^3.0.0" +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + make-error@^1.1.1: version "1.3.6" resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" @@ -1226,6 +1238,13 @@ semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== +semver@^7.3.5: + version "7.3.5" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" + integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== + dependencies: + lru-cache "^6.0.0" + shelljs@^0.8.3: version "0.8.4" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2" @@ -1525,6 +1544,11 @@ xtend@^4.0.0: resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + yn@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" From 8f7513b1033ca03e82d63f9663ab73ea0fd2f722 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 17 Apr 2021 14:49:29 +0200 Subject: [PATCH 3/3] v30 --- CHANGELOG.md | 4 ++-- src/handlers/upgrade.ts | 4 ++-- src/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4702962..e2b05cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -## 0.27 +## 0.30 -- fix locking issue +- prepare for new updates diff --git a/src/handlers/upgrade.ts b/src/handlers/upgrade.ts index 675f8ca..9273521 100644 --- a/src/handlers/upgrade.ts +++ b/src/handlers/upgrade.ts @@ -38,9 +38,9 @@ export async function upgrade() { chmodSync(to, 0o755) } else { - w.appendLn('Newer major version available, will not install automatically.') + w.done('Newer major version available, will not install automatically.\nDownload: https://github.com/cupcakearmy/autorestic') + return } } - w.done('All up to date! 🚀') } diff --git a/src/index.ts b/src/index.ts index 8077f0e..92e5bd4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ import install from './handlers/install' import { uninstall } from './handlers/uninstall' import { upgrade } from './handlers/upgrade' -export const VERSION = '0.29' +export const VERSION = '0.30' export const INSTALL_DIR = '/usr/local/bin' let requireConfig: boolean = true