Util.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. let Fs = require('fire-fs');
  2. let Path = require('fire-path');
  3. const OutPut = Editor.require('packages://hot-update-tools/core/OutPut.js');
  4. module.exports = {
  5. manifestResDir: null, // 在creator2.4之后,res变为了assets
  6. getLocalIP () {
  7. let ip = '';
  8. let os = require('os');
  9. let ifaces = os.networkInterfaces();
  10. Object.keys(ifaces).forEach((ifname) => {
  11. ifaces[ifname].forEach((iface) => {
  12. if ('IPv4' !== iface.family || iface.internal !== false) {
  13. // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
  14. return;
  15. }
  16. ip = iface.address;
  17. });
  18. });
  19. // let runPlatform = cc.sys.os;
  20. // let network = os.networkInterfaces();
  21. // if (runPlatform === "Windows") {//win
  22. // for (let i = 0; i < network.WLAN.length; i++) {
  23. // let json = network.WLAN[i];
  24. // if (json.family === 'IPv4') {
  25. // ip = json.address;
  26. // }
  27. // }
  28. // } else if (runPlatform === "OS X") {//mac
  29. // let ipDate = null;
  30. // if (network && network.en0) {
  31. // ipDate = network.en0;
  32. // }
  33. // if (ipDate) {
  34. // for (let i = 0; i < ipDate.length; i++) {
  35. // let item = network.en0[i];
  36. // if (item.family === 'IPv4') {
  37. // ip = item.address;
  38. // }
  39. // }
  40. // }
  41. // }
  42. return ip;
  43. },
  44. };