UNPKG

office-addin-dev-settings

Version:

Configure developer settings for Office Add-ins.

427 lines 17.9 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. Object.defineProperty(exports, "__esModule", { value: true }); exports.SourceBundleUrlComponents = exports.RegisteredAddin = exports.WebViewType = exports.DebuggingMethod = exports.toWebViewTypeName = void 0; exports.clearDevSettings = clearDevSettings; exports.disableDebugging = disableDebugging; exports.disableLiveReload = disableLiveReload; exports.disableRuntimeLogging = disableRuntimeLogging; exports.enableDebugging = enableDebugging; exports.enableLiveReload = enableLiveReload; exports.enableRuntimeLogging = enableRuntimeLogging; exports.getRegisteredAddIns = getRegisteredAddIns; exports.getEnabledDebuggingMethods = getEnabledDebuggingMethods; exports.getOpenDevTools = getOpenDevTools; exports.getRuntimeLoggingPath = getRuntimeLoggingPath; exports.getSourceBundleUrl = getSourceBundleUrl; exports.getWebView = getWebView; exports.isDebuggingEnabled = isDebuggingEnabled; exports.isLiveReloadEnabled = isLiveReloadEnabled; exports.registerAddIn = registerAddIn; exports.setSourceBundleUrl = setSourceBundleUrl; exports.setWebView = setWebView; exports.unregisterAddIn = unregisterAddIn; exports.unregisterAllAddIns = unregisterAllAddIns; exports.enableSourceBundleOverrideFile = enableSourceBundleOverrideFile; exports.disableSourceBundleOverrideFile = disableSourceBundleOverrideFile; exports.isSourceBundleOverriden = isSourceBundleOverriden; exports.getSourceBundleOverrideFilePath = getSourceBundleOverrideFilePath; exports.enableDiskManifests = enableDiskManifests; exports.disableDiskManifests = disableDiskManifests; exports.areDiskManifestsEnabled = areDiskManifestsEnabled; exports.getDiskManifestsPath = getDiskManifestsPath; 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 = DebuggingMethod = {})); var WebViewType; (function (WebViewType) { WebViewType["Default"] = "Default"; WebViewType["EdgeChromium"] = "Edge Chromium"; })(WebViewType || (exports.WebViewType = 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}.`); } }); } function disableDebugging(addinId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return enableDebugging(addinId, false); }); } function disableLiveReload(addinId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return enableLiveReload(addinId, false); }); } 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}.`); } }); } function enableDebugging(addinId_1) { return tslib_1.__awaiter(this, arguments, void 0, function* (addinId, enable = true, method = DebuggingMethod.Direct, openDevTools = false) { 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}.`); } }); } function enableLiveReload(addinId_1) { return tslib_1.__awaiter(this, arguments, void 0, function* (addinId, enable = true) { switch (process.platform) { case "win32": return devSettingsWindows.enableLiveReload(addinId, enable); default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } 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}.`); } }); } /** * 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } 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}.`); } }); } function enableSourceBundleOverrideFile(addInId, path) { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": { const isValidPath = isValidBundleOverrideFilePath(path); if (path && isValidPath) { return devSettingsWindows.enableSourceBundleOverrideFile(addInId, path); } throw new office_addin_usage_data_1.ExpectedError("The source bundle override file path is not specified or is invalid."); } default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function isValidBundleOverrideFilePath(path) { let isValid = false; try { if (path) { const pathExists = fs_1.default.existsSync(path); if (pathExists) { const stat = fs_1.default.statSync(path); isValid = stat.isFile(); } } } catch (err) { console.log(err); } return isValid; } function disableSourceBundleOverrideFile(addInId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": { return devSettingsWindows.disableSourceBundleOverrideFile(addInId); } default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function isSourceBundleOverriden(addInId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": { return devSettingsWindows.isSourceBundleOverriden(addInId); } default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function getSourceBundleOverrideFilePath(addInId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return devSettingsWindows.getSourceBundleOverrideFilePath(addInId); }); } function enableDiskManifests(path) { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": { const isValidPath = isValidDiskManifestsPath(path); if (path && isValidPath) { yield devSettingsWindows.enableDiskManifests(path); return path; } throw new office_addin_usage_data_1.ExpectedError("The disk manifests path is not specified or is invalid. Ensure that it is an existing directory path."); } default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function isValidDiskManifestsPath(path) { let isValid = false; try { if (path) { const pathExists = fs_1.default.existsSync(path); if (pathExists) { const stat = fs_1.default.statSync(path); isValid = stat.isDirectory(); } } } catch (err) { console.log(err); } return isValid; } function disableDiskManifests() { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": return devSettingsWindows.disableDiskManifests(); default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function areDiskManifestsEnabled() { return tslib_1.__awaiter(this, void 0, void 0, function* () { switch (process.platform) { case "win32": return devSettingsWindows.areDiskManifestsEnabled(); default: throw new office_addin_usage_data_1.ExpectedError(`Platform not supported: ${process.platform}.`); } }); } function getDiskManifestsPath() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return devSettingsWindows.getDiskManifestsPath(); }); } //# sourceMappingURL=dev-settings.js.map