@cloudbase/lowcode-builder 0.0.4 → 0.1.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.
- package/lib/builder/core/index.d.ts +2 -0
- package/lib/builder/core/index.js +7 -1
- package/lib/builder/h5/copy.js +17 -3
- package/lib/builder/mp/wxml.js +5 -1
- package/lib/tests/build.d.ts +1 -0
- package/lib/tests/build.js +19 -0
- package/lib/tests/build.test.d.ts +1 -0
- package/lib/tests/build.test.js +22 -0
- package/lib/tests/data.d.ts +18 -0
- package/lib/tests/data.js +94216 -0
- package/package.json +4 -3
- package/template/html/index.html.ejs +6 -9
- package/template/mp/app/weapps-api.js +17 -45
- package/template/mp/app.js +66 -66
- package/template/mp/common/weapp-page.js +3 -1
- package/template/mp/datasources/index.js +13 -4
- package/template/mp/package.json +12 -10
- package/template/package.json +4 -2
- package/template/src/app/global-api.js +6 -83
- package/template/src/app/material-actions.js +15 -13
- package/template/src/datasources/index.js +15 -2
- package/template/src/index.jsx +1 -1
- package/template/webpack/web.prod.js +62 -41
- package/template/src/pages/composite.tpl +0 -151
|
@@ -6,9 +6,10 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
6
6
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
7
7
|
const themeVars = require('./themeVars');
|
|
8
8
|
const HappyPack = require('happypack');
|
|
9
|
-
const core =
|
|
9
|
+
const core = 7;
|
|
10
10
|
const happyThreadPool = HappyPack.ThreadPool({ size: core });
|
|
11
11
|
|
|
12
|
+
const TS_LOADER_ID = 'ts-loader';
|
|
12
13
|
module.exports = function (options) {
|
|
13
14
|
const {
|
|
14
15
|
context,
|
|
@@ -22,54 +23,69 @@ module.exports = function (options) {
|
|
|
22
23
|
definePlugin = {},
|
|
23
24
|
} = options;
|
|
24
25
|
const isDevelopment = mode !== 'production';
|
|
26
|
+
const babelLoader = {
|
|
27
|
+
loader: 'babel-loader',
|
|
28
|
+
options: {
|
|
29
|
+
compact: false,
|
|
30
|
+
cacheDirectory: true,
|
|
31
|
+
cwd: context,
|
|
32
|
+
presets: [
|
|
33
|
+
[
|
|
34
|
+
'@babel/preset-env',
|
|
35
|
+
{
|
|
36
|
+
modules: false,
|
|
37
|
+
targets: {
|
|
38
|
+
esmodules: true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
'@babel/preset-react',
|
|
43
|
+
],
|
|
44
|
+
plugins: [
|
|
45
|
+
[
|
|
46
|
+
'babel-plugin-import',
|
|
47
|
+
{
|
|
48
|
+
libraryName: '@govcloud/gsd-kbone-react',
|
|
49
|
+
libraryDirectory: 'lib/components',
|
|
50
|
+
camel2DashComponentName: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
'@babel/plugin-proposal-class-properties',
|
|
54
|
+
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
55
|
+
'@babel/plugin-proposal-export-default-from',
|
|
56
|
+
'@babel/plugin-proposal-export-namespace-from',
|
|
57
|
+
'@babel/plugin-proposal-optional-chaining',
|
|
58
|
+
'@babel/plugin-proposal-partial-application',
|
|
59
|
+
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
|
|
60
|
+
].filter(Boolean),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
25
64
|
let plugins = [
|
|
26
65
|
new HappyPack({
|
|
27
|
-
id:
|
|
66
|
+
id: TS_LOADER_ID,
|
|
28
67
|
loaders: [
|
|
68
|
+
babelLoader,
|
|
29
69
|
{
|
|
30
|
-
loader: '
|
|
70
|
+
loader: 'ts-loader',
|
|
31
71
|
options: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
targets: {
|
|
40
|
-
esmodules: true,
|
|
41
|
-
},
|
|
42
|
-
useBuiltIns: 'usage',
|
|
43
|
-
corejs: '2.6.12',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
'@babel/preset-react',
|
|
47
|
-
],
|
|
48
|
-
plugins: [
|
|
49
|
-
[
|
|
50
|
-
'babel-plugin-import',
|
|
51
|
-
{
|
|
52
|
-
libraryName: '@govcloud/gsd-kbone-react',
|
|
53
|
-
libraryDirectory: 'lib/components',
|
|
54
|
-
camel2DashComponentName: false,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
'@babel/plugin-proposal-class-properties',
|
|
58
|
-
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
59
|
-
'@babel/plugin-proposal-export-default-from',
|
|
60
|
-
'@babel/plugin-proposal-export-namespace-from',
|
|
61
|
-
'@babel/plugin-proposal-optional-chaining',
|
|
62
|
-
'@babel/plugin-proposal-partial-application',
|
|
63
|
-
[
|
|
64
|
-
'@babel/plugin-proposal-pipeline-operator',
|
|
65
|
-
{ proposal: 'minimal' },
|
|
66
|
-
],
|
|
67
|
-
].filter(Boolean),
|
|
72
|
+
compilerOptions: {
|
|
73
|
+
target: 'ESNext',
|
|
74
|
+
module: 'ESNext',
|
|
75
|
+
esModuleInterop: true,
|
|
76
|
+
},
|
|
77
|
+
happyPackMode: true,
|
|
78
|
+
transpileOnly: true,
|
|
68
79
|
},
|
|
69
80
|
},
|
|
70
81
|
],
|
|
71
82
|
threadPool: happyThreadPool,
|
|
72
83
|
}),
|
|
84
|
+
new HappyPack({
|
|
85
|
+
id: 'babel',
|
|
86
|
+
loaders: [babelLoader],
|
|
87
|
+
threadPool: happyThreadPool,
|
|
88
|
+
}),
|
|
73
89
|
new HtmlWebpackPlugin({
|
|
74
90
|
template: htmlTemplatePath,
|
|
75
91
|
filename: 'index.html',
|
|
@@ -125,7 +141,7 @@ module.exports = function (options) {
|
|
|
125
141
|
},
|
|
126
142
|
devtool: isDevelopment ? 'eval' : false,
|
|
127
143
|
resolve: {
|
|
128
|
-
extensions: ['.js', '.jsx', '.tsx', '.json', '.scss', '.css'],
|
|
144
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.scss', '.css'],
|
|
129
145
|
modules: [...resolveModules],
|
|
130
146
|
symlinks: false,
|
|
131
147
|
cacheWithContext: false,
|
|
@@ -135,10 +151,15 @@ module.exports = function (options) {
|
|
|
135
151
|
},
|
|
136
152
|
module: {
|
|
137
153
|
rules: [
|
|
154
|
+
{
|
|
155
|
+
test: /\.tsx?$/,
|
|
156
|
+
exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
|
|
157
|
+
use: [`happypack/loader?id=${TS_LOADER_ID}`],
|
|
158
|
+
},
|
|
138
159
|
{
|
|
139
160
|
test: /\.(js|jsx)$/,
|
|
161
|
+
exclude: /node_modules\/(?!@cloudbase\/weda-ui)|gsd-kbone-react/,
|
|
140
162
|
use: ['happypack/loader?id=babel'],
|
|
141
|
-
exclude: /node_modules\/(?!@cloudbase\/weda-ui)/,
|
|
142
163
|
},
|
|
143
164
|
{
|
|
144
165
|
test: /\.(scss|sass)$/,
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { observer } from "mobx-react-lite";
|
|
3
|
-
import { observable } from "mobx";
|
|
4
|
-
import { get } from 'lodash'
|
|
5
|
-
|
|
6
|
-
import { AppRender } from "handlers/render";
|
|
7
|
-
import { createComputed } from "../../../../utils";
|
|
8
|
-
import { createWidgets, retryDataBinds, WidgetsContext, resolveComponentProps } from 'handlers/utils'
|
|
9
|
-
import getStateFn from "./lowcode/state.js";
|
|
10
|
-
import computed from "./lowcode/computed.js";
|
|
11
|
-
import lifecycle from "./lowcode/lifecycle.js";
|
|
12
|
-
import { app, $page } from '../../../../app/global-api'
|
|
13
|
-
|
|
14
|
-
<% handlersImports.forEach(handler => { %>
|
|
15
|
-
import handler$<%= handler.name %> from "./lowcode/handler/<%= handler.name %>.js";
|
|
16
|
-
<% }) %>
|
|
17
|
-
|
|
18
|
-
// Import Components
|
|
19
|
-
<% var componentsMap = {}; useComponents.forEach(compItem => {%>
|
|
20
|
-
<% if(compItem.entry){ %><% if(!componentsMap[compItem.moduleName]){ componentsMap[compItem.moduleName] = true %>
|
|
21
|
-
import <%= compItem.moduleNameVar %> from "libraries/<%= compItem.moduleName %>@<%= compItem.version %>/<%= compItem.entry %>";
|
|
22
|
-
<% } %>const { <%= compItem.name %>: <%= compItem.var %> } = <%= compItem.moduleNameVar %>.components
|
|
23
|
-
<% } else { %>import <%= compItem.var %> from "libraries/<%= compItem.moduleName %>@<%= compItem.version %>/components/<%= compItem.name %>";<% } %>
|
|
24
|
-
<%}) %>
|
|
25
|
-
|
|
26
|
-
import * as constObj from '../../libCommonRes/const'
|
|
27
|
-
import * as toolsObj from '../../libCommonRes/tools'
|
|
28
|
-
|
|
29
|
-
import "./lowcode/style.less";
|
|
30
|
-
|
|
31
|
-
const pluginInstances = [];
|
|
32
|
-
|
|
33
|
-
class CompositeCompWrapper extends React.Component {
|
|
34
|
-
|
|
35
|
-
$WEAPPS_COMP = {}
|
|
36
|
-
|
|
37
|
-
componentDidUpdate() {
|
|
38
|
-
const { data } = this.props
|
|
39
|
-
for(let prop in data) {
|
|
40
|
-
// 更新 propsData
|
|
41
|
-
this.propsData[prop] = data[prop]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
constructor(props) {
|
|
47
|
-
super(props);
|
|
48
|
-
|
|
49
|
-
this.compConfig = <%= JSON.stringify(compConfig, null, 2) %>
|
|
50
|
-
this.virtualFields = Object.assign({}, props.pageVirtualFields || {}, {
|
|
51
|
-
<% useComponents.forEach(compItem => {%>
|
|
52
|
-
"<%= compItem.key %>": <% if(compItem.isPlainProps) {%> (props) => <<%= compItem.var %> {...resolveComponentProps(props, 1)} /> <% } else {%> (props) => <<%= compItem.var %>{...resolveComponentProps(props, 0)} /> <% }%>,
|
|
53
|
-
<%}) %>
|
|
54
|
-
});
|
|
55
|
-
this.events = (<%= emitEvents %>).reduce((obj, trigger) => {
|
|
56
|
-
obj[trigger] = (event) => {
|
|
57
|
-
this.props.emit(trigger, event)
|
|
58
|
-
};
|
|
59
|
-
return obj
|
|
60
|
-
}, {});
|
|
61
|
-
this.handler = this.$WEAPPS_COMP.handler = {
|
|
62
|
-
<% handlersImports.forEach(handler => { %>
|
|
63
|
-
<%= handler.name %>: handler$<%= handler.name %>.bind(this),
|
|
64
|
-
<% }) %>
|
|
65
|
-
};
|
|
66
|
-
this.componentSchema = <%= componentSchema %>;
|
|
67
|
-
const widgetContext = <%= widgets %>
|
|
68
|
-
const dataBinds = <%= dataBinds %>
|
|
69
|
-
const defaultProps = <%= JSON.stringify(defaultProps, null, 2) %>
|
|
70
|
-
this.propsData = observable(Object.assign({}, defaultProps, this.props.data || {}))
|
|
71
|
-
this.$WEAPPS_COMP.lib = { const: constObj, tools: toolsObj }
|
|
72
|
-
this.$WEAPPS_COMP.props = { ...this.props, events: this.events, data: this.propsData }
|
|
73
|
-
this.state = this.$WEAPPS_COMP.state = observable(getStateFn.bind(this)())
|
|
74
|
-
this.computed = this.$WEAPPS_COMP.computed = createComputed(computed, this)
|
|
75
|
-
this.node = this.$WEAPPS_COMP.node = this.createWidgetNode(this) || {}
|
|
76
|
-
this.widgets = createWidgets(widgetContext, dataBinds, {})
|
|
77
|
-
// widgets 内的 dataBinds 可能需要关联 widgets,需要重新执行 dataBinds
|
|
78
|
-
retryDataBinds()
|
|
79
|
-
Object.keys(this.widgets || {}).forEach(widgetId => {
|
|
80
|
-
// 将实例 ownerWidget 挂到内部组件上。内部组件就可以通过 $comp.node.ownerWidget 获取到所在的组件实例
|
|
81
|
-
this.widgets[widgetId].ownerWidget = this.node
|
|
82
|
-
})
|
|
83
|
-
this.pageListenerInstances = [];
|
|
84
|
-
this.createCompAPI(this)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
createWidgetNode(compThis) {
|
|
88
|
-
// 当为数组时,需要判断自己属于 widgets 的哪一项
|
|
89
|
-
const {
|
|
90
|
-
compositeParent,
|
|
91
|
-
forIndexes,
|
|
92
|
-
id
|
|
93
|
-
} = compThis.props
|
|
94
|
-
let widgetData = compositeParent
|
|
95
|
-
? compositeParent.$WEAPPS_COMP.widgets[id]
|
|
96
|
-
: $page.widgets[id]
|
|
97
|
-
if(Array.isArray(widgetData)) {
|
|
98
|
-
widgetData = widgetData.length > 0 ? get(widgetData, forIndexes) : {}
|
|
99
|
-
}
|
|
100
|
-
widgetData = widgetData || {}
|
|
101
|
-
widgetData.getOwnerWidget = () => compThis.node.ownerWidget
|
|
102
|
-
widgetData.getConfig = () => compThis.compConfig
|
|
103
|
-
|
|
104
|
-
return widgetData
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
createCompAPI(compThis) {
|
|
108
|
-
compThis.$WEAPPS_COMP = {
|
|
109
|
-
compConfig: compThis.compConfig,
|
|
110
|
-
widgets: compThis.widgets,
|
|
111
|
-
node: compThis.node,
|
|
112
|
-
handler: compThis.handler,
|
|
113
|
-
lib: { const: constObj, tools: toolsObj },
|
|
114
|
-
get props() {
|
|
115
|
-
return {...compThis.props, events: compThis.events, data: compThis.propsData }
|
|
116
|
-
},
|
|
117
|
-
get state() {
|
|
118
|
-
return compThis.state
|
|
119
|
-
},
|
|
120
|
-
get computed() {
|
|
121
|
-
return compThis.computed
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
componentDidMount() {
|
|
127
|
-
lifecycle.onAttached && lifecycle.onAttached.bind(this)()
|
|
128
|
-
lifecycle.onReady && lifecycle.onReady.bind(this)()
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
componentWillUnmount() {
|
|
132
|
-
lifecycle.onDetached && lifecycle.onDetached.bind(this)()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
render() {
|
|
136
|
-
return (
|
|
137
|
-
<WidgetsContext.Provider value={{ parent: this }}>
|
|
138
|
-
<AppRender
|
|
139
|
-
className={this.props.className}
|
|
140
|
-
virtualFields={this.virtualFields}
|
|
141
|
-
componentSchema={this.componentSchema}
|
|
142
|
-
codeContext={this}
|
|
143
|
-
/>
|
|
144
|
-
</WidgetsContext.Provider>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default observer((props) => (
|
|
150
|
-
<CompositeCompWrapper {...props}></CompositeCompWrapper>
|
|
151
|
-
));
|