@cloudbase/framework-plugin-low-code 1.0.2-beta.1 → 1.0.2-beta.2

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 (217) hide show
  1. package/package.json +4 -4
  2. package/lib/builder/config/common.d.ts +0 -2
  3. package/lib/builder/config/common.d.ts.map +0 -1
  4. package/lib/builder/config/common.js +0 -13
  5. package/lib/builder/config/index.d.ts +0 -3
  6. package/lib/builder/config/index.d.ts.map +0 -1
  7. package/lib/builder/config/index.js +0 -29
  8. package/lib/builder/config/mp.d.ts +0 -2
  9. package/lib/builder/config/mp.d.ts.map +0 -1
  10. package/lib/builder/config/mp.js +0 -13
  11. package/lib/builder/core/copy.d.ts +0 -5
  12. package/lib/builder/core/copy.d.ts.map +0 -1
  13. package/lib/builder/core/copy.js +0 -62
  14. package/lib/builder/core/generate.d.ts +0 -9
  15. package/lib/builder/core/generate.d.ts.map +0 -1
  16. package/lib/builder/core/generate.js +0 -128
  17. package/lib/builder/core/index.d.ts +0 -32
  18. package/lib/builder/core/index.d.ts.map +0 -1
  19. package/lib/builder/core/index.js +0 -149
  20. package/lib/builder/core/material.d.ts +0 -4
  21. package/lib/builder/core/material.d.ts.map +0 -1
  22. package/lib/builder/core/material.js +0 -80
  23. package/lib/builder/core/plugin.d.ts +0 -4
  24. package/lib/builder/core/plugin.d.ts.map +0 -1
  25. package/lib/builder/core/plugin.js +0 -30
  26. package/lib/builder/core/prepare.d.ts +0 -8
  27. package/lib/builder/core/prepare.d.ts.map +0 -1
  28. package/lib/builder/core/prepare.js +0 -108
  29. package/lib/builder/core/webpack.d.ts +0 -15
  30. package/lib/builder/core/webpack.d.ts.map +0 -1
  31. package/lib/builder/core/webpack.js +0 -58
  32. package/lib/builder/mp/BuildContext.d.ts +0 -13
  33. package/lib/builder/mp/BuildContext.d.ts.map +0 -1
  34. package/lib/builder/mp/BuildContext.js +0 -2
  35. package/lib/builder/mp/index.d.ts +0 -33
  36. package/lib/builder/mp/index.d.ts.map +0 -1
  37. package/lib/builder/mp/index.js +0 -450
  38. package/lib/builder/mp/lowcode.d.ts +0 -8
  39. package/lib/builder/mp/lowcode.d.ts.map +0 -1
  40. package/lib/builder/mp/lowcode.js +0 -58
  41. package/lib/builder/mp/materials.d.ts +0 -15
  42. package/lib/builder/mp/materials.d.ts.map +0 -1
  43. package/lib/builder/mp/materials.js +0 -338
  44. package/lib/builder/mp/mixMode.d.ts +0 -10
  45. package/lib/builder/mp/mixMode.d.ts.map +0 -1
  46. package/lib/builder/mp/mixMode.js +0 -215
  47. package/lib/builder/mp/mp_config.d.ts +0 -18
  48. package/lib/builder/mp/mp_config.d.ts.map +0 -1
  49. package/lib/builder/mp/mp_config.js +0 -206
  50. package/lib/builder/mp/util.d.ts +0 -20
  51. package/lib/builder/mp/util.d.ts.map +0 -1
  52. package/lib/builder/mp/util.js +0 -243
  53. package/lib/builder/mp/wxml.d.ts +0 -16
  54. package/lib/builder/mp/wxml.d.ts.map +0 -1
  55. package/lib/builder/mp/wxml.js +0 -300
  56. package/lib/builder/service/builder/copy.d.ts +0 -14
  57. package/lib/builder/service/builder/copy.d.ts.map +0 -1
  58. package/lib/builder/service/builder/copy.js +0 -189
  59. package/lib/builder/service/builder/generate.d.ts +0 -52
  60. package/lib/builder/service/builder/generate.d.ts.map +0 -1
  61. package/lib/builder/service/builder/generate.js +0 -789
  62. package/lib/builder/service/builder/index.d.ts +0 -16
  63. package/lib/builder/service/builder/index.d.ts.map +0 -1
  64. package/lib/builder/service/builder/index.js +0 -69
  65. package/lib/builder/service/builder/plugin.d.ts +0 -8
  66. package/lib/builder/service/builder/plugin.d.ts.map +0 -1
  67. package/lib/builder/service/builder/plugin.js +0 -149
  68. package/lib/builder/service/builder/webpack.d.ts +0 -91
  69. package/lib/builder/service/builder/webpack.d.ts.map +0 -1
  70. package/lib/builder/service/builder/webpack.js +0 -589
  71. package/lib/builder/types/common.d.ts +0 -12
  72. package/lib/builder/types/common.d.ts.map +0 -1
  73. package/lib/builder/types/common.js +0 -7
  74. package/lib/builder/util/common.d.ts +0 -36
  75. package/lib/builder/util/common.d.ts.map +0 -1
  76. package/lib/builder/util/common.js +0 -257
  77. package/lib/builder/util/console.d.ts +0 -2
  78. package/lib/builder/util/console.d.ts.map +0 -1
  79. package/lib/builder/util/console.js +0 -13
  80. package/lib/builder/util/generateFiles.d.ts +0 -6
  81. package/lib/builder/util/generateFiles.d.ts.map +0 -1
  82. package/lib/builder/util/generateFiles.js +0 -94
  83. package/lib/builder/util/index.d.ts +0 -2
  84. package/lib/builder/util/index.d.ts.map +0 -1
  85. package/lib/builder/util/index.js +0 -13
  86. package/lib/builder/util/junk.d.ts +0 -3
  87. package/lib/builder/util/junk.d.ts.map +0 -1
  88. package/lib/builder/util/junk.js +0 -25
  89. package/lib/builder/util/mp.d.ts +0 -5
  90. package/lib/builder/util/mp.d.ts.map +0 -1
  91. package/lib/builder/util/mp.js +0 -99
  92. package/lib/builder/util/name-mangler.d.ts +0 -3
  93. package/lib/builder/util/name-mangler.d.ts.map +0 -1
  94. package/lib/builder/util/name-mangler.js +0 -7
  95. package/lib/builder/util/net.d.ts +0 -3
  96. package/lib/builder/util/net.d.ts.map +0 -1
  97. package/lib/builder/util/net.js +0 -54
  98. package/lib/builder/util/process.d.ts +0 -9
  99. package/lib/builder/util/process.d.ts.map +0 -1
  100. package/lib/builder/util/process.js +0 -28
  101. package/lib/builder/util/style.d.ts +0 -2
  102. package/lib/builder/util/style.d.ts.map +0 -1
  103. package/lib/builder/util/style.js +0 -13
  104. package/lib/builder/util/weapp.d.ts +0 -2
  105. package/lib/builder/util/weapp.d.ts.map +0 -1
  106. package/lib/builder/util/weapp.js +0 -13
  107. package/lib/generator/config/common.d.ts +0 -6
  108. package/lib/generator/config/common.d.ts.map +0 -1
  109. package/lib/generator/config/common.js +0 -25
  110. package/lib/generator/config/index.d.ts +0 -18
  111. package/lib/generator/config/index.d.ts.map +0 -1
  112. package/lib/generator/config/index.js +0 -43
  113. package/lib/generator/config/mp.d.ts +0 -56
  114. package/lib/generator/config/mp.d.ts.map +0 -1
  115. package/lib/generator/config/mp.js +0 -104
  116. package/lib/generator/core/generate.d.ts +0 -59
  117. package/lib/generator/core/generate.d.ts.map +0 -1
  118. package/lib/generator/core/generate.js +0 -669
  119. package/lib/generator/core/index.d.ts +0 -25
  120. package/lib/generator/core/index.d.ts.map +0 -1
  121. package/lib/generator/core/index.js +0 -102
  122. package/lib/generator/core/material.d.ts +0 -14
  123. package/lib/generator/core/material.d.ts.map +0 -1
  124. package/lib/generator/core/material.js +0 -230
  125. package/lib/generator/template.d.ts +0 -3
  126. package/lib/generator/template.d.ts.map +0 -1
  127. package/lib/generator/template.js +0 -3
  128. package/lib/generator/types/common.d.ts +0 -69
  129. package/lib/generator/types/common.d.ts.map +0 -1
  130. package/lib/generator/types/common.js +0 -21
  131. package/lib/generator/util/common.d.ts +0 -36
  132. package/lib/generator/util/common.d.ts.map +0 -1
  133. package/lib/generator/util/common.js +0 -238
  134. package/lib/generator/util/console.d.ts +0 -3
  135. package/lib/generator/util/console.d.ts.map +0 -1
  136. package/lib/generator/util/console.js +0 -17
  137. package/lib/generator/util/index.d.ts +0 -2
  138. package/lib/generator/util/index.d.ts.map +0 -1
  139. package/lib/generator/util/index.js +0 -13
  140. package/lib/generator/util/name-mangler.d.ts +0 -17
  141. package/lib/generator/util/name-mangler.d.ts.map +0 -1
  142. package/lib/generator/util/name-mangler.js +0 -63
  143. package/lib/generator/util/postcss-rpx.d.ts +0 -11
  144. package/lib/generator/util/postcss-rpx.d.ts.map +0 -1
  145. package/lib/generator/util/postcss-rpx.js +0 -16
  146. package/lib/generator/util/style.d.ts +0 -6
  147. package/lib/generator/util/style.d.ts.map +0 -1
  148. package/lib/generator/util/style.js +0 -92
  149. package/lib/generator/util/weapp.d.ts +0 -5
  150. package/lib/generator/util/weapp.d.ts.map +0 -1
  151. package/lib/generator/util/weapp.js +0 -17
  152. package/lib/types.d.ts +0 -14
  153. package/lib/types.d.ts.map +0 -1
  154. package/lib/types.js +0 -19
  155. package/lib/weapps-core/config/index.d.ts +0 -2
  156. package/lib/weapps-core/config/index.d.ts.map +0 -1
  157. package/lib/weapps-core/config/index.js +0 -13
  158. package/lib/weapps-core/config/style.d.ts +0 -7
  159. package/lib/weapps-core/config/style.d.ts.map +0 -1
  160. package/lib/weapps-core/config/style.js +0 -70
  161. package/lib/weapps-core/index.d.ts +0 -6
  162. package/lib/weapps-core/index.d.ts.map +0 -1
  163. package/lib/weapps-core/index.js +0 -31
  164. package/lib/weapps-core/types/action.d.ts +0 -25
  165. package/lib/weapps-core/types/action.d.ts.map +0 -1
  166. package/lib/weapps-core/types/action.js +0 -28
  167. package/lib/weapps-core/types/app.d.ts +0 -142
  168. package/lib/weapps-core/types/app.d.ts.map +0 -1
  169. package/lib/weapps-core/types/app.js +0 -21
  170. package/lib/weapps-core/types/appbuild.d.ts +0 -63
  171. package/lib/weapps-core/types/appbuild.d.ts.map +0 -1
  172. package/lib/weapps-core/types/appbuild.js +0 -78
  173. package/lib/weapps-core/types/code_types.d.ts +0 -26
  174. package/lib/weapps-core/types/code_types.d.ts.map +0 -1
  175. package/lib/weapps-core/types/code_types.js +0 -2
  176. package/lib/weapps-core/types/git.d.ts +0 -7
  177. package/lib/weapps-core/types/git.d.ts.map +0 -1
  178. package/lib/weapps-core/types/git.js +0 -2
  179. package/lib/weapps-core/types/index.d.ts +0 -11
  180. package/lib/weapps-core/types/index.d.ts.map +0 -1
  181. package/lib/weapps-core/types/index.js +0 -22
  182. package/lib/weapps-core/types/lowcode.d.ts +0 -26
  183. package/lib/weapps-core/types/lowcode.d.ts.map +0 -1
  184. package/lib/weapps-core/types/lowcode.js +0 -25
  185. package/lib/weapps-core/types/material.d.ts +0 -90
  186. package/lib/weapps-core/types/material.d.ts.map +0 -1
  187. package/lib/weapps-core/types/material.js +0 -9
  188. package/lib/weapps-core/types/plugins.d.ts +0 -17
  189. package/lib/weapps-core/types/plugins.d.ts.map +0 -1
  190. package/lib/weapps-core/types/plugins.js +0 -2
  191. package/lib/weapps-core/types/style.d.ts +0 -93
  192. package/lib/weapps-core/types/style.d.ts.map +0 -1
  193. package/lib/weapps-core/types/style.js +0 -2
  194. package/lib/weapps-core/types/web.d.ts +0 -120
  195. package/lib/weapps-core/types/web.d.ts.map +0 -1
  196. package/lib/weapps-core/types/web.js +0 -2
  197. package/lib/weapps-core/utils/appbuild.d.ts +0 -6
  198. package/lib/weapps-core/utils/appbuild.d.ts.map +0 -1
  199. package/lib/weapps-core/utils/appbuild.js +0 -40
  200. package/lib/weapps-core/utils/common.d.ts +0 -16
  201. package/lib/weapps-core/utils/common.d.ts.map +0 -1
  202. package/lib/weapps-core/utils/common.js +0 -90
  203. package/lib/weapps-core/utils/file.d.ts +0 -12
  204. package/lib/weapps-core/utils/file.d.ts.map +0 -1
  205. package/lib/weapps-core/utils/file.js +0 -142
  206. package/lib/weapps-core/utils/formily.d.ts +0 -5
  207. package/lib/weapps-core/utils/formily.d.ts.map +0 -1
  208. package/lib/weapps-core/utils/formily.js +0 -416
  209. package/lib/weapps-core/utils/index.d.ts +0 -7
  210. package/lib/weapps-core/utils/index.d.ts.map +0 -1
  211. package/lib/weapps-core/utils/index.js +0 -18
  212. package/lib/weapps-core/utils/lowcdoe.d.ts +0 -4
  213. package/lib/weapps-core/utils/lowcdoe.d.ts.map +0 -1
  214. package/lib/weapps-core/utils/lowcdoe.js +0 -69
  215. package/lib/weapps-core/utils/style.d.ts +0 -17
  216. package/lib/weapps-core/utils/style.d.ts.map +0 -1
  217. package/lib/weapps-core/utils/style.js +0 -330
@@ -1,789 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.generateCodeFromTpl = exports.writeLowCodeFilesForCompositeComp = exports.writeLowCodeFiles = exports.generateRouterFile = exports.pushActionToImportStringArr = exports.getActionImportStringArr = exports.getEntryImportStringArr = exports.getComponentImportStringArr = exports.getPluginImportStringArr = exports.getPluginInstancesString = exports.getListenersString = exports.getComponentSchemaString = exports.isSlot = exports.getVirtualFieldsString = exports.pullComponentToListByInstance = exports.pullActionToListByInstances = exports.getOriginPluginList = exports.getOriginComponentAndActionList = exports.generateSinglePageJsxFile = exports.generateAllPageJsxFile = exports.generateThemeVarsFile = exports.generateAppStyleLessFile = void 0;
16
- const path_1 = __importDefault(require("path"));
17
- const fs_extra_1 = __importDefault(require("fs-extra"));
18
- const lodash_1 = __importDefault(require("lodash"));
19
- const lodash_template_1 = __importDefault(require("lodash.template"));
20
- const react_schema_renderer_1 = require("@formily/react-schema-renderer");
21
- const chalk_1 = __importDefault(require("chalk"));
22
- const os_1 = __importDefault(require("os"));
23
- const weapps_core_1 = require("../../../weapps-core");
24
- const util_1 = require("../../util");
25
- const config_1 = require("../../config");
26
- const style_1 = require("../../util/style");
27
- const common_1 = require("../../types/common");
28
- const util_2 = require("../../util");
29
- const dataSource_1 = require("../../../utils/dataSource");
30
- const generateFiles_1 = require("../../util/generateFiles");
31
- const types_1 = require("../../../types");
32
- const util_3 = require("../../../generator/util");
33
- function generateAppStyleLessFile(allAppDataList, appBuildDir) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const appLessPath = path_1.default.join(appBuildDir, 'src/index.less');
36
- yield fs_extra_1.default.ensureFile(appLessPath);
37
- for (const appData of allAppDataList) {
38
- if (appData.codeModules) {
39
- let content = `@import "./lowcode/style.less";\n\n`;
40
- content += yield fs_extra_1.default.readFile(appLessPath, {
41
- encoding: 'utf8',
42
- });
43
- yield fs_extra_1.default.writeFile(appLessPath, `${content}${os_1.default.EOL}`, {
44
- encoding: 'utf8',
45
- });
46
- }
47
- }
48
- });
49
- }
50
- exports.generateAppStyleLessFile = generateAppStyleLessFile;
51
- function generateThemeVarsFile(themeVars = {}, appBuildDir) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const themeVarsPath = path_1.default.resolve(appBuildDir, './webpack/themeVars.js');
54
- for (const key in themeVars) {
55
- if (!themeVars[key]) {
56
- delete themeVars[key];
57
- }
58
- }
59
- yield fs_extra_1.default.writeFile(themeVarsPath, `module.exports = ${JSON.stringify(themeVars, null, 2)}`, {
60
- encoding: 'utf8',
61
- });
62
- });
63
- }
64
- exports.generateThemeVarsFile = generateThemeVarsFile;
65
- function generateAllPageJsxFile(pageInstanceList, appBuildDir, rootPath, dependencies = [], extraData = {
66
- isComposite: false,
67
- compProps: {},
68
- }, buildTypeList) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- yield Promise.all((0, weapps_core_1.loopDealWithFn)(pageInstanceList, (pageInstance) => generateSinglePageJsxFile(pageInstance, appBuildDir, rootPath, dependencies, extraData, buildTypeList)));
71
- });
72
- }
73
- exports.generateAllPageJsxFile = generateAllPageJsxFile;
74
- function generateSinglePageJsxFile(pageInstance, appBuildDir, rootPath, dependencies = [], extraData = {
75
- isComposite: false,
76
- compProps: {},
77
- }, buildTypeList) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const fixedDependencies = dependencies;
80
- const { componentSchemaJson, pluginInstances, listenerInstances: pageListenerInstances, style: PageStyle, data, } = pageInstance;
81
- const { originComponentList, originActionList } = getOriginComponentAndActionList(componentSchemaJson, fixedDependencies);
82
- const componentsMeta = yield (0, util_1.getComponentsInfo)(appBuildDir, dependencies);
83
- const originPluginList = getOriginPluginList(pluginInstances, dependencies);
84
- pullActionToListByInstances(pageListenerInstances, originActionList, fixedDependencies);
85
- const originEntryMap = {};
86
- originComponentList.forEach((component) => {
87
- if (!originEntryMap[component.materialName]) {
88
- const info = {
89
- materialName: component.materialName,
90
- version: component.materialVersion,
91
- entries: component.entries,
92
- };
93
- originEntryMap[component.materialName] = info;
94
- }
95
- });
96
- originActionList.forEach((action) => {
97
- if (!originEntryMap[action.materialName]) {
98
- const info = {
99
- materialName: action.materialName,
100
- version: action.materialVersion,
101
- entries: action.entries,
102
- };
103
- originEntryMap[action.materialName] = info;
104
- }
105
- });
106
- const entryImportStringArr = getEntryImportStringArr(Object.values(originEntryMap));
107
- const componentImportStringArr = getComponentImportStringArr(originComponentList);
108
- const actionImportStringArr = getActionImportStringArr(originActionList);
109
- const pluginImportStringArr = getPluginImportStringArr(originPluginList);
110
- const { widgets, dataBinds, componentSchema } = getComponentSchemaString(componentSchemaJson, false, componentsMeta);
111
- const pageStyleString = (0, weapps_core_1.toCssText)((0, weapps_core_1.toCssStyle)(PageStyle), (0, common_1.buildAsWebByBuildType)(buildTypeList) ? 'body' : 'page');
112
- const templateData = {
113
- pageUUID: rootPath ? `${rootPath}/${pageInstance.id}` : pageInstance.id,
114
- pageName: pageInstance.id,
115
- pageSource: pageInstance.data.src || '',
116
- pageStyleText: pageStyleString,
117
- entryImports: entryImportStringArr.join(';\n'),
118
- componentImports: componentImportStringArr.join(';\n'),
119
- pluginImports: pluginImportStringArr.join(';\n'),
120
- actionImports: actionImportStringArr.join(';\n'),
121
- pageListenerInstances: getListenersString(pageListenerInstances),
122
- virtualFields: getVirtualFieldsString(originComponentList),
123
- pluginInstances: getPluginInstancesString(pluginInstances),
124
- componentSchema,
125
- widgets,
126
- dataBinds,
127
- isComposite: extraData.isComposite,
128
- compProps: extraData.compProps,
129
- title: data.navigationBarTitleText || data.title || '',
130
- reachBottomDistance: data.reachBottomDistance || 0,
131
- };
132
- const dest = path_1.default.resolve(appBuildDir, `./pages/${pageInstance.id}/index.jsx`);
133
- const template = yield fs_extra_1.default.readFile(path_1.default.resolve(config_1.appTemplateDir, './src/pages/app.tpl'), {
134
- encoding: 'utf8',
135
- });
136
- const jsx = (0, lodash_template_1.default)(template)(templateData);
137
- yield fs_extra_1.default.ensureFile(dest);
138
- yield fs_extra_1.default.writeFile(dest, jsx);
139
- const pageStyleDest = path_1.default.resolve(appBuildDir, `./pages/${pageInstance.id}/index.less`);
140
- const prefixStyleImport = `@import "../../lowcode/${pageInstance.id}/style.less";`;
141
- yield fs_extra_1.default.ensureFile(pageStyleDest);
142
- yield fs_extra_1.default.writeFile(pageStyleDest, prefixStyleImport + os_1.default.EOL);
143
- });
144
- }
145
- exports.generateSinglePageJsxFile = generateSinglePageJsxFile;
146
- function getOriginComponentAndActionList(componentSchema, fixedDependencies, originComponentList = [], originActionList = []) {
147
- const fieldSchema = new react_schema_renderer_1.Schema(componentSchema);
148
- if (fieldSchema.isObject()) {
149
- const { 'x-props': xProps } = fieldSchema;
150
- if (xProps) {
151
- const { listenerInstances, sourceKey } = xProps;
152
- pullComponentToListByInstance(sourceKey, originComponentList, fixedDependencies);
153
- pullActionToListByInstances(listenerInstances, originActionList, fixedDependencies);
154
- }
155
- if (fieldSchema.properties) {
156
- for (let key in fieldSchema.properties) {
157
- const schema = fieldSchema.properties[key];
158
- const schemaJson = schema;
159
- getOriginComponentAndActionList(schemaJson, fixedDependencies, originComponentList, originActionList);
160
- }
161
- }
162
- }
163
- return {
164
- originComponentList,
165
- originActionList,
166
- };
167
- }
168
- exports.getOriginComponentAndActionList = getOriginComponentAndActionList;
169
- function getOriginPluginList(pluginInstances = [], dependencies = [], originPluginList = []) {
170
- pluginInstances.map((instance) => {
171
- var _a;
172
- const { sourceKey } = instance;
173
- const { materialName, name, variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
174
- const pluginKey = `${materialName}_${name}`;
175
- const isExist = originPluginList.find((item) => item.key === pluginKey);
176
- if (isExist) {
177
- return;
178
- }
179
- originPluginList.push({
180
- sourceKey,
181
- name: name || '',
182
- materialName: materialName || '',
183
- materialVersion: (_a = dependencies.find((m) => m.name === materialName)) === null || _a === void 0 ? void 0 : _a.version,
184
- key: pluginKey,
185
- variableName: variableName || '',
186
- });
187
- });
188
- return originPluginList;
189
- }
190
- exports.getOriginPluginList = getOriginPluginList;
191
- function pullActionToListByInstances(listenerInstances, originActionList, fixedDependencies) {
192
- if (!listenerInstances || !listenerInstances.length) {
193
- return;
194
- }
195
- listenerInstances.map((pageListenerInstance) => {
196
- const { sourceKey, type } = pageListenerInstance;
197
- const { materialName, name, variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
198
- const material = fixedDependencies.find((m) => m.name === materialName);
199
- const actionKey = `${materialName}_${name}`;
200
- const isExistAction = originActionList.find((item) => item.key === actionKey);
201
- if (!isExistAction) {
202
- originActionList.push({
203
- name,
204
- materialName,
205
- materialVersion: material === null || material === void 0 ? void 0 : material.version,
206
- key: actionKey,
207
- type,
208
- variableName,
209
- entries: material === null || material === void 0 ? void 0 : material.entries,
210
- });
211
- }
212
- });
213
- }
214
- exports.pullActionToListByInstances = pullActionToListByInstances;
215
- function pullComponentToListByInstance(sourceKey, originComponentList, fixedDependencies) {
216
- const { materialName, name, variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
217
- const componentKey = `${materialName}_${name}`;
218
- const isExistComponent = originComponentList.find((item) => item.key === componentKey);
219
- if (!isExistComponent) {
220
- const foundOne = fixedDependencies.find((m) => m.name === materialName);
221
- if (!foundOne)
222
- return;
223
- originComponentList.push({
224
- sourceKey,
225
- name: name || '',
226
- materialName: materialName || '',
227
- materialVersion: foundOne.version,
228
- key: componentKey,
229
- variableName: variableName || '',
230
- isPlainProps: !!(foundOne === null || foundOne === void 0 ? void 0 : foundOne.isPlainProps),
231
- entries: foundOne === null || foundOne === void 0 ? void 0 : foundOne.entries,
232
- });
233
- }
234
- }
235
- exports.pullComponentToListByInstance = pullComponentToListByInstance;
236
- function getVirtualFieldsString(components) {
237
- const fields = components.reduce((result, component) => {
238
- const { name, materialName, variableName, isPlainProps } = component;
239
- result[`${materialName}:${name}`] = `%%%React.forwardRef((props, ref) => <${lodash_1.default.upperFirst(variableName)} ${isPlainProps ? '{...resolveComponentProps(props, 1)}' : '{...resolveComponentProps(props, 0)}'} ref={ref} pageVirtualFields={virtualFields}/>)%%%`;
240
- return result;
241
- }, {});
242
- return JSON.stringify(fields, null, 2).replace(/"%%%(.*?)%%%"/g, function (match, expression) {
243
- return expression.replace(/\\"/g, '"');
244
- });
245
- }
246
- exports.getVirtualFieldsString = getVirtualFieldsString;
247
- function isSlot(comp) {
248
- return comp.path && !comp['x-props'];
249
- }
250
- exports.isSlot = isSlot;
251
- function getComponentSchemaString(componentSchema, isComposite = false, componentsInfoMap = {}, wrapperClass) {
252
- const componentInputProps = (0, util_1.getInputProps)(componentsInfoMap) || {};
253
- const copyJson = (0, util_1.simpleDeepClone)(componentSchema);
254
- const compWidgets = {};
255
- const compDataBinds = {};
256
- const componentSchemaJson = (0, util_1.deepDealSchema)(copyJson, (schema) => {
257
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
258
- const { 'x-props': xProps = {}, properties } = schema;
259
- const { dataBinds = [], commonStyle = {}, data = {}, classNameList = [], sourceKey, styleBind, classNameListBind, staticResourceAttribute = [], } = xProps;
260
- const componentInfo = componentsInfoMap[sourceKey];
261
- if ((_a = componentInfo) === null || _a === void 0 ? void 0 : _a.selectableBlock) {
262
- schema['selectableBlock'] = componentInfo['selectableBlock'];
263
- }
264
- if ((_b = componentInfo) === null || _b === void 0 ? void 0 : _b.compConfig) {
265
- schema['compConfig'] = componentInfo['compConfig'];
266
- }
267
- if ((_c = componentInfo) === null || _c === void 0 ? void 0 : _c.events) {
268
- schema['emitEvents'] = (_d = componentInfo) === null || _d === void 0 ? void 0 : _d.events.map((item) => item.name);
269
- }
270
- else if ((_e = componentInfo) === null || _e === void 0 ? void 0 : _e.emitEvents) {
271
- schema['emitEvents'] = componentInfo.emitEvents.map((item) => item.eventName);
272
- }
273
- if (!isSlot(schema) && schema.key) {
274
- compWidgets[schema.key] = Object.assign(Object.assign({}, data), { style: (0, weapps_core_1.toCssStyle)(commonStyle), classList: classNameList, widgetType: sourceKey, _parentId: isSlot(schema.parent) ? (_g = (_f = schema === null || schema === void 0 ? void 0 : schema.parent) === null || _f === void 0 ? void 0 : _f.parent) === null || _g === void 0 ? void 0 : _g.key : (_h = schema === null || schema === void 0 ? void 0 : schema.parent) === null || _h === void 0 ? void 0 : _h.key });
275
- if (dataBinds.length > 0) {
276
- compDataBinds[schema.key] = generateDataBinds(dataBinds, isComposite);
277
- }
278
- if (styleBind) {
279
- if (!styleBind.bindDataPath) {
280
- console.warn('无 bindDataPath', xProps);
281
- }
282
- else {
283
- styleBind.propertyPath = 'style';
284
- compDataBinds[schema.key] = Object.assign(Object.assign({}, (compDataBinds[schema.key] || {})), generateDataBinds([styleBind], isComposite));
285
- }
286
- }
287
- if (classNameListBind) {
288
- classNameListBind.propertyPath = 'classList';
289
- compDataBinds[schema.key] = Object.assign(Object.assign({}, (compDataBinds[schema.key] || {})), generateDataBinds([classNameListBind], isComposite));
290
- }
291
- }
292
- if (properties && (0, weapps_core_1.isEmptyObj)(properties)) {
293
- delete schema.properties;
294
- }
295
- delete schema.type;
296
- if (compWidgets[schema.key]) {
297
- const propsKeys = Object.keys(compWidgets[schema.key]);
298
- propsKeys.forEach((propsKey) => {
299
- const propsVaule = compWidgets[schema.key][propsKey];
300
- if (propsVaule && Array.isArray(propsVaule)) {
301
- propsVaule.map((block) => {
302
- var _a, _b;
303
- const blockInstance = (block === null || block === void 0 ? void 0 : block.selectableBlock) && ((_b = (_a = block === null || block === void 0 ? void 0 : block.selectableBlock) === null || _a === void 0 ? void 0 : _a['x-props']) === null || _b === void 0 ? void 0 : _b.listenerInstances);
304
- if (blockInstance) {
305
- block.selectableBlock['x-props'].listenerInstances = generateListnerInstances(blockInstance, isComposite);
306
- }
307
- return block;
308
- });
309
- }
310
- });
311
- }
312
- if (xProps) {
313
- if (isComposite) {
314
- if (!((_j = schema === null || schema === void 0 ? void 0 : schema.parent) === null || _j === void 0 ? void 0 : _j.parent)) {
315
- if (!xProps['classNameList'])
316
- xProps['classNameList'] = [];
317
- xProps['classNameList'].push(wrapperClass);
318
- }
319
- }
320
- xProps['commonStyle'] = (0, weapps_core_1.toCssStyle)(xProps['commonStyle']);
321
- xProps['staticResourceAttribute'] = staticResourceAttribute;
322
- if ((0, weapps_core_1.isEmptyObj)(xProps['commonStyle'])) {
323
- delete xProps['commonStyle'];
324
- }
325
- if ((0, weapps_core_1.isEmptyObj)(xProps['style'])) {
326
- delete xProps['style'];
327
- }
328
- if (xProps['dataBinds'] && xProps['dataBinds'].length === 0) {
329
- delete xProps['dataBinds'];
330
- }
331
- if (xProps['listenerInstances'] && xProps['listenerInstances'].length === 0) {
332
- delete xProps['listenerInstances'];
333
- }
334
- if (xProps['data']) {
335
- const xPropsData = xProps['data'];
336
- if (xPropsData._waFor && xPropsData._waFor.length === 0) {
337
- delete xPropsData._waFor;
338
- }
339
- if (xPropsData.title === '') {
340
- delete xPropsData.title;
341
- }
342
- if (xPropsData.staticResourceAttribute && xPropsData.staticResourceAttribute.length === 0) {
343
- delete xPropsData.staticResourceAttribute;
344
- }
345
- if ((0, weapps_core_1.isEmptyObj)(xPropsData)) {
346
- delete xProps['data'];
347
- }
348
- }
349
- if (xProps.listenerInstances) {
350
- xProps.listenerInstances = generateListnerInstances(xProps.listenerInstances, isComposite);
351
- }
352
- const syncProps = componentInputProps[xProps.sourceKey];
353
- if (syncProps) {
354
- if (!xProps.listenerInstances)
355
- xProps.listenerInstances = [];
356
- Object.keys(syncProps).forEach((key) => {
357
- let syncPropArr = [];
358
- const syncProp = syncProps[key];
359
- if (!Array.isArray(syncProp)) {
360
- syncPropArr = [syncProp];
361
- }
362
- syncPropArr.forEach(({ changeEvent, valueFromEvent }) => {
363
- xProps.listenerInstances.unshift({
364
- trigger: changeEvent,
365
- instanceFunction: `${config_1.REPLACE_SIGN}function({ event, forItems, $context }) {
366
- const $for = forItems;
367
- const wid = ${isComposite ? 'this.widgets' : '$page.widgets'}.${schema.key};
368
- const widgetData = (forItems.forIndexes && forItems.forIndexes.length > 0) ? get(wid, forItems.forIndexes) : wid;
369
- widgetData.${key} = ${valueFromEvent};
370
- }.bind(this)${config_1.REPLACE_SIGN}`,
371
- });
372
- });
373
- });
374
- }
375
- if (xProps.dataBinds) {
376
- xProps.dataBinds = generateDataBinds(xProps.dataBinds, isComposite);
377
- }
378
- if (xProps.styleBind) {
379
- xProps.styleBind = generateDataBinds([xProps.styleBind], isComposite);
380
- }
381
- if (xProps.classNameListBind) {
382
- xProps.classNameListBind = generateDataBinds([xProps.classNameListBind], isComposite);
383
- }
384
- }
385
- });
386
- return {
387
- widgets: (0, util_1.JsonToStringWithVariableName)(compWidgets),
388
- dataBinds: (0, util_1.JsonToStringWithVariableName)(compDataBinds),
389
- componentSchema: (0, util_1.JsonToStringWithVariableName)(componentSchemaJson),
390
- };
391
- }
392
- exports.getComponentSchemaString = getComponentSchemaString;
393
- function generateDataBinds(dataBinds, isComposite) {
394
- const dataBindFuncs = {};
395
- dataBinds.forEach((bind) => {
396
- if (!bind.bindDataPath) {
397
- return console.warn('无 bindDataPath', bind.propertyPath);
398
- }
399
- let funcCode = '() => {}';
400
- funcCode = `() => ${funcCode}`;
401
- if (bind.type === weapps_core_1.PropBindType.forItem) {
402
- funcCode = `(forItems) => forItems.${bind.bindDataPath}`;
403
- }
404
- else if (bind.type === weapps_core_1.PropBindType.scope) {
405
- funcCode = `() => ({__type: "scopedValue", getValue: ($scope)=>$scope.${bind.bindDataPath}})}`;
406
- }
407
- else if (bind.type === weapps_core_1.PropBindType.expression) {
408
- let code = bind.bindDataPath;
409
- if (isComposite) {
410
- funcCode = `(forItems, event, $context) => { const $for = forItems; return (${code.replace(/\$comp/g, 'this.$WEAPPS_COMP')})}`;
411
- }
412
- else {
413
- funcCode = /\$scope\./.test(code)
414
- ? `(forItems, event, $context) => ({__type: "scopedValue", getValue: ($scope) => { const $for = forItems; return (\n${code}\n)}})`
415
- : `(forItems, event, $context) => { const $for = forItems; return (\n${code}\n)}`;
416
- }
417
- }
418
- else if (bind.type === weapps_core_1.PropBindType.prop) {
419
- let bindDataPath = bind.bindDataPath;
420
- const isNegated = bindDataPath.startsWith('!');
421
- if (isNegated)
422
- bindDataPath = bindDataPath.replace(/^!/, '');
423
- if (isComposite) {
424
- funcCode = `() => ${isNegated ? '!' : ''}this.$WEAPPS_COMP.props.data.${bindDataPath}`;
425
- }
426
- else {
427
- funcCode = `() => ${isNegated ? '!' : ''}$page.props.data.${bindDataPath}`;
428
- }
429
- }
430
- else {
431
- const PREFIX_MAP = {
432
- [weapps_core_1.PropBindType.state]: 'state',
433
- [weapps_core_1.PropBindType.computed]: 'computed',
434
- [weapps_core_1.PropBindType.dataVar]: 'dataVar',
435
- [weapps_core_1.PropBindType.stateData]: 'dataset.state',
436
- [weapps_core_1.PropBindType.paramData]: 'dataset.params',
437
- };
438
- switch (bind.type) {
439
- case weapps_core_1.PropBindType.state:
440
- case weapps_core_1.PropBindType.computed:
441
- case weapps_core_1.PropBindType.dataVar:
442
- case weapps_core_1.PropBindType.stateData:
443
- case weapps_core_1.PropBindType.paramData: {
444
- if (bind.bindDataPath.startsWith('global.')) {
445
- funcCode = bind.bindDataPath.replace(/^global./, `app.${PREFIX_MAP[bind.type]}.`);
446
- }
447
- else {
448
- if (isComposite) {
449
- funcCode = bind.bindDataPath
450
- .replace(/^comp-\w+./, `this.$WEAPPS_COMP.${PREFIX_MAP[bind.type]}.`)
451
- .replace(/^\$comp_\w+./, `this.$WEAPPS_COMP.${PREFIX_MAP[bind.type]}.`);
452
- }
453
- else {
454
- funcCode = bind.bindDataPath.replace(/^\w+./, `$page.${PREFIX_MAP[bind.type]}.`);
455
- }
456
- }
457
- funcCode = `() => ${funcCode}`;
458
- break;
459
- }
460
- }
461
- }
462
- dataBindFuncs[bind.propertyPath] = `${config_1.REPLACE_SIGN}${funcCode}${config_1.REPLACE_SIGN}`;
463
- });
464
- return dataBindFuncs;
465
- }
466
- function generateListnerInstances(listenerInstances, isComposite = false) {
467
- return listenerInstances.map((listener) => {
468
- var _a, _b, _c, _d, _e;
469
- const generatedListener = {
470
- key: listener.key,
471
- trigger: listener.trigger,
472
- isCapturePhase: listener.isCapturePhase,
473
- noPropagation: listener.noPropagation,
474
- };
475
- if (listener.type === weapps_core_1.ActionType.Material) {
476
- const { sourceKey } = listener;
477
- const { variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
478
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}${variableName}${config_1.REPLACE_SIGN}`;
479
- }
480
- else if (listener.type === weapps_core_1.ActionType.Platform) {
481
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}function({data}) { return app.${((_a = listener.handler) === null || _a === void 0 ? void 0 : _a.name) || listener.jsCode}(data) }${config_1.REPLACE_SIGN}`;
482
- }
483
- else if (listener.type === weapps_core_1.ActionType.DataSource) {
484
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}function({data}) { return app.cloud.callDataSource(data) }${config_1.REPLACE_SIGN}`;
485
- }
486
- else if (listener.type === weapps_core_1.ActionType.PropEvent) {
487
- if (isComposite) {
488
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}function({data}) { this.props.emit('${((_b = listener.handler) === null || _b === void 0 ? void 0 : _b.name) || listener.jsCode}', data.target) }.bind(this)${config_1.REPLACE_SIGN}`;
489
- }
490
- else {
491
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}function(...args) { $page.props.events.${((_c = listener.handler) === null || _c === void 0 ? void 0 : _c.name) || listener.jsCode}.apply(null, args) }${config_1.REPLACE_SIGN}`;
492
- }
493
- }
494
- else {
495
- if (isComposite) {
496
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}this.handler.${((_d = listener.handler) === null || _d === void 0 ? void 0 : _d.name) || listener.jsCode}.bind(this)${config_1.REPLACE_SIGN}`;
497
- }
498
- else {
499
- generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}handler.${((_e = listener.handler) === null || _e === void 0 ? void 0 : _e.name) || listener.jsCode}${config_1.REPLACE_SIGN}`;
500
- }
501
- }
502
- if (!(0, weapps_core_1.isEmptyObj)(listener.data)) {
503
- generatedListener.data = listener.data;
504
- }
505
- if (listener.dataBinds && listener.dataBinds.length > 0) {
506
- generatedListener.dataBinds = generateDataBinds(listener.dataBinds, isComposite);
507
- }
508
- return generatedListener;
509
- });
510
- }
511
- function getListenersString(listeners = [], isComposite = false) {
512
- return (0, util_1.JsonToStringWithVariableName)(generateListnerInstances(listeners, isComposite));
513
- }
514
- exports.getListenersString = getListenersString;
515
- function getPluginInstancesString(instances) {
516
- if (!instances || !instances.length) {
517
- return '[]';
518
- }
519
- const copyInstances = (0, util_1.simpleDeepClone)(instances);
520
- copyInstances.map((itemInstance) => {
521
- const { sourceKey } = itemInstance;
522
- const { variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
523
- itemInstance.instanceFunction = `${config_1.REPLACE_SIGN}${variableName}${config_1.REPLACE_SIGN}`;
524
- });
525
- return (0, util_1.JsonToStringWithVariableName)(copyInstances);
526
- }
527
- exports.getPluginInstancesString = getPluginInstancesString;
528
- function getPluginImportStringArr(plugins, pluginImportStringArr = []) {
529
- plugins.map((plugin) => __awaiter(this, void 0, void 0, function* () {
530
- const { name, materialName, materialVersion, variableName } = plugin;
531
- const importString = `import ${variableName} from 'libraries/${`${materialName}@${materialVersion}`}/plugins/${name}'`;
532
- if (pluginImportStringArr.includes(importString)) {
533
- return;
534
- }
535
- pluginImportStringArr.push(importString);
536
- }));
537
- return pluginImportStringArr;
538
- }
539
- exports.getPluginImportStringArr = getPluginImportStringArr;
540
- function getComponentImportStringArr(components, componentImportStringArr = []) {
541
- components.map((component) => __awaiter(this, void 0, void 0, function* () {
542
- const { name, materialName, materialVersion, variableName, entries } = component;
543
- let importString = '';
544
- if (entries === null || entries === void 0 ? void 0 : entries.components) {
545
- importString = `import { ${name} as ${lodash_1.default.upperFirst(variableName)} } from '${path_1.default.posix.join(`libraries/${materialName}@${materialVersion}`, entries === null || entries === void 0 ? void 0 : entries.components)}'`;
546
- }
547
- else if (entries === null || entries === void 0 ? void 0 : entries.entry) {
548
- const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
549
- importString = `const { ${name}: ${lodash_1.default.upperFirst(variableName)} } = ${componentsLibVariableName}.components`;
550
- }
551
- else {
552
- importString = `import ${lodash_1.default.upperFirst(variableName)} from 'libraries/${`${materialName}@${materialVersion}`}/components/${name}'`;
553
- }
554
- if (!componentImportStringArr.includes(importString)) {
555
- componentImportStringArr.push(importString);
556
- }
557
- }));
558
- return componentImportStringArr.filter((item) => !!item);
559
- }
560
- exports.getComponentImportStringArr = getComponentImportStringArr;
561
- function getEntryImportStringArr(materialInfoList = [], entryImportStringArr = []) {
562
- materialInfoList.forEach(({ materialName, version, entries }) => {
563
- if (!((entries === null || entries === void 0 ? void 0 : entries.actions) && (entries === null || entries === void 0 ? void 0 : entries.components)) && (entries === null || entries === void 0 ? void 0 : entries.entry)) {
564
- const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
565
- const importComponentLibString = `import ${componentsLibVariableName} from '${path_1.default.posix.join(`libraries/${materialName}@${version}`, entries === null || entries === void 0 ? void 0 : entries.entry)}'`;
566
- if (!entryImportStringArr.includes(importComponentLibString)) {
567
- entryImportStringArr.push(importComponentLibString);
568
- }
569
- }
570
- });
571
- return entryImportStringArr || [];
572
- }
573
- exports.getEntryImportStringArr = getEntryImportStringArr;
574
- function getActionImportStringArr(originActionList, actionImportStringArr = []) {
575
- originActionList.map((action) => {
576
- if (action.type === weapps_core_1.ActionType.Material) {
577
- pushActionToImportStringArr(action, actionImportStringArr);
578
- }
579
- });
580
- return actionImportStringArr;
581
- }
582
- exports.getActionImportStringArr = getActionImportStringArr;
583
- function pushActionToImportStringArr(listenerInstance, actionImportStringArr) {
584
- const { name, materialName, materialVersion, variableName, entries } = listenerInstance;
585
- const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
586
- const importString = (entries === null || entries === void 0 ? void 0 : entries.actions)
587
- ? `import { ${name} as ${variableName} } from '${path_1.default.posix.join(`libraries/${materialName}@${materialVersion}`, entries === null || entries === void 0 ? void 0 : entries.actions)}'`
588
- : (entries === null || entries === void 0 ? void 0 : entries.entry)
589
- ? `const { ${name}: ${variableName} } = ${componentsLibVariableName}.actions`
590
- : `import ${variableName} from 'libraries/${materialName}@${materialVersion}/actions/${name}'`;
591
- if (actionImportStringArr.includes(importString)) {
592
- return;
593
- }
594
- actionImportStringArr.push(importString);
595
- }
596
- exports.pushActionToImportStringArr = pushActionToImportStringArr;
597
- function generateRouterFile(allAppDataList, appBuildDir, basename = '', buildTypeList = []) {
598
- return __awaiter(this, void 0, void 0, function* () {
599
- const routerImports = [];
600
- const routerRenders = [];
601
- const mountApis = [];
602
- yield Promise.all(allAppDataList.map((data) => __awaiter(this, void 0, void 0, function* () {
603
- const { pageInstanceList, rootPath = '' } = data;
604
- const pageFilePath = rootPath ? `packages/${rootPath}/` : '';
605
- mountApis.push(`import '${pageFilePath}app/mountAppApis';`);
606
- (0, weapps_core_1.loopDealWithFn)(pageInstanceList, (pageInstance) => {
607
- const pageId = [rootPath, pageInstance.id].filter((i) => i).join('_');
608
- if (pageInstance.isHome && !rootPath) {
609
- routerRenders.push(`<Route from="/" exact children={() => <Redirect to="/${pageId}" />} />`);
610
- }
611
- routerImports.push(`import Page${pageId} from '${pageFilePath}pages/${pageInstance.id}/index';`);
612
- routerRenders.push(`<Route path="/${pageId}" component={Page${pageId}}/>`);
613
- });
614
- })));
615
- const routerTemplate = yield fs_extra_1.default.readFile(path_1.default.resolve(config_1.appTemplateDir, './src/router/index.tpl'), {
616
- encoding: 'utf8',
617
- });
618
- const routerIndexStr = (0, lodash_template_1.default)(routerTemplate)({
619
- routerImports: routerImports.join('\n'),
620
- routerRenders: routerRenders.join('\n'),
621
- mountApis: mountApis.join('\n'),
622
- basename: basename,
623
- });
624
- const dest = path_1.default.resolve(appBuildDir, `src/router/index.jsx`);
625
- yield fs_extra_1.default.ensureFile(dest);
626
- yield fs_extra_1.default.writeFile(dest, routerIndexStr);
627
- });
628
- }
629
- exports.generateRouterFile = generateRouterFile;
630
- function writeLowCodeFiles(appData, appBuildDir) {
631
- return __awaiter(this, void 0, void 0, function* () {
632
- const lowcodeRootDir = path_1.default.join(appBuildDir, 'lowcode');
633
- console.log(chalk_1.default.blue.bold('Writing lowcode files:'));
634
- (0, generateFiles_1.cleanDir)(lowcodeRootDir, []);
635
- (0, style_1.generateDefaultTheme)(appData);
636
- const themeCode = appData.codeModules.find((mod) => mod.type === 'theme');
637
- yield Promise.all(appData.codeModules.map((m) => writeCode2file(m, 'global')));
638
- yield Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, (page) => __awaiter(this, void 0, void 0, function* () {
639
- (0, style_1.generateDefaultStyle)(page);
640
- yield page.codeModules.filter((m) => m.name !== '____index____').forEach((m) => writeCode2file(m, page.id));
641
- })));
642
- function writeCode2file(mod, pageId) {
643
- return __awaiter(this, void 0, void 0, function* () {
644
- const file = path_1.default.join(lowcodeRootDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId, mod));
645
- let weappsApiPrefix = '';
646
- if (mod.type !== 'theme') {
647
- weappsApiPrefix =
648
- mod.type !== 'style'
649
- ? `import { app, $page } from '${path_1.default
650
- .relative(path_1.default.dirname(file), appBuildDir + '/app/global-api')
651
- .replace(/\\/g, '/')}';\nconst $app = app;`
652
- : ``;
653
- }
654
- console.log(chalk_1.default.green(file));
655
- let code = mod.code;
656
- if (mod.type === 'style') {
657
- code = yield (0, style_1.processLess)(((themeCode === null || themeCode === void 0 ? void 0 : themeCode.code) || style_1.defaultThemeCode) + code);
658
- }
659
- yield fs_extra_1.default.ensureFile(file);
660
- yield fs_extra_1.default.writeFile(file, weappsApiPrefix + os_1.default.EOL + code);
661
- });
662
- }
663
- });
664
- }
665
- exports.writeLowCodeFiles = writeLowCodeFiles;
666
- function writeLowCodeFilesForCompositeComp(compositeGroups, appBuildDir) {
667
- return __awaiter(this, void 0, void 0, function* () {
668
- const lowcodeRootDir = path_1.default.join(appBuildDir, 'src', 'lowcode', 'composite');
669
- console.log(chalk_1.default.blue.bold('Writing composite component lowcode files:'));
670
- yield Promise.all(compositeGroups.map((gItem) => __awaiter(this, void 0, void 0, function* () {
671
- yield (0, util_2.writeLibCommonRes2file)(gItem, path_1.default.join(appBuildDir, 'src', 'libraries', `${gItem.name}@${gItem.version}`, 'libCommonRes'));
672
- const compLibCommonResource = gItem.compLibCommonResource;
673
- let themeCode = '';
674
- if (compLibCommonResource) {
675
- themeCode = `
676
- ${compLibCommonResource.theme.variable || ''}
677
- ${compLibCommonResource.class || ''}
678
- ${compLibCommonResource.theme.class || ''}
679
- `;
680
- }
681
- return yield Promise.all(gItem.components.map((component) => __awaiter(this, void 0, void 0, function* () {
682
- let cItem = component;
683
- return yield cItem.lowCodes.forEach((m) => writeCode2file(m, path_1.default.join(appBuildDir, 'src', 'libraries', `${gItem.name}@${gItem.version}`, 'components', cItem.name, 'lowcode'), cItem, themeCode));
684
- })));
685
- })));
686
- function writeCode2file(mod, lowcodeDir, comp, themeCode) {
687
- return __awaiter(this, void 0, void 0, function* () {
688
- const pageId = comp.name + '_' + comp.id;
689
- const file = path_1.default.join(lowcodeDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId, mod));
690
- yield fs_extra_1.default.ensureFile(file);
691
- let codeContent = '';
692
- if (mod.type === 'style') {
693
- codeContent = `.${(0, weapps_core_1.getCompositedComponentClass)(comp)} { \n${themeCode ? themeCode : ''}\n${mod.code}\n }`;
694
- try {
695
- codeContent = yield (0, style_1.processLess)(`${codeContent}`);
696
- }
697
- catch (e) {
698
- console.error(`样式转换失败 [${pageId}] :`, e, codeContent);
699
- }
700
- }
701
- else {
702
- codeContent = `import { app } from 'app/global-api';\nconst $app = app;\n
703
- ${mod.code.replace(/\$comp/g, 'this.$WEAPPS_COMP')};`;
704
- }
705
- yield fs_extra_1.default.writeFile(file, codeContent);
706
- });
707
- }
708
- });
709
- }
710
- exports.writeLowCodeFilesForCompositeComp = writeLowCodeFilesForCompositeComp;
711
- function generateCodeFromTpl(appData, appBuildDir, dependencies, appKey, rootPath, deployMode, buildTypeList, extraData) {
712
- var _a;
713
- return __awaiter(this, void 0, void 0, function* () {
714
- const componentsScope = yield (0, util_1.getScopeComponents)(appBuildDir, dependencies);
715
- const computedPageIds = [];
716
- const pageModules = {};
717
- (0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, (p) => {
718
- pageModules[p.id] = p.codeModules;
719
- if (p.codeModules.find((item) => item.type === 'computed')) {
720
- computedPageIds.push(p.id);
721
- }
722
- });
723
- const yyptConfig = yield (0, util_2.getYyptConfigInfo)(extraData);
724
- const templatesData = {
725
- 'store/index.js': {
726
- appId: appKey,
727
- rootPath: rootPath,
728
- },
729
- 'store/computed.js': {
730
- pageIds: computedPageIds,
731
- },
732
- 'app/handlers.js': {
733
- pageModules,
734
- },
735
- 'app/material-actions.js': {
736
- materials: dependencies || [],
737
- _: lodash_1.default,
738
- },
739
- 'app/common.js': {
740
- mods: appData.codeModules
741
- .filter((m) => m.type === 'normal-module' && m.name !== '____index____')
742
- .map((m) => m.name),
743
- },
744
- 'datasources/index.js.tpl': {
745
- isXPage: (0, common_1.buildAsXPageByBuildType)(buildTypeList),
746
- },
747
- 'datasources/config.js.tpl': {
748
- appID: appKey,
749
- envID: appData.envId,
750
- isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
751
- clientID: ((_a = appData.extra) === null || _a === void 0 ? void 0 : _a.clientId) || '',
752
- },
753
- 'datasources/datasource-profiles.js.tpl': {
754
- datasourceProfiles: (0, util_1.JsonToStringWithVariableName)((0, dataSource_1.getDatasourceProfiles)(appData.datasources || [])),
755
- },
756
- 'datasources/dataset-profiles.js.tpl': {
757
- datasetProfiles: (0, util_1.JsonToStringWithVariableName)((0, dataSource_1.getDatasetProfiles)(appData, [appData])),
758
- },
759
- 'handlers/utils/common.js': {
760
- isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
761
- isXPage: (0, common_1.buildAsXPageByBuildType)(buildTypeList),
762
- },
763
- 'utils/index.js': {
764
- componentsInfoMap: JSON.stringify(componentsScope),
765
- },
766
- };
767
- if (!rootPath) {
768
- templatesData['index.jsx'] = Object.assign(Object.assign({}, yyptConfig), { adminPortalKey: deployMode === types_1.DEPLOY_MODE.PREVIEW ? `${appKey}-preview` : appKey });
769
- }
770
- console.log(chalk_1.default.blue.bold('Generating code by templates:'));
771
- for (const file in templatesData) {
772
- const tplStr = yield fs_extra_1.default.readFile(path_1.default.join(config_1.appTemplateDir, 'src', file), {
773
- encoding: 'utf8',
774
- });
775
- const generatedCode = (0, lodash_template_1.default)(tplStr, {
776
- interpolate: /<%=([\s\S]+?)%>/g,
777
- })(templatesData[file]);
778
- const outFile = path_1.default.resolve(appBuildDir, file.replace(/.tpl$/, ''));
779
- const outTplPath = /.tpl$/.test(file) ? path_1.default.resolve(appBuildDir, file) : null;
780
- yield fs_extra_1.default.ensureFile(outFile);
781
- console.log(outFile);
782
- yield fs_extra_1.default.writeFile(outFile, generatedCode);
783
- if (outTplPath) {
784
- fs_extra_1.default.removeSync(outTplPath);
785
- }
786
- }
787
- });
788
- }
789
- exports.generateCodeFromTpl = generateCodeFromTpl;