Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

listDevices.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. const { superspawn: { spawn } } = require('cordova-common');
  18. const DEVICE_REGEX = /-o (iPhone|iPad|iPod)@.*?"USB Serial Number" = "([^"]*)"/gs;
  19. /**
  20. * Gets list of connected iOS devices
  21. * @return {Promise} Promise fulfilled with list of available iOS devices
  22. */
  23. function listDevices () {
  24. return spawn('ioreg', ['-p', 'IOUSB', '-l'])
  25. .then(output => {
  26. return [...matchAll(output, DEVICE_REGEX)]
  27. .map(m => m.slice(1).reverse().join(' '));
  28. });
  29. }
  30. // TODO: Should be replaced with String#matchAll once available
  31. function * matchAll (s, r) {
  32. let match;
  33. while ((match = r.exec(s))) yield match;
  34. }
  35. exports.run = listDevices;