forked from m10rten/validatees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-ci-version.ts
32 lines (30 loc) · 1.24 KB
/
check-ci-version.ts
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
/* eslint-disable no-console */
import { execSync } from "child_process";
import { readFileSync } from "fs";
try {
const packageJSON = readFileSync("./package.json", "utf8");
const localVersion = JSON.parse(packageJSON).version;
const npmVersion = execSync("npm view validatees version").toString().trim() || "1.0.0";
const split = npmVersion.split(".");
const pkgSplit = localVersion.split(".");
console.log(split, pkgSplit);
if (
split[0] > pkgSplit[0] ||
(split[0] >= pkgSplit[0] && split[1] >= pkgSplit[1]) ||
(split[0] >= pkgSplit[0] && split[1] >= pkgSplit[1] && split[2] >= pkgSplit[2])
) {
if (split[0] > pkgSplit[0]) {
throw new Error(`This major version is outdated, ${localVersion}`);
} else if (split[0] >= pkgSplit[0] && split[1] > pkgSplit[1]) {
throw new Error(`This minor version is outdated on this major version, ${localVersion}`);
} else if (split[0] >= pkgSplit[0] && split[1] >= pkgSplit[1] && split[2] >= pkgSplit[2]) {
throw new Error(`This patch version is outdated on this major+minor version, ${localVersion}`);
} else {
console.info("Your version of validatees is up to date.");
}
}
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}