serve.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.VueServeCLI = exports.VueServeRunner = void 0;
  27. const cli_framework_output_1 = require("@ionic/cli-framework-output");
  28. const utils_network_1 = require("@ionic/utils-network");
  29. const color_1 = require("../../color");
  30. const serve_1 = require("../../serve");
  31. class VueServeRunner extends serve_1.ServeRunner {
  32. constructor(e) {
  33. super();
  34. this.e = e;
  35. }
  36. async getCommandMetadata() {
  37. return {};
  38. }
  39. modifyOpenUrl(url, _options) {
  40. return url;
  41. }
  42. async serveProject(options) {
  43. const [externalIP, availableInterfaces] = await this.selectExternalIP(options);
  44. const port = options.port = await (0, utils_network_1.findClosestOpenPort)(options.port);
  45. const vueScripts = new VueServeCLI(this.e);
  46. await vueScripts.serve(options);
  47. return {
  48. custom: vueScripts.resolvedProgram !== vueScripts.program,
  49. protocol: options.https ? 'https' : 'http',
  50. localAddress: 'localhost',
  51. externalAddress: externalIP,
  52. externalNetworkInterfaces: availableInterfaces,
  53. port,
  54. externallyAccessible: ![serve_1.BIND_ALL_ADDRESS, ...serve_1.LOCAL_ADDRESSES].includes(externalIP),
  55. };
  56. }
  57. }
  58. exports.VueServeRunner = VueServeRunner;
  59. class VueServeCLI extends serve_1.ServeCLI {
  60. constructor() {
  61. super(...arguments);
  62. this.name = 'Vue CLI Service';
  63. this.pkg = '@vue/cli-service';
  64. this.program = 'vue-cli-service';
  65. this.prefix = 'vue-cli-service';
  66. this.script = serve_1.SERVE_SCRIPT;
  67. this.chunks = 0;
  68. }
  69. async serve(options) {
  70. this.on('compile', chunks => {
  71. if (chunks > 0) {
  72. this.e.log.info(`... and ${(0, color_1.strong)(chunks.toString())} additional chunks`);
  73. }
  74. });
  75. return super.serve(options);
  76. }
  77. stdoutFilter(line) {
  78. if (this.resolvedProgram !== this.program) {
  79. return super.stdoutFilter(line);
  80. }
  81. const strippedLine = (0, cli_framework_output_1.stripAnsi)(line);
  82. const compileMsgs = ['Compiled successfully', 'Compiled with', 'Failed to compile'];
  83. if (compileMsgs.some(msg => strippedLine.includes(msg))) {
  84. this.emit('ready');
  85. return false;
  86. }
  87. if (strippedLine.match(/.*chunk\s{\d+}.+/)) {
  88. this.chunks++;
  89. return false;
  90. }
  91. if (strippedLine.includes('Compiled successfully')) {
  92. this.emit('compile', this.chunks);
  93. this.chunks = 0;
  94. }
  95. // const endBannerMsgs = ['development build', 'production build']
  96. // if (endBannerMsgs.some(msg => strippedLine.includes(msg))) {
  97. // return false;
  98. // }
  99. return true;
  100. }
  101. stderrFilter(line) {
  102. if (this.resolvedProgram !== this.program) {
  103. return super.stderrFilter(line);
  104. }
  105. const strippedLine = (0, cli_framework_output_1.stripAnsi)(line);
  106. if (strippedLine.includes('webpack.Progress')) {
  107. return false;
  108. }
  109. return true;
  110. }
  111. async buildArgs(_options) {
  112. const { pkgManagerArgs } = await Promise.resolve().then(() => __importStar(require('../../utils/npm')));
  113. const separatedArgs = _options['--'];
  114. if (this.resolvedProgram === this.program) {
  115. return ['serve', ...separatedArgs];
  116. }
  117. else {
  118. const [, ...pkgArgs] = await pkgManagerArgs(this.e.config.get('npmClient'), { command: 'run', script: this.script, scriptArgs: separatedArgs });
  119. return pkgArgs;
  120. }
  121. }
  122. async buildEnvVars(options) {
  123. const env = {};
  124. // // Vue CLI binds to `localhost` by default, but if specified it prints a
  125. // // warning, so don't set `HOST` if the host is set to `localhost`.
  126. if (options.host !== serve_1.DEFAULT_ADDRESS) {
  127. env.HOST = options.host;
  128. }
  129. env.PORT = String(options.port);
  130. env.HTTPS = options.https ? 'true' : 'false';
  131. return { ...await super.buildEnvVars(options), ...env };
  132. }
  133. }
  134. exports.VueServeCLI = VueServeCLI;