304 lines
13 KiB
JavaScript
304 lines
13 KiB
JavaScript
|
// 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.getRegisterAddIns = 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 = require("fs");
|
||
|
const office_addin_manifest_1 = require("office-addin-manifest");
|
||
|
const fspath = require("path");
|
||
|
const devSettingsMac = require("./dev-settings-mac");
|
||
|
const devSettingsWindows = 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";
|
||
|
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 = fspath.normalize(`${tempDir}/${defaultRuntimeLogFileName}`);
|
||
|
}
|
||
|
const pathExists = fs.existsSync(path);
|
||
|
if (pathExists) {
|
||
|
const stat = fs.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.openSync(path, "a+");
|
||
|
fs.closeSync(file);
|
||
|
}
|
||
|
catch (err) {
|
||
|
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 getRegisterAddIns() {
|
||
|
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.getRegisterAddIns = getRegisterAddIns;
|
||
|
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.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.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
|