本文整理汇总了TypeScript中vsts-task-tool-lib/tool.findLocalToolVersions函数的典型用法代码示例。如果您正苦于以下问题:TypeScript findLocalToolVersions函数的具体用法?TypeScript findLocalToolVersions怎么用?TypeScript findLocalToolVersions使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了findLocalToolVersions函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: useRubyVersion
export async function useRubyVersion(parameters: TaskParameters, platform: Platform): Promise<void> {
const toolName: string = 'Ruby';
const installDir: string | null = tool.findLocalTool(toolName, parameters.versionSpec);
if (!installDir) {
// Fail and list available versions
throw new Error([
task.loc('VersionNotFound', parameters.versionSpec),
task.loc('ListAvailableVersions'),
tool.findLocalToolVersions('Ruby')
].join(os.EOL));
}
const toolPath: string = path.join(installDir, 'bin');
if (platform !== Platform.Windows) {
// replace the default
const dest: string = '/usr/bin/ruby';
if (fs.existsSync(dest)) {
task.debug('removing ' + dest);
fs.unlinkSync(dest);
}
fs.symlinkSync(path.join(toolPath, 'ruby'), dest);
}
task.setVariable('rubyLocation', toolPath);
if (parameters.addToPath) {
tool.prependPath(toolPath);
}
}
示例2: useRubyVersion
export async function useRubyVersion(parameters: TaskParameters, platform: Platform): Promise<void> {
const toolName: string = 'Ruby';
const installDir: string | null = tool.findLocalTool(toolName, parameters.versionSpec);
if (!installDir) {
// Fail and list available versions
throw new Error([
task.loc('VersionNotFound', parameters.versionSpec),
task.loc('ListAvailableVersions', task.getVariable('Agent.ToolsDirectory')),
tool.findLocalToolVersions('Ruby'),
task.loc('ToolNotFoundMicrosoftHosted', 'Ruby', 'https://aka.ms/hosted-agent-software'),
task.loc('ToolNotFoundSelfHosted', 'Ruby', 'https://go.microsoft.com/fwlink/?linkid=2005989')
].join(os.EOL));
}
const toolPath: string = path.join(installDir, 'bin');
if (platform !== Platform.Windows) {
// Ruby / Gem heavily use the '#!/usr/bin/ruby' to find ruby, so this task needs to
// replace that version of ruby so all the correct version of ruby gets selected
// replace the default
const dest: string = '/usr/bin/ruby';
task.execSync('sudo', `ln -sf ${path.join(toolPath, 'ruby')} ${dest}`); // replace any existing
}
task.setVariable('rubyLocation', toolPath);
if (parameters.addToPath) {
tool.prependPath(toolPath);
}
}
示例3: usePythonVersion
export async function usePythonVersion(parameters: Readonly<TaskParameters>, platform: Platform): Promise<void> {
// Python's prelease versions look like `3.7.0b2`.
// This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
// If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent
const semanticVersionSpec = pythonVersionToSemantic(parameters.versionSpec);
task.debug(`Semantic version spec of ${parameters.versionSpec} is ${semanticVersionSpec}`);
const installDir: string | null = tool.findLocalTool('Python', semanticVersionSpec, parameters.architecture);
if (!installDir) {
// Fail and list available versions
const x86Versions = tool.findLocalToolVersions('Python', 'x86')
.map(s => `${s} (x86)`)
.join(os.EOL);
const x64Versions = tool.findLocalToolVersions('Python', 'x64')
.map(s => `${s} (x64)`)
.join(os.EOL);
throw new Error([
task.loc('VersionNotFound', parameters.versionSpec),
task.loc('ListAvailableVersions'),
x86Versions,
x64Versions
].join(os.EOL));
}
task.setVariable('pythonLocation', installDir);
if (parameters.addToPath) {
toolUtil.prependPathSafe(installDir);
// Make sure Python's "bin" directories are in PATH.
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
// There is a seperate directory for `pip install --user`.
//
// For reference, these directories are as follows:
// macOS / Linux:
// <sys.prefix>/bin (by default /usr/local/bin, but not on hosted agents -- see the `else`)
// (--user) ~/.local/bin
// Windows:
// <Python installation dir>\Scripts
// (--user) %APPDATA%\Python\PythonXY\Scripts
// See https://docs.python.org/3/library/sysconfig.html
if (platform === Platform.Windows) {
// On Windows, these directories do not get added to PATH, so we will add them ourselves.
const scriptsDir = path.join(installDir, 'Scripts');
toolUtil.prependPathSafe(scriptsDir);
// Add --user directory
// `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(process.env['APPDATA'], 'Python', `Python${major}${minor}`, 'Scripts');
toolUtil.prependPathSafe(userScriptsDir);
} else {
// On Linux and macOS, tools cache should be set up so that each Python version has its own "bin" directory.
// We do this so that the tool cache can just be dropped on an agent with minimal installation (no copying to /usr/local).
// This allows us side-by-side the same minor version of Python with different patch versions or architectures (since Python uses /usr/local/lib/python3.6, etc.).
toolUtil.prependPathSafe(path.join(installDir, 'bin'));
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
}
}
}