-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from casper-network/feature/fetch-versions-github
Fetch available versions from GitHub tags
- Loading branch information
Showing
9 changed files
with
138 additions
and
82 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
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,42 @@ | ||
/* eslint-disable camelcase */ | ||
import * as fs from "node:fs"; | ||
import * as path from "node:path"; | ||
import axios from "axios"; | ||
|
||
import { WORK_DIR, githubTag } from "../config"; | ||
|
||
export interface Tag { | ||
name: string; | ||
zipball_url: string; | ||
tarball_url: string; | ||
commit: Commit; | ||
node_id: string; | ||
} | ||
|
||
export interface Commit { | ||
sha: string; | ||
url: string; | ||
} | ||
|
||
export const getVersions = async (): Promise<string[]> => { | ||
const { data } = await axios.get<Tag[]>(githubTag); | ||
const versions = data.map((tag) => tag.name); | ||
|
||
return versions; | ||
}; | ||
|
||
export const checkVersion = async (version: string): Promise<boolean> => { | ||
if (version === "dev") return true; | ||
const workDir = path.resolve(__dirname, "../..", WORK_DIR); | ||
|
||
// Return true for downloaded version | ||
if (fs.existsSync(path.resolve(workDir, version))) return true; | ||
|
||
const versions = await getVersions(); | ||
return versions.includes(version); | ||
}; | ||
|
||
export const fetchLatestVersion = async (): Promise<string> => { | ||
const versions = await getVersions(); | ||
return versions[0]; | ||
}; |
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