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

simctl.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014 Shazron Abdullah.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. var shell = require('shelljs');
  21. var util = require('util');
  22. var SimCtlExtensions = require('./lib/simctl-extensions');
  23. exports = module.exports = {
  24. set noxpc (b) {
  25. this._noxpc = b;
  26. },
  27. get noxpc () {
  28. return this._noxpc;
  29. },
  30. extensions: SimCtlExtensions,
  31. check_prerequisites: function () {
  32. var command = util.format('xcrun simctl help');
  33. var obj = shell.exec(command, {silent: true});
  34. if (obj.code !== 0) {
  35. obj.output = 'simctl was not found.\n';
  36. obj.output += 'Check that you have Xcode 8.x installed:\n';
  37. obj.output += '\txcodebuild --version\n';
  38. obj.output += 'Check that you have Xcode 8.x selected:\n';
  39. obj.output += '\txcode-select --print-path\n';
  40. }
  41. return obj;
  42. },
  43. create: function (name, device_type_id, runtime_id) {
  44. var command = util.format('xcrun simctl create "%s" "%s" "%s"', name, device_type_id, runtime_id);
  45. return shell.exec(command);
  46. },
  47. del: function (device) {
  48. var command = util.format('xcrun simctl delete "%s"', device);
  49. return shell.exec(command);
  50. },
  51. erase: function (device) {
  52. var command = util.format('xcrun simctl erase "%s"', device);
  53. return shell.exec(command);
  54. },
  55. boot: function (device) {
  56. var command = util.format('xcrun simctl boot "%s"', device);
  57. return shell.exec(command);
  58. },
  59. shutdown: function (device) {
  60. var command = util.format('xcrun simctl shutdown "%s"', device);
  61. return shell.exec(command);
  62. },
  63. rename: function (device, name) {
  64. var command = util.format('xcrun simctl rename "%s" "%s"', device, name);
  65. return shell.exec(command);
  66. },
  67. getenv: function (device, variable_name) {
  68. var command = util.format('xcrun simctl getenv "%s" "%s"', device, variable_name);
  69. return shell.exec(command);
  70. },
  71. openurl: function (device, url) {
  72. var command = util.format('xcrun simctl openurl "%s" "%s"', device, url);
  73. return shell.exec(command);
  74. },
  75. addphoto: function (device, path) {
  76. var command = util.format('xcrun simctl addphoto "%s" "%s"', device, path);
  77. return shell.exec(command);
  78. },
  79. install: function (device, path) {
  80. var command = util.format('xcrun simctl install "%s" "%s"', device, path);
  81. return shell.exec(command);
  82. },
  83. uninstall: function (device, app_identifier) {
  84. var command = util.format('xcrun simctl uninstall "%s" "%s"', device, app_identifier);
  85. return shell.exec(command);
  86. },
  87. launch: function (wait_for_debugger, device, app_identifier, argv) {
  88. var wait_flag = '';
  89. if (wait_for_debugger) {
  90. wait_flag = '--wait-for-debugger';
  91. }
  92. var argv_expanded = '';
  93. if (argv.length > 0) {
  94. argv_expanded = argv.map(function (arg) {
  95. return '\'' + arg + '\'';
  96. }).join(' ');
  97. }
  98. var command = util.format('xcrun simctl launch %s "%s" "%s" %s',
  99. wait_flag, device, app_identifier, argv_expanded);
  100. return shell.exec(command);
  101. },
  102. spawn: function (wait_for_debugger, arch, device, path_to_executable, argv) {
  103. var wait_flag = '';
  104. if (wait_for_debugger) {
  105. wait_flag = '--wait-for-debugger';
  106. }
  107. var arch_flag = '';
  108. if (arch) {
  109. arch_flag = util.format('--arch="%s"', arch);
  110. }
  111. var argv_expanded = '';
  112. if (argv.length > 0) {
  113. argv_expanded = argv.map(function (arg) {
  114. return '\'' + arg + '\'';
  115. }).join(' ');
  116. }
  117. var command = util.format('xcrun simctl spawn %s %s "%s" "%s" %s',
  118. wait_flag, arch_flag, device, path_to_executable, argv_expanded);
  119. return shell.exec(command);
  120. },
  121. list: function (options) {
  122. var sublist = '';
  123. options = options || {};
  124. if (options.devices) {
  125. sublist = 'devices';
  126. } else if (options.devicetypes) {
  127. sublist = 'devicetypes';
  128. } else if (options.runtimes) {
  129. sublist = 'runtimes';
  130. } else if (options.pairs) {
  131. sublist = 'pairs';
  132. }
  133. var command = util.format('xcrun simctl list %s --json', sublist);
  134. var obj = shell.exec(command, { silent: options.silent });
  135. if (obj.code === 0) {
  136. try {
  137. obj.json = JSON.parse(obj.output);
  138. } catch (err) {
  139. console.error(err.stack);
  140. }
  141. }
  142. return obj;
  143. },
  144. notify_post: function (device, notification_name) {
  145. var command = util.format('xcrun simctl notify_post "%s" "%s"', device, notification_name);
  146. return shell.exec(command);
  147. },
  148. icloud_sync: function (device) {
  149. var command = util.format('xcrun simctl icloud_sync "%s"', device);
  150. return shell.exec(command);
  151. },
  152. help: function (subcommand) {
  153. var command = util.format('xcrun simctl help "%s"', subcommand);
  154. return shell.exec(command);
  155. }
  156. };