UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

60 lines (59 loc) 2.78 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const pfs = require("../../../../util/misc/promisfied-fs"); const path = require("path"); const yazl = require("yazl"); const file_utils_1 = require("../file-utils"); function zip(updateContentsPath) { return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { const releaseFiles = []; try { if (!file_utils_1.isDirectory(updateContentsPath)) { releaseFiles.push({ sourceLocation: updateContentsPath, targetLocation: file_utils_1.normalizePath(path.basename(updateContentsPath)), // Put the file in the root }); } } catch (error) { error.message = error.message + " Make sure you have added the platform you are making a release to.`."; reject(error); } const directoryPath = updateContentsPath; const baseDirectoryPath = path.join(directoryPath, ".."); // For legacy reasons, put the root directory in the zip const files = yield pfs.walk(updateContentsPath); files.forEach((filePath) => { const relativePath = path.relative(baseDirectoryPath, filePath); releaseFiles.push({ sourceLocation: filePath, targetLocation: file_utils_1.normalizePath(relativePath), }); }); const packagePath = path.join(process.cwd(), file_utils_1.generateRandomFilename(15) + ".zip"); const zipFile = new yazl.ZipFile(); const writeStream = fs.createWriteStream(packagePath); zipFile.outputStream .pipe(writeStream) .on("error", (error) => { reject(error); }) .on("close", () => { resolve(packagePath); }); releaseFiles.forEach((releaseFile) => { zipFile.addFile(releaseFile.sourceLocation, releaseFile.targetLocation); }); zipFile.end(); })); } exports.default = zip;