151 lines
8.0 KiB
JavaScript
151 lines
8.0 KiB
JavaScript
"use strict";
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
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());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.stop = exports.start = void 0;
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const office_addin_cli_1 = require("office-addin-cli");
|
|
const office_addin_usage_data_1 = require("office-addin-usage-data");
|
|
const devSettings = __importStar(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_1.default.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, options) {
|
|
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 = options.app || process.env.npm_package_config_app_to_debug;
|
|
const app = appToDebug ? (0, office_addin_manifest_1.parseOfficeApp)(appToDebug) : undefined;
|
|
const dev = options.prod ? false : true;
|
|
const debuggingMethod = (0, start_1.parseDebuggingMethod)(options.debugMethod);
|
|
const devServer = options.devServer || (yield (0, office_addin_cli_1.getPackageJsonScript)("dev-server"));
|
|
const devServerPort = parseDevServerPort(options.devServerPort || process.env.npm_package_config_dev_server_port);
|
|
const document = options.document || process.env.npm_package_config_document;
|
|
const enableDebugging = options.debug;
|
|
const enableLiveReload = options.liveReload === true;
|
|
const enableSideload = options.sideload !== false; // enable if true or undefined; only disable if false
|
|
const openDevTools = options.devTools === true;
|
|
const packager = options.packager || (yield (0, office_addin_cli_1.getPackageJsonScript)("packager"));
|
|
const packagerHost = options.PackagerHost || process.env.npm_package_config_packager_host;
|
|
const packagerPort = options.PackagerPort || process.env.npm_package_config_packager_port;
|
|
const sourceBundleUrlComponents = new devSettings.SourceBundleUrlComponents(options.sourceBundleUrlHost, options.sourceBundleUrlPort, options.sourceBundleUrlPath, options.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, options) {
|
|
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 = options.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
|