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