serve.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CustomServeRunner = void 0;
  4. const utils_network_1 = require("@ionic/utils-network");
  5. const color_1 = require("../../color");
  6. const errors_1 = require("../../errors");
  7. const serve_1 = require("../../serve");
  8. class CustomServeRunner extends serve_1.ServeRunner {
  9. constructor(e) {
  10. super();
  11. this.e = e;
  12. }
  13. async getCommandMetadata() {
  14. return {};
  15. }
  16. modifyOpenUrl(url, options) {
  17. return url;
  18. }
  19. async serveProject(options) {
  20. const cli = this.getPkgManagerServeCLI();
  21. if (!await cli.resolveScript()) {
  22. throw new errors_1.RunnerException(`Cannot perform serve.\n` +
  23. `Since you're using the ${(0, color_1.strong)('custom')} project type, you must provide the ${(0, color_1.input)(cli.script)} npm script so the Ionic CLI can serve your project.`);
  24. }
  25. const [externalIP, availableInterfaces] = await this.selectExternalIP(options);
  26. const port = options.port = await (0, utils_network_1.findClosestOpenPort)(options.port);
  27. await cli.serve(options);
  28. return {
  29. custom: true,
  30. protocol: 'http',
  31. localAddress: 'localhost',
  32. externalAddress: externalIP,
  33. externalNetworkInterfaces: availableInterfaces,
  34. port,
  35. externallyAccessible: ![serve_1.BIND_ALL_ADDRESS, ...serve_1.LOCAL_ADDRESSES].includes(externalIP),
  36. };
  37. }
  38. }
  39. exports.CustomServeRunner = CustomServeRunner;