appcenter-cli
Version:
Command line tool for Visual Studio App Center
63 lines (62 loc) • 3.04 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.archiveAppBundle = void 0;
const os = require("os");
const path = require("path");
const pfs = require("./promisfied-fs");
const process = require("./process-helper");
const JsZip = require("jszip");
const JsZipHelper = require("../../util/misc/jszip-helper");
function archiveAppBundle(appPath, ipaPath) {
return __awaiter(this, void 0, void 0, function* () {
function archiveWithDitto(appPath, ipaPath) {
return __awaiter(this, void 0, void 0, function* () {
const appPathBase = path.parse(appPath).base;
const tempPath = yield pfs.mkTempDir("ios-bundle-archiver");
const payloadPath = path.join(tempPath, "Payload");
yield pfs.mkdir(payloadPath);
const tempAppPath = path.join(payloadPath, appPathBase);
let exitCode = yield process.execAndWait(`ditto "${appPath}" "${tempAppPath}"`);
if (exitCode !== 0) {
yield pfs.rmDir(tempPath, true);
throw new Error("Cannot archive app bundle.");
}
exitCode = yield process.execAndWait(`ditto -ck --sequesterRsrc "${tempPath}" "${ipaPath}"`);
if (exitCode !== 0) {
yield pfs.rmDir(tempPath, true);
throw new Error("Cannot archive app bundle.");
}
yield pfs.rmDir(tempPath, true);
});
}
function archiveWithZip(appPath, ipaPath) {
return __awaiter(this, void 0, void 0, function* () {
const zipArchive = new JsZip();
const payload = zipArchive.folder("Payload");
try {
yield JsZipHelper.addFolderToZipRecursively(appPath, payload);
yield JsZipHelper.writeZipToPath(ipaPath, zipArchive, "DEFLATE");
}
catch (error) {
throw Error(`unable to create ipa from ${appPath}`);
}
});
}
if (!(os.platform() === "darwin")) {
yield archiveWithZip(appPath, ipaPath);
}
else {
yield archiveWithDitto(appPath, ipaPath);
}
});
}
exports.archiveAppBundle = archiveAppBundle;