Outlook_Addin_LLM/node_modules/office-addin-manifest/lib/export.js

72 lines
3.1 KiB
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.exportMetadataPackage = void 0;
const fs = require("fs");
const fsExtra = require("fs-extra");
const AdmZip = require("adm-zip");
const path = require("path");
const teams_manifest_1 = require("@microsoft/teams-manifest");
/* global console */
function exportMetadataPackage(output = "", manifest = "manifest.json") {
return __awaiter(this, void 0, void 0, function* () {
const zip = yield createZip(manifest);
if (output === "") {
output = path.join(path.dirname(path.resolve(manifest)), "manifest.zip");
}
yield saveZip(zip, output);
return Promise.resolve(output);
});
}
exports.exportMetadataPackage = exportMetadataPackage;
function createZip(manifestPath) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const absolutePath = path.resolve(manifestPath);
const manifestDir = path.dirname(absolutePath);
const zip = new AdmZip();
if (fs.existsSync(manifestPath)) {
zip.addLocalFile(manifestPath, "", "manifest.json");
}
else {
throw new Error(`The file '${manifestPath}' does not exist`);
}
const manifest = yield teams_manifest_1.ManifestUtil.loadFromPath(manifestPath);
addIconFile((_a = manifest.icons) === null || _a === void 0 ? void 0 : _a.color, manifestDir, zip);
addIconFile((_b = manifest.icons) === null || _b === void 0 ? void 0 : _b.outline, manifestDir, zip);
return Promise.resolve(zip);
});
}
function addIconFile(iconPath, manifestDir, zip) {
if (iconPath && !iconPath.startsWith("https://")) {
const filePath = path.join(manifestDir, iconPath);
const iconDir = path.dirname(iconPath);
if (fs.existsSync(filePath)) {
zip.addLocalFile(filePath, iconDir === "." ? "" : iconDir);
}
else {
console.log(`Icon File ${filePath} does not exist`);
}
}
}
function saveZip(zip, outputPath) {
return __awaiter(this, void 0, void 0, function* () {
outputPath = path.resolve(outputPath);
fsExtra.ensureDirSync(path.dirname(outputPath));
const result = yield zip.writeZipPromise(outputPath);
if (result) {
console.log(`Manifest package saved to ${outputPath}`);
}
else {
throw new Error(`Error writting zip file to ${outputPath}`);
}
});
}
//# sourceMappingURL=export.js.map