@cloudbase/framework-plugin-low-code 1.7.3 → 1.7.5
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.
- package/lib/index.d.ts +0 -0
- package/lib/index.d.ts.map +0 -0
- package/lib/index.js +0 -0
- package/lib/utils/common.d.ts +0 -0
- package/lib/utils/common.d.ts.map +0 -0
- package/lib/utils/common.js +0 -0
- package/lib/utils/index.d.ts +0 -0
- package/lib/utils/index.d.ts.map +0 -0
- package/lib/utils/index.js +0 -0
- package/package.json +4 -4
- package/scripts/link.js +3 -7
- package/lib/builder/config/common.d.ts +0 -2
- package/lib/builder/config/common.d.ts.map +0 -1
- package/lib/builder/config/common.js +0 -13
- package/lib/builder/config/index.d.ts +0 -3
- package/lib/builder/config/index.d.ts.map +0 -1
- package/lib/builder/config/index.js +0 -29
- package/lib/builder/config/mp.d.ts +0 -2
- package/lib/builder/config/mp.d.ts.map +0 -1
- package/lib/builder/config/mp.js +0 -13
- package/lib/builder/core/copy.d.ts +0 -5
- package/lib/builder/core/copy.d.ts.map +0 -1
- package/lib/builder/core/copy.js +0 -62
- package/lib/builder/core/generate.d.ts +0 -9
- package/lib/builder/core/generate.d.ts.map +0 -1
- package/lib/builder/core/generate.js +0 -128
- package/lib/builder/core/index.d.ts +0 -32
- package/lib/builder/core/index.d.ts.map +0 -1
- package/lib/builder/core/index.js +0 -149
- package/lib/builder/core/material.d.ts +0 -4
- package/lib/builder/core/material.d.ts.map +0 -1
- package/lib/builder/core/material.js +0 -80
- package/lib/builder/core/plugin.d.ts +0 -4
- package/lib/builder/core/plugin.d.ts.map +0 -1
- package/lib/builder/core/plugin.js +0 -30
- package/lib/builder/core/prepare.d.ts +0 -8
- package/lib/builder/core/prepare.d.ts.map +0 -1
- package/lib/builder/core/prepare.js +0 -108
- package/lib/builder/core/webpack.d.ts +0 -15
- package/lib/builder/core/webpack.d.ts.map +0 -1
- package/lib/builder/core/webpack.js +0 -58
- package/lib/builder/mp/BuildContext.d.ts +0 -13
- package/lib/builder/mp/BuildContext.d.ts.map +0 -1
- package/lib/builder/mp/BuildContext.js +0 -2
- package/lib/builder/mp/index.d.ts +0 -33
- package/lib/builder/mp/index.d.ts.map +0 -1
- package/lib/builder/mp/index.js +0 -450
- package/lib/builder/mp/lowcode.d.ts +0 -8
- package/lib/builder/mp/lowcode.d.ts.map +0 -1
- package/lib/builder/mp/lowcode.js +0 -54
- package/lib/builder/mp/materials.d.ts +0 -15
- package/lib/builder/mp/materials.d.ts.map +0 -1
- package/lib/builder/mp/materials.js +0 -338
- package/lib/builder/mp/mixMode.d.ts +0 -10
- package/lib/builder/mp/mixMode.d.ts.map +0 -1
- package/lib/builder/mp/mixMode.js +0 -215
- package/lib/builder/mp/mp_config.d.ts +0 -18
- package/lib/builder/mp/mp_config.d.ts.map +0 -1
- package/lib/builder/mp/mp_config.js +0 -206
- package/lib/builder/mp/util.d.ts +0 -20
- package/lib/builder/mp/util.d.ts.map +0 -1
- package/lib/builder/mp/util.js +0 -243
- package/lib/builder/mp/wxml.d.ts +0 -16
- package/lib/builder/mp/wxml.d.ts.map +0 -1
- package/lib/builder/mp/wxml.js +0 -300
- package/lib/builder/service/builder/copy.d.ts +0 -14
- package/lib/builder/service/builder/copy.d.ts.map +0 -1
- package/lib/builder/service/builder/copy.js +0 -189
- package/lib/builder/service/builder/generate.d.ts +0 -52
- package/lib/builder/service/builder/generate.d.ts.map +0 -1
- package/lib/builder/service/builder/generate.js +0 -792
- package/lib/builder/service/builder/index.d.ts +0 -16
- package/lib/builder/service/builder/index.d.ts.map +0 -1
- package/lib/builder/service/builder/index.js +0 -69
- package/lib/builder/service/builder/plugin.d.ts +0 -8
- package/lib/builder/service/builder/plugin.d.ts.map +0 -1
- package/lib/builder/service/builder/plugin.js +0 -149
- package/lib/builder/service/builder/webpack.d.ts +0 -91
- package/lib/builder/service/builder/webpack.d.ts.map +0 -1
- package/lib/builder/service/builder/webpack.js +0 -589
- package/lib/builder/types/common.d.ts +0 -12
- package/lib/builder/types/common.d.ts.map +0 -1
- package/lib/builder/types/common.js +0 -7
- package/lib/builder/util/common.d.ts +0 -36
- package/lib/builder/util/common.d.ts.map +0 -1
- package/lib/builder/util/common.js +0 -257
- package/lib/builder/util/console.d.ts +0 -2
- package/lib/builder/util/console.d.ts.map +0 -1
- package/lib/builder/util/console.js +0 -13
- package/lib/builder/util/generateFiles.d.ts +0 -6
- package/lib/builder/util/generateFiles.d.ts.map +0 -1
- package/lib/builder/util/generateFiles.js +0 -94
- package/lib/builder/util/index.d.ts +0 -2
- package/lib/builder/util/index.d.ts.map +0 -1
- package/lib/builder/util/index.js +0 -13
- package/lib/builder/util/junk.d.ts +0 -3
- package/lib/builder/util/junk.d.ts.map +0 -1
- package/lib/builder/util/junk.js +0 -25
- package/lib/builder/util/mp.d.ts +0 -5
- package/lib/builder/util/mp.d.ts.map +0 -1
- package/lib/builder/util/mp.js +0 -99
- package/lib/builder/util/name-mangler.d.ts +0 -3
- package/lib/builder/util/name-mangler.d.ts.map +0 -1
- package/lib/builder/util/name-mangler.js +0 -7
- package/lib/builder/util/net.d.ts +0 -3
- package/lib/builder/util/net.d.ts.map +0 -1
- package/lib/builder/util/net.js +0 -54
- package/lib/builder/util/process.d.ts +0 -9
- package/lib/builder/util/process.d.ts.map +0 -1
- package/lib/builder/util/process.js +0 -28
- package/lib/builder/util/style.d.ts +0 -2
- package/lib/builder/util/style.d.ts.map +0 -1
- package/lib/builder/util/style.js +0 -13
- package/lib/builder/util/weapp.d.ts +0 -2
- package/lib/builder/util/weapp.d.ts.map +0 -1
- package/lib/builder/util/weapp.js +0 -13
- package/lib/config/private.d.ts +0 -3
- package/lib/config/private.d.ts.map +0 -1
- package/lib/config/private.js +0 -14
- package/lib/generate.d.ts +0 -2
- package/lib/generate.d.ts.map +0 -1
- package/lib/generate.js +0 -49
- package/lib/generator/config/common.d.ts +0 -6
- package/lib/generator/config/common.d.ts.map +0 -1
- package/lib/generator/config/common.js +0 -25
- package/lib/generator/config/index.d.ts +0 -18
- package/lib/generator/config/index.d.ts.map +0 -1
- package/lib/generator/config/index.js +0 -43
- package/lib/generator/config/mp.d.ts +0 -56
- package/lib/generator/config/mp.d.ts.map +0 -1
- package/lib/generator/config/mp.js +0 -104
- package/lib/generator/core/generate.d.ts +0 -59
- package/lib/generator/core/generate.d.ts.map +0 -1
- package/lib/generator/core/generate.js +0 -663
- package/lib/generator/core/index.d.ts +0 -25
- package/lib/generator/core/index.d.ts.map +0 -1
- package/lib/generator/core/index.js +0 -102
- package/lib/generator/core/material.d.ts +0 -14
- package/lib/generator/core/material.d.ts.map +0 -1
- package/lib/generator/core/material.js +0 -230
- package/lib/generator/template.d.ts +0 -3
- package/lib/generator/template.d.ts.map +0 -1
- package/lib/generator/template.js +0 -3
- package/lib/generator/types/common.d.ts +0 -69
- package/lib/generator/types/common.d.ts.map +0 -1
- package/lib/generator/types/common.js +0 -21
- package/lib/generator/util/common.d.ts +0 -36
- package/lib/generator/util/common.d.ts.map +0 -1
- package/lib/generator/util/common.js +0 -238
- package/lib/generator/util/console.d.ts +0 -3
- package/lib/generator/util/console.d.ts.map +0 -1
- package/lib/generator/util/console.js +0 -17
- package/lib/generator/util/index.d.ts +0 -2
- package/lib/generator/util/index.d.ts.map +0 -1
- package/lib/generator/util/index.js +0 -13
- package/lib/generator/util/name-mangler.d.ts +0 -17
- package/lib/generator/util/name-mangler.d.ts.map +0 -1
- package/lib/generator/util/name-mangler.js +0 -63
- package/lib/generator/util/postcss-rpx.d.ts +0 -11
- package/lib/generator/util/postcss-rpx.d.ts.map +0 -1
- package/lib/generator/util/postcss-rpx.js +0 -16
- package/lib/generator/util/style.d.ts +0 -6
- package/lib/generator/util/style.d.ts.map +0 -1
- package/lib/generator/util/style.js +0 -92
- package/lib/generator/util/weapp.d.ts +0 -5
- package/lib/generator/util/weapp.d.ts.map +0 -1
- package/lib/generator/util/weapp.js +0 -17
- package/lib/types.d.ts +0 -14
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -19
- package/lib/utils/dataSource.d.ts +0 -28
- package/lib/utils/dataSource.d.ts.map +0 -1
- package/lib/utils/dataSource.js +0 -171
- package/lib/utils/postProcess.d.ts +0 -3
- package/lib/utils/postProcess.d.ts.map +0 -1
- package/lib/utils/postProcess.js +0 -48
- package/lib/weapps-core/config/index.d.ts +0 -2
- package/lib/weapps-core/config/index.d.ts.map +0 -1
- package/lib/weapps-core/config/index.js +0 -13
- package/lib/weapps-core/config/style.d.ts +0 -7
- package/lib/weapps-core/config/style.d.ts.map +0 -1
- package/lib/weapps-core/config/style.js +0 -70
- package/lib/weapps-core/index.d.ts +0 -6
- package/lib/weapps-core/index.d.ts.map +0 -1
- package/lib/weapps-core/index.js +0 -31
- package/lib/weapps-core/types/action.d.ts +0 -25
- package/lib/weapps-core/types/action.d.ts.map +0 -1
- package/lib/weapps-core/types/action.js +0 -28
- package/lib/weapps-core/types/app.d.ts +0 -142
- package/lib/weapps-core/types/app.d.ts.map +0 -1
- package/lib/weapps-core/types/app.js +0 -21
- package/lib/weapps-core/types/appbuild.d.ts +0 -63
- package/lib/weapps-core/types/appbuild.d.ts.map +0 -1
- package/lib/weapps-core/types/appbuild.js +0 -78
- package/lib/weapps-core/types/code_types.d.ts +0 -26
- package/lib/weapps-core/types/code_types.d.ts.map +0 -1
- package/lib/weapps-core/types/code_types.js +0 -2
- package/lib/weapps-core/types/git.d.ts +0 -7
- package/lib/weapps-core/types/git.d.ts.map +0 -1
- package/lib/weapps-core/types/git.js +0 -2
- package/lib/weapps-core/types/index.d.ts +0 -11
- package/lib/weapps-core/types/index.d.ts.map +0 -1
- package/lib/weapps-core/types/index.js +0 -22
- package/lib/weapps-core/types/lowcode.d.ts +0 -26
- package/lib/weapps-core/types/lowcode.d.ts.map +0 -1
- package/lib/weapps-core/types/lowcode.js +0 -25
- package/lib/weapps-core/types/material.d.ts +0 -90
- package/lib/weapps-core/types/material.d.ts.map +0 -1
- package/lib/weapps-core/types/material.js +0 -9
- package/lib/weapps-core/types/plugins.d.ts +0 -17
- package/lib/weapps-core/types/plugins.d.ts.map +0 -1
- package/lib/weapps-core/types/plugins.js +0 -2
- package/lib/weapps-core/types/style.d.ts +0 -93
- package/lib/weapps-core/types/style.d.ts.map +0 -1
- package/lib/weapps-core/types/style.js +0 -2
- package/lib/weapps-core/types/web.d.ts +0 -120
- package/lib/weapps-core/types/web.d.ts.map +0 -1
- package/lib/weapps-core/types/web.js +0 -2
- package/lib/weapps-core/utils/appbuild.d.ts +0 -6
- package/lib/weapps-core/utils/appbuild.d.ts.map +0 -1
- package/lib/weapps-core/utils/appbuild.js +0 -40
- package/lib/weapps-core/utils/common.d.ts +0 -16
- package/lib/weapps-core/utils/common.d.ts.map +0 -1
- package/lib/weapps-core/utils/common.js +0 -90
- package/lib/weapps-core/utils/file.d.ts +0 -12
- package/lib/weapps-core/utils/file.d.ts.map +0 -1
- package/lib/weapps-core/utils/file.js +0 -142
- package/lib/weapps-core/utils/formily.d.ts +0 -5
- package/lib/weapps-core/utils/formily.d.ts.map +0 -1
- package/lib/weapps-core/utils/formily.js +0 -416
- package/lib/weapps-core/utils/index.d.ts +0 -7
- package/lib/weapps-core/utils/index.d.ts.map +0 -1
- package/lib/weapps-core/utils/index.js +0 -18
- package/lib/weapps-core/utils/lowcdoe.d.ts +0 -4
- package/lib/weapps-core/utils/lowcdoe.d.ts.map +0 -1
- package/lib/weapps-core/utils/lowcdoe.js +0 -69
- package/lib/weapps-core/utils/style.d.ts +0 -17
- package/lib/weapps-core/utils/style.d.ts.map +0 -1
- package/lib/weapps-core/utils/style.js +0 -330
|
@@ -1,792 +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
|
-
else {
|
|
363
|
-
syncPropArr = syncProp;
|
|
364
|
-
}
|
|
365
|
-
syncPropArr.forEach(({ changeEvent, valueFromEvent }) => {
|
|
366
|
-
xProps.listenerInstances.unshift({
|
|
367
|
-
trigger: changeEvent,
|
|
368
|
-
instanceFunction: `${config_1.REPLACE_SIGN}function({ event, forItems, $context }) {
|
|
369
|
-
const $for = forItems;
|
|
370
|
-
const wid = ${isComposite ? 'this.widgets' : '$page.widgets'}.${schema.key};
|
|
371
|
-
const widgetData = (forItems.forIndexes && forItems.forIndexes.length > 0) ? get(wid, forItems.forIndexes) : wid;
|
|
372
|
-
widgetData.${key} = ${valueFromEvent};
|
|
373
|
-
}.bind(this)${config_1.REPLACE_SIGN}`,
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
if (xProps.dataBinds) {
|
|
379
|
-
xProps.dataBinds = generateDataBinds(xProps.dataBinds, isComposite);
|
|
380
|
-
}
|
|
381
|
-
if (xProps.styleBind) {
|
|
382
|
-
xProps.styleBind = generateDataBinds([xProps.styleBind], isComposite);
|
|
383
|
-
}
|
|
384
|
-
if (xProps.classNameListBind) {
|
|
385
|
-
xProps.classNameListBind = generateDataBinds([xProps.classNameListBind], isComposite);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
return {
|
|
390
|
-
widgets: (0, util_1.JsonToStringWithVariableName)(compWidgets),
|
|
391
|
-
dataBinds: (0, util_1.JsonToStringWithVariableName)(compDataBinds),
|
|
392
|
-
componentSchema: (0, util_1.JsonToStringWithVariableName)(componentSchemaJson),
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
exports.getComponentSchemaString = getComponentSchemaString;
|
|
396
|
-
function generateDataBinds(dataBinds, isComposite) {
|
|
397
|
-
const dataBindFuncs = {};
|
|
398
|
-
dataBinds.forEach((bind) => {
|
|
399
|
-
if (!bind.bindDataPath) {
|
|
400
|
-
return console.warn('无 bindDataPath', bind.propertyPath);
|
|
401
|
-
}
|
|
402
|
-
let funcCode = '() => {}';
|
|
403
|
-
funcCode = `() => ${funcCode}`;
|
|
404
|
-
if (bind.type === weapps_core_1.PropBindType.forItem) {
|
|
405
|
-
funcCode = `(forItems) => forItems.${bind.bindDataPath}`;
|
|
406
|
-
}
|
|
407
|
-
else if (bind.type === weapps_core_1.PropBindType.scope) {
|
|
408
|
-
funcCode = `() => ({__type: "scopedValue", getValue: ($scope)=>$scope.${bind.bindDataPath}})}`;
|
|
409
|
-
}
|
|
410
|
-
else if (bind.type === weapps_core_1.PropBindType.expression) {
|
|
411
|
-
let code = bind.bindDataPath;
|
|
412
|
-
if (isComposite) {
|
|
413
|
-
funcCode = `(forItems, event, $context) => { const $for = forItems; return (${code.replace(/\$comp/g, 'this.$WEAPPS_COMP')})}`;
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
funcCode = /\$scope\./.test(code)
|
|
417
|
-
? `(forItems, event, $context) => ({__type: "scopedValue", getValue: ($scope) => { const $for = forItems; return (\n${code}\n)}})`
|
|
418
|
-
: `(forItems, event, $context) => { const $for = forItems; return (\n${code}\n)}`;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
else if (bind.type === weapps_core_1.PropBindType.prop) {
|
|
422
|
-
let bindDataPath = bind.bindDataPath;
|
|
423
|
-
const isNegated = bindDataPath.startsWith('!');
|
|
424
|
-
if (isNegated)
|
|
425
|
-
bindDataPath = bindDataPath.replace(/^!/, '');
|
|
426
|
-
if (isComposite) {
|
|
427
|
-
funcCode = `() => ${isNegated ? '!' : ''}this.$WEAPPS_COMP.props.data.${bindDataPath}`;
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
funcCode = `() => ${isNegated ? '!' : ''}$page.props.data.${bindDataPath}`;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
const PREFIX_MAP = {
|
|
435
|
-
[weapps_core_1.PropBindType.state]: 'state',
|
|
436
|
-
[weapps_core_1.PropBindType.computed]: 'computed',
|
|
437
|
-
[weapps_core_1.PropBindType.dataVar]: 'dataVar',
|
|
438
|
-
[weapps_core_1.PropBindType.stateData]: 'dataset.state',
|
|
439
|
-
[weapps_core_1.PropBindType.paramData]: 'dataset.params',
|
|
440
|
-
};
|
|
441
|
-
switch (bind.type) {
|
|
442
|
-
case weapps_core_1.PropBindType.state:
|
|
443
|
-
case weapps_core_1.PropBindType.computed:
|
|
444
|
-
case weapps_core_1.PropBindType.dataVar:
|
|
445
|
-
case weapps_core_1.PropBindType.stateData:
|
|
446
|
-
case weapps_core_1.PropBindType.paramData: {
|
|
447
|
-
if (bind.bindDataPath.startsWith('global.')) {
|
|
448
|
-
funcCode = bind.bindDataPath.replace(/^global./, `app.${PREFIX_MAP[bind.type]}.`);
|
|
449
|
-
}
|
|
450
|
-
else {
|
|
451
|
-
if (isComposite) {
|
|
452
|
-
funcCode = bind.bindDataPath
|
|
453
|
-
.replace(/^comp-\w+./, `this.$WEAPPS_COMP.${PREFIX_MAP[bind.type]}.`)
|
|
454
|
-
.replace(/^\$comp_\w+./, `this.$WEAPPS_COMP.${PREFIX_MAP[bind.type]}.`);
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
funcCode = bind.bindDataPath.replace(/^\w+./, `$page.${PREFIX_MAP[bind.type]}.`);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
funcCode = `() => ${funcCode}`;
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
dataBindFuncs[bind.propertyPath] = `${config_1.REPLACE_SIGN}${funcCode}${config_1.REPLACE_SIGN}`;
|
|
466
|
-
});
|
|
467
|
-
return dataBindFuncs;
|
|
468
|
-
}
|
|
469
|
-
function generateListnerInstances(listenerInstances, isComposite = false) {
|
|
470
|
-
return listenerInstances.map((listener) => {
|
|
471
|
-
var _a, _b, _c, _d, _e;
|
|
472
|
-
const generatedListener = {
|
|
473
|
-
key: listener.key,
|
|
474
|
-
trigger: listener.trigger,
|
|
475
|
-
isCapturePhase: listener.isCapturePhase,
|
|
476
|
-
noPropagation: listener.noPropagation,
|
|
477
|
-
};
|
|
478
|
-
if (listener.type === weapps_core_1.ActionType.Material) {
|
|
479
|
-
const { sourceKey } = listener;
|
|
480
|
-
const { variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
|
|
481
|
-
generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}${variableName}${config_1.REPLACE_SIGN}`;
|
|
482
|
-
}
|
|
483
|
-
else if (listener.type === weapps_core_1.ActionType.Platform) {
|
|
484
|
-
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}`;
|
|
485
|
-
}
|
|
486
|
-
else if (listener.type === weapps_core_1.ActionType.DataSource) {
|
|
487
|
-
generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}function({data}) { return app.cloud.callDataSource(data) }${config_1.REPLACE_SIGN}`;
|
|
488
|
-
}
|
|
489
|
-
else if (listener.type === weapps_core_1.ActionType.PropEvent) {
|
|
490
|
-
if (isComposite) {
|
|
491
|
-
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}`;
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
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}`;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
if (isComposite) {
|
|
499
|
-
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}`;
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
generatedListener.instanceFunction = `${config_1.REPLACE_SIGN}handler.${((_e = listener.handler) === null || _e === void 0 ? void 0 : _e.name) || listener.jsCode}${config_1.REPLACE_SIGN}`;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (!(0, weapps_core_1.isEmptyObj)(listener.data)) {
|
|
506
|
-
generatedListener.data = listener.data;
|
|
507
|
-
}
|
|
508
|
-
if (listener.dataBinds && listener.dataBinds.length > 0) {
|
|
509
|
-
generatedListener.dataBinds = generateDataBinds(listener.dataBinds, isComposite);
|
|
510
|
-
}
|
|
511
|
-
return generatedListener;
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
function getListenersString(listeners = [], isComposite = false) {
|
|
515
|
-
return (0, util_1.JsonToStringWithVariableName)(generateListnerInstances(listeners, isComposite));
|
|
516
|
-
}
|
|
517
|
-
exports.getListenersString = getListenersString;
|
|
518
|
-
function getPluginInstancesString(instances) {
|
|
519
|
-
if (!instances || !instances.length) {
|
|
520
|
-
return '[]';
|
|
521
|
-
}
|
|
522
|
-
const copyInstances = (0, util_1.simpleDeepClone)(instances);
|
|
523
|
-
copyInstances.map((itemInstance) => {
|
|
524
|
-
const { sourceKey } = itemInstance;
|
|
525
|
-
const { variableName } = (0, util_1.getMetaInfoBySourceKey)(sourceKey);
|
|
526
|
-
itemInstance.instanceFunction = `${config_1.REPLACE_SIGN}${variableName}${config_1.REPLACE_SIGN}`;
|
|
527
|
-
});
|
|
528
|
-
return (0, util_1.JsonToStringWithVariableName)(copyInstances);
|
|
529
|
-
}
|
|
530
|
-
exports.getPluginInstancesString = getPluginInstancesString;
|
|
531
|
-
function getPluginImportStringArr(plugins, pluginImportStringArr = []) {
|
|
532
|
-
plugins.map((plugin) => __awaiter(this, void 0, void 0, function* () {
|
|
533
|
-
const { name, materialName, materialVersion, variableName } = plugin;
|
|
534
|
-
const importString = `import ${variableName} from 'libraries/${`${materialName}@${materialVersion}`}/plugins/${name}'`;
|
|
535
|
-
if (pluginImportStringArr.includes(importString)) {
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
pluginImportStringArr.push(importString);
|
|
539
|
-
}));
|
|
540
|
-
return pluginImportStringArr;
|
|
541
|
-
}
|
|
542
|
-
exports.getPluginImportStringArr = getPluginImportStringArr;
|
|
543
|
-
function getComponentImportStringArr(components, componentImportStringArr = []) {
|
|
544
|
-
components.map((component) => __awaiter(this, void 0, void 0, function* () {
|
|
545
|
-
const { name, materialName, materialVersion, variableName, entries } = component;
|
|
546
|
-
let importString = '';
|
|
547
|
-
if (entries === null || entries === void 0 ? void 0 : entries.components) {
|
|
548
|
-
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)}'`;
|
|
549
|
-
}
|
|
550
|
-
else if (entries === null || entries === void 0 ? void 0 : entries.entry) {
|
|
551
|
-
const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
|
|
552
|
-
importString = `const { ${name}: ${lodash_1.default.upperFirst(variableName)} } = ${componentsLibVariableName}.components`;
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
importString = `import ${lodash_1.default.upperFirst(variableName)} from 'libraries/${`${materialName}@${materialVersion}`}/components/${name}'`;
|
|
556
|
-
}
|
|
557
|
-
if (!componentImportStringArr.includes(importString)) {
|
|
558
|
-
componentImportStringArr.push(importString);
|
|
559
|
-
}
|
|
560
|
-
}));
|
|
561
|
-
return componentImportStringArr.filter((item) => !!item);
|
|
562
|
-
}
|
|
563
|
-
exports.getComponentImportStringArr = getComponentImportStringArr;
|
|
564
|
-
function getEntryImportStringArr(materialInfoList = [], entryImportStringArr = []) {
|
|
565
|
-
materialInfoList.forEach(({ materialName, version, entries }) => {
|
|
566
|
-
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)) {
|
|
567
|
-
const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
|
|
568
|
-
const importComponentLibString = `import ${componentsLibVariableName} from '${path_1.default.posix.join(`libraries/${materialName}@${version}`, entries === null || entries === void 0 ? void 0 : entries.entry)}'`;
|
|
569
|
-
if (!entryImportStringArr.includes(importComponentLibString)) {
|
|
570
|
-
entryImportStringArr.push(importComponentLibString);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
return entryImportStringArr || [];
|
|
575
|
-
}
|
|
576
|
-
exports.getEntryImportStringArr = getEntryImportStringArr;
|
|
577
|
-
function getActionImportStringArr(originActionList, actionImportStringArr = []) {
|
|
578
|
-
originActionList.map((action) => {
|
|
579
|
-
if (action.type === weapps_core_1.ActionType.Material) {
|
|
580
|
-
pushActionToImportStringArr(action, actionImportStringArr);
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
return actionImportStringArr;
|
|
584
|
-
}
|
|
585
|
-
exports.getActionImportStringArr = getActionImportStringArr;
|
|
586
|
-
function pushActionToImportStringArr(listenerInstance, actionImportStringArr) {
|
|
587
|
-
const { name, materialName, materialVersion, variableName, entries } = listenerInstance;
|
|
588
|
-
const componentsLibVariableName = (0, util_3.camelcase)(`${materialName}`);
|
|
589
|
-
const importString = (entries === null || entries === void 0 ? void 0 : entries.actions)
|
|
590
|
-
? `import { ${name} as ${variableName} } from '${path_1.default.posix.join(`libraries/${materialName}@${materialVersion}`, entries === null || entries === void 0 ? void 0 : entries.actions)}'`
|
|
591
|
-
: (entries === null || entries === void 0 ? void 0 : entries.entry)
|
|
592
|
-
? `const { ${name}: ${variableName} } = ${componentsLibVariableName}.actions`
|
|
593
|
-
: `import ${variableName} from 'libraries/${materialName}@${materialVersion}/actions/${name}'`;
|
|
594
|
-
if (actionImportStringArr.includes(importString)) {
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
actionImportStringArr.push(importString);
|
|
598
|
-
}
|
|
599
|
-
exports.pushActionToImportStringArr = pushActionToImportStringArr;
|
|
600
|
-
function generateRouterFile(allAppDataList, appBuildDir, basename = '', buildTypeList = []) {
|
|
601
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
602
|
-
const routerImports = [];
|
|
603
|
-
const routerRenders = [];
|
|
604
|
-
const mountApis = [];
|
|
605
|
-
yield Promise.all(allAppDataList.map((data) => __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
const { pageInstanceList, rootPath = '' } = data;
|
|
607
|
-
const pageFilePath = rootPath ? `packages/${rootPath}/` : '';
|
|
608
|
-
mountApis.push(`import '${pageFilePath}app/mountAppApis';`);
|
|
609
|
-
(0, weapps_core_1.loopDealWithFn)(pageInstanceList, (pageInstance) => {
|
|
610
|
-
const pageId = [rootPath, pageInstance.id].filter((i) => i).join('_');
|
|
611
|
-
if (pageInstance.isHome && !rootPath) {
|
|
612
|
-
routerRenders.push(`<Route from="/" exact children={() => <Redirect to="/${pageId}" />} />`);
|
|
613
|
-
}
|
|
614
|
-
routerImports.push(`import Page${pageId} from '${pageFilePath}pages/${pageInstance.id}/index';`);
|
|
615
|
-
routerRenders.push(`<Route path="/${pageId}" component={Page${pageId}}/>`);
|
|
616
|
-
});
|
|
617
|
-
})));
|
|
618
|
-
const routerTemplate = yield fs_extra_1.default.readFile(path_1.default.resolve(config_1.appTemplateDir, './src/router/index.tpl'), {
|
|
619
|
-
encoding: 'utf8',
|
|
620
|
-
});
|
|
621
|
-
const routerIndexStr = (0, lodash_template_1.default)(routerTemplate)({
|
|
622
|
-
routerImports: routerImports.join('\n'),
|
|
623
|
-
routerRenders: routerRenders.join('\n'),
|
|
624
|
-
mountApis: mountApis.join('\n'),
|
|
625
|
-
basename: basename,
|
|
626
|
-
});
|
|
627
|
-
const dest = path_1.default.resolve(appBuildDir, `src/router/index.jsx`);
|
|
628
|
-
yield fs_extra_1.default.ensureFile(dest);
|
|
629
|
-
yield fs_extra_1.default.writeFile(dest, routerIndexStr);
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
exports.generateRouterFile = generateRouterFile;
|
|
633
|
-
function writeLowCodeFiles(appData, appBuildDir) {
|
|
634
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
635
|
-
const lowcodeRootDir = path_1.default.join(appBuildDir, 'lowcode');
|
|
636
|
-
console.log(chalk_1.default.blue.bold('Writing lowcode files:'));
|
|
637
|
-
(0, generateFiles_1.cleanDir)(lowcodeRootDir, []);
|
|
638
|
-
(0, style_1.generateDefaultTheme)(appData);
|
|
639
|
-
const themeCode = appData.codeModules.find((mod) => mod.type === 'theme');
|
|
640
|
-
yield Promise.all(appData.codeModules.map((m) => writeCode2file(m, 'global')));
|
|
641
|
-
yield Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, (page) => __awaiter(this, void 0, void 0, function* () {
|
|
642
|
-
(0, style_1.generateDefaultStyle)(page);
|
|
643
|
-
yield page.codeModules.filter((m) => m.name !== '____index____').forEach((m) => writeCode2file(m, page.id));
|
|
644
|
-
})));
|
|
645
|
-
function writeCode2file(mod, pageId) {
|
|
646
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
647
|
-
const file = path_1.default.join(lowcodeRootDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId, mod));
|
|
648
|
-
let weappsApiPrefix = '';
|
|
649
|
-
if (mod.type !== 'theme') {
|
|
650
|
-
weappsApiPrefix =
|
|
651
|
-
mod.type !== 'style'
|
|
652
|
-
? `import { app, $page } from '${path_1.default
|
|
653
|
-
.relative(path_1.default.dirname(file), appBuildDir + '/app/global-api')
|
|
654
|
-
.replace(/\\/g, '/')}';\nconst $app = app;`
|
|
655
|
-
: ``;
|
|
656
|
-
}
|
|
657
|
-
console.log(chalk_1.default.green(file));
|
|
658
|
-
let code = mod.code;
|
|
659
|
-
if (mod.type === 'style') {
|
|
660
|
-
code = yield (0, style_1.processLess)(((themeCode === null || themeCode === void 0 ? void 0 : themeCode.code) || style_1.defaultThemeCode) + code);
|
|
661
|
-
}
|
|
662
|
-
yield fs_extra_1.default.ensureFile(file);
|
|
663
|
-
yield fs_extra_1.default.writeFile(file, weappsApiPrefix + os_1.default.EOL + code);
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
exports.writeLowCodeFiles = writeLowCodeFiles;
|
|
669
|
-
function writeLowCodeFilesForCompositeComp(compositeGroups, appBuildDir) {
|
|
670
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
671
|
-
const lowcodeRootDir = path_1.default.join(appBuildDir, 'src', 'lowcode', 'composite');
|
|
672
|
-
console.log(chalk_1.default.blue.bold('Writing composite component lowcode files:'));
|
|
673
|
-
yield Promise.all(compositeGroups.map((gItem) => __awaiter(this, void 0, void 0, function* () {
|
|
674
|
-
yield (0, util_2.writeLibCommonRes2file)(gItem, path_1.default.join(appBuildDir, 'src', 'libraries', `${gItem.name}@${gItem.version}`, 'libCommonRes'));
|
|
675
|
-
const compLibCommonResource = gItem.compLibCommonResource;
|
|
676
|
-
let themeCode = '';
|
|
677
|
-
if (compLibCommonResource) {
|
|
678
|
-
themeCode = `
|
|
679
|
-
${compLibCommonResource.theme.variable || ''}
|
|
680
|
-
${compLibCommonResource.class || ''}
|
|
681
|
-
${compLibCommonResource.theme.class || ''}
|
|
682
|
-
`;
|
|
683
|
-
}
|
|
684
|
-
return yield Promise.all(gItem.components.map((component) => __awaiter(this, void 0, void 0, function* () {
|
|
685
|
-
let cItem = component;
|
|
686
|
-
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));
|
|
687
|
-
})));
|
|
688
|
-
})));
|
|
689
|
-
function writeCode2file(mod, lowcodeDir, comp, themeCode) {
|
|
690
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
691
|
-
const pageId = comp.name + '_' + comp.id;
|
|
692
|
-
const file = path_1.default.join(lowcodeDir, (0, weapps_core_1.getCodeModuleFilePath)(pageId, mod));
|
|
693
|
-
yield fs_extra_1.default.ensureFile(file);
|
|
694
|
-
let codeContent = '';
|
|
695
|
-
if (mod.type === 'style') {
|
|
696
|
-
codeContent = `.${(0, weapps_core_1.getCompositedComponentClass)(comp)} { \n${themeCode ? themeCode : ''}\n${mod.code}\n }`;
|
|
697
|
-
try {
|
|
698
|
-
codeContent = yield (0, style_1.processLess)(`${codeContent}`);
|
|
699
|
-
}
|
|
700
|
-
catch (e) {
|
|
701
|
-
console.error(`样式转换失败 [${pageId}] :`, e, codeContent);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
else {
|
|
705
|
-
codeContent = `import { app } from 'app/global-api';\nconst $app = app;\n
|
|
706
|
-
${mod.code.replace(/\$comp/g, 'this.$WEAPPS_COMP')};`;
|
|
707
|
-
}
|
|
708
|
-
yield fs_extra_1.default.writeFile(file, codeContent);
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
exports.writeLowCodeFilesForCompositeComp = writeLowCodeFilesForCompositeComp;
|
|
714
|
-
function generateCodeFromTpl(appData, appBuildDir, dependencies, appKey, rootPath, deployMode, buildTypeList, extraData) {
|
|
715
|
-
var _a;
|
|
716
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
717
|
-
const componentsScope = yield (0, util_1.getScopeComponents)(appBuildDir, dependencies);
|
|
718
|
-
const computedPageIds = [];
|
|
719
|
-
const pageModules = {};
|
|
720
|
-
(0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, (p) => {
|
|
721
|
-
pageModules[p.id] = p.codeModules;
|
|
722
|
-
if (p.codeModules.find((item) => item.type === 'computed')) {
|
|
723
|
-
computedPageIds.push(p.id);
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
const yyptConfig = yield (0, util_2.getYyptConfigInfo)(extraData);
|
|
727
|
-
const templatesData = {
|
|
728
|
-
'store/index.js': {
|
|
729
|
-
appId: appKey,
|
|
730
|
-
rootPath: rootPath,
|
|
731
|
-
},
|
|
732
|
-
'store/computed.js': {
|
|
733
|
-
pageIds: computedPageIds,
|
|
734
|
-
},
|
|
735
|
-
'app/handlers.js': {
|
|
736
|
-
pageModules,
|
|
737
|
-
},
|
|
738
|
-
'app/material-actions.js': {
|
|
739
|
-
materials: dependencies || [],
|
|
740
|
-
_: lodash_1.default,
|
|
741
|
-
},
|
|
742
|
-
'app/common.js': {
|
|
743
|
-
mods: appData.codeModules
|
|
744
|
-
.filter((m) => m.type === 'normal-module' && m.name !== '____index____')
|
|
745
|
-
.map((m) => m.name),
|
|
746
|
-
},
|
|
747
|
-
'datasources/index.js.tpl': {
|
|
748
|
-
isXPage: (0, common_1.buildAsXPageByBuildType)(buildTypeList),
|
|
749
|
-
},
|
|
750
|
-
'datasources/config.js.tpl': {
|
|
751
|
-
appID: appKey,
|
|
752
|
-
envID: appData.envId,
|
|
753
|
-
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
754
|
-
clientID: ((_a = appData.extra) === null || _a === void 0 ? void 0 : _a.clientId) || '',
|
|
755
|
-
},
|
|
756
|
-
'datasources/datasource-profiles.js.tpl': {
|
|
757
|
-
datasourceProfiles: (0, util_1.JsonToStringWithVariableName)((0, dataSource_1.getDatasourceProfiles)(appData.datasources || [])),
|
|
758
|
-
},
|
|
759
|
-
'datasources/dataset-profiles.js.tpl': {
|
|
760
|
-
datasetProfiles: (0, util_1.JsonToStringWithVariableName)((0, dataSource_1.getDatasetProfiles)(appData, [appData])),
|
|
761
|
-
},
|
|
762
|
-
'handlers/utils/common.js': {
|
|
763
|
-
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
764
|
-
isXPage: (0, common_1.buildAsXPageByBuildType)(buildTypeList),
|
|
765
|
-
},
|
|
766
|
-
'utils/index.js': {
|
|
767
|
-
componentsInfoMap: JSON.stringify(componentsScope),
|
|
768
|
-
},
|
|
769
|
-
};
|
|
770
|
-
if (!rootPath) {
|
|
771
|
-
templatesData['index.jsx'] = Object.assign(Object.assign({}, yyptConfig), { adminPortalKey: deployMode === types_1.DEPLOY_MODE.PREVIEW ? `${appKey}-preview` : appKey });
|
|
772
|
-
}
|
|
773
|
-
console.log(chalk_1.default.blue.bold('Generating code by templates:'));
|
|
774
|
-
for (const file in templatesData) {
|
|
775
|
-
const tplStr = yield fs_extra_1.default.readFile(path_1.default.join(config_1.appTemplateDir, 'src', file), {
|
|
776
|
-
encoding: 'utf8',
|
|
777
|
-
});
|
|
778
|
-
const generatedCode = (0, lodash_template_1.default)(tplStr, {
|
|
779
|
-
interpolate: /<%=([\s\S]+?)%>/g,
|
|
780
|
-
})(templatesData[file]);
|
|
781
|
-
const outFile = path_1.default.resolve(appBuildDir, file.replace(/.tpl$/, ''));
|
|
782
|
-
const outTplPath = /.tpl$/.test(file) ? path_1.default.resolve(appBuildDir, file) : null;
|
|
783
|
-
yield fs_extra_1.default.ensureFile(outFile);
|
|
784
|
-
console.log(outFile);
|
|
785
|
-
yield fs_extra_1.default.writeFile(outFile, generatedCode);
|
|
786
|
-
if (outTplPath) {
|
|
787
|
-
fs_extra_1.default.removeSync(outTplPath);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
exports.generateCodeFromTpl = generateCodeFromTpl;
|