77 lines
3.8 KiB
JavaScript
77 lines
3.8 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.OfficeAddinManifest = void 0;
|
||
|
const defaults_1 = require("./defaults");
|
||
|
const manifestHandlerJson_1 = require("./manifestHandler/manifestHandlerJson");
|
||
|
const manifestHandlerXml_1 = require("./manifestHandler/manifestHandlerXml");
|
||
|
var OfficeAddinManifest;
|
||
|
(function (OfficeAddinManifest) {
|
||
|
function modifyManifestFile(manifestPath, guid, displayName) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
if (manifestPath) {
|
||
|
if (guid === undefined && displayName === undefined) {
|
||
|
throw new Error("You need to specify something to change in the manifest.");
|
||
|
}
|
||
|
else {
|
||
|
try {
|
||
|
const manifestHandler = yield getManifestHandler(manifestPath);
|
||
|
const manifestData = yield manifestHandler.modifyManifest(guid, displayName);
|
||
|
yield manifestHandler.writeManifestData(manifestData);
|
||
|
const manifestInfo = yield manifestHandler.parseManifest();
|
||
|
defaults_1.usageDataObject.reportSuccess("modifyManifestFile()");
|
||
|
return manifestInfo;
|
||
|
}
|
||
|
catch (err) {
|
||
|
defaults_1.usageDataObject.reportException("modifyManifestFile()", err);
|
||
|
throw err;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
throw new Error(`Please provide the path to the manifest file.`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
OfficeAddinManifest.modifyManifestFile = modifyManifestFile;
|
||
|
function readManifestFile(manifestPath) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
if (manifestPath) {
|
||
|
const manifestHandler = yield getManifestHandler(manifestPath);
|
||
|
const manifest = yield manifestHandler.parseManifest();
|
||
|
return manifest;
|
||
|
}
|
||
|
else {
|
||
|
throw new Error(`Please provide the path to the manifest file.`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
OfficeAddinManifest.readManifestFile = readManifestFile;
|
||
|
})(OfficeAddinManifest = exports.OfficeAddinManifest || (exports.OfficeAddinManifest = {}));
|
||
|
function getManifestHandler(manifestPath) {
|
||
|
var _a;
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
let manifestHandler;
|
||
|
if (manifestPath.endsWith(".json")) {
|
||
|
manifestHandler = new manifestHandlerJson_1.ManifestHandlerJson(manifestPath);
|
||
|
}
|
||
|
else if (manifestPath.endsWith(".xml")) {
|
||
|
manifestHandler = new manifestHandlerXml_1.ManifestHandlerXml(manifestPath);
|
||
|
}
|
||
|
else {
|
||
|
const extension = (_a = manifestPath.split(".").pop()) !== null && _a !== void 0 ? _a : "<no extension>";
|
||
|
throw new Error(`Manifest operations are not supported in .${extension}.\nThey are only supported in .xml and in .json.`);
|
||
|
}
|
||
|
return manifestHandler;
|
||
|
});
|
||
|
}
|
||
|
//# sourceMappingURL=manifestOperations.js.map
|