index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. /**
  3. * Copyright 2021 Google LLC.
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var __importDefault = (this && this.__importDefault) || function (mod) {
  19. return (mod && mod.__esModule) ? mod : { "default": mod };
  20. };
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. exports.parseCommandLineArgs = void 0;
  23. const yargs_1 = __importDefault(require("yargs"));
  24. const helpers_1 = require("yargs/helpers");
  25. const WebSocketServer_js_1 = require("./WebSocketServer.js");
  26. function parseCommandLineArgs() {
  27. return (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
  28. .usage(`$0`, `[PORT=8080] [VERBOSE=8080]`)
  29. .option('port', {
  30. alias: 'p',
  31. describe: 'Port that BiDi server should listen to. Default is 8080.',
  32. type: 'number',
  33. default: process.env['PORT'] ? Number(process.env['PORT']) : 8080,
  34. })
  35. .option('verbose', {
  36. alias: 'v',
  37. describe: 'If present, the Mapper debug log, including CDP commands and events will be logged into the server output.',
  38. type: 'boolean',
  39. default: process.env['VERBOSE'] === 'true' || false,
  40. })
  41. .parseSync();
  42. }
  43. exports.parseCommandLineArgs = parseCommandLineArgs;
  44. (() => {
  45. try {
  46. const argv = parseCommandLineArgs();
  47. const { port, verbose } = argv;
  48. (0, WebSocketServer_js_1.debugInfo)('Launching BiDi server...');
  49. new WebSocketServer_js_1.WebSocketServer(port, verbose);
  50. (0, WebSocketServer_js_1.debugInfo)('BiDi server launched');
  51. }
  52. catch (e) {
  53. (0, WebSocketServer_js_1.debugInfo)('Error launching BiDi server', e);
  54. }
  55. })();
  56. //# sourceMappingURL=index.js.map