122 lines
6.8 KiB
JavaScript
122 lines
6.8 KiB
JavaScript
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||
|
// Licensed under the MIT license.
|
||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||
|
});
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.stop = exports.start = void 0;
|
||
|
const fs = require("fs");
|
||
|
const office_addin_cli_1 = require("office-addin-cli");
|
||
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
||
|
const devSettings = require("office-addin-dev-settings");
|
||
|
const office_addin_manifest_1 = require("office-addin-manifest");
|
||
|
const start_1 = require("./start");
|
||
|
const stop_1 = require("./stop");
|
||
|
const defaults_1 = require("./defaults");
|
||
|
const office_addin_usage_data_2 = require("office-addin-usage-data");
|
||
|
/* global process */
|
||
|
function determineManifestPath(platform, dev) {
|
||
|
let manifestPath = process.env.npm_package_config_manifest_location || "";
|
||
|
manifestPath = manifestPath.replace("${flavor}", dev ? "dev" : "prod").replace("${platform}", platform);
|
||
|
if (!manifestPath) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError(`The manifest path was not provided.`);
|
||
|
}
|
||
|
if (!fs.existsSync(manifestPath)) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError(`The manifest path does not exist: ${manifestPath}.`);
|
||
|
}
|
||
|
return manifestPath;
|
||
|
}
|
||
|
function parseDevServerPort(optionValue) {
|
||
|
const devServerPort = (0, office_addin_cli_1.parseNumber)(optionValue, "--dev-server-port should specify a number.");
|
||
|
if (devServerPort !== undefined) {
|
||
|
if (!Number.isInteger(devServerPort)) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError("--dev-server-port should be an integer.");
|
||
|
}
|
||
|
if (devServerPort < 0 || devServerPort > 65535) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError("--dev-server-port should be between 0 and 65535.");
|
||
|
}
|
||
|
}
|
||
|
return devServerPort;
|
||
|
}
|
||
|
function start(manifestPath, platform, command) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const appPlatformToDebug = (0, start_1.parsePlatform)(platform || process.env.npm_package_config_app_platform_to_debug || start_1.Platform.Win32);
|
||
|
const appTypeToDebug = devSettings.parseAppType(appPlatformToDebug || process.env.npm_package_config_app_type_to_debug || start_1.AppType.Desktop);
|
||
|
const appToDebug = command.app || process.env.npm_package_config_app_to_debug;
|
||
|
const app = appToDebug ? (0, office_addin_manifest_1.parseOfficeApp)(appToDebug) : undefined;
|
||
|
const dev = command.prod ? false : true;
|
||
|
const debuggingMethod = (0, start_1.parseDebuggingMethod)(command.debugMethod);
|
||
|
const devServer = command.devServer || (yield (0, office_addin_cli_1.getPackageJsonScript)("dev-server"));
|
||
|
const devServerPort = parseDevServerPort(command.devServerPort || process.env.npm_package_config_dev_server_port);
|
||
|
const document = command.document || process.env.npm_package_config_document;
|
||
|
const enableDebugging = command.debug;
|
||
|
const enableLiveReload = command.liveReload === true;
|
||
|
const enableSideload = command.sideload !== false; // enable if true or undefined; only disable if false
|
||
|
const openDevTools = command.devTools === true;
|
||
|
const packager = command.packager || (yield (0, office_addin_cli_1.getPackageJsonScript)("packager"));
|
||
|
const packagerHost = command.PackagerHost || process.env.npm_package_config_packager_host;
|
||
|
const packagerPort = command.PackagerPort || process.env.npm_package_config_packager_port;
|
||
|
const sourceBundleUrlComponents = new devSettings.SourceBundleUrlComponents(command.sourceBundleUrlHost, command.sourceBundleUrlPort, command.sourceBundleUrlPath, command.sourceBundleUrlExtension);
|
||
|
if (appPlatformToDebug === undefined) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError("Please specify the platform to debug.");
|
||
|
}
|
||
|
if (appTypeToDebug === undefined) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError("Please specify the application type to debug.");
|
||
|
}
|
||
|
if (appPlatformToDebug === start_1.Platform.Android || appPlatformToDebug === start_1.Platform.iOS) {
|
||
|
throw new office_addin_usage_data_2.ExpectedError(`Platform type ${appPlatformToDebug} not currently supported for debugging`);
|
||
|
}
|
||
|
if (!manifestPath) {
|
||
|
manifestPath = determineManifestPath(appPlatformToDebug, dev);
|
||
|
}
|
||
|
yield (0, start_1.startDebugging)(manifestPath, {
|
||
|
appType: appTypeToDebug,
|
||
|
app,
|
||
|
debuggingMethod,
|
||
|
sourceBundleUrlComponents,
|
||
|
devServerCommandLine: devServer,
|
||
|
devServerPort,
|
||
|
packagerCommandLine: packager,
|
||
|
packagerHost,
|
||
|
packagerPort,
|
||
|
enableDebugging,
|
||
|
enableLiveReload,
|
||
|
enableSideload,
|
||
|
openDevTools,
|
||
|
document,
|
||
|
});
|
||
|
defaults_1.usageDataObject.reportSuccess("start");
|
||
|
}
|
||
|
catch (err) {
|
||
|
defaults_1.usageDataObject.reportException("start", err);
|
||
|
(0, office_addin_usage_data_1.logErrorMessage)(`Unable to start debugging.\n${err}`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.start = start;
|
||
|
function stop(manifestPath, platform, command) {
|
||
|
return __awaiter(this, void 0, void 0, function* () {
|
||
|
try {
|
||
|
const appPlatformToDebug = (0, start_1.parsePlatform)(platform || process.env.npm_package_config_app_plaform_to_debug || start_1.Platform.Win32);
|
||
|
const dev = command.prod ? false : true;
|
||
|
if (manifestPath === "" && appPlatformToDebug !== undefined) {
|
||
|
manifestPath = determineManifestPath(appPlatformToDebug, dev);
|
||
|
}
|
||
|
yield (0, stop_1.stopDebugging)(manifestPath);
|
||
|
defaults_1.usageDataObject.reportSuccess("stop");
|
||
|
}
|
||
|
catch (err) {
|
||
|
defaults_1.usageDataObject.reportException("stop", err);
|
||
|
(0, office_addin_usage_data_1.logErrorMessage)(`Unable to stop debugging.\n${err}`);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
exports.stop = stop;
|
||
|
//# sourceMappingURL=commands.js.map
|