79 lines
4.4 KiB
JavaScript
79 lines
4.4 KiB
JavaScript
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
// Licensed under the MIT license.
|
||
|
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.ManifestHandlerJson = void 0;
|
||
|
const teams_manifest_1 = require("@microsoft/teams-manifest");
|
||
|
const uuid_1 = require("uuid");
|
||
|
const manifestInfo_1 = require("../manifestInfo");
|
||
|
const manifestHandler_1 = require("./manifestHandler");
|
||
|
class ManifestHandlerJson extends manifestHandler_1.ManifestHandler {
|
||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||
|
modifyManifest(guid, displayName) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const appManifest = yield teams_manifest_1.ManifestUtil.loadFromPath(this.manifestPath);
|
||
|
if (typeof guid !== "undefined") {
|
||
|
if (!guid || guid === "random") {
|
||
|
guid = (0, uuid_1.v4)();
|
||
|
}
|
||
|
appManifest.id = guid;
|
||
|
}
|
||
|
if (typeof displayName !== "undefined") {
|
||
|
appManifest.name.short = displayName;
|
||
|
}
|
||
|
return appManifest;
|
||
|
}
|
||
|
catch (err) {
|
||
|
throw new Error(`Unable to modify json data for manifest file: ${this.manifestPath}. \n${err}`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
parseManifest() {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const file = yield teams_manifest_1.ManifestUtil.loadFromPath(this.manifestPath);
|
||
|
return this.getManifestInfo(file);
|
||
|
}
|
||
|
catch (err) {
|
||
|
throw new Error(`Unable to read data for manifest file: ${this.manifestPath}. \n${err}`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
getManifestInfo(appManifest) {
|
||
|
var _a, _b, _c, _d, _e, _f, _g;
|
||
|
const manifestInfo = new manifestInfo_1.ManifestInfo();
|
||
|
// Need to handle mutliple version of the prerelease json manifest schema
|
||
|
const extensionElement = (_a = appManifest.extensions) === null || _a === void 0 ? void 0 : _a[0];
|
||
|
manifestInfo.id = appManifest.id;
|
||
|
manifestInfo.appDomains = appManifest.validDomains;
|
||
|
manifestInfo.defaultLocale = (_b = appManifest.localizationInfo) === null || _b === void 0 ? void 0 : _b.defaultLanguageTag;
|
||
|
manifestInfo.description = appManifest.description.short;
|
||
|
manifestInfo.displayName = appManifest.name.short;
|
||
|
manifestInfo.highResolutionIconUrl = appManifest.icons.color;
|
||
|
manifestInfo.hosts = (_c = extensionElement === null || extensionElement === void 0 ? void 0 : extensionElement.requirements) === null || _c === void 0 ? void 0 : _c.scopes;
|
||
|
manifestInfo.iconUrl = appManifest.icons.color;
|
||
|
manifestInfo.officeAppType = "TaskPaneApp"; // Should check "ContentRuntimes" in JSON the tell if the Office type is "ContentApp". Hard code here because web extension will be removed after all.
|
||
|
manifestInfo.permissions = (_g = (_f = (_e = (_d = appManifest.authorization) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.resourceSpecific) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.name;
|
||
|
manifestInfo.providerName = appManifest.developer.name;
|
||
|
manifestInfo.supportUrl = appManifest.developer.websiteUrl;
|
||
|
manifestInfo.version = appManifest.version;
|
||
|
manifestInfo.manifestType = manifestInfo_1.ManifestType.JSON;
|
||
|
return manifestInfo;
|
||
|
}
|
||
|
writeManifestData(manifestData) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
yield teams_manifest_1.ManifestUtil.writeToPath(this.manifestPath, manifestData);
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
exports.ManifestHandlerJson = ManifestHandlerJson;
|
||
|
//# sourceMappingURL=manifestHandlerJson.js.map
|