project.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseMiniProgramProjectJson = exports.isMiniProgramProjectJsonKey = void 0;
  4. const shared_1 = require("@vue/shared");
  5. const merge_1 = require("merge");
  6. const json_1 = require("../json");
  7. const projectKeys = [
  8. 'appid',
  9. 'setting',
  10. 'miniprogramRoot',
  11. 'cloudfunctionRoot',
  12. 'qcloudRoot',
  13. 'pluginRoot',
  14. 'compileType',
  15. 'libVersion',
  16. 'projectname',
  17. 'packOptions',
  18. 'debugOptions',
  19. 'scripts',
  20. 'cloudbaseRoot',
  21. ];
  22. function isMiniProgramProjectJsonKey(name) {
  23. return projectKeys.includes(name);
  24. }
  25. exports.isMiniProgramProjectJsonKey = isMiniProgramProjectJsonKey;
  26. function parseMiniProgramProjectJson(jsonStr, platform, { template, pagesJson }) {
  27. const projectJson = JSON.parse(JSON.stringify(template));
  28. const manifestJson = (0, json_1.parseJson)(jsonStr);
  29. if (manifestJson) {
  30. projectJson.projectname = manifestJson.name;
  31. const platformConfig = manifestJson[platform];
  32. if (platformConfig) {
  33. projectKeys.forEach((name) => {
  34. if ((0, shared_1.hasOwn)(platformConfig, name)) {
  35. if ((0, shared_1.isPlainObject)(platformConfig[name]) &&
  36. (0, shared_1.isPlainObject)(projectJson[name])) {
  37. ;
  38. projectJson[name] = (0, merge_1.recursive)(true, projectJson[name], platformConfig[name]);
  39. }
  40. else {
  41. ;
  42. projectJson[name] = platformConfig[name];
  43. }
  44. }
  45. });
  46. // 使用了微信小程序手势系统,自动开启 ES6=>ES5
  47. platform === 'mp-weixin' &&
  48. weixinSkyline(platformConfig) &&
  49. openES62ES5(projectJson);
  50. }
  51. }
  52. // 其实仅开发期间 condition 生效即可,暂不做判断
  53. const miniprogram = parseMiniProgramCondition(pagesJson);
  54. if (miniprogram) {
  55. if (!projectJson.condition) {
  56. projectJson.condition = {};
  57. }
  58. projectJson.condition.miniprogram = miniprogram;
  59. }
  60. if (!projectJson.appid) {
  61. projectJson.appid = 'touristappid';
  62. }
  63. return projectJson;
  64. }
  65. exports.parseMiniProgramProjectJson = parseMiniProgramProjectJson;
  66. function weixinSkyline(config) {
  67. return (config.renderer === 'skyline' &&
  68. config.lazyCodeLoading === 'requiredComponents');
  69. }
  70. function openES62ES5(config) {
  71. if (!config.setting) {
  72. config.setting = {};
  73. }
  74. if (!config.setting.es6) {
  75. config.setting.es6 = true;
  76. }
  77. }
  78. function parseMiniProgramCondition(pagesJson) {
  79. const launchPagePath = process.env.UNI_CLI_LAUNCH_PAGE_PATH || '';
  80. if (launchPagePath) {
  81. return {
  82. current: 0,
  83. list: [
  84. {
  85. id: 0,
  86. name: launchPagePath,
  87. pathName: launchPagePath,
  88. query: process.env.UNI_CLI_LAUNCH_PAGE_QUERY || '', // 启动参数,在页面的onLoad函数里面得到。
  89. },
  90. ],
  91. };
  92. }
  93. const condition = pagesJson.condition;
  94. if (!condition || !(0, shared_1.isArray)(condition.list) || !condition.list.length) {
  95. return;
  96. }
  97. condition.list.forEach(function (item, index) {
  98. item.id = item.id || index;
  99. if (item.path) {
  100. item.pathName = item.path;
  101. delete item.path;
  102. }
  103. });
  104. return condition;
  105. }