@dckj-npm/lowcode-plugin-code-generator 1.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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/es/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
  4. package/es/components/CodeGenActionBtn/CodeGenActionBtn.js +196 -0
  5. package/es/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
  6. package/es/components/CodeGenActionBtn/index.d.ts +1 -0
  7. package/es/components/CodeGenActionBtn/index.js +1 -0
  8. package/es/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
  9. package/es/components/CodeGenPreview/CodeGenPreview.js +40 -0
  10. package/es/components/CodeGenPreview/CodeGenPreview.scss +16 -0
  11. package/es/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
  12. package/es/components/CodeGenPreview/fixPreviewCode.js +101 -0
  13. package/es/components/CodeGenPreview/index.d.ts +1 -0
  14. package/es/components/CodeGenPreview/index.js +1 -0
  15. package/es/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
  16. package/es/components/CodeGenPreview/useIsInIntranet.js +66 -0
  17. package/es/components/CodeGenResult/CodeGenResult.d.ts +9 -0
  18. package/es/components/CodeGenResult/CodeGenResult.js +162 -0
  19. package/es/components/CodeGenResult/CodeGenResult.scss +7 -0
  20. package/es/components/CodeGenResult/index.d.ts +1 -0
  21. package/es/components/CodeGenResult/index.js +1 -0
  22. package/es/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
  23. package/es/components/CodeSandboxPreview/CodeSandboxPreview.js +186 -0
  24. package/es/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
  25. package/es/components/CodeSandboxPreview/index.d.ts +1 -0
  26. package/es/components/CodeSandboxPreview/index.js +1 -0
  27. package/es/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
  28. package/es/components/FileTypeIcon/FileTypeIcon.js +12 -0
  29. package/es/components/FileTypeIcon/FileTypeIcon.scss +36 -0
  30. package/es/components/FileTypeIcon/index.d.ts +1 -0
  31. package/es/components/FileTypeIcon/index.js +1 -0
  32. package/es/components/GravityCode/GravityCode.d.ts +9 -0
  33. package/es/components/GravityCode/GravityCode.js +1 -0
  34. package/es/components/GravityCode/index.d.ts +1 -0
  35. package/es/components/GravityCode/index.js +1 -0
  36. package/es/components/GravityPreview/ForceUpdate.d.ts +6 -0
  37. package/es/components/GravityPreview/ForceUpdate.js +12 -0
  38. package/es/components/GravityPreview/GravityPreview.d.ts +7 -0
  39. package/es/components/GravityPreview/GravityPreview.js +37 -0
  40. package/es/components/GravityPreview/GravitySdk.d.ts +10 -0
  41. package/es/components/GravityPreview/GravitySdk.js +183 -0
  42. package/es/components/GravityPreview/index.d.ts +1 -0
  43. package/es/components/GravityPreview/index.js +1 -0
  44. package/es/components/SourcesView/SourcesView.d.ts +9 -0
  45. package/es/components/SourcesView/SourcesView.js +197 -0
  46. package/es/components/SourcesView/SourcesView.scss +24 -0
  47. package/es/components/SourcesView/index.d.ts +1 -0
  48. package/es/components/SourcesView/index.js +1 -0
  49. package/es/demo/index.d.ts +1 -0
  50. package/es/demo/index.js +223 -0
  51. package/es/demo/index.scss +56 -0
  52. package/es/index.d.ts +30 -0
  53. package/es/index.js +67 -0
  54. package/es/style.js +2 -0
  55. package/es/types/SyncCodeGenResult.d.ts +7 -0
  56. package/es/types/SyncCodeGenResult.js +1 -0
  57. package/es/types/index.d.ts +1 -0
  58. package/es/types/index.js +1 -0
  59. package/es/typings.d.js +0 -0
  60. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
  61. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.js +204 -0
  62. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
  63. package/lib/components/CodeGenActionBtn/index.d.ts +1 -0
  64. package/lib/components/CodeGenActionBtn/index.js +9 -0
  65. package/lib/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
  66. package/lib/components/CodeGenPreview/CodeGenPreview.js +45 -0
  67. package/lib/components/CodeGenPreview/CodeGenPreview.scss +16 -0
  68. package/lib/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
  69. package/lib/components/CodeGenPreview/fixPreviewCode.js +106 -0
  70. package/lib/components/CodeGenPreview/index.d.ts +1 -0
  71. package/lib/components/CodeGenPreview/index.js +9 -0
  72. package/lib/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
  73. package/lib/components/CodeGenPreview/useIsInIntranet.js +72 -0
  74. package/lib/components/CodeGenResult/CodeGenResult.d.ts +9 -0
  75. package/lib/components/CodeGenResult/CodeGenResult.js +169 -0
  76. package/lib/components/CodeGenResult/CodeGenResult.scss +7 -0
  77. package/lib/components/CodeGenResult/index.d.ts +1 -0
  78. package/lib/components/CodeGenResult/index.js +9 -0
  79. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
  80. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.js +193 -0
  81. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
  82. package/lib/components/CodeSandboxPreview/index.d.ts +1 -0
  83. package/lib/components/CodeSandboxPreview/index.js +9 -0
  84. package/lib/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
  85. package/lib/components/FileTypeIcon/FileTypeIcon.js +17 -0
  86. package/lib/components/FileTypeIcon/FileTypeIcon.scss +36 -0
  87. package/lib/components/FileTypeIcon/index.d.ts +1 -0
  88. package/lib/components/FileTypeIcon/index.js +9 -0
  89. package/lib/components/GravityCode/GravityCode.d.ts +9 -0
  90. package/lib/components/GravityCode/GravityCode.js +3 -0
  91. package/lib/components/GravityCode/index.d.ts +1 -0
  92. package/lib/components/GravityCode/index.js +9 -0
  93. package/lib/components/GravityPreview/ForceUpdate.d.ts +6 -0
  94. package/lib/components/GravityPreview/ForceUpdate.js +17 -0
  95. package/lib/components/GravityPreview/GravityPreview.d.ts +7 -0
  96. package/lib/components/GravityPreview/GravityPreview.js +44 -0
  97. package/lib/components/GravityPreview/GravitySdk.d.ts +10 -0
  98. package/lib/components/GravityPreview/GravitySdk.js +196 -0
  99. package/lib/components/GravityPreview/index.d.ts +1 -0
  100. package/lib/components/GravityPreview/index.js +9 -0
  101. package/lib/components/SourcesView/SourcesView.d.ts +9 -0
  102. package/lib/components/SourcesView/SourcesView.js +204 -0
  103. package/lib/components/SourcesView/SourcesView.scss +24 -0
  104. package/lib/components/SourcesView/index.d.ts +1 -0
  105. package/lib/components/SourcesView/index.js +9 -0
  106. package/lib/demo/index.d.ts +1 -0
  107. package/lib/demo/index.js +228 -0
  108. package/lib/demo/index.scss +56 -0
  109. package/lib/index.d.ts +30 -0
  110. package/lib/index.js +74 -0
  111. package/lib/style.js +2 -0
  112. package/lib/types/SyncCodeGenResult.d.ts +7 -0
  113. package/lib/types/SyncCodeGenResult.js +3 -0
  114. package/lib/types/index.d.ts +1 -0
  115. package/lib/types/index.js +9 -0
  116. package/lib/typings.d.js +1 -0
  117. package/package.json +94 -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.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # 集团低代码引擎 - 出码插件(浏览器里进行出码)
2
+
3
+ ## 简介
4
+
5
+ 本项目是出码模块的对应的浏览器里进行出码的插件
6
+
7
+ ## 使用方法
8
+
9
+ 1. 安装依赖 `npm install --save @alilc/lowcode-plugin-code-generator`
10
+ 2. 注册插件:
11
+
12
+ ```ts
13
+ import { plugins } from '@alilc/lowcode-engine';
14
+ import CodeGenPlugin from '@alilc/lowcode-plugin-code-generator';
15
+
16
+ // 在你的初始化函数中:
17
+ await plugins.register(CodeGenPlugin);
18
+
19
+ // 如果您不希望自动加上出码按钮,则可以这样注册
20
+ await plugins.register(CodeGenPlugin, { disableCodeGenActionBtn: true });
21
+
22
+ ```
23
+
24
+ 然后运行你的低代码编辑器项目即可。
25
+
26
+ 参考:低代码编辑器的 Demo: <https://github.com/alibaba/lowcode-demo>
27
+
28
+ ## 插件 API
29
+
30
+ 本插件提供了出码的 API,注册了插件后, 可以这么样来用:
31
+
32
+ ```js
33
+ import { plugins } from '@alilc/lowcode-engine';
34
+
35
+ const codeGenResult = plugins.codeGenerator.generateCode({
36
+ solution: 'icejs',
37
+ schema: await ctx.project.exportSchema(),
38
+ });
39
+
40
+ console.log('出码结果:', codeGenResult); // 这里就是出码结果
41
+
42
+ ```
43
+
44
+ ## 本地开发
45
+
46
+ 常规两步即可开发调试:`npm i && npm start`
47
+
48
+ ## 共建
49
+
50
+ 欢迎参与共建,欢迎直接 fork 一份改改,补充您所需要的特性或修复 bug,然后提 PR 过来:
51
+
52
+ -- 代码仓库:<https://github.com/alibaba/lowcode-code-generator-demo>
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import './CodeGenActionBtn.scss';
3
+ import type { ILowCodePluginContext } from '@alilc/lowcode-engine';
4
+ import { ProjectSchema } from '@alilc/lowcode-types';
5
+ export declare function CodeGenActionBtn({ ctx }: {
6
+ ctx: ILowCodePluginContext;
7
+ }): JSX.Element;
8
+ export declare function fixSchema(schema: ProjectSchema): Promise<ProjectSchema>;
@@ -0,0 +1,196 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import './CodeGenActionBtn.scss';
5
+ import React, { useState } from 'react';
6
+ import * as CodeGenerator from '@dckj-npm/lowcode-code-generator/standalone-loader';
7
+ import { TransformStage } from '@alilc/lowcode-types';
8
+ import { Button, Drawer, Loading, Message } from '@alifd/next';
9
+ import coerce from 'semver/functions/coerce';
10
+ import { CodeGenResult } from '../CodeGenResult';
11
+ export function CodeGenActionBtn(_ref) {
12
+ var ctx = _ref.ctx;
13
+ var _useState = useState({
14
+ visible: false,
15
+ hasError: false,
16
+ error: null,
17
+ loading: false,
18
+ result: null,
19
+ schema: null,
20
+ originalSchema: null
21
+ }),
22
+ state = _useState[0],
23
+ setState = _useState[1];
24
+ var handleClick = /*#__PURE__*/function () {
25
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
26
+ var originalSchema, schema, result;
27
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
28
+ while (1) switch (_context.prev = _context.next) {
29
+ case 0:
30
+ _context.prev = 0;
31
+ // 打开基于 Gravity 的编辑器/出码预览器
32
+ setState(function (prev) {
33
+ return _extends({}, prev, {
34
+ loading: true,
35
+ visible: true,
36
+ hasError: false
37
+ });
38
+ });
39
+
40
+ // 获取 schema,并修正
41
+ _context.next = 4;
42
+ return ctx.project.exportSchema(TransformStage.Save);
43
+ case 4:
44
+ originalSchema = _context.sent;
45
+ _context.next = 7;
46
+ return fixSchema(originalSchema);
47
+ case 7:
48
+ schema = _context.sent;
49
+ console.log('got schema:222222 ', schema);
50
+ setState(function (prev) {
51
+ return _extends({}, prev, {
52
+ schema: schema,
53
+ originalSchema: originalSchema
54
+ });
55
+ });
56
+
57
+ // 出码...
58
+ _context.next = 12;
59
+ return CodeGenerator.generateCode({
60
+ solution: 'vuejs3',
61
+ schema: schema,
62
+ flattenResult: true
63
+ });
64
+ case 12:
65
+ result = _context.sent;
66
+ console.log('generated: ', result);
67
+ setState(function (prev) {
68
+ return _extends({}, prev, {
69
+ loading: false,
70
+ result: result
71
+ });
72
+ });
73
+ _context.next = 21;
74
+ break;
75
+ case 17:
76
+ _context.prev = 17;
77
+ _context.t0 = _context["catch"](0);
78
+ console.error('failed to run code generator: ', _context.t0);
79
+ setState(function (prev) {
80
+ return _extends({}, prev, {
81
+ hasError: true,
82
+ error: _context.t0 instanceof Error ? _context.t0 : new Error("" + ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0))
83
+ });
84
+ });
85
+ case 21:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }, _callee, null, [[0, 17]]);
90
+ }));
91
+ return function handleClick() {
92
+ return _ref2.apply(this, arguments);
93
+ };
94
+ }();
95
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
96
+ type: "primary",
97
+ onClick: handleClick
98
+ }, "\u51FA\u7801"), /*#__PURE__*/React.createElement(Drawer, {
99
+ visible: state.visible,
100
+ title: "\u51FA\u7801\u7ED3\u679C",
101
+ width: "95vw",
102
+ onClose: function onClose() {
103
+ setState(function (prev) {
104
+ return _extends({}, prev, {
105
+ visible: false
106
+ });
107
+ });
108
+ }
109
+ }, /*#__PURE__*/React.createElement("div", {
110
+ className: "code-gen-plugin-result"
111
+ }, function () {
112
+ if (state.hasError) {
113
+ var _state$error;
114
+ return /*#__PURE__*/React.createElement(Message, {
115
+ type: "error",
116
+ title: "\u51FA\u9519\u4E86"
117
+ }, (_state$error = state.error) === null || _state$error === void 0 ? void 0 : _state$error.message);
118
+ }
119
+ if (state.loading) {
120
+ return /*#__PURE__*/React.createElement(Loading, {
121
+ className: "code-gen-plugin-loading",
122
+ tip: "\u6B63\u5728\u51FA\u7801..."
123
+ });
124
+ }
125
+ return /*#__PURE__*/React.createElement(CodeGenResult, {
126
+ result: state.result,
127
+ schema: state.schema,
128
+ originalSchema: state.originalSchema
129
+ });
130
+ }())));
131
+ }
132
+ export function fixSchema(_x) {
133
+ return _fixSchema.apply(this, arguments);
134
+ }
135
+ function _fixSchema() {
136
+ _fixSchema = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(schema) {
137
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
138
+ while (1) switch (_context2.prev = _context2.next) {
139
+ case 0:
140
+ return _context2.abrupt("return", deepClone(_extends({}, schema, {
141
+ componentsMap: schema.componentsMap.filter(function (c) {
142
+ return c["package"];
143
+ }) // 去掉没有 package 的组件
144
+ .map(function (c) {
145
+ // 修正版本号(对于没有有效版本号的组件,默认使用 latest)
146
+ if (!isValidVersion(c.version)) {
147
+ console.warn('[WARN] got invalid version "%o" for component "%s", use "latest" as fallback', c.version, c);
148
+ return _extends({}, c, {
149
+ version: 'latest'
150
+ });
151
+ }
152
+
153
+ // 修正 @alifd/pro-layout 的版本
154
+ // -- 这个包没有 ^0.1.0 的版本,这里暂且替换下
155
+ if (c["package"] === '@alifd/pro-layout' && c.version === '^0.1.0') {
156
+ console.warn('[WARN] got invalid version "%o" for "@alifd/pro-layout"! use "latest" as fallback', c.version);
157
+ return _extends({}, c, {
158
+ version: 'latest'
159
+ });
160
+ }
161
+ return c;
162
+ })
163
+ })));
164
+ case 1:
165
+ case "end":
166
+ return _context2.stop();
167
+ }
168
+ }, _callee2);
169
+ }));
170
+ return _fixSchema.apply(this, arguments);
171
+ }
172
+ function deepClone(x) {
173
+ try {
174
+ return JSON.parse(JSON.stringify(x));
175
+ } catch (e) {
176
+ throw new Error("failed to clone schema -- " + e);
177
+ }
178
+ }
179
+ function isValidVersion(version) {
180
+ if (!version) {
181
+ return false;
182
+ }
183
+
184
+ // 对于一些明显非法的版本号过滤下
185
+ if (version === '{{version}}' || version === 'null' || version === 'undefined') {
186
+ return false;
187
+ }
188
+
189
+ // 对于 latest/beta/rc 这样的 tag 版本号要支持下
190
+ if (/^[a-z][a-z0-9]+([a-z0-9-]+)?$/i.test(version)) {
191
+ return true;
192
+ }
193
+
194
+ // 最后支持下所有 semver 能识别的版本
195
+ return coerce(version) !== null;
196
+ }
@@ -0,0 +1,13 @@
1
+ .code-gen-plugin-loading {
2
+ width: 100%;
3
+ margin: 2em auto;
4
+ }
5
+
6
+ .code-gen-plugin-result {
7
+ width: 100%;
8
+ .next-message-error {
9
+ .next-message-content {
10
+ white-space: pre-wrap;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export * from './CodeGenActionBtn';
@@ -0,0 +1 @@
1
+ export * from './CodeGenActionBtn';
@@ -0,0 +1,8 @@
1
+ import type { GravityCode } from '../GravityCode';
2
+ import './CodeGenPreview.scss';
3
+ export declare type CodeGenPreviewProps = {
4
+ code: GravityCode | null;
5
+ height: string | number;
6
+ refresh: string | number;
7
+ };
8
+ export declare function CodeGenPreview(props: CodeGenPreviewProps): any;
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { Tab } from '@alifd/next';
3
+ import { useIsInIntranet } from './useIsInIntranet';
4
+ import { GravityPreview } from '../GravityPreview';
5
+ import { CodeSandboxPreview } from '../CodeSandboxPreview';
6
+ import { ForceUpdate } from '../GravityPreview/ForceUpdate';
7
+ import './CodeGenPreview.scss';
8
+ export function CodeGenPreview(props) {
9
+ var isInIntranet = useIsInIntranet();
10
+ var previewPanes = [{
11
+ title: '基于 Gravity 预览',
12
+ available: isInIntranet,
13
+ render: function render() {
14
+ return /*#__PURE__*/React.createElement(GravityPreview, props);
15
+ }
16
+ }, {
17
+ title: '基于 CodeSandbox 预览',
18
+ available: true,
19
+ render: function render() {
20
+ return /*#__PURE__*/React.createElement(CodeSandboxPreview, props);
21
+ }
22
+ }];
23
+ var availablePreviewPanes = previewPanes.filter(function (pane) {
24
+ return pane.available;
25
+ });
26
+ if (availablePreviewPanes.length === 1) {
27
+ return availablePreviewPanes[0].render();
28
+ }
29
+ return /*#__PURE__*/React.createElement(Tab, {
30
+ className: "code-gen-preview-tabs",
31
+ size: "small"
32
+ }, availablePreviewPanes.map(function (pane) {
33
+ return /*#__PURE__*/React.createElement(Tab.Item, {
34
+ title: pane.title,
35
+ key: pane.title
36
+ }, /*#__PURE__*/React.createElement(ForceUpdate, {
37
+ watchKey: props.refresh
38
+ }, pane.render()));
39
+ }));
40
+ }
@@ -0,0 +1,16 @@
1
+ .code-gen-preview-tabs {
2
+ display: flex;
3
+ flex-direction: column;
4
+ height: 100%;
5
+
6
+ .next-tabs-bar {
7
+ flex-shrink: 0;
8
+ }
9
+
10
+ .next-tabs-content {
11
+ flex: 1;
12
+ .next-tabs-tabpane {
13
+ height: 100%;
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,2 @@
1
+ import { GravityCode } from '../GravityCode/GravityCode';
2
+ export declare function fixPreviewCode(code: GravityCode | null, unused?: unknown): GravityCode | null;
@@ -0,0 +1,101 @@
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\nimport './shims';\nimport './global.css';\n\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport Page from '" + Object.keys(fixedModules).find(function (fpath) {
45
+ return fpath.startsWith('/src/pages/');
46
+ }) + "';\n\nReactDOM.render(<Page/>, document.getElementById('root'));\n"
47
+ });
48
+
49
+ // 一些垫片,用于解决一些不能被 gravity 解析的问题
50
+ // 1. @alilc/lowcode-materials 中有部分代码直接使用了全局变量 PropTypes...
51
+ fixedCode.modules['/src/shims.js'] = {
52
+ fpath: '/src/shims.js',
53
+ code: "\n// \u4E00\u4E9B\u57AB\u7247\u4EE3\u7801\uFF0C\u7528\u6765\u89E3\u51B3\u76F4\u63A5\u5728\u6D4F\u89C8\u5668\u4E2D\u9884\u89C8\u7684\u65F6\u5019\u7684\u95EE\u9898\nimport PropTypes from 'prop-types';\n\nwindow.PropTypes = PropTypes;\n"
54
+ };
55
+ fixedCode.modules['/package.json'] = _extends({}, fixedCode.modules['/package.json'], {
56
+ code: JSON.stringify({
57
+ name: 'demo',
58
+ version: '1.0.0',
59
+ dependencies: _extends({
60
+ react: '^16.8.3',
61
+ 'react-dom': '^16.8.3'
62
+ }, (_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)
63
+ })
64
+ });
65
+ fixedCode.modules = pickKeys(fixedCode.modules, [
66
+ // '/tsconfig.json',
67
+ // '/jsconfig.json',
68
+ // '/build.json',
69
+ // '/abc.json',
70
+ '/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) {
71
+ return fpath.startsWith('/src/pages/');
72
+ })));
73
+ fixedCode.modules['/src/routes.js'] = _extends({}, fixedCode.modules['/src/routes.js'], {
74
+ code: "\n"
75
+ });
76
+ fixedCode.modules['/src/global.css'] = {
77
+ fpath: '/src/global.css',
78
+ code: "\nbody {\n -webkit-font-smoothing: antialiased;\n}\n"
79
+ };
80
+ Object.assign(fixedCode.modules, {
81
+ '/src/index.html': {
82
+ code: '<div id="root"></div>',
83
+ fpath: '/src/index.html'
84
+ },
85
+ '/src/index.less': {
86
+ fpath: '/src/index.less',
87
+ code: "\n@import \"~@alifd/next/dist/next.css\";\n@import '~@alifd/pro-layout/dist/AlifdProLayout.css';\n"
88
+ }
89
+ });
90
+ fixedCode.type = 'riddle';
91
+ return fixedCode;
92
+ }
93
+ function pickKeys(data, keys) {
94
+ return keys.reduce(function (acc, key) {
95
+ if (data[key]) {
96
+ var _extends3;
97
+ return _extends({}, acc, (_extends3 = {}, _extends3[key] = data[key], _extends3));
98
+ }
99
+ return acc;
100
+ }, {});
101
+ }
@@ -0,0 +1 @@
1
+ export * from './CodeGenPreview';
@@ -0,0 +1 @@
1
+ export * from './CodeGenPreview';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 判断是否在内网环境中中
3
+ */
4
+ export declare function useIsInIntranet(): any;
@@ -0,0 +1,66 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import React, { useEffect } from 'react';
4
+
5
+ // 预先检测下是否在内网环境中
6
+ var isInIntranetPromise = detectIsInIntranet();
7
+
8
+ /**
9
+ * 判断是否在内网环境中中
10
+ */
11
+ export function useIsInIntranet() {
12
+ var _React$useState = React.useState({
13
+ isInIntranet: false
14
+ }),
15
+ state = _React$useState[0],
16
+ setState = _React$useState[1];
17
+ useEffect(function () {
18
+ // 如果预加载失败了,可以尝试重试下
19
+ isInIntranetPromise["catch"](function () {
20
+ isInIntranetPromise = detectIsInIntranet();
21
+ return isInIntranetPromise;
22
+ }).then(function (isInIntranet) {
23
+ setState({
24
+ isInIntranet: isInIntranet
25
+ });
26
+ });
27
+ }, []);
28
+ return state.isInIntranet;
29
+ }
30
+
31
+ /**
32
+ * 判断是否在内网环境中中
33
+ */
34
+ function detectIsInIntranet() {
35
+ return _detectIsInIntranet.apply(this, arguments);
36
+ }
37
+ function _detectIsInIntranet() {
38
+ _detectIsInIntranet = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
39
+ var res;
40
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ _context.prev = 0;
44
+ _context.next = 3;
45
+ return fetch('https://dev.g.alicdn.com/ali-lowcode/ali-lowcode-materials/1.1.0/schema.json');
46
+ case 3:
47
+ res = _context.sent;
48
+ if (!res.ok) {
49
+ _context.next = 6;
50
+ break;
51
+ }
52
+ return _context.abrupt("return", true);
53
+ case 6:
54
+ return _context.abrupt("return", false);
55
+ case 9:
56
+ _context.prev = 9;
57
+ _context.t0 = _context["catch"](0);
58
+ return _context.abrupt("return", false);
59
+ case 12:
60
+ case "end":
61
+ return _context.stop();
62
+ }
63
+ }, _callee, null, [[0, 9]]);
64
+ }));
65
+ return _detectIsInIntranet.apply(this, arguments);
66
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import './CodeGenResult.scss';
3
+ import { Result } from '@alilc/lowcode-code-generator/standalone-loader';
4
+ import { ProjectSchema } from '@alilc/lowcode-types';
5
+ export declare function CodeGenResult({ result, schema }: {
6
+ result: Result | null | undefined;
7
+ schema: ProjectSchema | null;
8
+ originalSchema: ProjectSchema | null;
9
+ }): JSX.Element;