1
0
Fork 0

Export findVersions() (#14)

* Export findVersions()

* Rename `findVersions()` to `findAllVersions()`
pull/20/head
David Staheli 2019-06-07 15:17:27 -04:00 committed by Danny McCormick
parent 71a9b2d3ed
commit e3317c6632
1 changed files with 29 additions and 23 deletions

View File

@ -330,7 +330,7 @@ export async function cacheFile(
} }
/** /**
* finds the path to a tool in the local installed tool cache * Finds the path to a tool version in the local installed tool cache
* *
* @param toolName name of the tool * @param toolName name of the tool
* @param versionSpec version of the tool * @param versionSpec version of the tool
@ -353,7 +353,7 @@ export function find(
// attempt to resolve an explicit version // attempt to resolve an explicit version
if (!_isExplicitVersion(versionSpec)) { if (!_isExplicitVersion(versionSpec)) {
const localVersions: string[] = _findLocalToolVersions(toolName, arch) const localVersions: string[] = findAllVersions(toolName, arch)
const match = _evaluateVersions(localVersions, versionSpec) const match = _evaluateVersions(localVersions, versionSpec)
versionSpec = match versionSpec = match
} }
@ -374,6 +374,33 @@ export function find(
return toolPath return toolPath
} }
/**
* Finds the paths to all versions of a tool that are installed in the local tool cache
*
* @param toolName name of the tool
* @param arch optional arch. defaults to arch of computer
*/
export function findAllVersions(toolName: string, arch?: string): string[] {
const versions: string[] = []
arch = arch || os.arch()
const toolPath = path.join(cacheRoot, toolName)
if (fs.existsSync(toolPath)) {
const children: string[] = fs.readdirSync(toolPath)
for (const child of children) {
if (_isExplicitVersion(child)) {
const fullPath = path.join(toolPath, child, arch || '')
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
versions.push(child)
}
}
}
}
return versions
}
async function _createExtractFolder(dest?: string): Promise<string> { async function _createExtractFolder(dest?: string): Promise<string> {
if (!dest) { if (!dest) {
// create a temp dir // create a temp dir
@ -450,24 +477,3 @@ function _evaluateVersions(versions: string[], versionSpec: string): string {
return version return version
} }
function _findLocalToolVersions(toolName: string, arch?: string): string[] {
const versions: string[] = []
arch = arch || os.arch()
const toolPath = path.join(cacheRoot, toolName)
if (fs.existsSync(toolPath)) {
const children: string[] = fs.readdirSync(toolPath)
for (const child of children) {
if (_isExplicitVersion(child)) {
const fullPath = path.join(toolPath, child, arch || '')
if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
versions.push(child)
}
}
}
}
return versions
}