mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-22 10:03:24 +01:00
528687aaf4
and no lockfile is present. Fixes #180
31 lines
892 B
TypeScript
31 lines
892 B
TypeScript
import { existsSync } from "node:fs";
|
|
import * as path from "node:path";
|
|
|
|
/**
|
|
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
|
|
*/
|
|
export function semverCompare(version1: string, version2: string) {
|
|
if (version2 === "latest") return true;
|
|
|
|
const version1Parts = version1.split(".");
|
|
const version2Parts = version2.split(".");
|
|
|
|
for (const version1Part of version1Parts) {
|
|
const version2Part = version2Parts.shift();
|
|
|
|
if (version1Part !== version2Part && version2Part) {
|
|
return version1Part < version2Part ? true : false;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export function checkWorkingDirectory(workingDirectory = ".") {
|
|
const normalizedPath = path.normalize(workingDirectory);
|
|
if (existsSync(normalizedPath)) {
|
|
return normalizedPath;
|
|
} else {
|
|
throw new Error(`Directory ${workingDirectory} does not exist.`);
|
|
}
|
|
}
|