UNPKG

office-addin-manifest

Version:
99 lines 5.03 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.exportMetadataPackage = void 0; const fs_1 = __importDefault(require("fs")); const fs_extra_1 = __importDefault(require("fs-extra")); const adm_zip_1 = __importDefault(require("adm-zip")); const path_1 = __importDefault(require("path")); const app_manifest_1 = require("@microsoft/app-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_1.default.join(path_1.default.dirname(path_1.default.resolve(manifest)), "manifest.zip"); } yield saveZip(zip, output); return Promise.resolve(output); }); } exports.exportMetadataPackage = exportMetadataPackage; function createZip(manifestPath) { var _a, _b, _c, _d, _e; return __awaiter(this, void 0, void 0, function* () { const absolutePath = path_1.default.resolve(manifestPath); const manifestDir = path_1.default.dirname(absolutePath); const zip = new adm_zip_1.default(); if (fs_1.default.existsSync(manifestPath)) { zip.addLocalFile(manifestPath, "", "manifest.json"); } else { throw new Error(`The file '${manifestPath}' does not exist`); } const manifest = (yield app_manifest_1.AppManifestUtils.readTeamsManifest(manifestPath)); // Add icons addZipFile((_a = manifest.icons) === null || _a === void 0 ? void 0 : _a.color, manifestDir, zip); addZipFile((_b = manifest.icons) === null || _b === void 0 ? void 0 : _b.outline, manifestDir, zip); // Add localization files const languages = (_c = manifest.localizationInfo) === null || _c === void 0 ? void 0 : _c.additionalLanguages; if (languages) { languages.forEach((language) => { addZipFile(language === null || language === void 0 ? void 0 : language.file, manifestDir, zip); }); } // Add Declarative Copilot Agents const agents = (_d = manifest === null || manifest === void 0 ? void 0 : manifest.copilotAgents) === null || _d === void 0 ? void 0 : _d.declarativeAgents; if (agents) { for (const agent of agents) { const agentFile = agent === null || agent === void 0 ? void 0 : agent.file; addZipFile(agentFile, manifestDir, zip); const agentRelDir = path_1.default.dirname(agentFile); const agentManifest = yield app_manifest_1.AppManifestUtils.readDeclarativeAgentManifest(path_1.default.join(manifestDir, agentFile)); (_e = agentManifest === null || agentManifest === void 0 ? void 0 : agentManifest.actions) === null || _e === void 0 ? void 0 : _e.forEach((action) => { if (action === null || action === void 0 ? void 0 : action.file) { addZipFile(path_1.default.join(agentRelDir, action.file), manifestDir, zip); } }); } } return Promise.resolve(zip); }); } function addZipFile(filePath, baseDir, zip) { if (filePath && !filePath.startsWith("https://")) { const fullPath = path_1.default.join(baseDir, filePath); const fileDir = path_1.default.dirname(filePath); if (fs_1.default.existsSync(fullPath)) { zip.addLocalFile(fullPath, fileDir === "." ? "" : fileDir); } else { throw new Error(`File to zip "${fullPath}' does not exist`); } } } function saveZip(zip, outputPath) { return __awaiter(this, void 0, void 0, function* () { outputPath = path_1.default.resolve(outputPath); fs_extra_1.default.ensureDirSync(path_1.default.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