188 lines
9.1 KiB
JavaScript
188 lines
9.1 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.exportManifest = exports.validate = exports.modify = exports.info = void 0;
|
|
const chalk_1 = require("chalk");
|
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
|
const manifestOperations_1 = require("./manifestOperations");
|
|
const validate_1 = require("./validate");
|
|
const defaults_1 = require("./defaults");
|
|
const export_1 = require("./export");
|
|
/* global console, process */
|
|
function getCommandOptionString(option, defaultValue) {
|
|
// For a command option defined with an optional value, e.g. "--option [value]",
|
|
// when the option is provided with a value, it will be of type "string", return the specified value;
|
|
// when the option is provided without a value, it will be of type "boolean", return undefined.
|
|
return typeof option === "boolean" ? defaultValue : option;
|
|
}
|
|
function info(manifestPath) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
const manifest = yield manifestOperations_1.OfficeAddinManifest.readManifestFile(manifestPath);
|
|
logManifestInfo(manifestPath, manifest);
|
|
defaults_1.usageDataObject.reportSuccess("info");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("info", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.info = info;
|
|
function logManifestInfo(manifestPath, manifest) {
|
|
console.log(`Manifest: ${manifestPath}`);
|
|
console.log(` Id: ${manifest.id || ""}`);
|
|
console.log(` Name: ${manifest.displayName || ""}`);
|
|
console.log(` Provider: ${manifest.providerName || ""}`);
|
|
console.log(` Type: ${manifest.officeAppType || ""}`);
|
|
console.log(` Version: ${manifest.version || ""}`);
|
|
if (manifest.alternateId) {
|
|
console.log(` AlternateId: ${manifest.alternateId}`);
|
|
}
|
|
console.log(` AppDomains: ${manifest.appDomains ? manifest.appDomains.join(", ") : ""}`);
|
|
console.log(` Default Locale: ${manifest.defaultLocale || ""}`);
|
|
console.log(` Description: ${manifest.description || ""}`);
|
|
console.log(` High Resolution Icon Url: ${manifest.highResolutionIconUrl || ""}`);
|
|
console.log(` Hosts: ${manifest.hosts ? manifest.hosts.join(", ") : ""}`);
|
|
console.log(` Icon Url: ${manifest.iconUrl || ""}`);
|
|
console.log(` Permissions: ${manifest.permissions || ""}`);
|
|
console.log(` Support Url: ${manifest.supportUrl || ""}`);
|
|
if (manifest.defaultSettings) {
|
|
console.log(" Default Settings:");
|
|
console.log(` Requested Height: ${manifest.defaultSettings.requestedHeight || ""}`);
|
|
console.log(` Requested Width: ${manifest.defaultSettings.requestedWidth || ""}`);
|
|
console.log(` Source Location: ${manifest.defaultSettings.sourceLocation || ""}`);
|
|
}
|
|
}
|
|
function logManifestValidationErrors(errors) {
|
|
if (errors) {
|
|
let errorNumber = 1;
|
|
for (const currentError of errors) {
|
|
console.log(chalk_1.default.bold.red(`Error #${errorNumber}: `));
|
|
logManifestValidationIssue(currentError);
|
|
console.log();
|
|
++errorNumber;
|
|
}
|
|
}
|
|
}
|
|
function logManifestValidationInfos(infos) {
|
|
if (infos) {
|
|
console.log(chalk_1.default.bold.blue(`Validation Information: `));
|
|
for (const currentInfo of infos) {
|
|
logManifestValidationIssue(currentInfo);
|
|
console.log();
|
|
}
|
|
}
|
|
}
|
|
function logManifestValidationWarnings(warnings) {
|
|
if (warnings) {
|
|
let warningNumber = 1;
|
|
for (const currentWarning of warnings) {
|
|
console.log(chalk_1.default.bold.yellow(`Warning #${warningNumber}: `));
|
|
logManifestValidationIssue(currentWarning);
|
|
console.log();
|
|
++warningNumber;
|
|
}
|
|
}
|
|
}
|
|
function logManifestValidationIssue(issue) {
|
|
console.log(`${issue.title}: ${issue.content}` + (issue.helpUrl ? ` (link: ${issue.helpUrl})` : ``));
|
|
if (issue.code) {
|
|
console.log(` - Details: ${issue.code}`);
|
|
}
|
|
if (issue.line) {
|
|
console.log(` - Line: ${issue.line}`);
|
|
}
|
|
if (issue.column) {
|
|
console.log(` - Column: ${issue.column}`);
|
|
}
|
|
}
|
|
function logManifestValidationSupportedProducts(products) {
|
|
if (products) {
|
|
const productTitles = new Set(products.filter((product) => product.title).map((product) => product.title));
|
|
if (productTitles.size > 0) {
|
|
console.log(`\nBased on the requirements specified in your manifest, your add-in can run on the following platforms; your add-in will be tested on these platforms when you submit it to the Office Store:`);
|
|
for (const productTitle of productTitles) {
|
|
console.log(` - ${productTitle}`);
|
|
}
|
|
console.log(`Important: This analysis is based on the requirements specified in your manifest and does not account for any runtime JavaScript calls within your add-in. For information about which API sets and features are supported on each platform, see Office Add-in host and platform availability. (https://docs.microsoft.com/office/dev/add-ins/overview/office-add-in-availability).\n`);
|
|
console.log(`*This does not include mobile apps. You can opt-in to support mobile apps when you submit your add-in.`);
|
|
}
|
|
}
|
|
}
|
|
function modify(manifestPath, command) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
// if the --guid command option is provided without a value, use "" to specify to change to a random guid value.
|
|
const guid = getCommandOptionString(command.guid, "");
|
|
const displayName = getCommandOptionString(command.displayName);
|
|
const manifest = yield manifestOperations_1.OfficeAddinManifest.modifyManifestFile(manifestPath, guid, displayName);
|
|
logManifestInfo(manifestPath, manifest);
|
|
defaults_1.usageDataObject.reportSuccess("modify");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("modify", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.modify = modify;
|
|
function validate(manifestPath, command /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
const verifyProduction = command.production;
|
|
const validation = yield (0, validate_1.validateManifest)(manifestPath, verifyProduction);
|
|
if (validation.status && validation.status != 200) {
|
|
console.log(`Unable to validate the manifest.\n${validation.status}\n${validation.statusText}`);
|
|
}
|
|
else if (validation.report) {
|
|
logManifestValidationInfos(validation.report.notes);
|
|
logManifestValidationErrors(validation.report.errors);
|
|
logManifestValidationWarnings(validation.report.warnings);
|
|
if (validation.isValid) {
|
|
if (validation.report.addInDetails) {
|
|
logManifestValidationSupportedProducts(validation.report.addInDetails.supportedProducts);
|
|
console.log();
|
|
}
|
|
console.log(chalk_1.default.bold.green("The manifest is valid.\n"));
|
|
}
|
|
else {
|
|
console.log(chalk_1.default.bold.red("The manifest is not valid.\n"));
|
|
}
|
|
}
|
|
process.exitCode = validation.isValid ? 0 : 1;
|
|
defaults_1.usageDataObject.reportSuccess("validate");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("validate", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.validate = validate;
|
|
function exportManifest(command) {
|
|
var _a, _b;
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
const outputPath = (_a = command.output) !== null && _a !== void 0 ? _a : "";
|
|
const manifestPath = (_b = command.manifest) !== null && _b !== void 0 ? _b : "./manifest.json";
|
|
yield (0, export_1.exportMetadataPackage)(outputPath, manifestPath);
|
|
defaults_1.usageDataObject.reportSuccess("export");
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("export", err);
|
|
(0, office_addin_usage_data_1.logErrorMessage)(err);
|
|
}
|
|
});
|
|
}
|
|
exports.exportManifest = exportManifest;
|
|
//# sourceMappingURL=commands.js.map
|