@cuipengyu5/build-plugin-lowcode 0.0.1 → 0.0.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.
@@ -0,0 +1,273 @@
1
+ import init, { editor, project, material, setters, config } from '@alifd/lowcode-preset-plugin';
2
+ import mergeWith from 'lodash/mergeWith';
3
+ {{{setterImportStr}}}
4
+
5
+ const queryObject = new URLSearchParams(window.location.search);
6
+ const fullbackMeta = '{{{fullbackMeta}}}' || '';
7
+ let platform = queryObject.get('platform') || '';
8
+ let metaType = queryObject.get('metaType') || platform || '';
9
+ const metaPathMap = {{{metaPathMap}}};
10
+ const key = metaType ? `meta.${metaType}` : 'meta';
11
+ if (!metaPathMap[key]) {
12
+ console.warn(`[@alifd/build-plugin-lowcode] metaType can only in [${Object.keys(metaPathMap)}], current metaType is ${key}, fullback to ${fullbackMeta || 'default'}.`);
13
+ metaType = fullbackMeta === 'default' ? '' : fullbackMeta;
14
+ }
15
+ const isNewEngineVersion = !!material;
16
+ const devMode = !!{{{ devMode }}};
17
+ const baseLibrary = '{{{baseLibrary}}}';
18
+ const basePackages = [
19
+ {
20
+ package: 'moment',
21
+ version: '2.24.0',
22
+ urls: ['https://g.alicdn.com/mylib/moment/2.24.0/min/moment.min.js'],
23
+ library: 'moment',
24
+ },
25
+ {
26
+ package: "lodash",
27
+ library: "_",
28
+ urls: [
29
+ "https://g.alicdn.com/platform/c/lodash/4.6.1/lodash.min.js"
30
+ ]
31
+ },
32
+ {
33
+ title: 'fusion组件库',
34
+ package: '@alifd/next',
35
+ version: '1.25.23',
36
+ urls: [
37
+ 'https://g.alicdn.com/code/lib/alifd__next/1.25.23/next.min.css',
38
+ 'https://g.alicdn.com/code/lib/alifd__next/1.25.23/next-with-locales.min.js',
39
+ ],
40
+ library: 'Next',
41
+ },
42
+ {
43
+ package: 'antd',
44
+ version: '4.17.3',
45
+ urls: [
46
+ 'https://g.alicdn.com/code/lib/antd/4.17.3/antd.min.js',
47
+ 'https://g.alicdn.com/code/lib/antd/4.17.3/antd.min.css',
48
+ ],
49
+ library: 'antd',
50
+ },
51
+ ];
52
+
53
+ if (baseLibrary === 'rax') {
54
+ basePackages.push({
55
+ title: 'meet',
56
+ package: '@alifd/meet',
57
+ version: 'meet@2.4.2-beta.6',
58
+ urls: [
59
+ 'https://mc-fusion.alibaba-inc.com/unpkg/@alifd/meet@2.4.2-beta.6/umd/meet.lowcode.js',
60
+ 'https://mc-fusion.alibaba-inc.com/unpkg/@alifd/meet@2.4.2-beta.6/umd/meet.min.css',
61
+ ],
62
+ library: 'Meet',
63
+ });
64
+ }
65
+
66
+ const assets = {
67
+ packages: []
68
+ };
69
+
70
+ let assetsName = './assets-dev.json';
71
+
72
+ const setterMap = {{{setterMap}}};
73
+ const presetConfig = {{{presetConfig}}};
74
+ const customPlugins = {{{customPlugins}}};
75
+
76
+ const type = '{{{type}}}';
77
+
78
+ if (devMode && type !== 'setter') {
79
+ assets.packages.push({
80
+ "package": "{{{package}}}",
81
+ "version": "{{{version}}}",
82
+ "library": "{{{library}}}",
83
+ "urls": {{{ urls }}},
84
+ "editUrls": {{{editUrls}}},
85
+ "advancedUrls": {{{advancedRenderUrls}}},
86
+ });
87
+ assets.groupList = {{{groups}}};
88
+ assets.sort = {
89
+ "groupList": {{{groups}}},
90
+ "categoryList": {{{categories}}}
91
+ };
92
+ assets.ignoreComponents = {{{ignoreComponents}}};
93
+
94
+ assets.components = [{
95
+ exportName: '{{{metaExportName}}}',
96
+ url: metaType ? `/meta.${metaType}.js` : '/meta.js',
97
+ }];
98
+ }
99
+
100
+ const schema = getPageSchema() || {
101
+ componentName: 'Page',
102
+ id: 'node_dockcviv8fo1',
103
+ props: {
104
+ ref: 'outterView',
105
+ style: {
106
+ height: '100%',
107
+ },
108
+ },
109
+ fileName: 'lowcode',
110
+ dataSource: {
111
+ list: [],
112
+ },
113
+ state: {
114
+ text: 'outter',
115
+ isShowDialog: false,
116
+ },
117
+ css: 'body {font-size: 12px;} .botton{width:100px;color:#ff00ff}',
118
+ lifeCycles: {
119
+ componentDidMount: {
120
+ type: 'JSFunction',
121
+ value: "function() {\n console.log('did mount');\n }",
122
+ },
123
+ componentWillUnmount: {
124
+ type: 'JSFunction',
125
+ value: "function() {\n console.log('will umount');\n }",
126
+ },
127
+ },
128
+ methods: {
129
+ testFunc: {
130
+ type: 'JSFunction',
131
+ value: "function() {\n console.log('test func');\n }",
132
+ },
133
+ onClick: {
134
+ type: 'JSFunction',
135
+ value: 'function() {\n this.setState({\n isShowDialog: true\n })\n }',
136
+ },
137
+ closeDialog: {
138
+ type: 'JSFunction',
139
+ value: 'function() {\n this.setState({\n isShowDialog: false\n })\n }',
140
+ },
141
+ },
142
+ children: [],
143
+ };
144
+
145
+ const LCE_CONTAINER = document.getElementById('lce-container');
146
+
147
+ init(() => {
148
+ return {
149
+ name: 'editor-init',
150
+ async init() {
151
+ if (typeof setterMap === 'object' && Object.keys(setterMap).length) {
152
+ setters.registerSetter(setterMap);
153
+ }
154
+ if (!devMode) {
155
+ const devAssets = await (await fetch(assetsName)).json();
156
+ const packages = devAssets.packages;
157
+ assets.packages = assets.packages.concat(packages);
158
+ assets.components = devAssets.components.map(item => {
159
+ if (item.advancedUrls && metaType && item.advancedUrls[metaType] && item.advancedUrls[metaType].length) {
160
+ item.url = item.advancedUrls[metaType][0];
161
+ } else if (item.urls && metaType && item.urls[metaType]) {
162
+ item.url = item.urls[metaType];
163
+ }
164
+ return item;
165
+ });
166
+ assets.groupList = devAssets.groupList;
167
+ } else {
168
+ const extraAssets = {{{extraAssets}}};
169
+ const builtinAssets = {{{builtinAssets}}};
170
+ extraAssets && await handleExtraAssets(assets, extraAssets);
171
+ builtinAssets && await handleExtraAssets(assets, builtinAssets);
172
+ }
173
+
174
+ // Overwrite the same library in basePackages
175
+ const packagesMap = new Map();
176
+ const sortedKeys = [...new Set(
177
+ [...basePackages, ...assets.packages].map((item) => {
178
+ const { library } = item;
179
+ packagesMap.set(library, item);
180
+ return library;
181
+ })
182
+ )];
183
+ assets.packages = sortedKeys.map((key) => packagesMap.get(key));
184
+
185
+ assets.packages = assets.packages.map(item => {
186
+ if (item.editUrls && item.editUrls.length) {
187
+ item.renderUrls = item.urls;
188
+ item.urls = item.editUrls;
189
+ }
190
+ return item;
191
+ })
192
+
193
+ if (baseLibrary && baseLibrary === 'rax') {
194
+ if (isNewEngineVersion) {
195
+ config.set('renderEnv', 'rax');
196
+ config.set('simulatorUrl', undefined);
197
+ } else {
198
+ editor.set('renderEnv', 'rax');
199
+ project.onRendererReady(() => {
200
+ editor.get('designer').currentDocument.simulator._iframe.onload = () => {
201
+ editor.get('designer').currentDocument.simulator.set('device', 'phone');
202
+ }
203
+ });
204
+ }
205
+ }
206
+
207
+ if (isNewEngineVersion) {
208
+ material.setAssets(assets);
209
+ project.openDocument(schema);
210
+ } else {
211
+ editor.setAssets(assets);
212
+ project.open(schema);
213
+ }
214
+ },
215
+ }
216
+ }, customPlugins || [], LCE_CONTAINER, {
217
+ supportVariableGlobally: true,
218
+ presetConfig
219
+ });
220
+
221
+ function getPageSchema() {
222
+ const schema = JSON.parse(
223
+ window.localStorage.getItem('projectSchema') || '{}'
224
+ );
225
+
226
+ const pageSchema = schema?.componentsTree?.[0];
227
+ return pageSchema;
228
+ };
229
+
230
+ async function handleExtraAssets(assets, extraAssets) {
231
+ if (extraAssets && Array.isArray(extraAssets) && extraAssets.length) {
232
+ const baseSchemas = await Promise.all(
233
+ extraAssets.map(async (url) => {
234
+ if (typeof url === 'object') {
235
+ return url;
236
+ } else {
237
+ try {
238
+ return (await fetch(url)).json();
239
+ } catch (e) {
240
+ console.error(`get assets data from builtin assets ${url} failed: `, e);
241
+ return {};
242
+ }
243
+ }
244
+ })
245
+ );
246
+ baseSchemas.forEach((item) => {
247
+ const _assets = {
248
+ ...item,
249
+ packages: item.packages || [item.package],
250
+ components: item.components,
251
+ componentList: (item.componentList || []).map((comp) => {
252
+ if (comp.children) {
253
+ comp.children = comp.children.map((snippet) => {
254
+ if (!snippet.sort) {
255
+ snippet.sort = {
256
+ category: comp.title,
257
+ group: '原子组件',
258
+ };
259
+ }
260
+ return snippet;
261
+ });
262
+ }
263
+ return comp;
264
+ }),
265
+ };
266
+ mergeWith(assets, _assets, (objValue, srcValue) => {
267
+ if (Array.isArray(objValue) && Array.isArray(srcValue)) {
268
+ return srcValue.concat(objValue);
269
+ }
270
+ });
271
+ });
272
+ }
273
+ }
@@ -0,0 +1,168 @@
1
+ {{{ componentsImportStr }}}
2
+
3
+ const componentCategorySort = {};
4
+ {{{categories}}}
5
+ .reverse()
6
+ .forEach((item, index) => {
7
+ componentCategorySort[item] = ++index;
8
+ });
9
+
10
+ function generateComponentList(components) {
11
+ const componentList = [
12
+ {
13
+ title: '常用',
14
+ icon: '',
15
+ children: [],
16
+ },
17
+ {
18
+ title: '容器',
19
+ icon: '',
20
+ children: [],
21
+ },
22
+ {
23
+ title: '导航',
24
+ icon: '',
25
+ children: [],
26
+ },
27
+ {
28
+ title: '内容',
29
+ icon: '',
30
+ children: [],
31
+ },
32
+ {
33
+ title: 'Feedback 反馈',
34
+ icon: '',
35
+ children: [],
36
+ },
37
+ ];
38
+
39
+ const groupMap = {
40
+ 原子组件: true,
41
+ };
42
+ const compGroup = {};
43
+
44
+ components.forEach((comp) => {
45
+ const category = comp.category || '其他';
46
+ if (comp.group && !compGroup[comp.componentName]) {
47
+ compGroup[comp.componentName] = comp.group;
48
+ }
49
+ if (comp.group && !groupMap[comp.group]) {
50
+ groupMap[comp.group] = true;
51
+ }
52
+ let target = componentList.find((item) => item.title === category);
53
+ if (!target) {
54
+ target = {
55
+ title: category,
56
+ icon: '',
57
+ children: [],
58
+ };
59
+
60
+ componentList.push(target);
61
+ }
62
+
63
+ if (comp.snippets && comp.snippets.length) {
64
+ target.children.push({
65
+ componentName: comp.componentName,
66
+ title: comp.title || comp.componentName,
67
+ sort: {
68
+ category: target.title,
69
+ group: compGroup[comp.componentName] || '原子组件',
70
+ priority: componentCategorySort[target.title] || 0,
71
+ },
72
+ icon: '',
73
+ package: comp.npm.pkg,
74
+ snippets: comp.snippets || [],
75
+ });
76
+ }
77
+ });
78
+ return componentList;
79
+ }
80
+
81
+ function fillRealVersion(meta, packageName = '{{{packageName}}}', version = '{{{version}}}', basicLibraryVersion={{{basicLibraryVersion}}}) {
82
+ if (!meta || !version) {
83
+ return meta;
84
+ }
85
+ const { npm } = meta;
86
+ if (!npm) {
87
+ return meta;
88
+ }
89
+ if (typeof basicLibraryVersion === 'object' && basicLibraryVersion[npm.package]) {
90
+ meta.npm = {
91
+ ...npm,
92
+ version: basicLibraryVersion[npm.package]
93
+ };
94
+ } else if (npm.package === packageName) {
95
+ meta.npm = {
96
+ ...npm,
97
+ version
98
+ };
99
+ }
100
+ return meta;
101
+ }
102
+
103
+ const componentMetas = [{{{ components }}}];
104
+ const components = [];
105
+ const npmInfo = {{{ npmInfo }}};
106
+ componentMetas.forEach(meta => {
107
+ if (Array.isArray(meta)) {
108
+ components.push(
109
+ ...meta.map((item) => {
110
+ if (!item.npm) {
111
+ const { componentName } = item;
112
+ const names = componentName.split('.');
113
+ const [exportName, subName] = names;
114
+ item.npm = {
115
+ exportName: exportName,
116
+ main: '',
117
+ destructuring: true,
118
+ subName: names.length > 1 ? componentName.slice(componentName.indexOf('.') + 1) : subName,
119
+ };
120
+ }
121
+ item.npm = { ...npmInfo, ...(item.npm || {}) };
122
+ return fillRealVersion(item);
123
+ }),
124
+ );
125
+ } else if (meta.components) {
126
+ components.push(
127
+ ...meta.components.map((item) => {
128
+ if (!item.npm) {
129
+ const { componentName } = item;
130
+ const names = componentName.split('.');
131
+ const [exportName, subName] = names;
132
+ item.npm = {
133
+ exportName: exportName,
134
+ main: '',
135
+ destructuring: true,
136
+ subName: names.length > 1 ? componentName.slice(componentName.indexOf('.') + 1) : subName,
137
+ };
138
+ }
139
+ item.npm = { ...npmInfo, ...(item.npm || {}) };
140
+ return fillRealVersion(item);
141
+ }),
142
+ );
143
+ } else {
144
+ if (!meta.npm) {
145
+ const { componentName } = meta;
146
+ const names = componentName.split('.');
147
+ const [exportName, subName] = names;
148
+ meta.npm = {
149
+ exportName: exportName,
150
+ main: '',
151
+ destructuring: true,
152
+ subName: names.length > 1 ? componentName.slice(componentName.indexOf('.') + 1) : subName,
153
+ };
154
+ }
155
+ meta.npm = { ...npmInfo, ...(meta.npm || {}) };
156
+ components.push(fillRealVersion(meta));
157
+ }
158
+ });
159
+
160
+ const componentList = generateComponentList(components);
161
+
162
+ export { components, componentList };
163
+
164
+ const execCompile = !!{{{ execCompile }}};
165
+
166
+ if (!execCompile) {
167
+ window.{{{metaExportName}}} = { components, componentList };
168
+ }
@@ -0,0 +1,93 @@
1
+ {{#if isRax}}
2
+ const loadingStyle = {
3
+ width: '100vw',
4
+ height: '100vh',
5
+ display: 'flex',
6
+ alignItems: 'center',
7
+ justifyContent: 'center',
8
+ fontWeight: 300,
9
+ fontSize: '24px',
10
+ lineHeight: '36px',
11
+ };
12
+ import { useState, render } from "rax";
13
+ import Renderer from "@ali/lowcode-rax-renderer";
14
+ import UniversalDriver from 'driver-universal';
15
+ const Loading = () => <div style={loadingStyle} className="lowcode-plugin-sample-preview-loading"> <h1>Loading...</h1> </div>;
16
+ {{else}}
17
+ import ReactDOM from 'react-dom';
18
+ import React, { useState } from 'react';
19
+ import { Loading } from '@alifd/next';
20
+ import Renderer from '@alilc/lowcode-react-renderer';
21
+ {{/if}}
22
+
23
+ import { buildComponents, assetBundle, AssetLevel, AssetLoader } from '@alilc/lowcode-utils';
24
+
25
+ const queryObject = new URLSearchParams(window.location.search);
26
+ const platform = queryObject.get('platform') || 'default';
27
+
28
+ const SamplePreview = () => {
29
+ const [data, setData] = useState({});
30
+
31
+ async function init() {
32
+ const packages = JSON.parse(window.localStorage.getItem('packages'));
33
+ const projectSchema = JSON.parse(window.localStorage.getItem('projectSchema'));
34
+ const { componentsMap: componentsMapArray, componentsTree } = projectSchema;
35
+ const componentsMap = {};
36
+ componentsMapArray.forEach((component) => {
37
+ componentsMap[component.componentName] = component;
38
+ });
39
+ const schema = componentsTree[0];
40
+
41
+ const libraryMap = {};
42
+ const libraryAsset = [];
43
+ packages.forEach(({ package: _package, library, urls, renderUrls, advancedUrls }) => {
44
+ libraryMap[_package] = library;
45
+ if (advancedUrls && advancedUrls[platform]) {
46
+ libraryAsset.push(advancedUrls[platform]);
47
+ } else if (renderUrls) {
48
+ libraryAsset.push(renderUrls);
49
+ } else if (urls) {
50
+ libraryAsset.push(urls);
51
+ }
52
+ });
53
+
54
+ const vendors = [assetBundle(libraryAsset, AssetLevel.Library)];
55
+
56
+ // TODO asset may cause pollution
57
+ const assetLoader = new AssetLoader();
58
+ try{
59
+ await assetLoader.load(libraryAsset);
60
+ } catch (e) {
61
+ console.warn('[LowcodePreview] load resources failed: ', e);
62
+ }
63
+ const components = buildComponents(libraryMap, componentsMap);
64
+
65
+ setData({
66
+ schema,
67
+ components,
68
+ });
69
+ }
70
+
71
+ const { schema, components } = data;
72
+
73
+ if (!schema || !components) {
74
+ init();
75
+ return <Loading fullScreen />;
76
+ }
77
+
78
+ return (
79
+ <div className="lowcode-plugin-sample-preview">
80
+ <Renderer
81
+ className="lowcode-plugin-sample-preview-content"
82
+ schema={schema}
83
+ components={components}
84
+ />
85
+ </div>
86
+ );
87
+ };
88
+
89
+ {{#if isRax}}
90
+ render(<SamplePreview />, document.getElementById('ice-container'), { driver: UniversalDriver });
91
+ {{else}}
92
+ ReactDOM.render(<SamplePreview />, document.getElementById('ice-container'));
93
+ {{/if}}
@@ -0,0 +1,24 @@
1
+ import * as componentInstances from '{{{entryPath}}}';
2
+
3
+ {{{ componentViewsImportStr }}}
4
+
5
+ {{{scssImport}}}
6
+
7
+ {{{ componentViewsExportStr }}}
8
+
9
+ export * from '{{{entryPath}}}';
10
+
11
+ const coveredComponents = {{{componentViews}}};
12
+
13
+ const library = '{{{ library }}}';
14
+ const execCompile = !!{{{ execCompile }}};
15
+
16
+ if (!execCompile) {
17
+ window[library] = Object.assign({__esModule: true}, componentInstances || {}, coveredComponents || {});
18
+ }
19
+
20
+ function getRealComponent(component, componentName) {
21
+ if (component.default) return component.default;
22
+ if (component[componentName]) return component[componentName];
23
+ return component;
24
+ }
@@ -0,0 +1,16 @@
1
+ const { existsSync } = require('fs');
2
+ const { join } = require('path');
3
+
4
+ module.exports = function getDemoPath(projectDir) {
5
+ let demoDir;
6
+ // compatible with directory docs
7
+ const searchDirs = ['demo', 'docs'];
8
+ for (let i = 0; i < searchDirs.length; i++) {
9
+ const searchPath = join(projectDir, searchDirs[i]);
10
+ if (existsSync(searchPath)) {
11
+ demoDir = searchDirs[i];
12
+ break;
13
+ }
14
+ }
15
+ return demoDir;
16
+ };