@mybricks/to-code-taro 1.2.6 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/package.json +1 -1
  2. package/dist/cjs/abstractEventTypeDef.d.ts +0 -11
  3. package/dist/cjs/abstractEventTypeDef.js +0 -93
  4. package/dist/cjs/generate/compressImages.d.ts +0 -16
  5. package/dist/cjs/generate/compressImages.js +0 -76
  6. package/dist/cjs/generate/generateTaroProjectJson.d.ts +0 -13
  7. package/dist/cjs/generate/generateTaroProjectJson.js +0 -225
  8. package/dist/cjs/generate/generateTaroTempalteJson.d.ts +0 -15
  9. package/dist/cjs/generate/generateTaroTempalteJson.js +0 -103
  10. package/dist/cjs/generate/utils/appConfig.d.ts +0 -21
  11. package/dist/cjs/generate/utils/appConfig.js +0 -57
  12. package/dist/cjs/generate/utils/commonDir.d.ts +0 -21
  13. package/dist/cjs/generate/utils/commonDir.js +0 -63
  14. package/dist/cjs/generate/utils/customTabBar.d.ts +0 -11
  15. package/dist/cjs/generate/utils/customTabBar.js +0 -73
  16. package/dist/cjs/generate/utils/fileNode.d.ts +0 -21
  17. package/dist/cjs/generate/utils/fileNode.js +0 -67
  18. package/dist/cjs/generate/utils/index.d.ts +0 -7
  19. package/dist/cjs/generate/utils/index.js +0 -29
  20. package/dist/cjs/generate/utils/pageImages.d.ts +0 -14
  21. package/dist/cjs/generate/utils/pageImages.js +0 -36
  22. package/dist/cjs/generate/utils/tabBarImages.d.ts +0 -14
  23. package/dist/cjs/generate/utils/tabBarImages.js +0 -36
  24. package/dist/cjs/handleCom.d.ts +0 -8
  25. package/dist/cjs/handleCom.js +0 -280
  26. package/dist/cjs/handleDom.d.ts +0 -21
  27. package/dist/cjs/handleDom.js +0 -52
  28. package/dist/cjs/handleExtension.d.ts +0 -10
  29. package/dist/cjs/handleExtension.js +0 -300
  30. package/dist/cjs/handleGlobal.d.ts +0 -11
  31. package/dist/cjs/handleGlobal.js +0 -191
  32. package/dist/cjs/handleModule.d.ts +0 -15
  33. package/dist/cjs/handleModule.js +0 -104
  34. package/dist/cjs/handleSlot.d.ts +0 -29
  35. package/dist/cjs/handleSlot.js +0 -153
  36. package/dist/cjs/index.d.ts +0 -4
  37. package/dist/cjs/index.js +0 -48
  38. package/dist/cjs/processors/processComEvents.d.ts +0 -9
  39. package/dist/cjs/processors/processComEvents.js +0 -163
  40. package/dist/cjs/processors/processModule.d.ts +0 -31
  41. package/dist/cjs/processors/processModule.js +0 -159
  42. package/dist/cjs/processors/processScene.d.ts +0 -32
  43. package/dist/cjs/processors/processScene.js +0 -198
  44. package/dist/cjs/processors/processSceneLogic.d.ts +0 -7
  45. package/dist/cjs/processors/processSceneLogic.js +0 -230
  46. package/dist/cjs/shims-taro.d.ts +0 -20
  47. package/dist/cjs/taro-template.json +0 -154
  48. package/dist/cjs/toCodeTaro.d.ts +0 -168
  49. package/dist/cjs/toCodeTaro.js +0 -326
  50. package/dist/cjs/utils/builder/buildResult.d.ts +0 -24
  51. package/dist/cjs/utils/builder/buildResult.js +0 -163
  52. package/dist/cjs/utils/common/ImportManager.d.ts +0 -26
  53. package/dist/cjs/utils/common/ImportManager.js +0 -123
  54. package/dist/cjs/utils/common/helper.d.ts +0 -12
  55. package/dist/cjs/utils/common/helper.js +0 -52
  56. package/dist/cjs/utils/common/object.d.ts +0 -5
  57. package/dist/cjs/utils/common/object.js +0 -58
  58. package/dist/cjs/utils/common/string.d.ts +0 -18
  59. package/dist/cjs/utils/common/string.js +0 -59
  60. package/dist/cjs/utils/config/content/converter.d.ts +0 -17
  61. package/dist/cjs/utils/config/content/converter.js +0 -84
  62. package/dist/cjs/utils/config/content/index.d.ts +0 -10
  63. package/dist/cjs/utils/config/content/index.js +0 -33
  64. package/dist/cjs/utils/config/content/pageConfig.d.ts +0 -10
  65. package/dist/cjs/utils/config/content/pageConfig.js +0 -80
  66. package/dist/cjs/utils/config/content/saveBase64Image.d.ts +0 -24
  67. package/dist/cjs/utils/config/content/saveBase64Image.js +0 -113
  68. package/dist/cjs/utils/config/content/tabBarConfig.d.ts +0 -28
  69. package/dist/cjs/utils/config/content/tabBarConfig.js +0 -74
  70. package/dist/cjs/utils/config/content/types.d.ts +0 -73
  71. package/dist/cjs/utils/config/content/types.js +0 -17
  72. package/dist/cjs/utils/config/content/validator.d.ts +0 -13
  73. package/dist/cjs/utils/config/content/validator.js +0 -67
  74. package/dist/cjs/utils/config/handlePageConfig.d.ts +0 -31
  75. package/dist/cjs/utils/config/handlePageConfig.js +0 -88
  76. package/dist/cjs/utils/context/buildContext.d.ts +0 -31
  77. package/dist/cjs/utils/context/buildContext.js +0 -76
  78. package/dist/cjs/utils/context/buildFrameMap.d.ts +0 -16
  79. package/dist/cjs/utils/context/buildFrameMap.js +0 -106
  80. package/dist/cjs/utils/context/buildGlobalData.d.ts +0 -13
  81. package/dist/cjs/utils/context/buildGlobalData.js +0 -58
  82. package/dist/cjs/utils/context/collectJSModules.d.ts +0 -41
  83. package/dist/cjs/utils/context/collectJSModules.js +0 -93
  84. package/dist/cjs/utils/context/createEventQueries.d.ts +0 -45
  85. package/dist/cjs/utils/context/createEventQueries.js +0 -99
  86. package/dist/cjs/utils/context/createProvider.d.ts +0 -21
  87. package/dist/cjs/utils/context/createProvider.js +0 -49
  88. package/dist/cjs/utils/index.d.ts +0 -10
  89. package/dist/cjs/utils/index.js +0 -60
  90. package/dist/cjs/utils/logic/convertNamespace.d.ts +0 -11
  91. package/dist/cjs/utils/logic/convertNamespace.js +0 -43
  92. package/dist/cjs/utils/logic/genJSModules.d.ts +0 -16
  93. package/dist/cjs/utils/logic/genJSModules.js +0 -114
  94. package/dist/cjs/utils/logic/handleProcess.d.ts +0 -9
  95. package/dist/cjs/utils/logic/handleProcess.js +0 -462
  96. package/dist/cjs/utils/logic/processChildren.d.ts +0 -26
  97. package/dist/cjs/utils/logic/processChildren.js +0 -121
  98. package/dist/cjs/utils/style/color.d.ts +0 -4
  99. package/dist/cjs/utils/style/color.js +0 -45
  100. package/dist/cjs/utils/style/converter.d.ts +0 -7
  101. package/dist/cjs/utils/style/converter.js +0 -175
  102. package/dist/cjs/utils/style/getComponentClassName.d.ts +0 -16
  103. package/dist/cjs/utils/style/getComponentClassName.js +0 -47
  104. package/dist/cjs/utils/style/pxtransform.d.ts +0 -4
  105. package/dist/cjs/utils/style/pxtransform.js +0 -62
  106. package/dist/cjs/utils/style/types.d.ts +0 -23
  107. package/dist/cjs/utils/style/types.js +0 -17
  108. package/dist/cjs/utils/templates/component.d.ts +0 -19
  109. package/dist/cjs/utils/templates/component.js +0 -86
  110. package/dist/cjs/utils/templates/index.d.ts +0 -32
  111. package/dist/cjs/utils/templates/index.js +0 -116
  112. package/dist/cjs/utils/templates/renderManager.d.ts +0 -18
  113. package/dist/cjs/utils/templates/renderManager.js +0 -152
  114. package/dist/cjs/utils/templates/scene.d.ts +0 -23
  115. package/dist/cjs/utils/templates/scene.js +0 -113
  116. package/dist/esm/abstractEventTypeDef.d.ts +0 -11
  117. package/dist/esm/abstractEventTypeDef.js +0 -63
  118. package/dist/esm/generate/compressImages.d.ts +0 -16
  119. package/dist/esm/generate/compressImages.js +0 -108
  120. package/dist/esm/generate/generateTaroProjectJson.d.ts +0 -13
  121. package/dist/esm/generate/generateTaroProjectJson.js +0 -228
  122. package/dist/esm/generate/generateTaroTempalteJson.d.ts +0 -15
  123. package/dist/esm/generate/generateTaroTempalteJson.js +0 -94
  124. package/dist/esm/generate/utils/appConfig.d.ts +0 -21
  125. package/dist/esm/generate/utils/appConfig.js +0 -49
  126. package/dist/esm/generate/utils/commonDir.d.ts +0 -21
  127. package/dist/esm/generate/utils/commonDir.js +0 -53
  128. package/dist/esm/generate/utils/customTabBar.d.ts +0 -11
  129. package/dist/esm/generate/utils/customTabBar.js +0 -52
  130. package/dist/esm/generate/utils/fileNode.d.ts +0 -21
  131. package/dist/esm/generate/utils/fileNode.js +0 -62
  132. package/dist/esm/generate/utils/index.d.ts +0 -7
  133. package/dist/esm/generate/utils/index.js +0 -8
  134. package/dist/esm/generate/utils/pageImages.d.ts +0 -14
  135. package/dist/esm/generate/utils/pageImages.js +0 -15
  136. package/dist/esm/generate/utils/tabBarImages.d.ts +0 -14
  137. package/dist/esm/generate/utils/tabBarImages.js +0 -15
  138. package/dist/esm/handleCom.d.ts +0 -8
  139. package/dist/esm/handleCom.js +0 -350
  140. package/dist/esm/handleDom.d.ts +0 -21
  141. package/dist/esm/handleDom.js +0 -26
  142. package/dist/esm/handleExtension.d.ts +0 -10
  143. package/dist/esm/handleExtension.js +0 -243
  144. package/dist/esm/handleGlobal.d.ts +0 -11
  145. package/dist/esm/handleGlobal.js +0 -157
  146. package/dist/esm/handleModule.d.ts +0 -15
  147. package/dist/esm/handleModule.js +0 -73
  148. package/dist/esm/handleSlot.d.ts +0 -29
  149. package/dist/esm/handleSlot.js +0 -215
  150. package/dist/esm/index.d.ts +0 -4
  151. package/dist/esm/index.js +0 -4
  152. package/dist/esm/processors/processComEvents.d.ts +0 -9
  153. package/dist/esm/processors/processComEvents.js +0 -170
  154. package/dist/esm/processors/processModule.d.ts +0 -31
  155. package/dist/esm/processors/processModule.js +0 -177
  156. package/dist/esm/processors/processScene.d.ts +0 -32
  157. package/dist/esm/processors/processScene.js +0 -234
  158. package/dist/esm/processors/processSceneLogic.d.ts +0 -7
  159. package/dist/esm/processors/processSceneLogic.js +0 -247
  160. package/dist/esm/shims-taro.d.ts +0 -20
  161. package/dist/esm/taro-template.json +0 -154
  162. package/dist/esm/toCodeTaro.d.ts +0 -168
  163. package/dist/esm/toCodeTaro.js +0 -367
  164. package/dist/esm/utils/builder/buildResult.d.ts +0 -24
  165. package/dist/esm/utils/builder/buildResult.js +0 -119
  166. package/dist/esm/utils/common/ImportManager.d.ts +0 -26
  167. package/dist/esm/utils/common/ImportManager.js +0 -131
  168. package/dist/esm/utils/common/helper.d.ts +0 -12
  169. package/dist/esm/utils/common/helper.js +0 -33
  170. package/dist/esm/utils/common/object.d.ts +0 -5
  171. package/dist/esm/utils/common/object.js +0 -32
  172. package/dist/esm/utils/common/string.d.ts +0 -18
  173. package/dist/esm/utils/common/string.js +0 -37
  174. package/dist/esm/utils/config/content/converter.d.ts +0 -17
  175. package/dist/esm/utils/config/content/converter.js +0 -106
  176. package/dist/esm/utils/config/content/index.d.ts +0 -10
  177. package/dist/esm/utils/config/content/index.js +0 -11
  178. package/dist/esm/utils/config/content/pageConfig.d.ts +0 -10
  179. package/dist/esm/utils/config/content/pageConfig.js +0 -43
  180. package/dist/esm/utils/config/content/saveBase64Image.d.ts +0 -24
  181. package/dist/esm/utils/config/content/saveBase64Image.js +0 -127
  182. package/dist/esm/utils/config/content/tabBarConfig.d.ts +0 -28
  183. package/dist/esm/utils/config/content/tabBarConfig.js +0 -89
  184. package/dist/esm/utils/config/content/types.d.ts +0 -73
  185. package/dist/esm/utils/config/content/types.js +0 -1
  186. package/dist/esm/utils/config/content/validator.d.ts +0 -13
  187. package/dist/esm/utils/config/content/validator.js +0 -64
  188. package/dist/esm/utils/config/handlePageConfig.d.ts +0 -31
  189. package/dist/esm/utils/config/handlePageConfig.js +0 -89
  190. package/dist/esm/utils/context/buildContext.d.ts +0 -31
  191. package/dist/esm/utils/context/buildContext.js +0 -65
  192. package/dist/esm/utils/context/buildFrameMap.d.ts +0 -16
  193. package/dist/esm/utils/context/buildFrameMap.js +0 -131
  194. package/dist/esm/utils/context/buildGlobalData.d.ts +0 -13
  195. package/dist/esm/utils/context/buildGlobalData.js +0 -44
  196. package/dist/esm/utils/context/collectJSModules.d.ts +0 -41
  197. package/dist/esm/utils/context/collectJSModules.js +0 -87
  198. package/dist/esm/utils/context/createEventQueries.d.ts +0 -45
  199. package/dist/esm/utils/context/createEventQueries.js +0 -99
  200. package/dist/esm/utils/context/createProvider.d.ts +0 -21
  201. package/dist/esm/utils/context/createProvider.js +0 -33
  202. package/dist/esm/utils/index.d.ts +0 -10
  203. package/dist/esm/utils/index.js +0 -12
  204. package/dist/esm/utils/logic/convertNamespace.d.ts +0 -11
  205. package/dist/esm/utils/logic/convertNamespace.js +0 -27
  206. package/dist/esm/utils/logic/genJSModules.d.ts +0 -16
  207. package/dist/esm/utils/logic/genJSModules.js +0 -33
  208. package/dist/esm/utils/logic/handleProcess.d.ts +0 -9
  209. package/dist/esm/utils/logic/handleProcess.js +0 -520
  210. package/dist/esm/utils/logic/processChildren.d.ts +0 -26
  211. package/dist/esm/utils/logic/processChildren.js +0 -101
  212. package/dist/esm/utils/style/color.d.ts +0 -4
  213. package/dist/esm/utils/style/color.js +0 -17
  214. package/dist/esm/utils/style/converter.d.ts +0 -7
  215. package/dist/esm/utils/style/converter.js +0 -175
  216. package/dist/esm/utils/style/getComponentClassName.d.ts +0 -16
  217. package/dist/esm/utils/style/getComponentClassName.js +0 -37
  218. package/dist/esm/utils/style/pxtransform.d.ts +0 -4
  219. package/dist/esm/utils/style/pxtransform.js +0 -54
  220. package/dist/esm/utils/style/types.d.ts +0 -23
  221. package/dist/esm/utils/style/types.js +0 -1
  222. package/dist/esm/utils/templates/component.d.ts +0 -19
  223. package/dist/esm/utils/templates/component.js +0 -55
  224. package/dist/esm/utils/templates/index.d.ts +0 -32
  225. package/dist/esm/utils/templates/index.js +0 -97
  226. package/dist/esm/utils/templates/renderManager.d.ts +0 -18
  227. package/dist/esm/utils/templates/renderManager.js +0 -145
  228. package/dist/esm/utils/templates/scene.d.ts +0 -23
  229. package/dist/esm/utils/templates/scene.js +0 -66
@@ -1,228 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import { findDir, ensureDir } from "./utils/fileNode";
5
- import { handleCommonDir } from "./utils/commonDir";
6
- import { handleTabBarImages } from "./utils/tabBarImages";
7
- import { handlePageImages } from "./utils/pageImages";
8
- import { updateAppConfig } from "./utils/appConfig";
9
- import { updateCustomTabBar } from "./utils/customTabBar";
10
- import { genScopedJSModules } from "../utils/logic/genJSModules";
11
- /**
12
- * 根据数组生成文件结构 JSON 对象
13
- * @param result 包含 files 和 assets 的生成结果对象
14
- * @returns 返回文件结构的 JSON 对象数组
15
- */
16
- var generateTaroProjectJson = function generateTaroProjectJson(result) {
17
- var _pagesDir$children, _srcDir$children;
18
- var _result$files = result.files,
19
- files = _result$files === void 0 ? [] : _result$files,
20
- _result$assets = result.assets,
21
- assets = _result$assets === void 0 ? {} : _result$assets;
22
-
23
- // 读取模板 JSON 文件
24
- var templateJsonPath = path.join(__dirname, "../taro-template.json");
25
- if (!fs.existsSync(templateJsonPath)) {
26
- throw new Error("\u6A21\u677F\u6587\u4EF6\u4E0D\u5B58\u5728: ".concat(templateJsonPath));
27
- }
28
- var templateJson = JSON.parse(fs.readFileSync(templateJsonPath, "utf-8"));
29
-
30
- // 找到 src 目录
31
- var srcDir = templateJson.find(function (node) {
32
- return node.path === "src";
33
- });
34
- srcDir.children = srcDir.children || [];
35
-
36
- // 找到 pages 目录
37
- var pagesDir = findDir(templateJson, "src/pages");
38
- if (!pagesDir) {
39
- throw new Error("未找到 pages 目录");
40
- }
41
- pagesDir.children = pagesDir.children || [];
42
-
43
- // 确保 common 目录存在
44
- var commonDir = ensureDir(srcDir, "src/common");
45
-
46
- // 确保 assets/tabbar 目录存在
47
- var assetsDir = ensureDir(srcDir, "src/assets");
48
- var tabbarDir = ensureDir(assetsDir, "src/assets/tabbar");
49
-
50
- // 从 assets 中获取 TabBar 图片文件信息
51
- var imageFiles = assets.tabBarImages || [];
52
- var pageImages = assets.pageImages || [];
53
-
54
- // 过滤出类型为 normal 的项
55
- var normalItems = files.filter(function (item) {
56
- return item.type === "normal";
57
- });
58
-
59
- // 处理所有 normal 类型的项,生成页面节点数组
60
- var generatedPages = normalItems.map(function (item) {
61
- var _item$importManager;
62
- var pageName = item.meta.id;
63
-
64
- // 生成完整的文件内容:import 语句 + content
65
- var importCode = ((_item$importManager = item.importManager) === null || _item$importManager === void 0 ? void 0 : _item$importManager.toCode()) || "";
66
- var fileContent = item.content || "";
67
- var fullContent = importCode ? "".concat(importCode, "\n").concat(fileContent) : fileContent;
68
-
69
- // 使用 item 中的 pageConfigContent,如果没有则使用默认配置
70
- var configContent = item.pageConfigContent || "export default definePageConfig({\n navigationBarTitleText: '\u9875\u9762'\n})";
71
-
72
- // 固定生成三个文件节点
73
- var pageChildren = [{
74
- path: "src/pages/".concat(pageName, "/index.config.ts"),
75
- content: configContent
76
- }, {
77
- path: "src/pages/".concat(pageName, "/index.less"),
78
- content: item.cssContent || ""
79
- }, {
80
- path: "src/pages/".concat(pageName, "/index.tsx"),
81
- content: fullContent
82
- }];
83
- // 生成页面级 jsModules(如果有 JS 计算组件)
84
- if (item.jsModules && item.jsModules.length > 0) {
85
- pageChildren.push({
86
- path: "src/pages/".concat(pageName, "/index.jsModules.ts"),
87
- content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
88
- });
89
- }
90
-
91
- // 返回页面目录节点
92
- return {
93
- path: "src/pages/".concat(pageName),
94
- content: null,
95
- children: pageChildren
96
- };
97
- });
98
-
99
- // 一次性将所有生成的页面添加到 pages 目录
100
- (_pagesDir$children = pagesDir.children).push.apply(_pagesDir$children, _toConsumableArray(generatedPages));
101
-
102
- // --- 处理弹窗场景 (popup) ---
103
- var popupComponentsDir = ensureDir(srcDir, "src/popupComponents");
104
- var popupScenes = files.filter(function (item) {
105
- return item.type === "popup" && item.meta;
106
- });
107
- popupScenes.forEach(function (item) {
108
- var _item$importManager2;
109
- var popupId = item.meta.id;
110
- var importCode = ((_item$importManager2 = item.importManager) === null || _item$importManager2 === void 0 ? void 0 : _item$importManager2.toCode()) || "";
111
- var fullContent = "".concat(importCode, "\n").concat(item.content || "");
112
- var popupChildren = [{
113
- path: "src/popupComponents/".concat(popupId, "/index.tsx"),
114
- content: fullContent
115
- }, {
116
- path: "src/popupComponents/".concat(popupId, "/index.less"),
117
- content: item.cssContent || ""
118
- }];
119
- if (item.jsModules && item.jsModules.length > 0) {
120
- popupChildren.push({
121
- path: "src/popupComponents/".concat(popupId, "/index.jsModules.ts"),
122
- content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
123
- });
124
- }
125
- popupComponentsDir.children.push({
126
- path: "src/popupComponents/".concat(popupId),
127
- content: null,
128
- children: popupChildren
129
- });
130
- });
131
-
132
- // --- 处理模块/区块场景 (module) ---
133
- var componentsDir = ensureDir(srcDir, "src/components");
134
- var moduleScenes = files.filter(function (item) {
135
- return item.type === "module" && item.meta;
136
- });
137
- var moduleExports = [];
138
- moduleScenes.forEach(function (item) {
139
- var _item$importManager3;
140
- var moduleId = item.meta.id;
141
- var exportName = "C".concat(String(moduleId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
142
- var importCode = ((_item$importManager3 = item.importManager) === null || _item$importManager3 === void 0 ? void 0 : _item$importManager3.toCode()) || "";
143
- var fullContent = "".concat(importCode, "\n").concat(item.content || "");
144
- var moduleChildren = [{
145
- path: "src/components/".concat(moduleId, "/index.tsx"),
146
- content: fullContent
147
- }, {
148
- path: "src/components/".concat(moduleId, "/index.less"),
149
- content: item.cssContent || ""
150
- }];
151
- if (item.jsModules && item.jsModules.length > 0) {
152
- moduleChildren.push({
153
- path: "src/components/".concat(moduleId, "/index.jsModules.ts"),
154
- content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
155
- });
156
- }
157
- componentsDir.children.push({
158
- path: "src/components/".concat(moduleId),
159
- content: null,
160
- children: moduleChildren
161
- });
162
- moduleExports.push("export { default as ".concat(exportName, " } from \"./").concat(moduleId, "/index\";"));
163
- });
164
-
165
- // 生成 components/Index.ts 汇总导出
166
- if (moduleExports.length > 0) {
167
- componentsDir.children.push({
168
- path: "src/components/Index.ts",
169
- content: moduleExports.join("\n") + "\n"
170
- });
171
- }
172
-
173
- // 更新 app.config.ts (只传入 normalItems 作为真正的页面)
174
- var appConfigFile = (_srcDir$children = srcDir.children) === null || _srcDir$children === void 0 ? void 0 : _srcDir$children.find(function (node) {
175
- return node.path === "src/app.config.ts";
176
- });
177
- if (appConfigFile) {
178
- updateAppConfig(appConfigFile, normalItems, files);
179
- }
180
-
181
- // 处理 TabBar 图片文件
182
- handleTabBarImages(tabbarDir, imageFiles);
183
-
184
- // 处理页面 base64 图片文件(与 tabbar 同级别)
185
- handlePageImages(assetsDir, pageImages);
186
-
187
- // 替换自定义 Tabbar 配置文件
188
- updateCustomTabBar(srcDir, files);
189
-
190
- // 处理 common 目录下的文件
191
- handleCommonDir(commonDir, files);
192
-
193
- // 生成全局 jsModules(如果全局 Fx 中有 JS 计算组件)
194
- var globalItem = files.find(function (item) {
195
- return item.type === 'global';
196
- });
197
- if (globalItem !== null && globalItem !== void 0 && globalItem.jsModules && globalItem.jsModules.length > 0) {
198
- commonDir.children.push({
199
- path: 'src/common/index.jsModules.ts',
200
- content: genScopedJSModules(globalItem.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
201
- });
202
- }
203
-
204
- // 处理 common 目录下的 api.ts
205
- var apiItem = files.find(function (item) {
206
- return item.type === 'connector-api';
207
- });
208
- if (apiItem) {
209
- commonDir.children = commonDir.children || [];
210
- commonDir.children.push({
211
- path: 'src/common/api.ts',
212
- content: apiItem.content
213
- });
214
- }
215
-
216
- // 处理 popup 汇总文件 (type 为 popup 且无 meta)
217
- var popupFile = files.find(function (f) {
218
- return f.type === "popup" && !f.meta;
219
- });
220
- if (popupFile) {
221
- commonDir.children.push({
222
- path: "src/common/".concat(popupFile.name, ".ts"),
223
- content: popupFile.content
224
- });
225
- }
226
- return templateJson;
227
- };
228
- export default generateTaroProjectJson;
@@ -1,15 +0,0 @@
1
- interface FileNode {
2
- path: string;
3
- content: string | null;
4
- children?: FileNode[];
5
- }
6
- interface TemplateJson {
7
- rootDir: string;
8
- files: FileNode[];
9
- }
10
- /**
11
- * 递归遍历目录并生成文件树结构
12
- * @param templateDir 模板目录路径,默认为当前文件所在目录下的 template 目录
13
- */
14
- declare const generateTaroTemplateJson: (templateDir?: string) => TemplateJson;
15
- export default generateTaroTemplateJson;
@@ -1,94 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import * as fs from 'fs';
4
- import * as path from 'path';
5
- var _templateDir = path.join(__dirname, '../_template');
6
-
7
- /**
8
- * 递归遍历目录并生成文件树结构
9
- * @param templateDir 模板目录路径,默认为当前文件所在目录下的 template 目录
10
- */
11
- var generateTaroTemplateJson = function generateTaroTemplateJson() {
12
- var templateDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _templateDir;
13
- var rootDir = path.basename(templateDir);
14
- var files = [];
15
-
16
- // 需要忽略的目录和文件
17
- var ignoreList = ['node_modules', 'dist', '.git', '.husky', '.swc', 'yarn.lock', 'package-lock.json'];
18
-
19
- /**
20
- * 递归读取目录
21
- */
22
- var readDirectory = function readDirectory(dirPath) {
23
- var relativePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
24
- var items = [];
25
- var entries = fs.readdirSync(dirPath, {
26
- withFileTypes: true
27
- });
28
-
29
- // 按名称排序,目录在前
30
- entries.sort(function (a, b) {
31
- if (a.isDirectory() && !b.isDirectory()) return -1;
32
- if (!a.isDirectory() && b.isDirectory()) return 1;
33
- return a.name.localeCompare(b.name);
34
- });
35
- var _iterator = _createForOfIteratorHelper(entries),
36
- _step;
37
- try {
38
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
39
- var entry = _step.value;
40
- // 跳过忽略列表中的项
41
- if (ignoreList.includes(entry.name)) {
42
- continue;
43
- }
44
- var fullPath = path.join(dirPath, entry.name);
45
- var itemRelativePath = relativePath ? "".concat(relativePath, "/").concat(entry.name) : entry.name;
46
- if (entry.isDirectory()) {
47
- // 递归读取子目录
48
- var children = readDirectory(fullPath, itemRelativePath);
49
- items.push({
50
- path: itemRelativePath,
51
- content: null,
52
- children: children.length > 0 ? children : undefined
53
- });
54
- } else {
55
- // 读取文件内容
56
- try {
57
- var content = fs.readFileSync(fullPath, 'utf-8');
58
- items.push({
59
- path: itemRelativePath,
60
- content: content,
61
- children: undefined
62
- });
63
- } catch (error) {
64
- // 如果读取失败(如二进制文件),内容设为空字符串
65
- items.push({
66
- path: itemRelativePath,
67
- content: '',
68
- children: undefined
69
- });
70
- }
71
- }
72
- }
73
- } catch (err) {
74
- _iterator.e(err);
75
- } finally {
76
- _iterator.f();
77
- }
78
- return items;
79
- };
80
- files.push.apply(files, _toConsumableArray(readDirectory(templateDir)));
81
- // console.log(files);
82
-
83
- // 写入 JSON 文件,如果已存在则先删除
84
- var jsonFilePath = path.join(__dirname, '../taro-template.json');
85
- if (fs.existsSync(jsonFilePath)) {
86
- fs.unlinkSync(jsonFilePath);
87
- }
88
- fs.writeFileSync(jsonFilePath, JSON.stringify(files, null, 2));
89
- return {
90
- rootDir: rootDir,
91
- files: files
92
- };
93
- };
94
- export default generateTaroTemplateJson;
@@ -1,21 +0,0 @@
1
- /**
2
- * app.config.ts 更新工具
3
- */
4
- interface FileNode {
5
- path: string;
6
- content: string | null;
7
- children?: FileNode[];
8
- }
9
- interface GenerateItem {
10
- type: string;
11
- meta?: {
12
- id: string;
13
- coms?: Record<string, any>;
14
- };
15
- [key: string]: any;
16
- }
17
- /**
18
- * 更新 app.config.ts
19
- */
20
- export declare function updateAppConfig(appConfigFile: FileNode, normalItems: GenerateItem[], items: GenerateItem[]): void;
21
- export {};
@@ -1,49 +0,0 @@
1
- import { parseLooseObject } from "./fileNode";
2
-
3
- /**
4
- * app.config.ts 更新工具
5
- */
6
-
7
- /**
8
- * 更新 app.config.ts
9
- */
10
- export function updateAppConfig(appConfigFile, normalItems, items) {
11
- var _appConfigFile$conten;
12
- if (!appConfigFile.content) {
13
- return;
14
- }
15
-
16
- // 提取export default defineAppConfig()里的内容
17
- var content = parseLooseObject(((_appConfigFile$conten = appConfigFile.content.match(/defineAppConfig\(([\s\S]*?)\)/)) === null || _appConfigFile$conten === void 0 ? void 0 : _appConfigFile$conten[1]) || '{}');
18
-
19
- // 更新 pages 配置(使用 scene id)
20
- var newPagePaths = normalItems.map(function (item) {
21
- return "pages/".concat(item.meta.id, "/index");
22
- });
23
- content.pages = newPagePaths;
24
-
25
- // 提取首页
26
- var entryPagePath = '';
27
- normalItems.forEach(function (item) {
28
- var _Object$values, _item$meta;
29
- (_Object$values = Object.values((_item$meta = item.meta) === null || _item$meta === void 0 ? void 0 : _item$meta.coms)) === null || _Object$values === void 0 || _Object$values.forEach(function (com) {
30
- var _com$model;
31
- if (com !== null && com !== void 0 && com.asRoot && com !== null && com !== void 0 && (_com$model = com.model) !== null && _com$model !== void 0 && (_com$model = _com$model.data) !== null && _com$model !== void 0 && _com$model.isEntryPagePath) {
32
- entryPagePath = "pages/".concat(item.meta.id, "/index");
33
- }
34
- });
35
- });
36
- if (entryPagePath) {
37
- content.entryPagePath = entryPagePath;
38
- }
39
-
40
- // 添加 TabBar 配置(从 items 中读取)
41
- var tabBarConfigItem = items.find(function (item) {
42
- return item.type === 'tabBarConfig';
43
- });
44
- if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.content) {
45
- var tabBar = parseLooseObject("{".concat(tabBarConfigItem.content, "}"));
46
- Object.assign(content, tabBar);
47
- }
48
- appConfigFile.content = "export default defineAppConfig(".concat(JSON.stringify(content, null, 2), ")");
49
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Common 目录处理工具
3
- */
4
- interface FileNode {
5
- path: string;
6
- content: string | null;
7
- children?: FileNode[];
8
- }
9
- interface GenerateItem {
10
- type: string;
11
- content?: string;
12
- importManager?: {
13
- toCode: () => string;
14
- };
15
- [key: string]: any;
16
- }
17
- /**
18
- * 处理 common 目录下的文件
19
- */
20
- export declare function handleCommonDir(commonDir: FileNode, items: GenerateItem[]): void;
21
- export {};
@@ -1,53 +0,0 @@
1
- /**
2
- * Common 目录处理工具
3
- */
4
-
5
- /**
6
- * 处理 common 目录下的文件
7
- */
8
- export function handleCommonDir(commonDir, items) {
9
- commonDir.children = commonDir.children || [];
10
-
11
- // 处理 jsModulesRuntime
12
- var jsModulesRuntimeItem = items.find(function (item) {
13
- return item.type === 'jsModulesRuntime';
14
- });
15
- if (jsModulesRuntimeItem) {
16
- var _jsModulesRuntimeItem;
17
- var importCode = ((_jsModulesRuntimeItem = jsModulesRuntimeItem.importManager) === null || _jsModulesRuntimeItem === void 0 ? void 0 : _jsModulesRuntimeItem.toCode()) || '';
18
- var fileContent = jsModulesRuntimeItem.content || '';
19
- var fullContent = importCode ? "".concat(importCode, "\n").concat(fileContent) : fileContent;
20
- commonDir.children.push({
21
- path: 'src/common/jsModulesRuntime.ts',
22
- content: fullContent
23
- });
24
- }
25
-
26
- // 处理 global
27
- var globalItem = items.find(function (item) {
28
- return item.type === 'global';
29
- });
30
- if (globalItem) {
31
- var _globalItem$importMan;
32
- var _importCode = ((_globalItem$importMan = globalItem.importManager) === null || _globalItem$importMan === void 0 ? void 0 : _globalItem$importMan.toCode()) || '';
33
- var _fileContent = globalItem.content || '';
34
- var _fullContent = _importCode ? "".concat(_importCode, "\n").concat(_fileContent) : _fileContent;
35
- commonDir.children.push({
36
- path: 'src/common/global.ts',
37
- content: _fullContent
38
- });
39
- }
40
-
41
- // 处理rootConfig
42
- var rootConfigItem = items.find(function (item) {
43
- return item.type === 'rootConfig';
44
- });
45
- if (rootConfigItem) {
46
- var _fileContent2 = rootConfigItem.content || '{}';
47
- var _fullContent2 = "export default ".concat(_fileContent2);
48
- commonDir.children.push({
49
- path: 'src/common/rootConfig.ts',
50
- content: _fullContent2
51
- });
52
- }
53
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * 更新自定义 TabBar 配置文件
3
- */
4
- import { GeneratedFile } from '../../toCodeTaro';
5
- interface FileNode {
6
- path: string;
7
- content: string | null;
8
- children?: FileNode[];
9
- }
10
- export declare function updateCustomTabBar(srcDir: FileNode, files: GeneratedFile[]): void;
11
- export {};
@@ -1,52 +0,0 @@
1
- /**
2
- * 更新自定义 TabBar 配置文件
3
- */
4
-
5
- import { ensureDir } from "./fileNode";
6
- import { parseLooseObject } from "./fileNode";
7
- export function updateCustomTabBar(srcDir, files) {
8
- var customTabBarDir = ensureDir(srcDir, 'src/custom-tab-bar');
9
-
10
- // 将mybricks的tabbar数据写入/custom-tab-bar/mybricks/tabbar-config.ts
11
- var customTabBarItem = files.find(function (item) {
12
- return item.type === 'customTabBar';
13
- });
14
- if (customTabBarItem !== null && customTabBarItem !== void 0 && customTabBarItem.content) {
15
- var _mybricksDir$children;
16
- var CUSTOM_TAB_BAR_CONFIG_PATH = 'src/custom-tab-bar/mybricks/tabbar-config.ts';
17
- var mybricksDir = ensureDir(customTabBarDir, 'src/custom-tab-bar/mybricks');
18
- var tabbarConfigFileIndex = (_mybricksDir$children = mybricksDir.children) === null || _mybricksDir$children === void 0 ? void 0 : _mybricksDir$children.findIndex(function (node) {
19
- return node.path === CUSTOM_TAB_BAR_CONFIG_PATH;
20
- });
21
- if (tabbarConfigFileIndex === -1) {
22
- mybricksDir.children.push({
23
- path: CUSTOM_TAB_BAR_CONFIG_PATH,
24
- content: customTabBarItem.content
25
- });
26
- } else {
27
- mybricksDir.children[tabbarConfigFileIndex].content = customTabBarItem.content;
28
- }
29
- }
30
-
31
- // 将app.config.ts中的tabbar配置写入/custom-tab-bar/tabBar.json
32
- // 后续可以用来判断页面是否标签页
33
- var tabBarConfigItem = files.find(function (item) {
34
- return item.type === 'tabBarConfig';
35
- });
36
- if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.content) {
37
- var _customTabBarDir$chil;
38
- var contentStr = JSON.stringify(parseLooseObject("{".concat(tabBarConfigItem.content, "}")), null, 2);
39
- var tabBarJsonPath = "".concat(customTabBarDir.path, "/tabBar.json");
40
- var tabBarJsonIndex = (_customTabBarDir$chil = customTabBarDir.children) === null || _customTabBarDir$chil === void 0 ? void 0 : _customTabBarDir$chil.findIndex(function (node) {
41
- return node.path === tabBarJsonPath;
42
- });
43
- if (tabBarJsonIndex === -1) {
44
- customTabBarDir.children.push({
45
- path: tabBarJsonPath,
46
- content: contentStr
47
- });
48
- } else {
49
- customTabBarDir.children[tabBarJsonIndex].content = contentStr;
50
- }
51
- }
52
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * 文件节点相关工具函数
3
- */
4
- interface FileNode {
5
- path: string;
6
- content: string | null;
7
- children?: FileNode[];
8
- }
9
- /**
10
- * 查找目录节点
11
- */
12
- export declare function findDir(nodes: FileNode[], targetPath: string): FileNode | null;
13
- /**
14
- * 确保目录存在,如果不存在则创建
15
- */
16
- export declare function ensureDir(parentDir: FileNode, dirPath: string): FileNode;
17
- /**
18
- * 解析宽松格式的对象字符串
19
- */
20
- export declare function parseLooseObject(raw: string): any;
21
- export {};
@@ -1,62 +0,0 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import { runInNewContext } from 'node:vm';
3
-
4
- /**
5
- * 文件节点相关工具函数
6
- */
7
-
8
- /**
9
- * 查找目录节点
10
- */
11
- export function findDir(nodes, targetPath) {
12
- var _iterator = _createForOfIteratorHelper(nodes),
13
- _step;
14
- try {
15
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
16
- var node = _step.value;
17
- if (node.path === targetPath) {
18
- return node;
19
- }
20
- if (node.children) {
21
- var found = findDir(node.children, targetPath);
22
- if (found) return found;
23
- }
24
- }
25
- } catch (err) {
26
- _iterator.e(err);
27
- } finally {
28
- _iterator.f();
29
- }
30
- return null;
31
- }
32
-
33
- /**
34
- * 确保目录存在,如果不存在则创建
35
- */
36
- export function ensureDir(parentDir, dirPath) {
37
- parentDir.children = parentDir.children || [];
38
- var dir = parentDir.children.find(function (node) {
39
- return node.path === dirPath;
40
- });
41
- if (!dir) {
42
- dir = {
43
- path: dirPath,
44
- content: null,
45
- children: []
46
- };
47
- parentDir.children.push(dir);
48
- }
49
- dir.children = dir.children || [];
50
- return dir;
51
- }
52
-
53
- /**
54
- * 解析宽松格式的对象字符串
55
- */
56
- export function parseLooseObject(raw) {
57
- try {
58
- return JSON.parse(raw);
59
- } catch (_unused) {
60
- return runInNewContext("(".concat(raw, ")"), Object.create(null));
61
- }
62
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * generate 工具函数统一导出
3
- */
4
- export * from './fileNode';
5
- export * from './commonDir';
6
- export * from './tabBarImages';
7
- export * from './appConfig';
@@ -1,8 +0,0 @@
1
- /**
2
- * generate 工具函数统一导出
3
- */
4
-
5
- export * from "./fileNode";
6
- export * from "./commonDir";
7
- export * from "./tabBarImages";
8
- export * from "./appConfig";
@@ -1,14 +0,0 @@
1
- /**
2
- * 页面图片文件处理工具
3
- */
4
- import type { ImageFileInfo } from '../../utils/config/content';
5
- interface FileNode {
6
- path: string;
7
- content: string | null;
8
- children?: FileNode[];
9
- }
10
- /**
11
- * 处理页面 base64 图片文件
12
- */
13
- export declare function handlePageImages(assetsDir: FileNode, imageFiles: ImageFileInfo[]): void;
14
- export {};