appcenter-cli
Version:
Command line tool for Visual Studio App Center
73 lines (72 loc) • 3.68 kB
JavaScript
;
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 });
exports.getChildrenDsymFolderPaths = exports.packDsymParentFolderContents = exports.getSymbolsZipFromXcarchive = void 0;
const Path = require("path");
const Fs = require("fs");
const JsZip = require("jszip");
const util_1 = require("util");
const commandline_1 = require("../../../util/commandline");
const JsZipHelper = require("../../../util/misc/jszip-helper");
function getSymbolsZipFromXcarchive(path, debug) {
return __awaiter(this, void 0, void 0, function* () {
// the DSYM folders from "*.xcarchive/dSYMs" should be compressed
const dsymsFolderPath = Path.join(path, "dSYMs");
return yield packDsymParentFolderContents(dsymsFolderPath, debug);
});
}
exports.getSymbolsZipFromXcarchive = getSymbolsZipFromXcarchive;
function packDsymParentFolderContents(path, debug) {
return __awaiter(this, void 0, void 0, function* () {
debug(`Compressing the dSYM sub-folders of ${path} to the in-memory ZIP archive`);
const zipArchive = new JsZip();
const childrenDsymFolders = getChildrenDsymFolderPaths(path, debug);
for (const dSymPath of childrenDsymFolders) {
try {
debug(`Adding the sub-folder ${dSymPath} to the ZIP archive`);
yield JsZipHelper.addFolderToZipRecursively(dSymPath, zipArchive);
}
catch (error) {
debug(`Unable to add folder ${dSymPath} to the ZIP archive - ${util_1.inspect(error)}`);
throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `unable to add folder ${dSymPath} to the ZIP archive`);
}
}
return zipArchive;
});
}
exports.packDsymParentFolderContents = packDsymParentFolderContents;
function getChildrenDsymFolderPaths(parentPath, debug) {
// get paths for all the DSym folders which belong to the specified folder
let childrenEntriesList;
try {
childrenEntriesList = Fs.readdirSync(parentPath);
}
catch (error) {
debug(`error when looking into directory ${parentPath} content - ${util_1.inspect(error)}`);
throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `error when looking into directory ${parentPath} content`);
}
return childrenEntriesList
.map((childPath) => Path.join(parentPath, childPath))
.filter((childPath) => {
if (Path.extname(childPath).toLowerCase() !== ".dsym") {
return false;
}
try {
const childStats = Fs.statSync(childPath);
return childStats.isDirectory();
}
catch (error) {
debug(`Error when getting statistics for the file ${parentPath} - ${util_1.inspect(error)}`);
throw commandline_1.failure(commandline_1.ErrorCodes.Exception, `error when getting statistics for the file ${parentPath}`);
}
});
}
exports.getChildrenDsymFolderPaths = getChildrenDsymFolderPaths;