Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
* The type of Office application.
*/
export declare enum AppType {
/**
* Office application for Windows or Mac
*/
Desktop = "desktop",
/**
* Office application for the web browser
*/
Web = "web"
}
/**
* Parse the input text and get the associated AppType
* @param text app-type/platform text
* @returns AppType or undefined.
*/
export declare function parseAppType(text: string | undefined): AppType | undefined;
+41
View File
@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseAppType = exports.AppType = void 0;
const office_addin_usage_data_1 = require("office-addin-usage-data");
/**
* The type of Office application.
*/
var AppType;
(function (AppType) {
/**
* Office application for Windows or Mac
*/
AppType["Desktop"] = "desktop";
/**
* Office application for the web browser
*/
AppType["Web"] = "web";
})(AppType = exports.AppType || (exports.AppType = {}));
/**
* Parse the input text and get the associated AppType
* @param text app-type/platform text
* @returns AppType or undefined.
*/
function parseAppType(text) {
switch (text ? text.toLowerCase() : undefined) {
case "desktop":
case "macos":
case "win32":
case "ios":
case "android":
return AppType.Desktop;
case "web":
return AppType.Web;
case undefined:
return undefined;
default:
throw new office_addin_usage_data_1.ExpectedError(`Please select a valid app type instead of '${text}'.`);
}
}
exports.parseAppType = parseAppType;
//# sourceMappingURL=appType.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"appType.js","sourceRoot":"","sources":["../src/appType.ts"],"names":[],"mappings":";;;AAAA,qEAAwD;AAExD;;GAEG;AACH,IAAY,OAUX;AAVD,WAAY,OAAO;IACjB;;OAEG;IACH,8BAAmB,CAAA;IAEnB;;OAEG;IACH,sBAAW,CAAA;AACb,CAAC,EAVW,OAAO,GAAP,eAAO,KAAP,eAAO,QAUlB;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAwB;IACnD,QAAQ,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE;QAC7C,KAAK,SAAS,CAAC;QACf,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;QACb,KAAK,KAAK,CAAC;QACX,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,OAAO,CAAC;QACzB,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,GAAG,CAAC;QACrB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,MAAM,IAAI,uCAAa,CAAC,8CAA8C,IAAI,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AAfD,oCAeC"}
+42
View File
@@ -0,0 +1,42 @@
export declare const EdgeBrowserAppcontainerName: string;
export declare const EdgeWebViewAppcontainerName: string;
export declare const EdgeBrowserName: string;
export declare const EdgeWebViewName: string;
/**
* Adds a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform does not support appcontainers.
*/
export declare function addLoopbackExemptionForAppcontainer(name: string): Promise<void>;
/**
* Returns whether appcontainer is supported on the current platform.
* @returns True if platform supports using appcontainer; false otherwise.
*/
export declare function isAppcontainerSupported(): boolean;
/**
* Adds a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform does not support appcontainers.
*/
export declare function isLoopbackExemptionForAppcontainer(name: string): Promise<boolean>;
/**
* Returns the name of the appcontainer used to run an Office Add-in.
* @param sourceLocation Source location of the Office Add-in.
* @param isFromStore True if installed from the Store; false otherwise.
*/
export declare function getAppcontainerName(sourceLocation: string, isFromStore?: boolean): string;
export declare function getUserConfirmation(name: string): Promise<boolean>;
export declare function getAppcontainerNameFromManifestPath(manifestPath: string): Promise<string>;
export declare function getDisplayNameFromManifestPath(manifestPath: string): string;
export declare function ensureLoopbackIsEnabled(manifestPath: string, askForConfirmation?: boolean): Promise<boolean>;
/**
* Returns the name of the appcontainer used to run an Office Add-in.
* @param manifestPath Path of the manifest file.
*/
export declare function getAppcontainerNameFromManifest(manifestPath: string): Promise<string>;
/**
* Removes a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform doesn't support appcontainers.
*/
export declare function removeLoopbackExemptionForAppcontainer(name: string): Promise<void>;
+179
View File
@@ -0,0 +1,179 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeLoopbackExemptionForAppcontainer = exports.getAppcontainerNameFromManifest = exports.ensureLoopbackIsEnabled = exports.getDisplayNameFromManifestPath = exports.getAppcontainerNameFromManifestPath = exports.getUserConfirmation = exports.getAppcontainerName = exports.isLoopbackExemptionForAppcontainer = exports.isAppcontainerSupported = exports.addLoopbackExemptionForAppcontainer = exports.EdgeWebViewName = exports.EdgeBrowserName = exports.EdgeWebViewAppcontainerName = exports.EdgeBrowserAppcontainerName = void 0;
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const office_addin_manifest_1 = require("office-addin-manifest");
const whatwg_url_1 = require("whatwg-url");
const office_addin_usage_data_1 = require("office-addin-usage-data");
/* global process */
exports.EdgeBrowserAppcontainerName = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe";
exports.EdgeWebViewAppcontainerName = "Microsoft.win32webviewhost_cw5n1h2txyewy";
exports.EdgeBrowserName = "Microsoft Edge Web Browser";
exports.EdgeWebViewName = "Microsoft Edge WebView";
/**
* Adds a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform does not support appcontainers.
*/
function addLoopbackExemptionForAppcontainer(name) {
if (!isAppcontainerSupported()) {
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
return new Promise((resolve, reject) => {
const command = `CheckNetIsolation.exe LoopbackExempt -a -n=${name}`;
child_process_1.default.exec(command, (error, stdout) => {
if (error) {
reject(stdout);
}
else {
resolve();
}
});
});
}
exports.addLoopbackExemptionForAppcontainer = addLoopbackExemptionForAppcontainer;
/**
* Returns whether appcontainer is supported on the current platform.
* @returns True if platform supports using appcontainer; false otherwise.
*/
function isAppcontainerSupported() {
return process.platform === "win32";
}
exports.isAppcontainerSupported = isAppcontainerSupported;
/**
* Adds a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform does not support appcontainers.
*/
function isLoopbackExemptionForAppcontainer(name) {
if (!isAppcontainerSupported()) {
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
return new Promise((resolve, reject) => {
const command = `CheckNetIsolation.exe LoopbackExempt -s`;
child_process_1.default.exec(command, (error, stdout) => {
if (error) {
reject(stdout);
}
else {
const expr = new RegExp(`Name: ${name}`, "i");
const found = expr.test(stdout);
resolve(found);
}
});
});
}
exports.isLoopbackExemptionForAppcontainer = isLoopbackExemptionForAppcontainer;
/**
* Returns the name of the appcontainer used to run an Office Add-in.
* @param sourceLocation Source location of the Office Add-in.
* @param isFromStore True if installed from the Store; false otherwise.
*/
function getAppcontainerName(sourceLocation, isFromStore = false) {
const url = new whatwg_url_1.URL(sourceLocation);
const origin = url.origin;
const addinType = isFromStore ? 0 : 1; // 0 if from Office Add-in store, 1 otherwise.
const guid = "04ACA5EC-D79A-43EA-AB47-E50E47DD96FC";
// Appcontainer name format is "{addinType}_{origin}{guid}".
// Replace characters ":" and "/" with "_".
const name = `${addinType}_${origin}${guid}`.replace(/[://]/g, "_");
return name;
}
exports.getAppcontainerName = getAppcontainerName;
function getUserConfirmation(name) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const question = {
message: `Allow localhost loopback for ${name}?`,
name: "didUserConfirm",
type: "confirm",
};
const answers = yield inquirer_1.default.prompt([question]);
return answers.didUserConfirm;
});
}
exports.getUserConfirmation = getUserConfirmation;
function getAppcontainerNameFromManifestPath(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (manifestPath.toLowerCase()) {
case "edgewebview":
return exports.EdgeWebViewAppcontainerName;
case "edgewebbrowser":
case "edge":
return exports.EdgeBrowserAppcontainerName;
default:
return yield getAppcontainerNameFromManifest(manifestPath);
}
});
}
exports.getAppcontainerNameFromManifestPath = getAppcontainerNameFromManifestPath;
function getDisplayNameFromManifestPath(manifestPath) {
switch (manifestPath.toLowerCase()) {
case "edgewebview":
return exports.EdgeWebViewName;
case "edgewebbrowser":
case "edge":
return exports.EdgeBrowserName;
default:
return manifestPath;
}
}
exports.getDisplayNameFromManifestPath = getDisplayNameFromManifestPath;
function ensureLoopbackIsEnabled(manifestPath, askForConfirmation = true) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const name = yield getAppcontainerNameFromManifestPath(manifestPath);
let isEnabled = yield isLoopbackExemptionForAppcontainer(name);
if (!isEnabled) {
if (!askForConfirmation ||
(yield getUserConfirmation(getDisplayNameFromManifestPath(manifestPath)))) {
yield addLoopbackExemptionForAppcontainer(name);
isEnabled = true;
}
}
return isEnabled;
});
}
exports.ensureLoopbackIsEnabled = ensureLoopbackIsEnabled;
/**
* Returns the name of the appcontainer used to run an Office Add-in.
* @param manifestPath Path of the manifest file.
*/
function getAppcontainerNameFromManifest(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const sourceLocation = manifest.defaultSettings
? manifest.defaultSettings.sourceLocation
: undefined;
if (sourceLocation === undefined) {
throw new office_addin_usage_data_1.ExpectedError(`The source location could not be retrieved from the manifest.`);
}
return getAppcontainerName(sourceLocation, false);
});
}
exports.getAppcontainerNameFromManifest = getAppcontainerNameFromManifest;
/**
* Removes a loopback exemption for the appcontainer.
* @param name Appcontainer name
* @throws Error if platform doesn't support appcontainers.
*/
function removeLoopbackExemptionForAppcontainer(name) {
if (!isAppcontainerSupported()) {
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
return new Promise((resolve, reject) => {
const command = `CheckNetIsolation.exe LoopbackExempt -d -n=${name}`;
child_process_1.default.exec(command, (error, stdout) => {
if (error) {
reject(stdout);
}
else {
resolve();
}
});
});
}
exports.removeLoopbackExemptionForAppcontainer = removeLoopbackExemptionForAppcontainer;
//# sourceMappingURL=appcontainer.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"appcontainer.js","sourceRoot":"","sources":["../src/appcontainer.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,0EAAyC;AACzC,gEAAgC;AAChC,iEAA4D;AAC5D,2CAAiC;AACjC,qEAAwD;AAExD,oBAAoB;AAEP,QAAA,2BAA2B,GAAW,uCAAuC,CAAC;AAC9E,QAAA,2BAA2B,GAAW,0CAA0C,CAAC;AACjF,QAAA,eAAe,GAAW,4BAA4B,CAAC;AACvD,QAAA,eAAe,GAAW,wBAAwB,CAAC;AAEhE;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,IAAY;IAC9D,IAAI,CAAC,uBAAuB,EAAE,EAAE;QAC9B,MAAM,IAAI,uCAAa,CAAC,2BAA2B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KACzE;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,8CAA8C,IAAI,EAAE,CAAC;QAErE,uBAAY,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,KAAK,EAAE;gBACT,MAAM,CAAC,MAAM,CAAC,CAAC;aAChB;iBAAM;gBACL,OAAO,EAAE,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,kFAgBC;AAED;;;GAGG;AACH,SAAgB,uBAAuB;IACrC,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AACtC,CAAC;AAFD,0DAEC;AAED;;;;GAIG;AACH,SAAgB,kCAAkC,CAAC,IAAY;IAC7D,IAAI,CAAC,uBAAuB,EAAE,EAAE;QAC9B,MAAM,IAAI,uCAAa,CAAC,2BAA2B,OAAO,CAAC,QA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2CAAmB,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAC1E,MAAM,cAAc,GAAG,QAAQ,CAAC,eAAe;YAC7C,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc;YACzC,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,cAAc,KAAK,SAAS,EAAE;YAChC,MAAM,IAAI,uCAAa,CAAC,+DAA+D,CAAC,CAAC;SAC1F;QAED,OAAO,mBAAmB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CAAA;AAXD,0EAWC;AAED;;;;GAIG;AACH,SAAgB,sCAAsC,CAAC,IAAY;IACjE,IAAI,CAAC,uBAAuB,EAAE,EAAE;QAC9B,MAAM,IAAI,uCAAa,CAAC,2BAA2B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KACzE;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,8CAA8C,IAAI,EAAE,CAAC;QAErE,uBAAY,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,KAAK,EAAE;gBACT,MAAM,CAAC,MAAM,CAAC,CAAC;aAChB;iBAAM;gBACL,OAAO,EAAE,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,wFAgBC"}
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env node
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const commander_1 = require("commander");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const commands = tslib_1.__importStar(require("./commands"));
/* global console process */
const commander = new commander_1.Command();
commander.name("office-addin-dev-settings");
commander.version(process.env.npm_package_version || "(version not available)");
commander
.command("appcontainer <manifest-path>")
.description("Display or configure the appcontainer used to run the Office Add-in.")
.option("--loopback", `Allow access to loopback addresses such as "localhost".`)
.option("--prevent-loopback", `Prevent access to loopback addresses such as "localhost".`)
.option("-y,--yes", "Provide approval without any prompts.")
.action(commands.appcontainer);
commander
.command("clear [manifest-path]")
.description("Clear all dev settings for the Office Add-in.")
.action(commands.clear);
commander
.command("debugging <manifest-path>")
.option("--enable", `Enable debugging for the add-in.`)
.option("--disable", "Disable debugging for the add-in.")
.option("--debug-method <method>", "Specify the debug method: 'direct' or 'proxy'.")
.option("--open-dev-tools", "Open the web browser dev tools (if supported).")
.description("Configure debugging for the Office Add-in.")
.action(commands.debugging);
commander
.command("live-reload <manifest-path>")
.option("--enable", `Enable live-reload for the add-in.`)
.option("--disable", "Disable live-reload for the add-in")
.description("Configure live-reload for the Office Add-in.")
.action(commands.liveReload);
commander
.command("m365-account <operation>")
.description("Update the M365 account used for registration.")
.action(commands.m365Account);
commander
.command("register <manifest-path>")
.description("Register the Office Add-in for development.")
.action(commands.register);
commander
.command("registered")
.description("Show the Office Add-ins registered for development.")
.action(commands.registered);
commander
.command("runtime-log")
.option("--enable [path]", `Enable the runtime log.`)
.option("--disable", "Disable the runtime log.")
.description("Configure the runtime log for all Office Add-ins.")
.action(commands.runtimeLogging);
commander
.command("sideload <manifest-path> [app-type]")
.description("Launch Office with the Office Add-in loaded.")
.option("-a,--app <app>", `The Office app to launch. ("Excel", "Outlook", "PowerPoint", or "Word")`)
.option("-d,--document <document>", `The file path or url of the Office document to open.`)
.option("--registration <registration>", `Id of the registered add-in`)
.action(commands.sideload)
.on("--help", () => {
console.log("\n[app-type] specifies the type of Office app::\n");
console.log(" 'desktop': Office app for Windows or Mac (default)");
console.log(" 'web': Office running in the web browser");
});
commander
.command("source-bundle-url <manifest-path>")
.description("Specify values for components of the source bundle url.")
.option("-h,--host <host>", `The host name to use, or "" to use the default ('localhost').`)
.option("-p,--port <port>", `The port number to use, or "" to use the default (8081).`)
.option("--path <path>", `The path to use, or "" to use the default.`)
.option("-e,--extension <extension>", `The extension to use, or "" to use the default (".bundle").`)
.action(commands.sourceBundleUrl);
commander
.command("unregister <manifest-path>")
.description("Unregister the Office Add-in for development.")
.action(commands.unregister);
commander
.command("webview <manifest-path> [web-view-type]")
.description("Specify the type of web view to use when debugging. Windows only.")
.action(commands.webView)
.on("--help", () => {
console.log("\nFor [web-view-type], choose one of the following values:\n");
console.log("\t'edge' or 'edge-chromium' for Microsoft Edge (Chromium)");
console.log("\t'edge-legacy' for the legacy Microsoft Edge (EdgeHTML)");
console.log("\t'ie' for Internet Explorer 11");
console.log("\t'default' to remove any preference");
console.log("\nOmit [web-view-type] to see the current setting.");
});
// if the command is not known, display an error
commander.on("command:*", function () {
(0, office_addin_usage_data_1.logErrorMessage)(`The command syntax is not valid.\n`);
process.exitCode = 1;
commander.help();
});
if (process.argv.length > 2) {
commander.parse(process.argv);
}
else {
commander.help();
}
//# sourceMappingURL=cli.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAEA,4DAA4D;AAC5D,kCAAkC;;;AAElC,yCAAoC;AACpC,qEAA0D;AAC1D,6DAAuC;AAEvC,4BAA4B;AAE5B,MAAM,SAAS,GAAG,IAAI,mBAAO,EAAE,CAAC;AAEhC,SAAS,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;AAC5C,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,yBAAyB,CAAC,CAAC;AAEhF,SAAS;KACN,OAAO,CAAC,8BAA8B,CAAC;KACvC,WAAW,CAAC,sEAAsE,CAAC;KACnF,MAAM,CAAC,YAAY,EAAE,yDAAyD,CAAC;KAC/E,MAAM,CAAC,oBAAoB,EAAE,2DAA2D,CAAC;KACzF,MAAM,CAAC,UAAU,EAAE,uCAAuC,CAAC;KAC3D,MAAM,CAAC,QAAQ,CAAC,YA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OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEL,gDAAgD;AAChD,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE;IACxB,IAAA,yCAAe,EAAC,oCAAoC,CAAC,CAAC;IACtD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrB,SAAS,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC,CAAC,CAAC;AAEH,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;KAAM;IACL,SAAS,CAAC,IAAI,EAAE,CAAC;CAClB"}
+27
View File
@@ -0,0 +1,27 @@
import { OptionValues } from "commander";
import * as devSettings from "./dev-settings";
import { AccountOperation } from "./publish";
export declare function appcontainer(manifestPath: string, options: OptionValues): Promise<void>;
export declare function clear(manifestPath: string): Promise<void>;
export declare function debugging(manifestPath: string, options: OptionValues): Promise<void>;
export declare function disableDebugging(manifestPath: string): Promise<void>;
export declare function disableLiveReload(manifestPath: string): Promise<void>;
export declare function disableRuntimeLogging(): Promise<void>;
export declare function enableDebugging(manifestPath: string, options: OptionValues): Promise<void>;
export declare function enableLiveReload(manifestPath: string): Promise<void>;
export declare function enableRuntimeLogging(path?: string): Promise<void>;
export declare function getSourceBundleUrl(manifestPath: string): Promise<void>;
export declare function isDebuggingEnabled(manifestPath: string): Promise<void>;
export declare function isLiveReloadEnabled(manifestPath: string): Promise<void>;
export declare function isRuntimeLoggingEnabled(): Promise<void>;
export declare function liveReload(manifestPath: string, options: OptionValues): Promise<void>;
export declare function parseWebViewType(webViewString?: string): devSettings.WebViewType | undefined;
export declare function m365Account(operation: AccountOperation, options: OptionValues): Promise<void>;
export declare function register(manifestPath: string, options: OptionValues): Promise<void>;
export declare function registered(options: OptionValues): Promise<void>;
export declare function runtimeLogging(options: OptionValues): Promise<void>;
export declare function sideload(manifestPath: string, type: string | undefined, options: OptionValues): Promise<void>;
export declare function setSourceBundleUrl(manifestPath: string, options: OptionValues): Promise<void>;
export declare function sourceBundleUrl(manifestPath: string, options: OptionValues): Promise<void>;
export declare function unregister(manifestPath: string, options: OptionValues): Promise<void>;
export declare function webView(manifestPath: string, webViewString?: string): Promise<void>;
+519
View File
@@ -0,0 +1,519 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.webView = exports.unregister = exports.sourceBundleUrl = exports.setSourceBundleUrl = exports.sideload = exports.runtimeLogging = exports.registered = exports.register = exports.m365Account = exports.parseWebViewType = exports.liveReload = exports.isRuntimeLoggingEnabled = exports.isLiveReloadEnabled = exports.isDebuggingEnabled = exports.getSourceBundleUrl = exports.enableRuntimeLogging = exports.enableLiveReload = exports.enableDebugging = exports.disableRuntimeLogging = exports.disableLiveReload = exports.disableDebugging = exports.debugging = exports.clear = exports.appcontainer = void 0;
const tslib_1 = require("tslib");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const office_addin_manifest_1 = require("office-addin-manifest");
const appcontainer_1 = require("./appcontainer");
const appType_1 = require("./appType");
const devSettings = tslib_1.__importStar(require("./dev-settings"));
const sideload_1 = require("./sideload");
const defaults_1 = require("./defaults");
const office_addin_usage_data_2 = require("office-addin-usage-data");
const publish_1 = require("./publish");
/* global console process */
function appcontainer(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if ((0, appcontainer_1.isAppcontainerSupported)()) {
try {
if (options.loopback) {
try {
const askForConfirmation = options.yes !== true;
const allowed = yield (0, appcontainer_1.ensureLoopbackIsEnabled)(manifestPath, askForConfirmation);
console.log(allowed ? "Loopback is allowed." : "Loopback is not allowed.");
}
catch (err) {
throw new Error(`Unable to allow loopback for the appcontainer. \n${err}`);
}
}
else if (options.preventLoopback) {
try {
const name = yield (0, appcontainer_1.getAppcontainerNameFromManifestPath)(manifestPath);
yield (0, appcontainer_1.removeLoopbackExemptionForAppcontainer)(name);
console.log(`Loopback is no longer allowed.`);
}
catch (err) {
throw new Error(`Unable to disallow loopback. \n${err}`);
}
}
else {
try {
const name = yield (0, appcontainer_1.getAppcontainerNameFromManifestPath)(manifestPath);
const allowed = yield (0, appcontainer_1.isLoopbackExemptionForAppcontainer)(name);
console.log(allowed ? "Loopback is allowed." : "Loopback is not allowed.");
}
catch (err) {
throw new Error(`Unable to determine if appcontainer allows loopback. \n${err}`);
}
}
defaults_1.usageDataObject.reportSuccess("appcontainer");
}
catch (err) {
defaults_1.usageDataObject.reportException("appcontainer", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
}
else {
console.log("Appcontainer is not supported.");
}
});
}
exports.appcontainer = appcontainer;
function clear(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
yield devSettings.clearDevSettings(manifest.id);
console.log("Developer settings have been cleared.");
defaults_1.usageDataObject.reportSuccess("clear");
}
catch (err) {
defaults_1.usageDataObject.reportException("clear", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.clear = clear;
function debugging(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (options.enable) {
yield enableDebugging(manifestPath, options);
}
else if (options.disable) {
yield disableDebugging(manifestPath);
}
else {
yield isDebuggingEnabled(manifestPath);
}
defaults_1.usageDataObject.reportSuccess("debugging");
}
catch (err) {
defaults_1.usageDataObject.reportException("debugging", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.debugging = debugging;
function displaySourceBundleUrl(components) {
console.log(`host: ${components.host !== undefined ? `"${components.host}"` : '"localhost" (default)'}`);
console.log(`port: ${components.port !== undefined ? `"${components.port}"` : '"8081" (default)'}`);
console.log(`path: ${components.path !== undefined ? `"${components.path}"` : "(default)"}`);
console.log(`extension: ${components.extension !== undefined ? `"${components.extension}"` : '".bundle" (default)'}`);
console.log();
console.log(`Source bundle url: ${components.url}`);
console.log();
}
function disableDebugging(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
yield devSettings.disableDebugging(manifest.id);
console.log("Debugging has been disabled.");
defaults_1.usageDataObject.reportSuccess("disableDebugging()");
}
catch (err) {
defaults_1.usageDataObject.reportException("disableDebugging()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.disableDebugging = disableDebugging;
function disableLiveReload(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
yield devSettings.disableLiveReload(manifest.id);
console.log("Live reload has been disabled.");
defaults_1.usageDataObject.reportSuccess("disableLiveReload()");
}
catch (err) {
defaults_1.usageDataObject.reportException("disableLiveReload()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.disableLiveReload = disableLiveReload;
function disableRuntimeLogging() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield devSettings.disableRuntimeLogging();
console.log("Runtime logging has been disabled.");
defaults_1.usageDataObject.reportSuccess("disableRuntimeLogging()");
}
catch (err) {
defaults_1.usageDataObject.reportException("disableRuntimeLogging()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.disableRuntimeLogging = disableRuntimeLogging;
function enableDebugging(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
yield devSettings.enableDebugging(manifest.id, true, toDebuggingMethod(options.debugMethod), options.openDevTools);
console.log("Debugging has been enabled.");
defaults_1.usageDataObject.reportSuccess("enableDebugging()");
}
catch (err) {
defaults_1.usageDataObject.reportException("enableDebugging()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.enableDebugging = enableDebugging;
function enableLiveReload(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
yield devSettings.enableLiveReload(manifest.id);
console.log("Live reload has been enabled.");
defaults_1.usageDataObject.reportSuccess("enableLiveReload()");
}
catch (err) {
defaults_1.usageDataObject.reportException("enableLiveReload()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.enableLiveReload = enableLiveReload;
function enableRuntimeLogging(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const logPath = yield devSettings.enableRuntimeLogging(path);
console.log(`Runtime logging has been enabled. File: ${logPath}`);
defaults_1.usageDataObject.reportSuccess("enableRuntimeLogging()");
}
catch (err) {
defaults_1.usageDataObject.reportException("enableRuntimeLogging()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.enableRuntimeLogging = enableRuntimeLogging;
function getSourceBundleUrl(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
const components = yield devSettings.getSourceBundleUrl(manifest.id);
displaySourceBundleUrl(components);
defaults_1.usageDataObject.reportSuccess("getSourceBundleUrl()");
}
catch (err) {
defaults_1.usageDataObject.reportException("getSourceBundleUrl()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.getSourceBundleUrl = getSourceBundleUrl;
function isDebuggingEnabled(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
const enabled = yield devSettings.isDebuggingEnabled(manifest.id);
console.log(enabled ? "Debugging is enabled." : "Debugging is not enabled.");
defaults_1.usageDataObject.reportSuccess("isDebuggingEnabled()");
}
catch (err) {
defaults_1.usageDataObject.reportException("isDebuggingEnabled()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.isDebuggingEnabled = isDebuggingEnabled;
function isLiveReloadEnabled(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
const enabled = yield devSettings.isLiveReloadEnabled(manifest.id);
console.log(enabled ? "Live reload is enabled." : "Live reload is not enabled.");
defaults_1.usageDataObject.reportSuccess("isLiveReloadEnabled()");
}
catch (err) {
defaults_1.usageDataObject.reportException("isLiveReloadEnabled()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.isLiveReloadEnabled = isLiveReloadEnabled;
function isRuntimeLoggingEnabled() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const path = yield devSettings.getRuntimeLoggingPath();
console.log(path ? `Runtime logging is enabled. File: ${path}` : "Runtime logging is not enabled.");
defaults_1.usageDataObject.reportSuccess("isRuntimeLoggingEnabled()");
}
catch (err) {
defaults_1.usageDataObject.reportException("isRuntimeLoggingEnabled()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.isRuntimeLoggingEnabled = isRuntimeLoggingEnabled;
function liveReload(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (options.enable) {
yield enableLiveReload(manifestPath);
}
else if (options.disable) {
yield disableLiveReload(manifestPath);
}
else {
yield isLiveReloadEnabled(manifestPath);
}
defaults_1.usageDataObject.reportSuccess("liveReload");
}
catch (err) {
defaults_1.usageDataObject.reportException("liveReload", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.liveReload = liveReload;
function parseStringCommandOption(optionValue) {
return typeof optionValue === "string" ? optionValue : undefined;
}
function parseWebViewType(webViewString) {
switch (webViewString ? webViewString.toLowerCase() : undefined) {
case "ie":
case "ie11":
case "internet explorer":
case "internetexplorer":
return devSettings.WebViewType.IE;
case "edgelegacy":
case "edge-legacy":
case "spartan":
return devSettings.WebViewType.Edge;
case "edge chromium":
case "edgechromium":
case "edge-chromium":
case "anaheim":
case "edge":
return devSettings.WebViewType.EdgeChromium;
case "default":
case "":
case null:
case undefined:
return undefined;
default:
throw new office_addin_usage_data_2.ExpectedError(`Please select a valid web view type instead of '${webViewString}'.`);
}
}
exports.parseWebViewType = parseWebViewType;
function m365Account(operation, options /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield (0, publish_1.updateM365Account)(operation);
defaults_1.usageDataObject.reportSuccess("m365Account");
}
catch (err) {
defaults_1.usageDataObject.reportException("m365Account", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.m365Account = m365Account;
function register(manifestPath, options /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield devSettings.registerAddIn(manifestPath);
defaults_1.usageDataObject.reportSuccess("register");
}
catch (err) {
defaults_1.usageDataObject.reportException("register", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.register = register;
function registered(options /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const registeredAddins = yield devSettings.getRegisteredAddIns();
if (registeredAddins.length > 0) {
for (const addin of registeredAddins) {
let id = addin.id;
if (!id && addin.manifestPath) {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(addin.manifestPath);
id = manifest.id || "";
}
catch (_a) {
// ignore errors
}
}
console.log(`${id ? id + " " : ""}${addin.manifestPath}`);
}
}
else {
console.log("No add-ins are registered.");
}
defaults_1.usageDataObject.reportSuccess("registered");
}
catch (err) {
defaults_1.usageDataObject.reportException("registered", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.registered = registered;
function runtimeLogging(options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (options.enable) {
const path = typeof options.enable === "string" ? options.enable : undefined;
yield enableRuntimeLogging(path);
}
else if (options.disable) {
yield disableRuntimeLogging();
}
else {
yield isRuntimeLoggingEnabled();
}
defaults_1.usageDataObject.reportSuccess("runtimeLogging");
}
catch (err) {
defaults_1.usageDataObject.reportException("runtimeLogging", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.runtimeLogging = runtimeLogging;
function sideload(manifestPath, type, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const app = options.app ? (0, office_addin_manifest_1.parseOfficeApp)(options.app) : undefined;
const canPrompt = true;
const document = options.document ? options.document : undefined;
const appType = (0, appType_1.parseAppType)(type || process.env.npm_package_config_app_platform_to_debug);
const registration = options.registration;
yield (0, sideload_1.sideloadAddIn)(manifestPath, app, canPrompt, appType, document, registration);
defaults_1.usageDataObject.reportSuccess("sideload");
}
catch (err) {
defaults_1.usageDataObject.reportException("sideload", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.sideload = sideload;
function setSourceBundleUrl(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const host = parseStringCommandOption(options.host);
const port = parseStringCommandOption(options.port);
const path = parseStringCommandOption(options.path);
const extension = parseStringCommandOption(options.extension);
const components = new devSettings.SourceBundleUrlComponents(host, port, path, extension);
validateManifestId(manifest);
yield devSettings.setSourceBundleUrl(manifest.id, components);
console.log("Configured source bundle url.");
displaySourceBundleUrl(yield devSettings.getSourceBundleUrl(manifest.id));
defaults_1.usageDataObject.reportSuccess("setSourceBundleUrl()");
}
catch (err) {
defaults_1.usageDataObject.reportException("setSourceBundleUrl()", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.setSourceBundleUrl = setSourceBundleUrl;
function sourceBundleUrl(manifestPath, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (options.host !== undefined ||
options.port !== undefined ||
options.path !== undefined ||
options.extension !== undefined) {
yield setSourceBundleUrl(manifestPath, options);
}
else {
yield getSourceBundleUrl(manifestPath);
}
defaults_1.usageDataObject.reportSuccess("sourceBundleUrl");
}
catch (err) {
defaults_1.usageDataObject.reportException("sourceBundleUrl", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.sourceBundleUrl = sourceBundleUrl;
function toDebuggingMethod(text) {
switch (text) {
case "direct":
return devSettings.DebuggingMethod.Direct;
case "proxy":
return devSettings.DebuggingMethod.Proxy;
case "":
case null:
case undefined:
// preferred debug method
return devSettings.DebuggingMethod.Direct;
default:
throw new office_addin_usage_data_2.ExpectedError(`Please provide a valid debug method instead of '${text}'.`);
}
}
function unregister(manifestPath, options /* eslint-disable-line @typescript-eslint/no-unused-vars */) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (manifestPath === "all") {
yield devSettings.unregisterAllAddIns();
}
else {
yield devSettings.unregisterAddIn(manifestPath);
}
defaults_1.usageDataObject.reportSuccess("unregister");
}
catch (err) {
defaults_1.usageDataObject.reportException("unregister", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.unregister = unregister;
function validateManifestId(manifest) {
if (!manifest.id) {
throw new office_addin_usage_data_2.ExpectedError(`The manifest file doesn't contain the id of the Office Add-in.`);
}
}
function webView(manifestPath, webViewString) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
validateManifestId(manifest);
let webViewType;
if (webViewString === undefined) {
webViewType = yield devSettings.getWebView(manifest.id);
}
else {
webViewType = parseWebViewType(webViewString);
yield devSettings.setWebView(manifest.id, webViewType);
}
const webViewTypeName = devSettings.toWebViewTypeName(webViewType);
console.log(webViewTypeName
? `The web view type is set to ${webViewTypeName}.`
: "The web view type has not been set.");
defaults_1.usageDataObject.reportSuccess("webView");
}
catch (err) {
defaults_1.usageDataObject.reportException("webView", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.webView = webView;
//# sourceMappingURL=commands.js.map
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
import { OfficeAddinUsageData } from "office-addin-usage-data";
export declare const usageDataObject: OfficeAddinUsageData;
+13
View File
@@ -0,0 +1,13 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.usageDataObject = void 0;
const office_addin_usage_data_1 = require("office-addin-usage-data");
// Usage data defaults
exports.usageDataObject = new office_addin_usage_data_1.OfficeAddinUsageData({
projectName: "office-addin-dev-settings",
instrumentationKey: office_addin_usage_data_1.instrumentationKeyForOfficeAddinCLITools,
raisePrompt: false,
});
//# sourceMappingURL=defaults.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,qEAGiC;AAEjC,sBAAsB;AACT,QAAA,eAAe,GAAyB,IAAI,8CAAoB,CAAC;IAC5E,WAAW,EAAE,2BAA2B;IACxC,kBAAkB,EAAE,kEAAwC;IAC5D,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC"}
+6
View File
@@ -0,0 +1,6 @@
import { OfficeApp } from "office-addin-manifest";
import { RegisteredAddin } from "./dev-settings";
export declare function getRegisteredAddIns(): Promise<RegisteredAddin[]>;
export declare function registerAddIn(manifestPath: string, officeApps?: OfficeApp[], registration?: string): Promise<void>;
export declare function unregisterAddIn(addinId: string, manifestPath: string): Promise<void>;
export declare function unregisterAllAddIns(): Promise<void>;
+120
View File
@@ -0,0 +1,120 @@
"use strict";
// copyright (c) Microsoft Corporation. All rights reserved.
// licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.unregisterAllAddIns = exports.unregisterAddIn = exports.registerAddIn = exports.getRegisteredAddIns = void 0;
const tslib_1 = require("tslib");
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const junk_1 = tslib_1.__importDefault(require("junk"));
const office_addin_manifest_1 = require("office-addin-manifest");
const os_1 = tslib_1.__importDefault(require("os"));
const path_1 = tslib_1.__importDefault(require("path"));
const dev_settings_1 = require("./dev-settings");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const publish_1 = require("./publish");
const path_2 = tslib_1.__importDefault(require("path"));
function getRegisteredAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registeredAddins = [];
for (const app of (0, office_addin_manifest_1.getOfficeApps)()) {
const sideloadDirectory = getSideloadDirectory(app);
if (sideloadDirectory && fs_extra_1.default.existsSync(sideloadDirectory)) {
for (const fileName of fs_extra_1.default.readdirSync(sideloadDirectory).filter(junk_1.default.not)) {
const manifestPath = fs_extra_1.default.realpathSync(path_1.default.join(sideloadDirectory, fileName));
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
registeredAddins.push(new dev_settings_1.RegisteredAddin(manifest.id || "", manifestPath));
}
}
}
return registeredAddins;
});
}
exports.getRegisteredAddIns = getRegisteredAddIns;
function getSideloadDirectory(app) {
switch (app) {
case office_addin_manifest_1.OfficeApp.Excel:
return path_1.default.join(os_1.default.homedir(), "Library/Containers/com.microsoft.Excel/Data/Documents/wef");
case office_addin_manifest_1.OfficeApp.PowerPoint:
return path_1.default.join(os_1.default.homedir(), "Library/Containers/com.microsoft.Powerpoint/Data/Documents/wef");
case office_addin_manifest_1.OfficeApp.Word:
return path_1.default.join(os_1.default.homedir(), "Library/Containers/com.microsoft.Word/Data/Documents/wef");
}
}
function registerAddIn(manifestPath, officeApps, registration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
if (!officeApps) {
officeApps = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
if (officeApps.length === 0) {
throw new office_addin_usage_data_1.ExpectedError("The manifest file doesn't specify any hosts for the Office Add-in.");
}
}
if (!manifest.id) {
throw new office_addin_usage_data_1.ExpectedError("The manifest file doesn't contain the id of the Office Add-in.");
}
if (manifestPath.endsWith(".json")) {
if (!registration) {
const targetPath = path_2.default.join(os_1.default.tmpdir(), "manifest.zip");
const zipPath = yield (0, office_addin_manifest_1.exportMetadataPackage)(targetPath, manifestPath);
registration = yield (0, publish_1.registerWithTeams)(zipPath);
}
// TODO: Save registration in "OutlookSideloadManifestPath" as "TitleId"
// and add support for refreshing add-ins in Outlook via registry key
}
else if (manifestPath.endsWith(".xml")) {
// TODO: Look for "Outlook" in manifests.hosts and enable outlook sideloading if there.
// and add support for refreshing add-ins in Outlook via registry key
}
// Save manifest path in "registry"
for (const app of officeApps) {
const sideloadDirectory = getSideloadDirectory(app);
if (sideloadDirectory) {
// include manifest id in sideload filename
const sideloadPath = path_1.default.join(sideloadDirectory, `${manifest.id}.${path_1.default.basename(manifestPath)}`);
fs_extra_1.default.ensureDirSync(sideloadDirectory);
fs_extra_1.default.ensureLinkSync(manifestPath, sideloadPath);
}
}
}
catch (err) {
throw new Error(`Unable to register the Office Add-in.\n${err}`);
}
});
}
exports.registerAddIn = registerAddIn;
function unregisterAddIn(addinId, manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!addinId) {
throw new office_addin_usage_data_1.ExpectedError("The manifest file doesn't contain the id of the Office Add-in.");
}
const registeredAddIns = yield getRegisteredAddIns();
for (const registeredAddIn of registeredAddIns) {
const registeredFileName = path_1.default.basename(registeredAddIn.manifestPath);
const manifestFileName = path_1.default.basename(manifestPath);
if (registeredFileName === manifestFileName || registeredFileName.startsWith(addinId)) {
if (!registeredFileName.endsWith(".xml")) {
(0, publish_1.uninstallWithTeams)(registeredFileName.substring(registeredFileName.indexOf(".") + 1));
// TODO: Add support for refreshing add-ins in Outlook via registry key
}
fs_extra_1.default.unlinkSync(registeredAddIn.manifestPath);
}
}
});
}
exports.unregisterAddIn = unregisterAddIn;
function unregisterAllAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registeredAddIns = yield getRegisteredAddIns();
for (const registeredAddIn of registeredAddIns) {
const registeredFileName = path_1.default.basename(registeredAddIn.manifestPath);
if (!registeredFileName.endsWith(".xml")) {
(0, publish_1.uninstallWithTeams)(registeredFileName.substring(registeredFileName.indexOf(".") + 1));
// TODO: Add support for refreshing add-ins in Outlook via registry key
}
fs_extra_1.default.unlinkSync(registeredAddIn.manifestPath);
}
});
}
exports.unregisterAllAddIns = unregisterAllAddIns;
//# sourceMappingURL=dev-settings-mac.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"dev-settings-mac.js","sourceRoot":"","sources":["../src/dev-settings-mac.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,gEAA0B;AAC1B,wDAAwB;AACxB,iEAO+B;AAC/B,oDAAoB;AACpB,wDAAwB;AACxB,iDAAiD;AACjD,qEAAwD;AACxD,uCAAkE;AAClE,wDAA0B;AAE1B,SAAsB,mBAAmB;;QACvC,MAAM,gBAAgB,GAAsB,EAAE,CAAC;QAE/C,KAAK,MAAM,GAAG,IAAI,IAAA,qCAAa,GAAE,EAAE;YACjC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;YAEpD,IAAI,iBAAiB,IAAI,kBAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;gBACzD,KAAK,MAAM,QAAQ,IAAI,kBAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,cAAI,CAAC,GAAG,CAAC,EAAE;oBACzE,MAAM,YAAY,GAAG,kBAAE,CAAC,YAAY,CAA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D,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;YAC9C,MAAM,kBAAkB,GAAG,cAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACvE,MAAM,gBAAgB,GAAG,cAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAErD,IAAI,kBAAkB,KAAK,gBAAgB,IAAI,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;gBACrF,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;oBACxC,IAAA,4BAAkB,EAAC,kBAAkB,CAAC,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACtF,uEAAuE;iBACxE;gBACD,kBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;aAC7C;SACF;IACH,CAAC;CAAA;AAnBD,0CAmBC;AAED,SAAsB,mBAAmB;;QACvC,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,EAAE,CAAC;QAErD,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;YAC9C,MAAM,kBAAkB,GAAG,cAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YACvE,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBACxC,IAAA,4BAAkB,EAAC,kBAAkB,CAAC,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACtF,uEAAuE;aACxE;YACD,kBAAE,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;SAC7C;IACH,CAAC;CAAA;AAXD,kDAWC"}
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env node
import { DebuggingMethod, RegisteredAddin, SourceBundleUrlComponents, WebViewType } from "./dev-settings";
import * as registry from "./registry";
export declare const OutlookSideloadManifestPath: string;
export declare function clearDevSettings(addinId: string): Promise<void>;
export declare function deleteDeveloperSettingsRegistryKey(addinId: string): Promise<void>;
export declare function disableRuntimeLogging(): Promise<void>;
export declare function enableDebugging(addinId: string, enable?: boolean, method?: DebuggingMethod, openDevTools?: boolean): Promise<void>;
export declare function enableLiveReload(addinId: string, enable?: boolean): Promise<void>;
export declare function enableRuntimeLogging(path: string): Promise<void>;
export declare function getDeveloperSettingsRegistryKey(addinId: string): registry.RegistryKey;
export declare function getEnabledDebuggingMethods(addinId: string): Promise<DebuggingMethod[]>;
export declare function getOpenDevTools(addinId: string): Promise<boolean>;
export declare function getRegisteredAddIns(): Promise<RegisteredAddin[]>;
export declare function getRuntimeLoggingPath(): Promise<string | undefined>;
export declare function getSourceBundleUrl(addinId: string): Promise<SourceBundleUrlComponents>;
export declare function getWebView(addinId: string): Promise<WebViewType | undefined>;
export declare function isDebuggingEnabled(addinId: string): Promise<boolean>;
export declare function isLiveReloadEnabled(addinId: string): Promise<boolean>;
export declare function registerAddIn(manifestPath: string, registration?: string): Promise<void>;
export declare function setSourceBundleUrl(addinId: string, components: SourceBundleUrlComponents): Promise<void>;
export declare function setWebView(addinId: string, webViewType: WebViewType | undefined): Promise<void>;
export declare function toWebViewTypeName(webViewType?: WebViewType): string | undefined;
export declare function unregisterAddIn(addinId: string, manifestPath: string): Promise<void>;
export declare function unregisterAllAddIns(): Promise<void>;
export declare function disableRefreshAddins(): Promise<void>;
+342
View File
@@ -0,0 +1,342 @@
#!/usr/bin/env node
"use strict";
// copyright (c) Microsoft Corporation. All rights reserved.
// licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.disableRefreshAddins = exports.unregisterAllAddIns = exports.unregisterAddIn = exports.toWebViewTypeName = exports.setWebView = exports.setSourceBundleUrl = exports.registerAddIn = exports.isLiveReloadEnabled = exports.isDebuggingEnabled = exports.getWebView = exports.getSourceBundleUrl = exports.getRuntimeLoggingPath = exports.getRegisteredAddIns = exports.getOpenDevTools = exports.getEnabledDebuggingMethods = exports.getDeveloperSettingsRegistryKey = exports.enableRuntimeLogging = exports.enableLiveReload = exports.enableDebugging = exports.disableRuntimeLogging = exports.deleteDeveloperSettingsRegistryKey = exports.clearDevSettings = exports.OutlookSideloadManifestPath = void 0;
const tslib_1 = require("tslib");
const office_addin_manifest_1 = require("office-addin-manifest");
const dev_settings_1 = require("./dev-settings");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const registry = tslib_1.__importStar(require("./registry"));
const publish_1 = require("./publish");
const path_1 = tslib_1.__importDefault(require("path"));
/* global process */
const DeveloperSettingsRegistryKey = `HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Office\\16.0\\Wef\\Developer`;
const OpenDevTools = "OpenDevTools";
exports.OutlookSideloadManifestPath = "OutlookSideloadManifestPath";
const RefreshAddins = "RefreshAddins";
const RuntimeLogging = "RuntimeLogging";
const SourceBundleExtension = "SourceBundleExtension";
const SourceBundleHost = "SourceBundleHost";
const SourceBundlePath = "SourceBundlePath";
const SourceBundlePort = "SourceBundlePort";
const TitleId = "TitleId";
const UseDirectDebugger = "UseDirectDebugger";
const UseLiveReload = "UseLiveReload";
const UseProxyDebugger = "UseWebDebugger";
const WebViewSelection = "WebViewSelection";
function clearDevSettings(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return deleteDeveloperSettingsRegistryKey(addinId);
});
}
exports.clearDevSettings = clearDevSettings;
function deleteDeveloperSettingsRegistryKey(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
return registry.deleteKey(key);
});
}
exports.deleteDeveloperSettingsRegistryKey = deleteDeveloperSettingsRegistryKey;
function disableRuntimeLogging() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.deleteKey(key);
});
}
exports.disableRuntimeLogging = disableRuntimeLogging;
function enableDebugging(addinId, enable = true, method = dev_settings_1.DebuggingMethod.Proxy, openDevTools = false) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const useDirectDebugger = enable && method === dev_settings_1.DebuggingMethod.Direct;
const useProxyDebugger = enable && method === dev_settings_1.DebuggingMethod.Proxy;
yield registry.addBooleanValue(key, UseDirectDebugger, useDirectDebugger);
yield registry.addBooleanValue(key, UseProxyDebugger, useProxyDebugger);
if (enable && openDevTools) {
yield registry.addBooleanValue(key, OpenDevTools, true);
}
else {
yield registry.deleteValue(key, OpenDevTools);
}
});
}
exports.enableDebugging = enableDebugging;
function enableLiveReload(addinId, enable = true) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
return registry.addBooleanValue(key, UseLiveReload, enable);
});
}
exports.enableLiveReload = enableLiveReload;
function enableRuntimeLogging(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.addStringValue(key, "", path); // empty string for the default value
});
}
exports.enableRuntimeLogging = enableRuntimeLogging;
function getDeveloperSettingsRegistryKey(addinId) {
if (!addinId) {
throw new office_addin_usage_data_1.ExpectedError("The addIn parameter is required.");
}
if (typeof addinId !== "string") {
throw new office_addin_usage_data_1.ExpectedError("The addIn parameter should be a string.");
}
return new registry.RegistryKey(`${DeveloperSettingsRegistryKey}\\${addinId}`);
}
exports.getDeveloperSettingsRegistryKey = getDeveloperSettingsRegistryKey;
function getEnabledDebuggingMethods(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const methods = [];
if (isRegistryValueTrue(yield registry.getValue(key, UseDirectDebugger))) {
methods.push(dev_settings_1.DebuggingMethod.Direct);
}
if (isRegistryValueTrue(yield registry.getValue(key, UseProxyDebugger))) {
methods.push(dev_settings_1.DebuggingMethod.Proxy);
}
return methods;
});
}
exports.getEnabledDebuggingMethods = getEnabledDebuggingMethods;
function getOpenDevTools(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
return isRegistryValueTrue(yield registry.getValue(key, OpenDevTools));
});
}
exports.getOpenDevTools = getOpenDevTools;
function getRegisteredAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
const values = yield registry.getValues(key);
const filteredValues = values.filter((value) => value.name !== RefreshAddins);
// if the registry value name and data are the same, then the manifest path was used as the name
return filteredValues.map((value) => new dev_settings_1.RegisteredAddin(value.name !== value.data ? value.name : "", value.data));
});
}
exports.getRegisteredAddIns = getRegisteredAddIns;
function getRuntimeLoggingPath() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.getStringValue(key, ""); // empty string for the default value
});
}
exports.getRuntimeLoggingPath = getRuntimeLoggingPath;
function getSourceBundleUrl(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const components = new dev_settings_1.SourceBundleUrlComponents(yield registry.getStringValue(key, SourceBundleHost), yield registry.getStringValue(key, SourceBundlePort), yield registry.getStringValue(key, SourceBundlePath), yield registry.getStringValue(key, SourceBundleExtension));
return components;
});
}
exports.getSourceBundleUrl = getSourceBundleUrl;
function getWebView(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const webViewString = yield registry.getStringValue(key, WebViewSelection);
return toWebViewType(webViewString);
});
}
exports.getWebView = getWebView;
function isDebuggingEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const useDirectDebugger = isRegistryValueTrue(yield registry.getValue(key, UseDirectDebugger));
const useWebDebugger = isRegistryValueTrue(yield registry.getValue(key, UseProxyDebugger));
return useDirectDebugger || useWebDebugger;
});
}
exports.isDebuggingEnabled = isDebuggingEnabled;
function isLiveReloadEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const enabled = isRegistryValueTrue(yield registry.getValue(key, UseLiveReload));
return enabled;
});
}
exports.isLiveReloadEnabled = isLiveReloadEnabled;
function isRegistryValueTrue(value) {
if (value) {
switch (value.type) {
case registry.RegistryTypes.REG_DWORD:
case registry.RegistryTypes.REG_QWORD:
case registry.RegistryTypes.REG_SZ:
return parseInt(value.data, undefined) !== 0;
}
}
return false;
}
function registerAddIn(manifestPath, registration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const appsInManifest = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
// Register using the service
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON ||
appsInManifest.indexOf(office_addin_manifest_1.OfficeApp.Outlook) >= 0) {
if (!registration) {
let filePath = "";
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON) {
const targetPath = path_1.default.join(process.env.TEMP, "manifest.zip");
filePath = yield (0, office_addin_manifest_1.exportMetadataPackage)(targetPath, manifestPath);
}
else if (manifest.manifestType === office_addin_manifest_1.ManifestType.XML) {
filePath = manifestPath;
}
registration = yield (0, publish_1.registerWithTeams)(filePath);
yield enableRefreshAddins();
}
const key = getDeveloperSettingsRegistryKey(exports.OutlookSideloadManifestPath);
yield registry.addStringValue(key, TitleId, registration);
}
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.deleteValue(key, manifestPath); // in case the manifest path was previously used as the key
return registry.addStringValue(key, manifest.id || "", manifestPath);
});
}
exports.registerAddIn = registerAddIn;
function setSourceBundleUrl(addinId, components) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
if (components.host !== undefined) {
if (components.host) {
yield registry.addStringValue(key, SourceBundleHost, components.host);
}
else {
yield registry.deleteValue(key, SourceBundleHost);
}
}
if (components.port !== undefined) {
if (components.port) {
yield registry.addStringValue(key, SourceBundlePort, components.port);
}
else {
yield registry.deleteValue(key, SourceBundlePort);
}
}
if (components.path !== undefined) {
if (components.path) {
yield registry.addStringValue(key, SourceBundlePath, components.path);
}
else {
yield registry.deleteValue(key, SourceBundlePath);
}
}
if (components.extension !== undefined) {
if (components.extension) {
yield registry.addStringValue(key, SourceBundleExtension, components.extension);
}
else {
yield registry.deleteValue(key, SourceBundleExtension);
}
}
});
}
exports.setSourceBundleUrl = setSourceBundleUrl;
function setWebView(addinId, webViewType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
switch (webViewType) {
case undefined:
case dev_settings_1.WebViewType.Default:
yield registry.deleteValue(key, WebViewSelection);
break;
case dev_settings_1.WebViewType.IE:
case dev_settings_1.WebViewType.Edge:
case dev_settings_1.WebViewType.EdgeChromium: {
const webViewString = webViewType;
yield registry.addStringValue(key, WebViewSelection, webViewString);
break;
}
default:
throw new office_addin_usage_data_1.ExpectedError(`The webViewType ${webViewType} is not supported.`);
}
});
}
exports.setWebView = setWebView;
function toWebViewType(webViewString) {
switch (webViewString ? webViewString.toLowerCase() : undefined) {
case "ie":
return dev_settings_1.WebViewType.IE;
case "edge":
return dev_settings_1.WebViewType.Edge;
case "edge chromium":
return dev_settings_1.WebViewType.EdgeChromium;
default:
return undefined;
}
}
function toWebViewTypeName(webViewType) {
switch (webViewType) {
case dev_settings_1.WebViewType.Edge:
return "legacy Microsoft Edge (EdgeHTML)";
case dev_settings_1.WebViewType.EdgeChromium:
return "Microsoft Edge (Chromium)";
case dev_settings_1.WebViewType.IE:
return "Microsoft Internet Explorer";
default:
return undefined;
}
}
exports.toWebViewTypeName = toWebViewTypeName;
function unregisterAddIn(addinId, manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
if (addinId) {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const appsInManifest = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
// Unregister using the service
// TODO: remove if statement when the service supports all hosts
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON ||
appsInManifest.indexOf(office_addin_manifest_1.OfficeApp.Outlook) >= 0) {
yield unacquire(key, addinId);
}
yield registry.deleteValue(key, addinId);
}
// since the key used to be manifest path, delete it too
if (manifestPath) {
yield registry.deleteValue(key, manifestPath);
}
});
}
exports.unregisterAddIn = unregisterAddIn;
function unregisterAllAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registeredAddins = yield getRegisteredAddIns();
for (const addin of registeredAddins) {
yield unregisterAddIn(addin.id, addin.manifestPath);
}
});
}
exports.unregisterAllAddIns = unregisterAllAddIns;
function unacquire(key, id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield registry.getStringValue(key, id);
if (manifest != undefined) {
const key = getDeveloperSettingsRegistryKey(exports.OutlookSideloadManifestPath);
const registration = yield registry.getStringValue(key, TitleId);
const uninstallId = registration != undefined ? registration : id;
if (yield (0, publish_1.uninstallWithTeams)(uninstallId)) {
if (registration != undefined) {
registry.deleteValue(key, TitleId);
}
yield enableRefreshAddins();
}
}
});
}
function enableRefreshAddins() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.addBooleanValue(key, RefreshAddins, true);
});
}
function disableRefreshAddins() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.deleteValue(key, RefreshAddins);
});
}
exports.disableRefreshAddins = disableRefreshAddins;
//# sourceMappingURL=dev-settings-windows.js.map
File diff suppressed because one or more lines are too long
+49
View File
@@ -0,0 +1,49 @@
export { toWebViewTypeName } from "./dev-settings-windows";
export declare enum DebuggingMethod {
Direct = 0,
Proxy = 1,
/** @deprecated use Proxy */
Web = 1
}
export declare enum WebViewType {
Default = "Default",
IE = "IE",
Edge = "Edge",
EdgeChromium = "Edge Chromium"
}
export declare class RegisteredAddin {
id: string;
manifestPath: string;
constructor(id: string, manifestPath: string);
}
export declare class SourceBundleUrlComponents {
host?: string;
port?: string;
path?: string;
extension?: string;
get url(): string;
constructor(host?: string, port?: string, path?: string, extension?: string);
}
export declare function clearDevSettings(addinId: string): Promise<void>;
export declare function disableDebugging(addinId: string): Promise<void>;
export declare function disableLiveReload(addinId: string): Promise<void>;
export declare function disableRuntimeLogging(): Promise<void>;
export declare function enableDebugging(addinId: string, enable?: boolean, method?: DebuggingMethod, openDevTools?: boolean): Promise<void>;
export declare function enableLiveReload(addinId: string, enable?: boolean): Promise<void>;
export declare function enableRuntimeLogging(path?: string): Promise<string>;
/**
* Returns the manifest paths for the add-ins that are registered
*/
export declare function getRegisteredAddIns(): Promise<RegisteredAddin[]>;
export declare function getEnabledDebuggingMethods(addinId: string): Promise<DebuggingMethod[]>;
export declare function getOpenDevTools(addinId: string): Promise<boolean>;
export declare function getRuntimeLoggingPath(): Promise<string | undefined>;
export declare function getSourceBundleUrl(addinId: string): Promise<SourceBundleUrlComponents>;
export declare function getWebView(addinId: string): Promise<WebViewType | undefined>;
export declare function isDebuggingEnabled(addinId: string): Promise<boolean>;
export declare function isLiveReloadEnabled(addinId: string): Promise<boolean>;
export declare function registerAddIn(manifestPath: string, registration?: string): Promise<void>;
export declare function setSourceBundleUrl(addinId: string, components: SourceBundleUrlComponents): Promise<void>;
export declare function setWebView(addinId: string, webViewType: WebViewType | undefined): Promise<void>;
export declare function unregisterAddIn(manifestPath: string): Promise<void>;
export declare function unregisterAllAddIns(): Promise<void>;
+306
View File
@@ -0,0 +1,306 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.unregisterAllAddIns = exports.unregisterAddIn = exports.setWebView = exports.setSourceBundleUrl = exports.registerAddIn = exports.isLiveReloadEnabled = exports.isDebuggingEnabled = exports.getWebView = exports.getSourceBundleUrl = exports.getRuntimeLoggingPath = exports.getOpenDevTools = exports.getEnabledDebuggingMethods = exports.getRegisteredAddIns = exports.enableRuntimeLogging = exports.enableLiveReload = exports.enableDebugging = exports.disableRuntimeLogging = exports.disableLiveReload = exports.disableDebugging = exports.clearDevSettings = exports.SourceBundleUrlComponents = exports.RegisteredAddin = exports.WebViewType = exports.DebuggingMethod = exports.toWebViewTypeName = void 0;
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const office_addin_manifest_1 = require("office-addin-manifest");
const path_1 = tslib_1.__importDefault(require("path"));
const devSettingsMac = tslib_1.__importStar(require("./dev-settings-mac"));
const devSettingsWindows = tslib_1.__importStar(require("./dev-settings-windows"));
const office_addin_usage_data_1 = require("office-addin-usage-data");
/* global process */
const defaultRuntimeLogFileName = "OfficeAddins.log.txt";
var dev_settings_windows_1 = require("./dev-settings-windows");
Object.defineProperty(exports, "toWebViewTypeName", { enumerable: true, get: function () { return dev_settings_windows_1.toWebViewTypeName; } });
var DebuggingMethod;
(function (DebuggingMethod) {
DebuggingMethod[DebuggingMethod["Direct"] = 0] = "Direct";
DebuggingMethod[DebuggingMethod["Proxy"] = 1] = "Proxy";
/** @deprecated use Proxy */
DebuggingMethod[DebuggingMethod["Web"] = 1] = "Web";
})(DebuggingMethod = exports.DebuggingMethod || (exports.DebuggingMethod = {}));
var WebViewType;
(function (WebViewType) {
WebViewType["Default"] = "Default";
WebViewType["IE"] = "IE";
WebViewType["Edge"] = "Edge";
WebViewType["EdgeChromium"] = "Edge Chromium";
})(WebViewType = exports.WebViewType || (exports.WebViewType = {}));
class RegisteredAddin {
constructor(id, manifestPath) {
this.id = id;
this.manifestPath = manifestPath;
}
}
exports.RegisteredAddin = RegisteredAddin;
class SourceBundleUrlComponents {
get url() {
const host = this.host !== undefined ? this.host : "localhost";
const port = this.port !== undefined ? this.port : "8081";
const path = this.path !== undefined ? this.path : "{path}";
const extension = this.extension !== undefined ? this.extension : ".bundle";
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
return `http://${host}${host && port ? ":" : ""}${port}/${path}${extension}`;
}
constructor(host, port, path, extension) {
this.host = host;
this.port = port;
this.path = path;
this.extension = extension;
}
}
exports.SourceBundleUrlComponents = SourceBundleUrlComponents;
function clearDevSettings(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.clearDevSettings(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.clearDevSettings = clearDevSettings;
function disableDebugging(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return enableDebugging(addinId, false);
});
}
exports.disableDebugging = disableDebugging;
function disableLiveReload(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return enableLiveReload(addinId, false);
});
}
exports.disableLiveReload = disableLiveReload;
function disableRuntimeLogging() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.disableRuntimeLogging();
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.disableRuntimeLogging = disableRuntimeLogging;
function enableDebugging(addinId, enable = true, method = DebuggingMethod.Direct, openDevTools = false) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.enableDebugging(addinId, enable, method, openDevTools);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.enableDebugging = enableDebugging;
function enableLiveReload(addinId, enable = true) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.enableLiveReload(addinId, enable);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.enableLiveReload = enableLiveReload;
function enableRuntimeLogging(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32": {
if (!path) {
const tempDir = process.env.TEMP;
if (!tempDir) {
throw new office_addin_usage_data_1.ExpectedError("The TEMP environment variable is not defined.");
}
path = path_1.default.normalize(`${tempDir}/${defaultRuntimeLogFileName}`);
}
const pathExists = fs_1.default.existsSync(path);
if (pathExists) {
const stat = fs_1.default.statSync(path);
if (stat.isDirectory()) {
throw new office_addin_usage_data_1.ExpectedError(`You need to specify the path to a file. This is a directory: "${path}".`);
}
}
try {
const file = fs_1.default.openSync(path, "a+");
fs_1.default.closeSync(file);
}
catch (_a) {
throw new office_addin_usage_data_1.ExpectedError(pathExists
? `You need to specify the path to a writable file. Unable to write to: "${path}".`
: `You need to specify the path where the file can be written. Unable to write to: "${path}".`);
}
yield devSettingsWindows.enableRuntimeLogging(path);
return path;
}
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.enableRuntimeLogging = enableRuntimeLogging;
/**
* Returns the manifest paths for the add-ins that are registered
*/
function getRegisteredAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "darwin":
return devSettingsMac.getRegisteredAddIns();
case "win32":
return devSettingsWindows.getRegisteredAddIns();
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getRegisteredAddIns = getRegisteredAddIns;
function getEnabledDebuggingMethods(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.getEnabledDebuggingMethods(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getEnabledDebuggingMethods = getEnabledDebuggingMethods;
function getOpenDevTools(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.getOpenDevTools(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getOpenDevTools = getOpenDevTools;
function getRuntimeLoggingPath() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.getRuntimeLoggingPath();
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getRuntimeLoggingPath = getRuntimeLoggingPath;
function getSourceBundleUrl(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.getSourceBundleUrl(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getSourceBundleUrl = getSourceBundleUrl;
function getWebView(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.getWebView(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.getWebView = getWebView;
function isDebuggingEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.isDebuggingEnabled(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.isDebuggingEnabled = isDebuggingEnabled;
function isLiveReloadEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.isLiveReloadEnabled(addinId);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.isLiveReloadEnabled = isLiveReloadEnabled;
function registerAddIn(manifestPath, registration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32": {
const realManifestPath = fs_1.default.realpathSync(manifestPath);
return devSettingsWindows.registerAddIn(realManifestPath, registration);
}
case "darwin":
return devSettingsMac.registerAddIn(manifestPath);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.registerAddIn = registerAddIn;
function setSourceBundleUrl(addinId, components) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.setSourceBundleUrl(addinId, components);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.setSourceBundleUrl = setSourceBundleUrl;
function setWebView(addinId, webViewType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "win32":
return devSettingsWindows.setWebView(addinId, webViewType);
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.setWebView = setWebView;
function unregisterAddIn(manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
switch (process.platform) {
case "darwin":
return devSettingsMac.unregisterAddIn(manifest.id || "", manifestPath);
case "win32": {
const realManifestPath = fs_1.default.realpathSync(manifestPath);
return devSettingsWindows.unregisterAddIn(manifest.id || "", realManifestPath);
}
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.unregisterAddIn = unregisterAddIn;
function unregisterAllAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
switch (process.platform) {
case "darwin":
return devSettingsMac.unregisterAllAddIns();
case "win32":
return devSettingsWindows.unregisterAllAddIns();
default:
throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`);
}
});
}
exports.unregisterAllAddIns = unregisterAllAddIns;
//# sourceMappingURL=dev-settings.js.map
File diff suppressed because one or more lines are too long
+7
View File
@@ -0,0 +1,7 @@
export * from "./appcontainer";
export * from "./appType";
export * from "./dev-settings";
export * from "./process";
export * from "./sideload";
export { parseWebViewType } from "./commands";
export { updateM365Account } from "./publish";
+16
View File
@@ -0,0 +1,16 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateM365Account = exports.parseWebViewType = void 0;
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./appcontainer"), exports);
tslib_1.__exportStar(require("./appType"), exports);
tslib_1.__exportStar(require("./dev-settings"), exports);
tslib_1.__exportStar(require("./process"), exports);
tslib_1.__exportStar(require("./sideload"), exports);
var commands_1 = require("./commands");
Object.defineProperty(exports, "parseWebViewType", { enumerable: true, get: function () { return commands_1.parseWebViewType; } });
var publish_1 = require("./publish");
Object.defineProperty(exports, "updateM365Account", { enumerable: true, get: function () { return publish_1.updateM365Account; } });
//# sourceMappingURL=main.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,yDAA+B;AAC/B,oDAA0B;AAC1B,yDAA+B;AAC/B,oDAA0B;AAC1B,qDAA2B;AAC3B,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AACzB,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA"}
+5
View File
@@ -0,0 +1,5 @@
/// <reference types="node" />
import { ChildProcess } from "child_process";
export declare function startProcess(commandLine: string, verbose?: boolean): Promise<void>;
export declare function startDetachedProcess(commandLine: string, verbose?: boolean): ChildProcess;
export declare function stopProcess(processId: number): void;
+60
View File
@@ -0,0 +1,60 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.stopProcess = exports.startDetachedProcess = exports.startProcess = void 0;
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
/* global console process */
function startProcess(commandLine, verbose = false) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if (verbose) {
console.log(`Starting: ${commandLine}`);
}
child_process_1.default.exec(commandLine, (error, stdout /* eslint-disable-line @typescript-eslint/no-unused-vars */, stderr /* eslint-disable-line @typescript-eslint/no-unused-vars */) => {
if (error) {
reject(error);
}
else {
resolve();
}
});
});
});
}
exports.startProcess = startProcess;
function startDetachedProcess(commandLine, verbose = false) {
if (verbose) {
console.log(`Starting: ${commandLine}`);
}
const subprocess = child_process_1.default.spawn(commandLine, [], {
detached: true,
shell: true,
stdio: "ignore",
windowsHide: false,
});
subprocess.on("error", (err) => {
console.log(`Unable to run command: ${commandLine}.\n${err}`);
});
subprocess.unref();
return subprocess;
}
exports.startDetachedProcess = startDetachedProcess;
function stopProcess(processId) {
if (processId) {
try {
if (process.platform === "win32") {
child_process_1.default.spawn("taskkill", ["/pid", `${processId}`, "/f", "/t"]);
}
else {
process.kill(processId);
}
}
catch (err) {
console.log(`Unable to kill process id ${processId}: ${err}`);
}
}
}
exports.stopProcess = stopProcess;
//# sourceMappingURL=process.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,0EAAyC;AAGzC,4BAA4B;AAE5B,SAAsB,YAAY,CAAC,WAAmB,EAAE,UAAmB,KAAK;;QAC9E,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,aAAa,WAAW,EAAE,CAAC,CAAC;aACzC;YAED,uBAAY,CAAC,IAAI,CACf,WAAW,EACX,CACE,KAA2B,EAC3B,MAAc,CAAC,2DAA2D,EAC1E,MAAc,CAAC,2DAA2D,EAC1E,EAAE;gBACF,IAAI,KAAK,EAAE;oBACT,MAAM,CAAC,KAAK,CAAC,CAAC;iBACf;qBAAM;oBACL,OAAO,EAAE,CAAC;iBACX;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AArBD,oCAqBC;AAED,SAAgB,oBAAoB,CAAC,WAAmB,EAAE,UAAmB,KAAK;IAChF,IAAI,OAAO,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,aAAa,WAAW,EAAE,CAAC,CAAC;KACzC;IAED,MAAM,UAAU,GAAG,uBAAY,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,EAAE;QACrD,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;IAEH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC7B,OAAO,CAAC,GAAG,CAAC,0BAA0B,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,OAAO,UAAU,CAAC;AACpB,CAAC;AAlBD,oDAkBC;AAED,SAAgB,WAAW,CAAC,SAAiB;IAC3C,IAAI,SAAS,EAAE;QACb,IAAI;YACF,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;gBAChC,uBAAY,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;aACtE;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACzB;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,GAAG,CAAC,6BAA6B,SAAS,KAAK,GAAG,EAAE,CAAC,CAAC;SAC/D;KACF;AACH,CAAC;AAZD,kCAYC"}
+2
View File
@@ -0,0 +1,2 @@
import { OfficeApp } from "office-addin-manifest";
export declare function chooseOfficeApp(apps: OfficeApp[]): Promise<OfficeApp>;
+28
View File
@@ -0,0 +1,28 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.chooseOfficeApp = void 0;
const tslib_1 = require("tslib");
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const office_addin_manifest_1 = require("office-addin-manifest");
function chooseOfficeApp(apps) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const questionName = "app";
const question = {
choices: apps
.map((app) => {
return { name: (0, office_addin_manifest_1.getOfficeAppName)(app), value: app };
})
.sort((first, second) => first.name.localeCompare(second.name)),
message: "Which Office app?",
name: questionName,
type: "list",
};
const answer = yield inquirer_1.default.prompt([question]);
const choice = answer[questionName];
return choice;
});
}
exports.chooseOfficeApp = chooseOfficeApp;
//# sourceMappingURL=prompt.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,gEAAgC;AAChC,iEAAoE;AAEpE,SAAsB,eAAe,CAAC,IAAiB;;QACrD,MAAM,YAAY,GAAG,KAAK,CAAC;QAC3B,MAAM,QAAQ,GAAmD;YAC/D,OAAO,EAAE,IAAI;iBACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;gBACX,OAAO,EAAE,IAAI,EAAE,IAAA,wCAAgB,EAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;YACrD,CAAC,CAAC;iBACD,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjE,OAAO,EAAE,mBAAmB;YAC5B,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,MAAM;SACb,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjD,MAAM,MAAM,GAAc,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAhBD,0CAgBC"}
+4
View File
@@ -0,0 +1,4 @@
export type AccountOperation = "login" | "logout";
export declare function registerWithTeams(filePath: string): Promise<string>;
export declare function updateM365Account(operation: AccountOperation): Promise<void>;
export declare function uninstallWithTeams(id: string): Promise<boolean>;
+89
View File
@@ -0,0 +1,89 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.uninstallWithTeams = exports.updateM365Account = exports.registerWithTeams = void 0;
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const fs_1 = tslib_1.__importDefault(require("fs"));
function registerWithTeams(filePath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
if ((filePath.endsWith(".zip") || filePath.endsWith(".xml")) && fs_1.default.existsSync(filePath)) {
const pathSwitch = filePath.endsWith(".zip") ? "--file-path" : "--xml-path";
const sideloadCommand = `npx @microsoft/teamsapp-cli install ${pathSwitch} "${filePath}" --interactive false`;
console.log(`running: ${sideloadCommand}`);
child_process_1.default.exec(sideloadCommand, (error, stdout, stderr) => {
let titleIdMatch = stdout.match(/TitleId:\s*(.*)/);
let titleId = titleIdMatch !== null ? titleIdMatch[1] : "??";
if (error || stderr.match('"error"')) {
console.log(`\n${stdout}\n--Error sideloading!--\nError: ${error}\nSTDERR:\n${stderr}`);
reject(error);
}
else {
console.log(`\n${stdout}\nSuccessfully registered package! (${titleId})\n STDERR: ${stderr}\n`);
resolve(titleId);
}
});
}
else {
reject(new Error(`The file '${filePath}' is not valid`));
}
});
});
}
exports.registerWithTeams = registerWithTeams;
function updateM365Account(operation) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const authCommand = `npx @microsoft/teamsapp-cli auth ${operation} m365`;
console.log(`running: ${authCommand}`);
child_process_1.default.exec(authCommand, (error, stdout, stderr) => {
if (error || (stderr.length > 0 && /Debugger attached\./.test(stderr) == false)) {
console.log(`Error running auth command\n STDOUT: ${stdout}\n ERROR: ${error}\n STDERR: ${stderr}`);
reject(error);
}
else {
console.log(`Successfully ran auth command.\n`);
resolve();
}
});
});
});
}
exports.updateM365Account = updateM365Account;
function uninstallWithTeams(id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const guidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/;
const manifestIdRegex = new RegExp(`^${guidRegex.source}$`);
const titleIdRegex = new RegExp(`^U_${guidRegex.source}$`);
let mode = "";
if (titleIdRegex.test(id)) {
mode = `--mode title-id --title-id ${id}`;
}
else if (manifestIdRegex.test(id)) {
mode = `--mode manifest-id --manifest-id ${id}`;
}
else {
console.error(`Error: Invalid id "${id}". Add-in is still installed.`);
resolve(false);
return;
}
const uninstallCommand = `npx @microsoft/teamsapp-cli uninstall ${mode} --interactive false`;
console.log(`running: ${uninstallCommand}`);
child_process_1.default.exec(uninstallCommand, (error, stdout, stderr) => {
if (error || stderr.match('"error"')) {
console.log(`\n${stdout}\n--Error uninstalling!--\n${error}\n STDERR: ${stderr}`);
reject(error);
}
else {
console.log(`\n${stdout}\nSuccessfully uninstalled!\n STDERR: ${stderr}\n`);
resolve(true);
}
});
});
});
}
exports.uninstallWithTeams = uninstallWithTeams;
//# sourceMappingURL=publish.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC,0EAAyC;AACzC,oDAAoB;AAMpB,SAAsB,iBAAiB,CAAC,QAAgB;;QACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,YAAE,CAAC,UAAU,CAAC,QAA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OAAO;aACR;YAED,MAAM,gBAAgB,GAAG,yCAAyC,IAAI,sBAAsB,CAAC;YAC7F,OAAO,CAAC,GAAG,CAAC,YAAY,gBAAgB,EAAE,CAAC,CAAC;YAC5C,uBAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBAC5D,IAAI,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;oBACpC,OAAO,CAAC,GAAG,CAAC,KAAK,MAAM,8BAA8B,KAAK,cAAc,MAAM,EAAE,CAAC,CAAC;oBAClF,MAAM,CAAC,KAAK,CAAC,CAAC;iBACf;qBAAM;oBACL,OAAO,CAAC,GAAG,CAAC,KAAK,MAAM,yCAAyC,MAAM,IAAI,CAAC,CAAC;oBAC5E,OAAO,CAAC,IAAI,CAAC,CAAC;iBACf;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AA7BD,gDA6BC"}
+37
View File
@@ -0,0 +1,37 @@
import winreg from "winreg";
export declare class RegistryKey {
winreg: winreg.Registry;
get path(): string;
constructor(path: string);
}
export declare class RegistryTypes {
static readonly REG_BINARY: string;
static readonly REG_DWORD: string;
static readonly REG_EXPAND_SZ: string;
static readonly REG_MULTI_SZ: string;
static readonly REG_NONE: string;
static readonly REG_QWORD: string;
static readonly REG_SZ: string;
}
export declare class RegistryValue {
key: string;
name: string;
type: string;
data: string;
get isNumberType(): boolean;
get isStringType(): boolean;
constructor(key: string, name: string, type: string, data: string);
}
export declare function addBooleanValue(key: RegistryKey, value: string, data: boolean): Promise<void>;
export declare function addNumberValue(key: RegistryKey, value: string, data: number): Promise<void>;
export declare function addStringValue(key: RegistryKey, value: string, data: string): Promise<void>;
export declare function deleteKey(key: RegistryKey): Promise<void>;
export declare function deleteValue(key: RegistryKey, value: string): Promise<void>;
export declare function doesKeyExist(key: RegistryKey): Promise<boolean>;
export declare function doesValueExist(key: RegistryKey, value: string): Promise<boolean>;
export declare function getNumberValue(key: RegistryKey, value: string): Promise<number | undefined>;
export declare function getStringValue(key: RegistryKey, value: string): Promise<string | undefined>;
export declare function getValue(key: RegistryKey, value: string): Promise<RegistryValue | undefined>;
export declare function getValues(key: RegistryKey): Promise<RegistryValue[]>;
export declare function isNumberType(registryType: string): boolean;
export declare function isStringType(registryType: string): boolean;
+279
View File
@@ -0,0 +1,279 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.isStringType = exports.isNumberType = exports.getValues = exports.getValue = exports.getStringValue = exports.getNumberValue = exports.doesValueExist = exports.doesKeyExist = exports.deleteValue = exports.deleteKey = exports.addStringValue = exports.addNumberValue = exports.addBooleanValue = exports.RegistryValue = exports.RegistryTypes = exports.RegistryKey = void 0;
const tslib_1 = require("tslib");
const winreg_1 = tslib_1.__importDefault(require("winreg"));
const office_addin_usage_data_1 = require("office-addin-usage-data");
class RegistryKey {
get path() {
return this.winreg.path;
}
constructor(path) {
if (!path) {
throw new office_addin_usage_data_1.ExpectedError("Please provide a registry key path.");
}
const index = path.indexOf("\\");
if (index <= 0) {
throw new office_addin_usage_data_1.ExpectedError(`The registry key path is not valid: "${path}".`);
}
const hive = path.substring(0, index);
const subpath = path.substring(index);
this.winreg = new winreg_1.default({
hive: normalizeRegistryHive(hive),
key: subpath,
});
}
}
exports.RegistryKey = RegistryKey;
class RegistryTypes {
}
exports.RegistryTypes = RegistryTypes;
RegistryTypes.REG_BINARY = winreg_1.default.REG_BINARY;
RegistryTypes.REG_DWORD = winreg_1.default.REG_DWORD;
RegistryTypes.REG_EXPAND_SZ = winreg_1.default.REG_EXPAND_SZ;
RegistryTypes.REG_MULTI_SZ = winreg_1.default.REG_MULTI_SZ;
RegistryTypes.REG_NONE = winreg_1.default.REG_NONE;
RegistryTypes.REG_QWORD = winreg_1.default.REG_QWORD;
RegistryTypes.REG_SZ = winreg_1.default.REG_SZ;
class RegistryValue {
get isNumberType() {
return isNumberType(this.type);
}
get isStringType() {
return isStringType(this.type);
}
constructor(key, name, type, data) {
this.key = key;
this.name = name;
this.type = type;
this.data = data;
}
}
exports.RegistryValue = RegistryValue;
function addValue(key, value, type, data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const onError = (err) => {
if (err) {
reject(new Error(`Unable to set registry value "${value}" to "${data}" (${type}) for key "${key.path}".\n${err}`));
}
else {
resolve();
}
};
try {
key.winreg.set(value, type, data, onError);
}
catch (err) {
onError(err);
}
});
});
}
function addBooleanValue(key, value, data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return addValue(key, value, winreg_1.default.REG_DWORD, data ? "1" : "0");
});
}
exports.addBooleanValue = addBooleanValue;
function addNumberValue(key, value, data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return addValue(key, value, winreg_1.default.REG_DWORD, data.toString());
});
}
exports.addNumberValue = addNumberValue;
function addStringValue(key, value, data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return addValue(key, value, winreg_1.default.REG_SZ, data);
});
}
exports.addStringValue = addStringValue;
function deleteKey(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const onError = (err) => {
if (err) {
reject(new Error(`Unable to delete registry key "${key.path}".\n${err}`));
}
else {
resolve();
}
};
try {
key.winreg.keyExists((keyExistsError, exists) => {
if (exists) {
key.winreg.destroy(onError);
}
else {
onError(keyExistsError);
}
});
}
catch (err) {
onError(err);
}
});
});
}
exports.deleteKey = deleteKey;
function deleteValue(key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const onError = (err) => {
if (err) {
reject(new Error(`Unable to delete registry value "${value}" in key "${key.path}".\n${err}`));
}
else {
resolve();
}
};
try {
key.winreg.valueExists(value, (_, exists) => {
if (exists) {
key.winreg.remove(value, onError);
}
else {
resolve();
}
});
}
catch (err) {
onError(err);
}
});
});
}
exports.deleteValue = deleteValue;
function doesKeyExist(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const onError = (err, exists = false) => {
if (err) {
reject(new Error(`Unable to determine if registry key exists: "${key.path}".\n${err}`));
}
else {
resolve(exists);
}
};
try {
key.winreg.keyExists(onError);
}
catch (err) {
onError(err);
}
});
});
}
exports.doesKeyExist = doesKeyExist;
function doesValueExist(key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const onError = (err, exists = false) => {
if (err) {
reject(new Error(`Unable to determine if registry value "${value}" exists for key "${key.path}".\n${err}`));
}
else {
resolve(exists);
}
};
try {
key.winreg.valueExists(value, onError);
}
catch (err) {
onError(err);
}
});
});
}
exports.doesValueExist = doesValueExist;
function getNumberValue(key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registryValue = yield getValue(key, value);
return registryValue && registryValue.isNumberType
? parseInt(registryValue.data, undefined)
: undefined;
});
}
exports.getNumberValue = getNumberValue;
function getStringValue(key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registryValue = yield getValue(key, value);
return registryValue && registryValue.isStringType ? registryValue.data : undefined;
});
}
exports.getStringValue = getStringValue;
function getValue(key, value) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve) => {
const onError = (err, item) => {
if (err) {
resolve(undefined);
}
else {
resolve(item ? new RegistryValue(key.path, item.name, item.type, item.value) : undefined);
}
};
try {
key.winreg.get(value, onError);
}
catch (err) {
onError(err);
}
});
});
}
exports.getValue = getValue;
function getValues(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const callback = (err, items) => {
if (err) {
reject(err);
}
else {
resolve(items.map((item) => new RegistryValue(key.path, item.name, item.type, item.value)));
}
};
try {
key.winreg.values(callback);
}
catch (err) {
reject(err);
}
});
});
}
exports.getValues = getValues;
function isNumberType(registryType) {
// NOTE: REG_QWORD is not included as a number type since it cannot be returned as a "number".
return registryType === RegistryTypes.REG_DWORD;
}
exports.isNumberType = isNumberType;
function isStringType(registryType) {
switch (registryType) {
case RegistryTypes.REG_SZ:
return true;
default:
return false;
}
}
exports.isStringType = isStringType;
function normalizeRegistryHive(hive) {
switch (hive) {
case "HKEY_CURRENT_USER":
return winreg_1.default.HKCU;
case "HKEY_LOCAL_MACHINE":
return winreg_1.default.HKLM;
case "HKEY_CLASSES_ROOT":
return winreg_1.default.HKCR;
case "HKEY_CURRENT_CONFIG":
return winreg_1.default.HKCC;
case "HKEY_USERS":
return winreg_1.default.HKU;
default:
return hive;
}
}
//# sourceMappingURL=registry.js.map
File diff suppressed because one or more lines are too long
+33
View File
@@ -0,0 +1,33 @@
import { AddInType, ManifestInfo, OfficeApp } from "office-addin-manifest";
import { AppType } from "./appType";
/**
* Create an Office document in the temporary files directory
* which can be opened to launch the Office app and load the add-in.
* @param app Office app
* @param manifest Manifest for the add-in.
* @returns Path to the file.
*/
export declare function generateSideloadFile(app: OfficeApp, manifest: ManifestInfo, document?: string): Promise<string>;
/**
* Create an Office document url with query params which can be opened
* to register an Office add-in in Office Online.
* @param manifestPath Path to the manifest file for the Office Add-in.
* @param documentUrl Office Online document url
* @param isTest Indicates whether to append test query param to suppress Office Online dialogs.
* @returns Document url with query params appended.
*/
export declare function generateSideloadUrl(manifestFileName: string, manifest: ManifestInfo, documentUrl: string, isTest?: boolean): Promise<string>;
/**
* Returns the path to the document used as a template for sideloading,
* or undefined if sideloading is not supported.
* @param app Specifies the Office app.
* @param addInType Specifies the type of add-in.
*/
export declare function getTemplatePath(app: OfficeApp, addInType: AddInType): string | undefined;
/**
* Starts the Office app and loads the Office Add-in.
* @param manifestPath Path to the manifest file for the Office Add-in.
* @param app Office app to launch.
* @param canPrompt
*/
export declare function sideloadAddIn(manifestPath: string, app?: OfficeApp, canPrompt?: boolean, appType?: AppType, document?: string, registration?: string): Promise<void>;
+366
View File
@@ -0,0 +1,366 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.sideloadAddIn = exports.getTemplatePath = exports.generateSideloadUrl = exports.generateSideloadFile = void 0;
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const adm_zip_1 = tslib_1.__importDefault(require("adm-zip"));
const office_addin_manifest_1 = require("office-addin-manifest");
const open = require("open");
const semver = require("semver");
const os_1 = tslib_1.__importDefault(require("os"));
const path_1 = tslib_1.__importDefault(require("path"));
const appType_1 = require("./appType");
const dev_settings_1 = require("./dev-settings");
const process_1 = require("./process");
const prompt_1 = require("./prompt");
const registry = tslib_1.__importStar(require("./registry"));
const defaults_1 = require("./defaults");
const office_addin_usage_data_1 = require("office-addin-usage-data");
/* global Buffer console process URL __dirname */
/**
* Create an Office document in the temporary files directory
* which can be opened to launch the Office app and load the add-in.
* @param app Office app
* @param manifest Manifest for the add-in.
* @returns Path to the file.
*/
function generateSideloadFile(app, manifest, document) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!manifest.id) {
throw new office_addin_usage_data_1.ExpectedError("The manifest does not contain the id for the add-in.");
}
if (!manifest.officeAppType) {
throw new office_addin_usage_data_1.ExpectedError("The manifest does not contain the OfficeApp xsi:type.");
}
if (!manifest.version) {
throw new office_addin_usage_data_1.ExpectedError("The manifest does not contain the version for the add-in.");
}
const addInType = (0, office_addin_manifest_1.getAddInTypeForManifestOfficeAppType)(manifest.officeAppType);
if (!addInType) {
throw new office_addin_usage_data_1.ExpectedError("The manifest contains an unsupported OfficeApp xsi:type.");
}
const documentWasProvided = document && document !== "";
const templatePath = documentWasProvided
? path_1.default.resolve(document)
: getTemplatePath(app, addInType);
if (!templatePath) {
throw new office_addin_usage_data_1.ExpectedError(`Sideload is not supported for apptype: ${addInType}.`);
}
const appName = (0, office_addin_manifest_1.getOfficeAppName)(app);
const extension = path_1.default.extname(templatePath);
const pathToWrite = makePathUnique(path_1.default.join(os_1.default.tmpdir(), `${appName} add-in ${manifest.id}${extension}`), true);
if (!documentWasProvided) {
const webExtensionPath = getWebExtensionPath(app, addInType);
if (!webExtensionPath) {
throw new office_addin_usage_data_1.ExpectedError("Don't know the webextension path.");
}
// replace the placeholder id and version
const templateZip = new adm_zip_1.default(templatePath);
const outZip = new adm_zip_1.default();
const extEntry = templateZip.getEntry(webExtensionPath);
if (!extEntry) {
throw new office_addin_usage_data_1.ExpectedError("webextension was not found.");
}
const webExtensionXml = templateZip
.readAsText(extEntry)
.replace(/00000000-0000-0000-0000-000000000000/g, manifest.id)
.replace(/1.0.0.0/g, manifest.version);
const webExtensionFolderPath = webExtensionPath.substring(0, webExtensionPath.lastIndexOf("/"));
templateZip.getEntries().forEach(function (entry) {
var data = entry.getData();
if (entry == extEntry && manifest.manifestType == office_addin_manifest_1.ManifestType.XML) {
data = Buffer.from(webExtensionXml);
}
// If manifestType is JSON, remove the web extension folder
if (!entry.entryName.startsWith(webExtensionFolderPath) ||
manifest.manifestType !== office_addin_manifest_1.ManifestType.JSON) {
outZip.addFile(entry.entryName, data, entry.comment, entry.attr);
}
});
// Write the file
yield outZip.writeZipPromise(pathToWrite);
}
else {
yield fs_1.default.promises.copyFile(templatePath, pathToWrite);
}
return pathToWrite;
});
}
exports.generateSideloadFile = generateSideloadFile;
/**
* Create an Office document url with query params which can be opened
* to register an Office add-in in Office Online.
* @param manifestPath Path to the manifest file for the Office Add-in.
* @param documentUrl Office Online document url
* @param isTest Indicates whether to append test query param to suppress Office Online dialogs.
* @returns Document url with query params appended.
*/
function generateSideloadUrl(manifestFileName, manifest, documentUrl, isTest = false) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const testQueryParam = "&wdaddintest=true";
if (!manifest.id) {
throw new office_addin_usage_data_1.ExpectedError("The manifest does not contain the id for the add-in.");
}
if (manifest.defaultSettings === undefined ||
manifest.defaultSettings.sourceLocation === undefined) {
throw new office_addin_usage_data_1.ExpectedError("The manifest does not contain the SourceLocation for the add-in");
}
const sourceLocationUrl = new URL(manifest.defaultSettings.sourceLocation);
if (sourceLocationUrl.protocol.indexOf("https") === -1) {
throw new office_addin_usage_data_1.ExpectedError("The SourceLocation in the manifest does not use the HTTPS protocol.");
}
if (sourceLocationUrl.host.indexOf("localhost") === -1 &&
sourceLocationUrl.host.indexOf("127.0.0.1") === -1) {
throw new office_addin_usage_data_1.ExpectedError("The hostname specified by the SourceLocation in the manifest is not supported for sideload. The hostname should be 'localhost' or 127.0.0.1.");
}
let queryParms = `&wdaddindevserverport=${sourceLocationUrl.port}&wdaddinmanifestfile=${manifestFileName}&wdaddinmanifestguid=${manifest.id}`;
if (isTest) {
queryParms = `${queryParms}${testQueryParam}`;
}
return `${documentUrl}${queryParms}`;
});
}
exports.generateSideloadUrl = generateSideloadUrl;
/**
* Returns the path to the document used as a template for sideloading,
* or undefined if sideloading is not supported.
* @param app Specifies the Office app.
* @param addInType Specifies the type of add-in.
*/
function getTemplatePath(app, addInType) {
switch (app) {
case office_addin_manifest_1.OfficeApp.Excel:
switch (addInType) {
case office_addin_manifest_1.AddInType.Content:
return path_1.default.resolve(__dirname, "../templates/ExcelWorkbookWithContent.xlsx");
case office_addin_manifest_1.AddInType.TaskPane:
return path_1.default.resolve(__dirname, "../templates/ExcelWorkbookWithTaskPane.xlsx");
}
break;
case office_addin_manifest_1.OfficeApp.PowerPoint:
switch (addInType) {
case office_addin_manifest_1.AddInType.Content:
return path_1.default.resolve(__dirname, "../templates/PowerPointPresentationWithContent.pptx");
case office_addin_manifest_1.AddInType.TaskPane:
return path_1.default.resolve(__dirname, "../templates/PowerPointPresentationWithTaskPane.pptx");
}
break;
case office_addin_manifest_1.OfficeApp.Word:
switch (addInType) {
case office_addin_manifest_1.AddInType.TaskPane:
return path_1.default.resolve(__dirname, "../templates/WordDocumentWithTaskPane.docx");
}
break;
}
}
exports.getTemplatePath = getTemplatePath;
/**
* Returns the web extension path in the sideload document.
* @param app Specifies the Office app.
* @param addInType Specifies the type of add-in.
*/
function getWebExtensionPath(app, addInType) {
switch (app) {
case office_addin_manifest_1.OfficeApp.Excel:
return "xl/webextensions/webextension.xml";
case office_addin_manifest_1.OfficeApp.PowerPoint:
switch (addInType) {
case office_addin_manifest_1.AddInType.Content:
return "ppt/slides/udata/data.xml";
case office_addin_manifest_1.AddInType.TaskPane:
return "ppt/webextensions/webextension.xml";
}
break;
case office_addin_manifest_1.OfficeApp.Word:
return "word/webextensions/webextension.xml";
}
}
function isSideloadingSupportedForDesktopHost(app) {
if (app === office_addin_manifest_1.OfficeApp.Excel ||
(app === office_addin_manifest_1.OfficeApp.Outlook && process.platform === "win32") ||
app === office_addin_manifest_1.OfficeApp.PowerPoint ||
app === office_addin_manifest_1.OfficeApp.Word) {
return true;
}
return false;
}
function isSideloadingSupportedForWebHost(app) {
if (app === office_addin_manifest_1.OfficeApp.Excel ||
app === office_addin_manifest_1.OfficeApp.PowerPoint ||
app === office_addin_manifest_1.OfficeApp.Project ||
app === office_addin_manifest_1.OfficeApp.Word) {
return true;
}
return false;
}
function hasOfficeVersion(targetVersion, currentVersion) {
return semver.gte(currentVersion, targetVersion);
}
function getOutlookVersion() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const key = new registry.RegistryKey(`HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\ClickToRun\\Configuration`);
const outlookInstallVersion = yield registry.getStringValue(key, "ClientVersionToReport");
const outlookSmallerVersion = outlookInstallVersion === null || outlookInstallVersion === void 0 ? void 0 : outlookInstallVersion.split(`.`, 3).join(`.`);
return outlookSmallerVersion;
}
catch (_a) {
return undefined;
}
});
}
function getOutlookExePath() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const OutlookInstallPathRegistryKey = `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.EXE`;
const key = new registry.RegistryKey(`${OutlookInstallPathRegistryKey}`);
const outlookExePath = yield registry.getStringValue(key, "");
if (!outlookExePath) {
throw new Error("Outlook.exe registry empty");
}
return outlookExePath;
}
catch (err) {
const errorMessage = `Unable to find Outlook install location: \n${err}`;
throw new Error(errorMessage);
}
});
}
/**
* Given a file path, returns a unique file path where the file doesn't exist by
* appending a period and a numeric suffix, starting from 2.
* @param tryToDelete If true, first try to delete the file if it exists.
*/
function makePathUnique(originalPath, tryToDelete = false) {
let currentPath = originalPath;
let parsedPath = null;
let suffix = 1;
while (fs_1.default.existsSync(currentPath)) {
let deleted = false;
if (tryToDelete) {
try {
fs_1.default.unlinkSync(currentPath);
deleted = true;
}
catch (_a) {
// no error (file is in use)
}
}
if (!deleted) {
++suffix;
if (parsedPath == null) {
parsedPath = path_1.default.parse(originalPath);
}
currentPath = path_1.default.join(parsedPath.dir, `${parsedPath.name}.${suffix}${parsedPath.ext}`);
}
}
return currentPath;
}
/**
* Starts the Office app and loads the Office Add-in.
* @param manifestPath Path to the manifest file for the Office Add-in.
* @param app Office app to launch.
* @param canPrompt
*/
function sideloadAddIn(manifestPath, app, canPrompt = false, appType, document, registration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
if (appType === undefined) {
appType = appType_1.AppType.Desktop;
}
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const appsInManifest = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
if (app) {
if (appsInManifest.indexOf(app) < 0) {
throw new office_addin_usage_data_1.ExpectedError(`The Office Add-in manifest does not support ${(0, office_addin_manifest_1.getOfficeAppName)(app)}.`);
}
}
else {
switch (appsInManifest.length) {
case 0:
throw new office_addin_usage_data_1.ExpectedError("The manifest does not support any Office apps.");
case 1:
app = appsInManifest[0];
break;
default:
if (canPrompt) {
app = yield (0, prompt_1.chooseOfficeApp)(appsInManifest);
}
break;
}
}
if (!app) {
throw new office_addin_usage_data_1.ExpectedError("Please specify the Office app.");
}
switch (appType) {
case appType_1.AppType.Desktop:
yield (0, dev_settings_1.registerAddIn)(manifestPath, registration);
yield launchDesktopApp(app, manifest, document);
break;
case appType_1.AppType.Web: {
if (!document) {
throw new office_addin_usage_data_1.ExpectedError(`For sideload to web, you need to specify a document url.`);
}
yield launchWebApp(app, manifestPath, manifest, document);
break;
}
default:
throw new office_addin_usage_data_1.ExpectedError("Sideload is not supported for the specified app type.");
}
defaults_1.usageDataObject.reportSuccess("sideloadAddIn()");
}
catch (err) {
defaults_1.usageDataObject.reportException("sideloadAddIn()", err);
throw err;
}
});
}
exports.sideloadAddIn = sideloadAddIn;
function launchDesktopApp(app, manifest, document) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!isSideloadingSupportedForDesktopHost(app)) {
throw new office_addin_usage_data_1.ExpectedError(`Sideload to the ${(0, office_addin_manifest_1.getOfficeAppName)(app)} app is not supported.`);
}
// for Outlook, open Outlook.exe; for other Office apps, open the document
if (app == office_addin_manifest_1.OfficeApp.Outlook) {
const version = yield getOutlookVersion();
if (version && !hasOfficeVersion("16.0.13709", version)) {
throw new office_addin_usage_data_1.ExpectedError(`The current version of Outlook does not support sideload. Please use version 16.0.13709 or greater.`);
}
yield launchApp(app, yield getOutlookExePath());
}
else {
yield launchApp(app, yield generateSideloadFile(app, manifest, document));
}
});
}
function launchWebApp(app, manifestPath, manifest, document) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!isSideloadingSupportedForWebHost(app)) {
throw new office_addin_usage_data_1.ExpectedError(`Sideload to the ${(0, office_addin_manifest_1.getOfficeAppName)(app)} web app is not supported.`);
}
const manifestFileName = path_1.default.basename(manifestPath);
const isTest = process.env.WEB_SIDELOAD_TEST !== undefined;
yield launchApp(app, yield generateSideloadUrl(manifestFileName, manifest, document, isTest));
});
}
function launchApp(app, sideloadFile) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
console.log(`Launching ${app} via ${sideloadFile}`);
if (sideloadFile) {
if (app === office_addin_manifest_1.OfficeApp.Outlook) {
// put the Outlook.exe path in quotes if it contains spaces
if (sideloadFile.indexOf(" ") >= 0) {
sideloadFile = `"${sideloadFile}"`;
}
(0, process_1.startDetachedProcess)(sideloadFile);
}
else {
yield open(sideloadFile, { wait: false });
}
}
});
}
//# sourceMappingURL=sideload.js.map
File diff suppressed because one or more lines are too long