@gant-lowcode/plugin-code-generator 1.0.10 → 2.0.0
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/LICENSE +21 -0
- package/{dist → es}/components/code-gen-action/index.d.ts +2 -1
- package/es/components/code-gen-action/index.js +330 -0
- package/es/components/code-gen-action/index.less +20 -0
- package/es/components/code-gen-preview/fixPreviewCode.js +100 -0
- package/{dist → es}/components/code-gen-preview/index.d.ts +3 -2
- package/es/components/code-gen-preview/index.js +5 -0
- package/es/components/code-gen-preview/index.less +16 -0
- package/{dist → es}/components/code-gen-result/index.d.ts +2 -2
- package/es/components/code-gen-result/index.js +207 -0
- package/es/components/code-gen-result/index.less +20 -0
- package/{dist → es}/components/codesandbox-preview/index.d.ts +2 -1
- package/es/components/codesandbox-preview/index.js +192 -0
- package/es/components/codesandbox-preview/index.less +18 -0
- package/{dist → es}/components/file-tree/index.d.ts +3 -2
- package/es/components/file-tree/index.js +162 -0
- package/es/components/file-tree/index.less +54 -0
- package/{dist → es}/components/file-type-icon/index.d.ts +2 -2
- package/es/components/file-type-icon/index.js +12 -0
- package/es/components/file-type-icon/index.less +77 -0
- package/{dist → es}/components/sources-view/index.d.ts +2 -1
- package/es/components/sources-view/index.js +128 -0
- package/es/components/sources-view/index.less +12 -0
- package/{dist → es}/index.d.ts +3 -4
- package/es/index.js +67 -0
- package/es/style.js +9 -0
- package/{dist → es}/types/index.d.ts +3 -3
- package/es/types/index.js +1 -0
- package/lib/components/code-gen-action/index.d.ts +7 -0
- package/lib/components/code-gen-action/index.js +336 -0
- package/lib/components/code-gen-action/index.less +20 -0
- package/lib/components/code-gen-preview/fixPreviewCode.d.ts +2 -0
- package/lib/components/code-gen-preview/fixPreviewCode.js +105 -0
- package/lib/components/code-gen-preview/index.d.ts +9 -0
- package/lib/components/code-gen-preview/index.js +9 -0
- package/lib/components/code-gen-preview/index.less +16 -0
- package/lib/components/code-gen-result/index.d.ts +14 -0
- package/lib/components/code-gen-result/index.js +215 -0
- package/lib/components/code-gen-result/index.less +20 -0
- package/lib/components/codesandbox-preview/index.d.ts +4 -0
- package/lib/components/codesandbox-preview/index.js +199 -0
- package/lib/components/codesandbox-preview/index.less +18 -0
- package/lib/components/file-tree/index.d.ts +21 -0
- package/lib/components/file-tree/index.js +170 -0
- package/lib/components/file-tree/index.less +54 -0
- package/lib/components/file-type-icon/index.d.ts +6 -0
- package/lib/components/file-type-icon/index.js +17 -0
- package/lib/components/file-type-icon/index.less +77 -0
- package/lib/components/sources-view/index.d.ts +8 -0
- package/lib/components/sources-view/index.js +135 -0
- package/lib/components/sources-view/index.less +12 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +74 -0
- package/lib/style.js +9 -0
- package/lib/types/index.d.ts +17 -0
- package/lib/types/index.js +3 -0
- package/package.json +27 -19
- package/dist/components/code-gen-action/index.css +0 -18
- package/dist/components/code-gen-action/index.js +0 -203
- package/dist/components/code-gen-preview/fixPreviewCode.js +0 -119
- package/dist/components/code-gen-preview/index.css +0 -18
- package/dist/components/code-gen-preview/index.js +0 -9
- package/dist/components/code-gen-result/index.css +0 -18
- package/dist/components/code-gen-result/index.js +0 -147
- package/dist/components/codesandbox-preview/index.css +0 -17
- package/dist/components/codesandbox-preview/index.js +0 -147
- package/dist/components/file-tree/index.css +0 -55
- package/dist/components/file-tree/index.js +0 -138
- package/dist/components/file-type-icon/index.css +0 -73
- package/dist/components/file-type-icon/index.js +0 -10
- package/dist/components/sources-view/index.css +0 -11
- package/dist/components/sources-view/index.js +0 -128
- package/dist/index.js +0 -50
- package/dist/types/index.js +0 -1
- /package/{dist → es}/components/code-gen-preview/fixPreviewCode.d.ts +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alibaba
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { IPublicTypeProjectSchema, IPublicModelPluginContext } from "@gant-lowcode/lowcode-types";
|
|
2
3
|
import "./index.less";
|
|
3
4
|
export declare function CodeGenActionBtn({ ctx }: {
|
|
4
5
|
ctx: IPublicModelPluginContext;
|
|
5
|
-
}): import("react
|
|
6
|
+
}): import("react").JSX.Element;
|
|
6
7
|
export declare function fixSchema(schema: IPublicTypeProjectSchema): Promise<IPublicTypeProjectSchema>;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import _Drawer from "antd/es/drawer";
|
|
2
|
+
import _Space from "antd/es/space";
|
|
3
|
+
import _Button from "antd/es/button";
|
|
4
|
+
import _Spin from "antd/es/spin";
|
|
5
|
+
import _Alert from "antd/es/alert";
|
|
6
|
+
import _message from "antd/es/message";
|
|
7
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
8
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
9
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
|
+
import { useRef, useState } from "react";
|
|
11
|
+
import { generateCode } from "@gant-lowcode/code-generator/standalone-loader";
|
|
12
|
+
import { IPublicEnumTransformStage } from "@gant-lowcode/lowcode-types";
|
|
13
|
+
import coerce from "semver/functions/coerce.js";
|
|
14
|
+
import compare from "semver/functions/compare.js";
|
|
15
|
+
import { CodeGenResult } from "../code-gen-result/index";
|
|
16
|
+
import "./index.less";
|
|
17
|
+
import { CodeOutlined } from "@ant-design/icons";
|
|
18
|
+
import FileSaver from "file-saver";
|
|
19
|
+
import { useRequest } from "ahooks";
|
|
20
|
+
export function CodeGenActionBtn(_ref) {
|
|
21
|
+
var ctx = _ref.ctx;
|
|
22
|
+
var _useState = useState({
|
|
23
|
+
open: false,
|
|
24
|
+
hasError: false,
|
|
25
|
+
error: null,
|
|
26
|
+
loading: false,
|
|
27
|
+
result: null,
|
|
28
|
+
schema: null,
|
|
29
|
+
originalSchema: null
|
|
30
|
+
}),
|
|
31
|
+
state = _useState[0],
|
|
32
|
+
setState = _useState[1];
|
|
33
|
+
var codeGenResultRef = useRef(null);
|
|
34
|
+
var handleClick = /*#__PURE__*/function () {
|
|
35
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
36
|
+
var getProjectSchema, originalSchema, schema, result;
|
|
37
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
_context.prev = 0;
|
|
41
|
+
// 打开基于 Gravity 的编辑器/出码预览器
|
|
42
|
+
setState(function (prev) {
|
|
43
|
+
return _extends({}, prev, {
|
|
44
|
+
loading: true,
|
|
45
|
+
open: true,
|
|
46
|
+
hasError: false
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
console.log("--ctx", ctx);
|
|
50
|
+
getProjectSchema = ctx.config.get("getProjectSchema");
|
|
51
|
+
if (!getProjectSchema) {
|
|
52
|
+
_context.next = 10;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
_context.next = 7;
|
|
56
|
+
return getProjectSchema();
|
|
57
|
+
case 7:
|
|
58
|
+
originalSchema = _context.sent;
|
|
59
|
+
_context.next = 13;
|
|
60
|
+
break;
|
|
61
|
+
case 10:
|
|
62
|
+
_context.next = 12;
|
|
63
|
+
return ctx.project.exportSchema(IPublicEnumTransformStage.Save);
|
|
64
|
+
case 12:
|
|
65
|
+
originalSchema = _context.sent;
|
|
66
|
+
case 13:
|
|
67
|
+
_context.next = 15;
|
|
68
|
+
return fixSchema(originalSchema);
|
|
69
|
+
case 15:
|
|
70
|
+
schema = _context.sent;
|
|
71
|
+
console.log("got schema: ", schema);
|
|
72
|
+
setState(function (prev) {
|
|
73
|
+
return _extends({}, prev, {
|
|
74
|
+
schema: schema,
|
|
75
|
+
originalSchema: originalSchema
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// 出码...
|
|
80
|
+
_context.next = 20;
|
|
81
|
+
return generateCode({
|
|
82
|
+
solution: "gantLegacy",
|
|
83
|
+
schema: schema,
|
|
84
|
+
flattenResult: true,
|
|
85
|
+
builderOptions: {
|
|
86
|
+
// mode: 'fully',
|
|
87
|
+
rootPaths: ["packages", "icost"],
|
|
88
|
+
pagePaths: [],
|
|
89
|
+
configPaths: []
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
case 20:
|
|
93
|
+
result = _context.sent;
|
|
94
|
+
console.log("generated: ", result);
|
|
95
|
+
setState(function (prev) {
|
|
96
|
+
return _extends({}, prev, {
|
|
97
|
+
loading: false,
|
|
98
|
+
result: result
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
_context.next = 29;
|
|
102
|
+
break;
|
|
103
|
+
case 25:
|
|
104
|
+
_context.prev = 25;
|
|
105
|
+
_context.t0 = _context["catch"](0);
|
|
106
|
+
console.error("failed to run code generator: ", _context.t0);
|
|
107
|
+
setState(function (prev) {
|
|
108
|
+
return _extends({}, prev, {
|
|
109
|
+
hasError: true,
|
|
110
|
+
error: _context.t0 instanceof Error ? _context.t0 : new Error("" + ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0))
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
case 29:
|
|
114
|
+
case "end":
|
|
115
|
+
return _context.stop();
|
|
116
|
+
}
|
|
117
|
+
}, _callee, null, [[0, 25]]);
|
|
118
|
+
}));
|
|
119
|
+
return function handleClick() {
|
|
120
|
+
return _ref2.apply(this, arguments);
|
|
121
|
+
};
|
|
122
|
+
}();
|
|
123
|
+
var _useRequest = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
124
|
+
var codeGen, content;
|
|
125
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
126
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
_context2.prev = 0;
|
|
129
|
+
codeGen = codeGenResultRef.current;
|
|
130
|
+
if (codeGen) {
|
|
131
|
+
_context2.next = 4;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return _context2.abrupt("return");
|
|
135
|
+
case 4:
|
|
136
|
+
_context2.next = 6;
|
|
137
|
+
return codeGen.codeZip();
|
|
138
|
+
case 6:
|
|
139
|
+
content = _context2.sent;
|
|
140
|
+
FileSaver.saveAs(content, "gant-lowcode-generated-sources.zip");
|
|
141
|
+
_context2.next = 14;
|
|
142
|
+
break;
|
|
143
|
+
case 10:
|
|
144
|
+
_context2.prev = 10;
|
|
145
|
+
_context2.t0 = _context2["catch"](0);
|
|
146
|
+
console.log("failed to download sources: ", _context2.t0);
|
|
147
|
+
_message.error("下载失败!");
|
|
148
|
+
case 14:
|
|
149
|
+
case "end":
|
|
150
|
+
return _context2.stop();
|
|
151
|
+
}
|
|
152
|
+
}, _callee2, null, [[0, 10]]);
|
|
153
|
+
})), {
|
|
154
|
+
manual: true
|
|
155
|
+
}),
|
|
156
|
+
run = _useRequest.run,
|
|
157
|
+
downloading = _useRequest.loading;
|
|
158
|
+
var handleDownload = /*#__PURE__*/function () {
|
|
159
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(e) {
|
|
160
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
161
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
run();
|
|
166
|
+
case 3:
|
|
167
|
+
case "end":
|
|
168
|
+
return _context3.stop();
|
|
169
|
+
}
|
|
170
|
+
}, _callee3);
|
|
171
|
+
}));
|
|
172
|
+
return function handleDownload(_x) {
|
|
173
|
+
return _ref4.apply(this, arguments);
|
|
174
|
+
};
|
|
175
|
+
}();
|
|
176
|
+
var _useRequest2 = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
177
|
+
var codeGen, blob, setCodeUpload;
|
|
178
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
179
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
180
|
+
case 0:
|
|
181
|
+
codeGen = codeGenResultRef.current;
|
|
182
|
+
if (codeGen) {
|
|
183
|
+
_context4.next = 3;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
return _context4.abrupt("return");
|
|
187
|
+
case 3:
|
|
188
|
+
_context4.prev = 3;
|
|
189
|
+
_context4.next = 6;
|
|
190
|
+
return codeGen.codeZip();
|
|
191
|
+
case 6:
|
|
192
|
+
blob = _context4.sent;
|
|
193
|
+
setCodeUpload = ctx.config.get("setCodeUpload");
|
|
194
|
+
if (!setCodeUpload) {
|
|
195
|
+
_context4.next = 11;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
_context4.next = 11;
|
|
199
|
+
return setCodeUpload({
|
|
200
|
+
zipFile: blob
|
|
201
|
+
});
|
|
202
|
+
case 11:
|
|
203
|
+
_context4.next = 17;
|
|
204
|
+
break;
|
|
205
|
+
case 13:
|
|
206
|
+
_context4.prev = 13;
|
|
207
|
+
_context4.t0 = _context4["catch"](3);
|
|
208
|
+
console.log("failed to git push: ", _context4.t0);
|
|
209
|
+
_message.error("上传失败!");
|
|
210
|
+
case 17:
|
|
211
|
+
case "end":
|
|
212
|
+
return _context4.stop();
|
|
213
|
+
}
|
|
214
|
+
}, _callee4, null, [[3, 13]]);
|
|
215
|
+
})), {
|
|
216
|
+
manual: true
|
|
217
|
+
}),
|
|
218
|
+
handleUpload = _useRequest2.run,
|
|
219
|
+
uploading = _useRequest2.loading;
|
|
220
|
+
var drawerChildren = null;
|
|
221
|
+
if (state.hasError) {
|
|
222
|
+
var _state$error;
|
|
223
|
+
drawerChildren = /*#__PURE__*/React.createElement(_Alert, {
|
|
224
|
+
type: "error",
|
|
225
|
+
message: "\u51FA\u9519\u4E86",
|
|
226
|
+
description: (_state$error = state.error) === null || _state$error === void 0 ? void 0 : _state$error.message
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (state.loading) {
|
|
230
|
+
drawerChildren = /*#__PURE__*/React.createElement(_Spin, {
|
|
231
|
+
className: "code-gen-plugin-loading",
|
|
232
|
+
spinning: true,
|
|
233
|
+
tip: "\u6B63\u5728\u51FA\u7801..."
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
drawerChildren = /*#__PURE__*/React.createElement(CodeGenResult, {
|
|
237
|
+
ref: codeGenResultRef,
|
|
238
|
+
result: state.result,
|
|
239
|
+
schema: state.schema,
|
|
240
|
+
originalSchema: state.originalSchema
|
|
241
|
+
});
|
|
242
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
|
243
|
+
type: "text",
|
|
244
|
+
onClick: handleClick
|
|
245
|
+
}, /*#__PURE__*/React.createElement(CodeOutlined, null)), /*#__PURE__*/React.createElement(_Drawer, {
|
|
246
|
+
open: state.open,
|
|
247
|
+
title: "\u51FA\u7801\u7ED3\u679C",
|
|
248
|
+
width: "95vw",
|
|
249
|
+
rootClassName: "code-gen-drawer",
|
|
250
|
+
extra: /*#__PURE__*/React.createElement(_Space, null, /*#__PURE__*/React.createElement(_Button, {
|
|
251
|
+
type: "link",
|
|
252
|
+
onClick: handleUpload,
|
|
253
|
+
loading: uploading
|
|
254
|
+
}, "\u4E0A\u4F20git"), /*#__PURE__*/React.createElement(_Button, {
|
|
255
|
+
type: "link",
|
|
256
|
+
onClick: handleDownload,
|
|
257
|
+
loading: downloading
|
|
258
|
+
}, "\u4E0B\u8F7D\u6E90\u4EE3\u7801")),
|
|
259
|
+
onClose: function onClose() {
|
|
260
|
+
setState(function (prev) {
|
|
261
|
+
return _extends({}, prev, {
|
|
262
|
+
open: false
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}, drawerChildren));
|
|
267
|
+
}
|
|
268
|
+
export function fixSchema(_x2) {
|
|
269
|
+
return _fixSchema.apply(this, arguments);
|
|
270
|
+
}
|
|
271
|
+
function _fixSchema() {
|
|
272
|
+
_fixSchema = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(schema) {
|
|
273
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
274
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
275
|
+
case 0:
|
|
276
|
+
return _context5.abrupt("return", deepClone(_extends({}, schema, {
|
|
277
|
+
componentsMap: schema.componentsMap.filter(function (c) {
|
|
278
|
+
return c["package"];
|
|
279
|
+
}) // 去掉没有 package 的组件
|
|
280
|
+
.map(function (c) {
|
|
281
|
+
// 修正版本号(对于没有有效版本号的组件,默认使用 latest)
|
|
282
|
+
if (!isValidVersion(c.version)) {
|
|
283
|
+
console.warn('[WARN] got invalid version "%o" for component "%s", use "latest" as fallback', c.version, c);
|
|
284
|
+
return _extends({}, c, {
|
|
285
|
+
version: "latest"
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// 修正 gantd-lowcode-materials 的版本,最小为1.1.0
|
|
290
|
+
if (c["package"] === 'gantd-lowcode-materials' && compare(coerce(c.version) || '', '1.1.0') <= 0) {
|
|
291
|
+
return _extends({}, c, {
|
|
292
|
+
version: 'latest'
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return c;
|
|
296
|
+
})
|
|
297
|
+
})));
|
|
298
|
+
case 1:
|
|
299
|
+
case "end":
|
|
300
|
+
return _context5.stop();
|
|
301
|
+
}
|
|
302
|
+
}, _callee5);
|
|
303
|
+
}));
|
|
304
|
+
return _fixSchema.apply(this, arguments);
|
|
305
|
+
}
|
|
306
|
+
function deepClone(x) {
|
|
307
|
+
try {
|
|
308
|
+
return JSON.parse(JSON.stringify(x));
|
|
309
|
+
} catch (e) {
|
|
310
|
+
throw new Error("failed to clone schema -- " + e);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function isValidVersion(version) {
|
|
314
|
+
if (!version) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 对于一些明显非法的版本号过滤下
|
|
319
|
+
if (version === "{{version}}" || version === "null" || version === "undefined") {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 对于 latest/beta/rc 这样的 tag 版本号要支持下
|
|
324
|
+
if (/^[a-z][a-z0-9]+([a-z0-9-]+)?$/i.test(version)) {
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 最后支持下所有 semver 能识别的版本
|
|
329
|
+
return coerce(version) !== null;
|
|
330
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.code-gen-plugin-loading {
|
|
2
|
+
width: 100%;
|
|
3
|
+
margin: 2em auto;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.code-gen-drawer {
|
|
7
|
+
.ant-drawer-body {
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.code-gen-plugin-result {
|
|
14
|
+
width: 100%;
|
|
15
|
+
.next-message-error {
|
|
16
|
+
.next-message-content {
|
|
17
|
+
white-space: pre-wrap;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
// 默认生成的代码不符合在线预览的规则,需要处理下
|
|
3
|
+
export function fixPreviewCode(code, unused) {
|
|
4
|
+
var _JSON$parse, _fixedCode$modules$P;
|
|
5
|
+
if (!code) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
var fixedModules = Object.entries(code.modules || {})
|
|
9
|
+
// 去掉隐藏文件和 html 以及 md 等无用文件:
|
|
10
|
+
.filter(function (_ref) {
|
|
11
|
+
var fpath = _ref[0];
|
|
12
|
+
return !fpath.startsWith("/.") && !fpath.endsWith(".html") && !fpath.endsWith(".md");
|
|
13
|
+
})
|
|
14
|
+
// 所有的 jsx 文件改成 js 文件(因为 gravity 不支持 jsx)
|
|
15
|
+
.map(function (_ref2) {
|
|
16
|
+
var fpath = _ref2[0],
|
|
17
|
+
module = _ref2[1];
|
|
18
|
+
return [fpath.replace(/\.jsx$/, ".js"), module];
|
|
19
|
+
}).map(function (_ref3) {
|
|
20
|
+
var fpath = _ref3[0],
|
|
21
|
+
module = _ref3[1];
|
|
22
|
+
return [fpath.replace(/\.scss$/, ".css"), module];
|
|
23
|
+
}).reduce(function (acc, _ref4) {
|
|
24
|
+
var _extends2;
|
|
25
|
+
var fpath = _ref4[0],
|
|
26
|
+
module = _ref4[1];
|
|
27
|
+
return _extends({}, acc, (_extends2 = {}, _extends2[fpath] = _extends({}, module, {
|
|
28
|
+
fpath: fpath,
|
|
29
|
+
code: module.code
|
|
30
|
+
// 所有的 import xxx from '@/yyy' 转换为 import xxx from '/src/yyy'
|
|
31
|
+
.replace(/import\s+([^\s]+)\s+from\s+['"]@\/([^'"]+)['"]/g, function (_, name, path) {
|
|
32
|
+
return "import " + name + " from '/src/" + path + "'";
|
|
33
|
+
})
|
|
34
|
+
// 所有的 import styles from 'xxx.scss' 转换为 import styles from '/src/xxx.css'
|
|
35
|
+
.replace(/import\s+([^\s]+)\s+from\s+['"]([^'"]+)\.scss['"]/g, function (_, name, path) {
|
|
36
|
+
return "import " + name + " from '" + path + ".css'";
|
|
37
|
+
})
|
|
38
|
+
}), _extends2));
|
|
39
|
+
}, {});
|
|
40
|
+
var fixedCode = _extends({}, code, {
|
|
41
|
+
modules: fixedModules
|
|
42
|
+
});
|
|
43
|
+
fixedCode.modules["/src/app.js"] = _extends({}, fixedCode.modules["/src/app.js"], {
|
|
44
|
+
code: "\n // \u6CE8\u610F\uFF1A\u4E3A\u4E86\u65B9\u4FBF\u5728\u6D4F\u89C8\u5668\u4E2D\u8FDB\u884C\u9884\u89C8\uFF0C\u8FD9\u91CC\u7B80\u5316\u4E86\u4E00\u4E9B\u5185\u5BB9\n import './shims';\n import './global.css';\n\n import React from 'react';\n import ReactDOM from 'react-dom';\n\n import Page from '" + Object.keys(fixedModules).find(function (fpath) {
|
|
45
|
+
return fpath.startsWith("/src/pages/");
|
|
46
|
+
}) + "';\n\n ReactDOM.render(<Page/>, document.getElementById('root'));\n"
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 一些垫片
|
|
50
|
+
fixedCode.modules["/src/shims.js"] = {
|
|
51
|
+
fpath: "/src/shims.js",
|
|
52
|
+
code: ""
|
|
53
|
+
};
|
|
54
|
+
fixedCode.modules["/package.json"] = _extends({}, fixedCode.modules["/package.json"], {
|
|
55
|
+
code: JSON.stringify({
|
|
56
|
+
name: "demo",
|
|
57
|
+
version: "1.0.0",
|
|
58
|
+
dependencies: _extends({
|
|
59
|
+
react: "^16.8.3",
|
|
60
|
+
"react-dom": "^16.8.3"
|
|
61
|
+
}, (_JSON$parse = JSON.parse(((_fixedCode$modules$P = fixedCode.modules["/package.json"]) === null || _fixedCode$modules$P === void 0 ? void 0 : _fixedCode$modules$P.code) || "{}")) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.dependencies)
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
fixedCode.modules = pickKeys(fixedCode.modules, [
|
|
65
|
+
// '/tsconfig.json',
|
|
66
|
+
// '/jsconfig.json',
|
|
67
|
+
// '/build.json',
|
|
68
|
+
// '/abc.json',
|
|
69
|
+
"/package.json", "/src/routes.js", "/src/app.js", "/src/constants.js", "/src/utils.js", "/src/i18n.js", "/src/global.css", "/src/index.js", "/src/shims.js"].concat(Object.keys(fixedModules).filter(function (fpath) {
|
|
70
|
+
return fpath.startsWith("/src/pages/");
|
|
71
|
+
})));
|
|
72
|
+
fixedCode.modules["/src/routes.js"] = _extends({}, fixedCode.modules["/src/routes.js"], {
|
|
73
|
+
code: "\n"
|
|
74
|
+
});
|
|
75
|
+
fixedCode.modules["/src/global.css"] = {
|
|
76
|
+
fpath: "/src/global.css",
|
|
77
|
+
code: "\nbody {\n -webkit-font-smoothing: antialiased;\n}\n"
|
|
78
|
+
};
|
|
79
|
+
Object.assign(fixedCode.modules, {
|
|
80
|
+
"/src/index.html": {
|
|
81
|
+
code: '<div id="root"></div>',
|
|
82
|
+
fpath: "/src/index.html"
|
|
83
|
+
},
|
|
84
|
+
"/src/index.less": {
|
|
85
|
+
fpath: "/src/index.less",
|
|
86
|
+
code: "\n\n "
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
fixedCode.type = "riddle";
|
|
90
|
+
return fixedCode;
|
|
91
|
+
}
|
|
92
|
+
function pickKeys(data, keys) {
|
|
93
|
+
return keys.reduce(function (acc, key) {
|
|
94
|
+
if (data[key]) {
|
|
95
|
+
var _extends3;
|
|
96
|
+
return _extends({}, acc, (_extends3 = {}, _extends3[key] = data[key], _extends3));
|
|
97
|
+
}
|
|
98
|
+
return acc;
|
|
99
|
+
}, {});
|
|
100
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { GravityCode } from "../../types";
|
|
2
3
|
import "./index.less";
|
|
3
|
-
export type CodeGenPreviewProps = {
|
|
4
|
+
export declare type CodeGenPreviewProps = {
|
|
4
5
|
code: GravityCode | null;
|
|
5
6
|
height: string | number;
|
|
6
7
|
refresh: string | number;
|
|
7
8
|
};
|
|
8
|
-
export declare function CodeGenPreview(props: CodeGenPreviewProps): import("react
|
|
9
|
+
export declare function CodeGenPreview(props: CodeGenPreviewProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { IPublicTypeProjectSchema } from "@gant-lowcode/lowcode-types";
|
|
3
3
|
import { Result } from "@gant-lowcode/code-generator/standalone-loader";
|
|
4
4
|
import "./index.less";
|
|
@@ -10,5 +10,5 @@ interface CodeGenResultProps {
|
|
|
10
10
|
export interface CodeGenResultRef {
|
|
11
11
|
codeZip: () => Promise<Blob>;
|
|
12
12
|
}
|
|
13
|
-
export declare const CodeGenResult:
|
|
13
|
+
export declare const CodeGenResult: import("react").ForwardRefExoticComponent<CodeGenResultProps & import("react").RefAttributes<CodeGenResultRef>>;
|
|
14
14
|
export {};
|