UNPKG

7.54 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license.
3var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5 return new (P || (P = Promise))(function (resolve, reject) {
6 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9 step((generator = generator.apply(thisArg, _arguments || [])).next());
10 });
11};
12Object.defineProperty(exports, "__esModule", { value: true });
13const chalk_1 = require("chalk");
14const office_addin_cli_1 = require("office-addin-cli");
15const manifestInfo = require("./manifestInfo");
16const validate_1 = require("./validate");
17function getCommandOptionString(option, defaultValue) {
18 // For a command option defined with an optional value, e.g. "--option [value]",
19 // when the option is provided with a value, it will be of type "string", return the specified value;
20 // when the option is provided without a value, it will be of type "boolean", return undefined.
21 return (typeof (option) === "boolean") ? defaultValue : option;
22}
23function info(manifestPath) {
24 return __awaiter(this, void 0, void 0, function* () {
25 try {
26 const manifest = yield manifestInfo.readManifestFile(manifestPath);
27 logManifestInfo(manifestPath, manifest);
28 }
29 catch (err) {
30 office_addin_cli_1.logErrorMessage(err);
31 }
32 });
33}
34exports.info = info;
35function logManifestInfo(manifestPath, manifest) {
36 console.log(`Manifest: ${manifestPath}`);
37 console.log(` Id: ${manifest.id || ""}`);
38 console.log(` Name: ${manifest.displayName || ""}`);
39 console.log(` Provider: ${manifest.providerName || ""}`);
40 console.log(` Type: ${manifest.officeAppType || ""}`);
41 console.log(` Version: ${manifest.version || ""}`);
42 if (manifest.alternateId) {
43 console.log(` AlternateId: ${manifest.alternateId}`);
44 }
45 console.log(` AppDomains: ${manifest.appDomains ? manifest.appDomains.join(", ") : ""}`);
46 console.log(` Default Locale: ${manifest.defaultLocale || ""}`);
47 console.log(` Description: ${manifest.description || ""}`);
48 console.log(` High Resolution Icon Url: ${manifest.highResolutionIconUrl || ""}`);
49 console.log(` Hosts: ${manifest.hosts ? manifest.hosts.join(", ") : ""}`);
50 console.log(` Icon Url: ${manifest.iconUrl || ""}`);
51 console.log(` Permissions: ${manifest.permissions || ""}`);
52 console.log(` Support Url: ${manifest.supportUrl || ""}`);
53 if (manifest.defaultSettings) {
54 console.log(" Default Settings:");
55 console.log(` Requested Height: ${manifest.defaultSettings.requestedHeight || ""}`);
56 console.log(` Requested Width: ${manifest.defaultSettings.requestedWidth || ""}`);
57 console.log(` Source Location: ${manifest.defaultSettings.sourceLocation || ""}`);
58 }
59}
60function logManifestValidationErrors(errors) {
61 if (errors) {
62 let errorNumber = 1;
63 for (const currentError of errors) {
64 console.log(chalk_1.default.bold.red(`\nError # ${errorNumber}: `));
65 logManifestValidationIssue(currentError);
66 ++errorNumber;
67 }
68 }
69}
70function logManifestValidationInfos(infos) {
71 if (infos) {
72 for (const currentInfo of infos) {
73 console.log(chalk_1.default.bold.blue(` Additional information: `));
74 logManifestValidationIssue(currentInfo);
75 }
76 }
77}
78function logManifestValidationWarnings(warnings) {
79 if (warnings) {
80 let warningNumber = 1;
81 for (const currentWarning of warnings) {
82 console.log(chalk_1.default.bold.yellow(` Warning # ${warningNumber}: `));
83 logManifestValidationIssue(currentWarning);
84 ++warningNumber;
85 }
86 }
87}
88function logManifestValidationIssue(issue) {
89 console.log(`${issue.title}: ${issue.detail} (link: ${issue.link})`);
90 if (issue.code) {
91 console.log(` - Details: ${issue.code}`);
92 }
93 if (issue.line) {
94 console.log(` - Line: ${issue.line}`);
95 }
96 if (issue.column) {
97 console.log(` - Column: ${issue.column}`);
98 }
99}
100function logManifestValidationSupportedProducts(products) {
101 if (products) {
102 const productTitles = new Set(products.filter(product => product.title).map(product => product.title));
103 if (productTitles.size > 0) {
104 console.log(`Based 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:`);
105 for (const productTitle of productTitles) {
106 console.log(` - ${productTitle}`);
107 }
108 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`);
109 console.log(`*This does not include mobile apps. You can opt-in to support mobile apps when you submit your add-in.`);
110 }
111 }
112}
113function modify(manifestPath, command) {
114 return __awaiter(this, void 0, void 0, function* () {
115 try {
116 // if the --guid command option is provided without a value, use "" to specify to change to a random guid value.
117 const guid = getCommandOptionString(command.guid, "");
118 const displayName = getCommandOptionString(command.displayName);
119 const manifest = yield manifestInfo.modifyManifestFile(manifestPath, guid, displayName);
120 logManifestInfo(manifestPath, manifest);
121 }
122 catch (err) {
123 office_addin_cli_1.logErrorMessage(err);
124 }
125 });
126}
127exports.modify = modify;
128function validate(manifestPath, command) {
129 return __awaiter(this, void 0, void 0, function* () {
130 try {
131 const validation = yield validate_1.validateManifest(manifestPath);
132 if (validation.isValid) {
133 console.log("The manifest is valid.");
134 }
135 else {
136 console.log("The manifest is not valid.");
137 }
138 console.log();
139 if (validation.report) {
140 logManifestValidationErrors(validation.report.errors);
141 logManifestValidationWarnings(validation.report.warnings);
142 logManifestValidationInfos(validation.report.infos);
143 if (validation.isValid) {
144 if (validation.details) {
145 logManifestValidationSupportedProducts(validation.details.supportedProducts);
146 }
147 }
148 }
149 }
150 catch (err) {
151 office_addin_cli_1.logErrorMessage(err);
152 }
153 });
154}
155exports.validate = validate;
156//# sourceMappingURL=commands.js.map
\No newline at end of file