@cloudbase/lowcode-builder 0.1.0 → 0.1.4

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.
@@ -1,2 +0,0 @@
1
- export declare function postprocessProjectConfig(projectJsonPath: any, data: any): void;
2
- export declare function postprocessDeployExtraJson(projectPath: any, deployOptions: any): void;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.postprocessDeployExtraJson = exports.postprocessProjectConfig = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const lodash_1 = require("lodash");
9
- const path_1 = __importDefault(require("path"));
10
- function postprocessProjectConfig(projectJsonPath, data) {
11
- let projectJson = fs_extra_1.default.readJsonSync(projectJsonPath);
12
- fs_extra_1.default.writeJsonSync(projectJsonPath, (0, lodash_1.merge)(projectJson, data), { spaces: 2 });
13
- }
14
- exports.postprocessProjectConfig = postprocessProjectConfig;
15
- function postprocessDeployExtraJson(projectPath, deployOptions) {
16
- let { targetMpAppId, mpAppId } = deployOptions;
17
- if (targetMpAppId !== mpAppId) {
18
- let projectJson = fs_extra_1.default.readJsonSync(path_1.default.resolve(projectPath, 'project.config.json'));
19
- const miniprogramRoot = (projectJson === null || projectJson === void 0 ? void 0 : projectJson.miniprogramRoot) || './';
20
- fs_extra_1.default.writeFileSync(path_1.default.resolve(projectPath, miniprogramRoot, 'ext.json'), JSON.stringify({
21
- extEnable: true,
22
- extAppid: targetMpAppId,
23
- directCommit: true,
24
- }, null, 2));
25
- }
26
- }
27
- exports.postprocessDeployExtraJson = postprocessDeployExtraJson;
@@ -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
- ));