Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

initialiseServices.js 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.initialiseWorkerService = exports.initialiseLauncherService = void 0;
  7. const logger_1 = __importDefault(require("@wdio/logger"));
  8. const initialisePlugin_1 = __importDefault(require("./initialisePlugin"));
  9. const log = logger_1.default('@wdio/utils:initialiseServices');
  10. function initialiseServices(services) {
  11. const initialisedServices = [];
  12. for (let [serviceName, serviceConfig = {}] of services) {
  13. if (typeof serviceName === 'object') {
  14. log.debug('initialise custom initiated service');
  15. initialisedServices.push([serviceName, {}]);
  16. continue;
  17. }
  18. if (typeof serviceName === 'function') {
  19. log.debug(`initialise custom service "${serviceName.name}"`);
  20. initialisedServices.push([serviceName, serviceConfig]);
  21. continue;
  22. }
  23. log.debug(`initialise service "${serviceName}" as NPM package`);
  24. const service = initialisePlugin_1.default(serviceName, 'service');
  25. initialisedServices.push([service, serviceConfig, serviceName]);
  26. }
  27. return initialisedServices;
  28. }
  29. function sanitizeServiceArray(service) {
  30. return Array.isArray(service) ? service : [service, {}];
  31. }
  32. function initialiseLauncherService(config, caps) {
  33. const ignoredWorkerServices = [];
  34. const launcherServices = [];
  35. try {
  36. const services = initialiseServices(config.services.map(sanitizeServiceArray));
  37. for (const [service, serviceConfig, serviceName] of services) {
  38. if (typeof service === 'object' && !serviceName) {
  39. launcherServices.push(service);
  40. continue;
  41. }
  42. const Launcher = service.launcher;
  43. if (typeof Launcher === 'function' && serviceName) {
  44. launcherServices.push(new Launcher(serviceConfig, caps, config));
  45. }
  46. if (typeof service === 'function' && !serviceName) {
  47. launcherServices.push(new service(serviceConfig, caps, config));
  48. }
  49. if (serviceName &&
  50. typeof service.default !== 'function' &&
  51. typeof service !== 'function') {
  52. ignoredWorkerServices.push(serviceName);
  53. }
  54. }
  55. }
  56. catch (err) {
  57. log.error(err);
  58. }
  59. return { ignoredWorkerServices, launcherServices };
  60. }
  61. exports.initialiseLauncherService = initialiseLauncherService;
  62. function initialiseWorkerService(config, caps, ignoredWorkerServices = []) {
  63. const workerServices = config.services
  64. .map(sanitizeServiceArray)
  65. .filter(([serviceName]) => !ignoredWorkerServices.includes(serviceName));
  66. try {
  67. const services = initialiseServices(workerServices);
  68. return services.map(([service, serviceConfig, serviceName]) => {
  69. if (typeof service === 'object' && !serviceName) {
  70. return service;
  71. }
  72. const Service = service.default || service;
  73. if (typeof Service === 'function') {
  74. return new Service(serviceConfig, caps, config);
  75. }
  76. }).filter((service) => Boolean(service));
  77. }
  78. catch (err) {
  79. log.error(err);
  80. return [];
  81. }
  82. }
  83. exports.initialiseWorkerService = initialiseWorkerService;