Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private isLatestInstalledVersion(version: string): boolean {
var pathTobeChecked = this.packageType == utils.Constants.sdk ? path.join(this.installationPath, utils.Constants.relativeSdkPath) : path.join(this.installationPath, utils.Constants.relativeRuntimePath);
if (!tl.exist(pathTobeChecked)) {
throw tl.loc("PathNotFoundException", pathTobeChecked);
}
var allEnteries: string[] = tl.ls("", [pathTobeChecked]).map(name => path.join(pathTobeChecked, name));
var folderPaths: string[] = allEnteries.filter(element => fs.lstatSync(element).isDirectory());
var isLatest: boolean = folderPaths.findIndex(folderPath => {
try {
let versionFolderName = path.basename(folderPath);
tl.debug(tl.loc("ComparingInstalledFolderVersions", version, versionFolderName));
return utils.versionCompareFunction(versionFolderName, version) > 0;
}
catch (ex) {
// no op, folder name might not be in version format
}
}) < 0;
public isVersionInstalled(version: string): boolean {
if (!toolLib.isExplicitVersion(version)) {
throw tl.loc("ExplicitVersionRequired", version);
}
var isInstalled: boolean = false;
if (this.packageType == utils.Constants.sdk) {
isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, `${version}.complete`));
}
else {
isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, `${version}.complete`));
}
isInstalled ? console.log(tl.loc("VersionFoundInCache", version)) : console.log(tl.loc("VersionNotFoundInCache", version));
return isInstalled;
}
public isVersionInstalled(version: string): boolean {
if (!toolLib.isExplicitVersion(version)) {
throw tl.loc("ExplicitVersionRequired", version);
}
var isInstalled: boolean = false;
if (this.packageType == utils.Constants.sdk) {
isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeSdkPath, `${version}.complete`));
}
else {
isInstalled = tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, version)) && tl.exist(path.join(this.installationPath, utils.Constants.relativeRuntimePath, `${version}.complete`));
}
isInstalled ? console.log(tl.loc("VersionFoundInCache", version)) : console.log(tl.loc("VersionNotFoundInCache", version));
return isInstalled;
}
async function run() {
tl.setResourcePath(path.join(__dirname, "task.json"));
const pypircPath = tl.getVariable("PYPIRC_PATH");
if (tl.exist(pypircPath)) {
tl.debug(tl.loc("Info_RemovingPypircFile", pypircPath));
tl.rmRF(pypircPath);
}
else {
console.log(tl.loc("NoPypircFile"));
}
}
run();
private loadParametersFromFile(parametersFile: string): CloudFormation.Parameters | undefined {
if (!parametersFile) {
console.log(tl.loc('NoParametersFileSpecified'))
return undefined
}
console.log(tl.loc('LoadingTemplateParametersFile', parametersFile))
if (!tl.exist(parametersFile)) {
throw new Error(tl.loc('ParametersFileDoesNotExist', parametersFile))
}
const parameterContent = fs.readFileSync(parametersFile, 'utf8')
const templateParameters = this.parseParameters(parameterContent)
return templateParameters
}
async function run() {
try {
tl.setResourcePath(path.join(__dirname, 'task.json'));
const keystoreFile: string = tl.getTaskVariable('KEYSTORE_FILE_PATH');
if (keystoreFile && tl.exist(keystoreFile)) {
fs.unlinkSync(keystoreFile);
tl.debug('Deleted keystore file downloaded from the server: ' + keystoreFile);
}
} catch (err) {
tl.warning(tl.loc('DeleteKeystoreFileFailed', err));
}
}
await new Promise(function (resolve, reject) {
if (tl.exist(unzipLocation)) {
tl.rmRF(unzipLocation);
}
tl.debug('Extracting ' + zipLocation + ' to ' + unzipLocation);
var unzipper = new DecompressZip(zipLocation);
unzipper.on('error', err => {
return reject(tl.loc("ExtractionFailed", err))
});
unzipper.on('extract', log => {
tl.debug('Extracted ' + zipLocation + ' to ' + unzipLocation + ' successfully');
return resolve();
});
unzipper.extract({
path: unzipLocation
public static pathExistsAsFile(path: string) {
return tl.exist(path) && tl.stats(path).isFile();
}
export function getTempPath(): string {
let tempNpmrcDir =
tl.getVariable("Agent.BuildDirectory") ||
tl.getVariable("Agent.ReleaseDirectory") ||
process.cwd();
let tempPath = path.join(tempNpmrcDir, "yarn");
if (tl.exist(tempPath) === false) {
tl.mkdirP(tempPath);
}
return tempPath;
}