UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const chalk_1 = require("chalk");
  5. const errors_1 = require("./errors");
  6. exports.DEFAULT_DEV_LOGGER_PORT = 53703;
  7. exports.DEFAULT_LIVERELOAD_PORT = 35729;
  8. exports.DEFAULT_SERVER_PORT = 8100;
  9. exports.IONIC_LAB_URL = '/ionic-lab';
  10. exports.BIND_ALL_ADDRESS = '0.0.0.0';
  11. exports.LOCAL_ADDRESSES = ['localhost', '127.0.0.1'];
  12. exports.BROWSERS = ['safari', 'firefox', process.platform === 'win32' ? 'chrome' : (process.platform === 'darwin' ? 'google chrome' : 'google-chrome')];
  13. function selectExternalIP(env, options) {
  14. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  15. const { getSuitableNetworkInterfaces } = yield Promise.resolve().then(() => require('./utils/network'));
  16. let availableInterfaces = [];
  17. let chosenIP = options.address;
  18. if (options.address === exports.BIND_ALL_ADDRESS) {
  19. availableInterfaces = getSuitableNetworkInterfaces();
  20. if (availableInterfaces.length === 0) {
  21. if (options.externalAddressRequired) {
  22. throw new errors_1.FatalException(`No external network interfaces detected. In order to use livereload with run/emulate you will need one.\n` +
  23. `Are you connected to a local network?\n`);
  24. }
  25. }
  26. else if (availableInterfaces.length === 1) {
  27. chosenIP = availableInterfaces[0].address;
  28. }
  29. else if (availableInterfaces.length > 1) {
  30. if (options.externalAddressRequired) {
  31. env.log.warn('Multiple network interfaces detected!\n' +
  32. 'You will be prompted to select an external-facing IP for the livereload server that your device or emulator has access to.\n\n' +
  33. `You may also use the ${chalk_1.default.green('--address')} option to skip this prompt.`);
  34. const promptedIp = yield env.prompt({
  35. type: 'list',
  36. name: 'promptedIp',
  37. message: 'Please select which IP to use:',
  38. choices: availableInterfaces.map(i => ({
  39. name: `${i.address} ${chalk_1.default.dim(`(${i.deviceName})`)}`,
  40. value: i.address,
  41. })),
  42. });
  43. chosenIP = promptedIp;
  44. }
  45. }
  46. }
  47. return [chosenIP, availableInterfaces];
  48. });
  49. }
  50. exports.selectExternalIP = selectExternalIP;
  51. function gatherDevAppDetails(env, options) {
  52. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  53. let devAppActive = !options.iscordovaserve && options.devapp;
  54. if (devAppActive) {
  55. const { getSuitableNetworkInterfaces } = yield Promise.resolve().then(() => require('./utils/network'));
  56. const { computeBroadcastAddress } = yield Promise.resolve().then(() => require('./devapp'));
  57. const availableInterfaces = getSuitableNetworkInterfaces();
  58. // TODO: Unfortunately, we can't do this yet--there is no
  59. // accurate/reliable/realistic way to identify a WiFi network uniquely in
  60. // NodeJS. The best thing we can do is tell the dev what is happening.
  61. // const config = await env.config.load();
  62. // const knownInterfaces = new Set(config.devapp.knownInterfaces.map(i => i.mac));
  63. // const diff = [...new Set(availableInterfaces.filter(i => !knownInterfaces.has(i.mac)))];
  64. // if (diff.length > 0) {
  65. // env.log.warn(
  66. // `New network interface(s) detected!\n` +
  67. // `You will be prompted to select which network interfaces are trusted for your app to show up in Ionic DevApp. If you're on public WiFi, you may not want to broadcast your app. To trust all networks, just press ${chalk.cyan.bold('<enter>')}.\n\n` +
  68. // `Need to install the DevApp? ${emoji('👉 ', '-->')} ${chalk.bold('https://bit.ly/ionic-dev-app')}`
  69. // );
  70. // const trustedInterfaceMacs = await env.prompt({
  71. // type: 'checkbox',
  72. // name: 'checkbox',
  73. // message: 'Please select trusted interfaces:',
  74. // choices: diff.map(i => ({
  75. // name: `${chalk.bold(i.address)} ${chalk.dim(`(mac: ${i.mac}, label: ${i.deviceName})`)}`,
  76. // value: i.mac,
  77. // checked: true,
  78. // })),
  79. // });
  80. // const untrustedInterfaceMacs = diff
  81. // .filter(i => !trustedInterfaceMacs.includes(i.mac))
  82. // .map(i => i.mac);
  83. // const trustedInterfaces = trustedInterfaceMacs.map(mac => ({ trusted: true, mac }));
  84. // const untrustedInterfaces = untrustedInterfaceMacs.map(mac => ({ trusted: false, mac }));
  85. // config.devapp.knownInterfaces = config.devapp.knownInterfaces.concat(trustedInterfaces);
  86. // config.devapp.knownInterfaces = config.devapp.knownInterfaces.concat(untrustedInterfaces);
  87. // }
  88. // const trustedInterfaceMacs = config.devapp.knownInterfaces
  89. // .filter(i => i.trusted)
  90. // .map(i => i.mac);
  91. // const availableTrustedInterfaces = availableInterfaces.filter(i => trustedInterfaceMacs.includes(i.mac));
  92. const interfaces = availableInterfaces
  93. .map(i => (Object.assign({}, i, { broadcast: computeBroadcastAddress(i.address, i.netmask) })));
  94. return { interfaces };
  95. }
  96. });
  97. }
  98. exports.gatherDevAppDetails = gatherDevAppDetails;
  99. function publishDevApp(env, options, details) {
  100. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  101. let devAppActive = !options.iscordovaserve && options.devapp;
  102. if (devAppActive) {
  103. const { createPublisher } = yield Promise.resolve().then(() => require('./devapp'));
  104. const publisher = yield createPublisher(env, details.port);
  105. publisher.interfaces = details.interfaces;
  106. publisher.on('error', (err) => {
  107. env.log.debug(`Error in DevApp service: ${String(err.stack ? err.stack : err)}`);
  108. });
  109. try {
  110. yield publisher.start();
  111. }
  112. catch (e) {
  113. env.log.error(`Could not publish DevApp service: ${String(e.stack ? e.stack : e)}`);
  114. }
  115. return publisher.name;
  116. }
  117. });
  118. }
  119. exports.publishDevApp = publishDevApp;