76 lines
3.5 KiB
JavaScript
76 lines
3.5 KiB
JavaScript
"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 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_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;
|
|
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 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_1.default.join(manifestDir, iconPath);
|
|
const iconDir = path_1.default.dirname(iconPath);
|
|
if (fs_1.default.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_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
|