UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

57 lines (56 loc) 2.98 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const commandline_1 = require("../../util/commandline"); const fsHelper = require("../../util/misc/fs-helper"); const Fs = require("fs"); const os = require("os"); const path = require("path"); const Request = require("request"); const util_1 = require("util"); const debug = require("debug")("appcenter-cli:util:misc:download"); function downloadFileAndSave(downloadUrl, filePath) { debug(`Downloading file from ${downloadUrl} to the path ${filePath}`); return new Promise((resolve, reject) => { Request.get(downloadUrl) .on("error", (error) => { debug(`Failed to download the file from ${downloadUrl} - ${util_1.inspect(error)}`); reject(commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to download the file from ${downloadUrl}`)); }) .pipe(Fs.createWriteStream(filePath) .on("error", (error) => { debug(`Failed to save the file to ${filePath} - ${util_1.inspect(error)}`); reject(commandline_1.failure(commandline_1.ErrorCodes.Exception, `failed to save the file to ${filePath}`)); }) .on("finish", () => resolve())); }); } exports.downloadFileAndSave = downloadFileAndSave; function downloadArtifacts(command, streamingOutput, outputDir, testRunId, artifacts) { return __awaiter(this, void 0, void 0, function* () { for (const key in artifacts) { const reportPath = fsHelper.generateAbsolutePath(outputDir); const pathToArchive = path.join(reportPath, `${key.toString()}.zip`); fsHelper.createLongPath(reportPath); yield downloadFileAndSave(artifacts[key], pathToArchive); // Print only in VSTS environment // https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?view=vsts&tabs=batch#tfbuild if (process.env["TF_BUILD"]) { streamingOutput.text((command) => { return `##vso[task.setvariable variable=${key}]${pathToArchive}${os.EOL}`; }, command); } streamingOutput.text((command) => { return `Downloaded artifacts to ${pathToArchive}`; }, command); } }); } exports.downloadArtifacts = downloadArtifacts;