-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export function isValidVersion(version: string): boolean { | ||
const versionRegex = | ||
/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; | ||
return versionRegex.test(version); | ||
} | ||
|
||
/** | ||
* Parse command line arguments. | ||
* | ||
* @returns {Record<string, string>} An object containing parsed argument key-value pairs. | ||
*/ | ||
export function parseArgv(): Record<string, string> { | ||
const parsedArgv: Record<string, string> = {}; | ||
|
||
if (process.argv.length > 2) { | ||
for (let i = 2; i < process.argv.length; i++) { | ||
const arg = process.argv[i].toLowerCase(); | ||
if (/--(version|prerelease)/.test(arg)) { | ||
const [key, value] = arg.split('='); | ||
const cleanKey = key.replace('--', ''); | ||
parsedArgv[cleanKey] = value ?? 'true'; | ||
} | ||
} | ||
} | ||
|
||
return parsedArgv; | ||
} | ||
|
||
/** | ||
* Retrieves the version from the parsed command-line arguments. | ||
* @returns The version string if available, otherwise undefined. | ||
*/ | ||
export function getVersion(): string | undefined { | ||
const parsedArgv = parseArgv(); | ||
if (isValidVersion(parsedArgv?.version)) { | ||
return parsedArgv?.version; | ||
} | ||
} | ||
|
||
/** | ||
* Determines if should download a prerelease version of the Explorer. | ||
* @returns A boolean value indicating if the Explorer should be downloaded as a prerelease version. | ||
*/ | ||
export function getIsPrerelease(): boolean { | ||
const parsedArgv = parseArgv(); | ||
return parsedArgv?.prerelease === 'true'; | ||
} |
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