action.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.runBuild = exports.runDev = void 0;
  27. const shared_1 = require("@vue/shared");
  28. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  29. const build_1 = require("./build");
  30. const server_1 = require("./server");
  31. const utils_1 = require("./utils");
  32. const easycom_1 = require("../utils/easycom");
  33. const uvue_1 = require("./uvue");
  34. async function runDev(options) {
  35. (0, shared_1.extend)(options, {
  36. watch: {},
  37. });
  38. if (process.env.UNI_MINIMIZE === 'true') {
  39. ;
  40. options.minify = true;
  41. }
  42. (0, utils_1.initEnv)('dev', options);
  43. if (process.env.UNI_APP_X === 'true' &&
  44. process.env.UNI_UTS_PLATFORM === 'app-android') {
  45. return (0, uvue_1.runUVueAndroidDev)(options);
  46. }
  47. const createLogger = await Promise.resolve().then(() => __importStar(require('vite'))).then(({ createLogger }) => createLogger);
  48. try {
  49. if (options.platform === 'h5') {
  50. const server = await (options.ssr
  51. ? (0, server_1.createSSRServer)(options)
  52. : (0, server_1.createServer)(options));
  53. (0, easycom_1.initEasycom)(server.watcher);
  54. }
  55. else {
  56. const watcher = (await (0, build_1.build)(options));
  57. (0, easycom_1.initEasycom)();
  58. let isFirstStart = true;
  59. let isFirstEnd = true;
  60. watcher.on('event', (event) => {
  61. if (event.code === 'BUNDLE_START') {
  62. if (isFirstStart) {
  63. isFirstStart = false;
  64. return;
  65. }
  66. (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.start']);
  67. }
  68. else if (event.code === 'BUNDLE_END') {
  69. event.result.close();
  70. if (isFirstEnd) {
  71. // 首次全量同步
  72. if (options.platform === 'app') {
  73. process.env.UNI_APP_CHANGED_PAGES = '';
  74. process.env.UNI_APP_CHANGED_FILES = '';
  75. process.env.UNI_APP_UTS_CHANGED_FILES = '';
  76. }
  77. isFirstEnd = false;
  78. (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end']);
  79. (0, utils_1.showRunPrompt)(options.platform);
  80. (0, utils_1.printStartupDuration)(createLogger(options.logLevel), false);
  81. if (process.env.UNI_UTS_ERRORS) {
  82. console.error(process.env.UNI_UTS_ERRORS);
  83. }
  84. if (process.env.UNI_UTS_TIPS) {
  85. console.warn(process.env.UNI_UTS_TIPS);
  86. }
  87. return;
  88. }
  89. if (options.platform === 'app') {
  90. const files = process.env.UNI_APP_CHANGED_FILES;
  91. const pages = process.env.UNI_APP_CHANGED_PAGES;
  92. const dex = process.env.UNI_APP_UTS_CHANGED_FILES;
  93. const changedFiles = pages || files;
  94. process.env.UNI_APP_CHANGED_PAGES = '';
  95. process.env.UNI_APP_CHANGED_FILES = '';
  96. process.env.UNI_APP_UTS_CHANGED_FILES = '';
  97. if ((changedFiles &&
  98. !changedFiles.includes(uni_cli_shared_1.APP_CONFIG_SERVICE) &&
  99. !changedFiles.includes(uni_cli_shared_1.APP_SERVICE_FILENAME)) ||
  100. dex) {
  101. if (pages) {
  102. return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end.pages'].replace('{pages}', changedFiles));
  103. }
  104. return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end.files'].replace('{files}', JSON.stringify(JSON.parse(changedFiles || JSON.stringify([])).concat(JSON.parse(dex || JSON.stringify([]))))));
  105. }
  106. }
  107. return (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['dev.watching.end']);
  108. }
  109. else if (event.code === 'END') {
  110. if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
  111. (0, uni_cli_shared_1.output)('log', uni_cli_shared_1.M['build.failed']);
  112. process.exit(0);
  113. }
  114. }
  115. });
  116. }
  117. }
  118. catch (e) {
  119. if (options.platform === 'h5') {
  120. console.error(`error when starting dev server:\n${e.stack || e}`);
  121. }
  122. else {
  123. console.error(`error during build:\n${e.stack || e}`);
  124. }
  125. process.exit(1);
  126. }
  127. }
  128. exports.runDev = runDev;
  129. async function runBuild(options) {
  130. (0, utils_1.initEnv)('build', options);
  131. if (process.env.UNI_APP_X === 'true' &&
  132. process.env.UNI_UTS_PLATFORM === 'app-android') {
  133. return (0, uvue_1.runUVueAndroidBuild)(options);
  134. }
  135. try {
  136. await (options.ssr && options.platform === 'h5'
  137. ? (0, build_1.buildSSR)(options)
  138. : (0, build_1.build)(options));
  139. console.log(uni_cli_shared_1.M['build.done']);
  140. if (options.platform !== 'h5') {
  141. (0, utils_1.showRunPrompt)(options.platform);
  142. }
  143. }
  144. catch (e) {
  145. console.error(`Build failed with errors.`);
  146. process.exit(1);
  147. }
  148. }
  149. exports.runBuild = runBuild;