Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 3e73d4f

Browse files
feat: added check to see if new version available (#8)
1 parent bbdd0ab commit 3e73d4f

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

cli.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Command, InvalidOptionArgumentError } from "commander";
22
import dayjs from "dayjs";
33
import { readFile } from "fs";
4+
import fetch from 'node-fetch';
45
import * as path from "path";
56
import puppeteer from "puppeteer";
67
import { BrowserFetcher } from "puppeteer/lib/cjs/puppeteer/node/BrowserFetcher";
8+
import semver from 'semver';
79
import { promisify } from "util";
810

911
import { logger } from "./logger";
@@ -175,7 +177,30 @@ async function downloadChrome() {
175177
return revisionInfo.executablePath;
176178
}
177179

180+
async function checkCliUpdate() {
181+
const res = await fetch(
182+
"https://github.com/silverAndroid/drivetest-ca-availabilities/releases/latest"
183+
);
184+
const { version: currentVersion } = require('./package.json');
185+
const newVersion = res.url.split('/').slice(-1)[0];
186+
187+
if (semver.lt(currentVersion, newVersion)) {
188+
return res.url;
189+
}
190+
191+
return null;
192+
}
193+
178194
async function main() {
195+
logger.info('Checking for updates...');
196+
const updateUrl = await checkCliUpdate();
197+
if (updateUrl) {
198+
logger.info('Found new update at %s! Please update to the latest version.', updateUrl);
199+
return;
200+
} else {
201+
logger.info('No new updates found, current version %s', require('./package.json').version);
202+
}
203+
179204
let executablePath: string | undefined = undefined;
180205
if (!configPromise) {
181206
executablePath = await downloadChrome();

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drivetest-ca-availabilities",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "See available dates for driving test on drivetest.ca",
55
"main": "index.js",
66
"repository": "https://github.com/silverAndroid/drivetest-ca-availabilities.git",
@@ -17,6 +17,7 @@
1717
"@types/node-fetch": "^2.5.8",
1818
"@types/pino": "^6.3.8",
1919
"@types/pino-multi-stream": "^5.1.1",
20+
"@types/semver": "^7.3.5",
2021
"@types/tough-cookie": "^4.0.0",
2122
"pkg": "^5.1.0",
2223
"typescript": "^4.1.3"
@@ -30,6 +31,7 @@
3031
"pino-multi-stream": "^5.3.0",
3132
"pino-pretty": "^4.7.1",
3233
"progress": "^2.0.3",
33-
"puppeteer": "^8.0.0"
34+
"puppeteer": "^8.0.0",
35+
"semver": "^7.3.5"
3436
}
3537
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
"@types/pino-std-serializers" "*"
9292
"@types/sonic-boom" "*"
9393

94+
"@types/semver@^7.3.5":
95+
version "7.3.5"
96+
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.5.tgz#74deebbbcb1e86634dbf10a5b5e8798626f5a597"
97+
integrity sha512-iotVxtCCsPLRAvxMFFgxL8HD2l4mAZ2Oin7/VJ2ooWO0VOK4EGOGmZWZn1uCq7RofR3I/1IOSjCHlFT71eVK0Q==
98+
9499
"@types/sonic-boom@*":
95100
version "0.7.0"
96101
resolved "https://registry.yarnpkg.com/@types/sonic-boom/-/sonic-boom-0.7.0.tgz#38337036293992a1df65dd3161abddf8fb9b7176"

0 commit comments

Comments
 (0)