generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: app version requires check
Signed-off-by: Ryan Wang <[email protected]>
- Loading branch information
Showing
5 changed files
with
33 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import semver from "semver"; | ||
|
||
const VERSION_REGEX = /^\d+\.\d+\.\d+$/g; | ||
|
||
/** | ||
* Checks if a given version satisfies a required version range. | ||
* | ||
* @see https://github.com/halo-dev/halo/blob/a5a69780a37410d2734043d6cae1b718b57c722b/application/src/main/java/run/halo/app/infra/utils/VersionUtils.java#L18 | ||
* @param version - The version to check. | ||
* @param requires - The required version range. | ||
* @returns A boolean indicating whether the version satisfies the required range. | ||
*/ | ||
export function satisfiesRequires(version?: string, requires?: string): boolean { | ||
if (!version || !requires) { | ||
return false; | ||
} | ||
|
||
requires = requires.trim(); | ||
|
||
if (VERSION_REGEX.test(requires)) { | ||
requires = `>=${requires}`; | ||
} | ||
|
||
return semver.satisfies(version, requires, { includePrerelease: true }); | ||
} |