@dckj-npm/lowcode-plugin-code-generator 1.3.5 → 1.3.7

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.
@@ -7,7 +7,7 @@ import * as CodeGenerator from '@dckj-npm/lowcode-code-generator/standalone-load
7
7
  import { Button, Drawer, Loading, Message } from '@alifd/next';
8
8
  import coerce from 'semver/functions/coerce';
9
9
  import { CodeGenResult } from '../CodeGenResult';
10
- import { getAllSchemaByResourceList, getProjectId, getResourceListFromLocalStorage } from "../../utils/utils";
10
+ import { getAllSchemaByResourceList, getProjectId, getResourceListFromLocalStorage } from '../../utils/utils';
11
11
  export function CodeGenActionBtn(_ref) {
12
12
  var ctx = _ref.ctx;
13
13
  var _useState = useState({
@@ -23,85 +23,108 @@ export function CodeGenActionBtn(_ref) {
23
23
  setState = _useState[1];
24
24
  var handleClick = /*#__PURE__*/function () {
25
25
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
26
- var name, resourceList, allSchema, resultSchema, result, _t;
26
+ var _sanitizedSchemas$, name, resourceList, allSchema, invalidIndex, resource, sanitizedSchemas, primarySchema, originalPrimarySchema, result, error, _t;
27
27
  return _regeneratorRuntime.wrap(function (_context) {
28
28
  while (1) switch (_context.prev = _context.next) {
29
29
  case 0:
30
30
  _context.prev = 0;
31
- // 打开基于 Gravity 的编辑器/出码预览器
32
31
  setState(function (prev) {
33
32
  return _extends({}, prev, {
34
33
  loading: true,
35
34
  visible: true,
36
- hasError: false
35
+ hasError: false,
36
+ error: null
37
37
  });
38
38
  });
39
-
40
- // 获取 schema,并修正
41
- // const originalSchema = await project.exportSchema();
42
39
  name = getProjectId();
43
- _context.next = 1;
44
- return getResourceListFromLocalStorage(name);
40
+ if (name) {
41
+ _context.next = 1;
42
+ break;
43
+ }
44
+ throw new Error('无法获取 projectId,请确认已在低代码编辑器内打开该插件。');
45
45
  case 1:
46
- resourceList = _context.sent;
47
46
  _context.next = 2;
48
- return getAllSchemaByResourceList(name, resourceList);
47
+ return getResourceListFromLocalStorage(name);
49
48
  case 2:
49
+ resourceList = _context.sent;
50
+ if (resourceList.length) {
51
+ _context.next = 3;
52
+ break;
53
+ }
54
+ throw new Error('未找到页面配置,请先保存页面后再尝试出码。');
55
+ case 3:
56
+ _context.next = 4;
57
+ return getAllSchemaByResourceList(name, resourceList);
58
+ case 4:
50
59
  allSchema = _context.sent;
51
- _context.next = 3;
60
+ if (allSchema.length) {
61
+ _context.next = 5;
62
+ break;
63
+ }
64
+ throw new Error('未找到页面 schema,请先保存页面后再尝试出码。');
65
+ case 5:
66
+ if (!(allSchema.length !== resourceList.length)) {
67
+ _context.next = 6;
68
+ break;
69
+ }
70
+ throw new Error('页面 schema 数量异常,请刷新页面后重试。');
71
+ case 6:
72
+ invalidIndex = allSchema.findIndex(function (schema) {
73
+ return !schema || typeof schema !== 'object';
74
+ });
75
+ if (!(invalidIndex !== -1)) {
76
+ _context.next = 7;
77
+ break;
78
+ }
79
+ resource = resourceList[invalidIndex];
80
+ throw new Error("\u9875\u9762 \"" + ((resource === null || resource === void 0 ? void 0 : resource.title) || (resource === null || resource === void 0 ? void 0 : resource.id)) + "\" \u7F3A\u5C11\u6709\u6548 schema\uFF0C\u8BF7\u5148\u5728\u8BBE\u8BA1\u5668\u4E2D\u4FDD\u5B58\u8BE5\u9875\u9762\u3002");
81
+ case 7:
82
+ _context.next = 8;
52
83
  return Promise.all(allSchema.map(function (item) {
53
84
  return fixSchema(item);
54
85
  }));
55
- case 3:
56
- resultSchema = _context.sent;
57
- // console.log('ctx ', ctx)
58
- // console.log('isActive ', ctx.workspace.isActive)
59
- // console.log('window.exportSchema ', ctx.workspace.window.exportSchema())
60
- // console.log('skeleton ', ctx.workspace.skeleton)
61
- // console.log('windows ', ctx.workspace.windows)
62
- // const originalSchema2 = await ctx.project.exportSchema();
63
- // const schema = await fixSchema(originalSchema);
64
- // console.log('got schema:222222 ', schema);
65
- // console.log('got schema:33333333 ', originalSchema2);
66
-
67
- setState(function (prev) {
68
- return _extends({}, prev);
69
- });
70
-
71
- // 出码...
72
- _context.next = 4;
86
+ case 8:
87
+ sanitizedSchemas = _context.sent;
88
+ primarySchema = (_sanitizedSchemas$ = sanitizedSchemas[0]) !== null && _sanitizedSchemas$ !== void 0 ? _sanitizedSchemas$ : null;
89
+ originalPrimarySchema = allSchema[0] ? deepClone(allSchema[0]) : null; // 出码...
90
+ _context.next = 9;
73
91
  return CodeGenerator.generateCode({
74
92
  solution: 'vuejs3',
75
- schema: resultSchema,
93
+ schema: sanitizedSchemas,
76
94
  flattenResult: true,
77
95
  resourceList: resourceList
78
96
  });
79
- case 4:
97
+ case 9:
80
98
  result = _context.sent;
81
99
  console.log('generated: ', result);
82
100
  setState(function (prev) {
83
101
  return _extends({}, prev, {
84
102
  loading: false,
85
- result: result
103
+ result: result,
104
+ schema: primarySchema,
105
+ originalSchema: originalPrimarySchema
86
106
  });
87
107
  });
88
- _context.next = 6;
108
+ _context.next = 11;
89
109
  break;
90
- case 5:
91
- _context.prev = 5;
110
+ case 10:
111
+ _context.prev = 10;
92
112
  _t = _context["catch"](0);
93
113
  console.error('failed to run code generator: ', _t);
114
+ error = _t instanceof Error ? _t : new Error("" + ((_t === null || _t === void 0 ? void 0 : _t.message) || _t));
94
115
  setState(function (prev) {
95
116
  return _extends({}, prev, {
117
+ loading: false,
96
118
  hasError: true,
97
- error: _t instanceof Error ? _t : new Error("" + ((_t === null || _t === void 0 ? void 0 : _t.message) || _t))
119
+ error: error
98
120
  });
99
121
  });
100
- case 6:
122
+ Message.error(error.message);
123
+ case 11:
101
124
  case "end":
102
125
  return _context.stop();
103
126
  }
104
- }, _callee, null, [[0, 5]]);
127
+ }, _callee, null, [[0, 10]]);
105
128
  }));
106
129
  return function handleClick() {
107
130
  return _ref2.apply(this, arguments);
@@ -149,14 +172,18 @@ export function fixSchema(_x) {
149
172
  }
150
173
  function _fixSchema() {
151
174
  _fixSchema = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(schema) {
175
+ var componentsMap;
152
176
  return _regeneratorRuntime.wrap(function (_context2) {
153
177
  while (1) switch (_context2.prev = _context2.next) {
154
178
  case 0:
179
+ componentsMap = Array.isArray(schema.componentsMap) ? schema.componentsMap : [];
180
+ if (!Array.isArray(schema.componentsMap)) {
181
+ console.warn('schema.componentsMap 缺失,已回退为空数组。');
182
+ }
155
183
  return _context2.abrupt("return", deepClone(_extends({}, schema, {
156
- componentsMap: schema.componentsMap.filter(function (c) {
157
- return c["package"];
158
- }) // 去掉没有 package 的组件
159
- .map(function (c) {
184
+ componentsMap: componentsMap.filter(function (c) {
185
+ return c && typeof c === 'object' && c["package"];
186
+ }).map(function (c) {
160
187
  // 修正版本号(对于没有有效版本号的组件,默认使用 latest)
161
188
  if (!isValidVersion(c.version)) {
162
189
  console.warn('[WARN] got invalid version "%o" for component "%s", use "latest" as fallback', c.version, c);
package/es/utils/utils.js CHANGED
@@ -1,11 +1,22 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ var DEFAULT_RESOURCE_LIST = [{
4
+ title: '首页',
5
+ slug: 'index',
6
+ id: 'index',
7
+ firstPage: 'true'
8
+ }];
9
+ var toFirstPageFlag = function toFirstPageFlag(value) {
10
+ return value === 'true' ? 'true' : 'false';
11
+ };
12
+
3
13
  /**
4
14
  * 从缓存获取ResourceList
5
15
  * @param scenarioName
6
16
  */
7
17
  export var getResourceListFromLocalStorage = /*#__PURE__*/function () {
8
18
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(scenarioName) {
19
+ var raw, parsed, normalized, _t;
9
20
  return _regeneratorRuntime.wrap(function (_context) {
10
21
  while (1) switch (_context.prev = _context.next) {
11
22
  case 0:
@@ -14,14 +25,47 @@ export var getResourceListFromLocalStorage = /*#__PURE__*/function () {
14
25
  break;
15
26
  }
16
27
  console.error('scenarioName is required!');
17
- return _context.abrupt("return");
28
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
18
29
  case 1:
19
- return _context.abrupt("return", JSON.parse(window.localStorage.getItem(getResourceName(scenarioName)) || '[{"title":"首页","slug":"index","id": "index"}]'));
30
+ raw = window.localStorage.getItem(getResourceName(scenarioName));
31
+ if (raw) {
32
+ _context.next = 2;
33
+ break;
34
+ }
35
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
20
36
  case 2:
37
+ _context.prev = 2;
38
+ parsed = JSON.parse(raw);
39
+ if (Array.isArray(parsed)) {
40
+ _context.next = 3;
41
+ break;
42
+ }
43
+ console.error('resourceList should be an array, got: %o', parsed);
44
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
45
+ case 3:
46
+ normalized = parsed.filter(function (item) {
47
+ return !!item && typeof item === 'object';
48
+ }).map(function (item) {
49
+ return {
50
+ title: typeof item.title === 'string' ? item.title : '',
51
+ slug: typeof item.slug === 'string' ? item.slug : '',
52
+ id: typeof item.id === 'string' ? item.id : '',
53
+ firstPage: toFirstPageFlag(item.firstPage)
54
+ };
55
+ }).filter(function (item) {
56
+ return item.id;
57
+ });
58
+ return _context.abrupt("return", normalized.length ? normalized : DEFAULT_RESOURCE_LIST);
59
+ case 4:
60
+ _context.prev = 4;
61
+ _t = _context["catch"](2);
62
+ console.error('failed to parse resourceList from localStorage', _t);
63
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
64
+ case 5:
21
65
  case "end":
22
66
  return _context.stop();
23
67
  }
24
- }, _callee);
68
+ }, _callee, null, [[2, 4]]);
25
69
  }));
26
70
  return function getResourceListFromLocalStorage(_x) {
27
71
  return _ref.apply(this, arguments);
@@ -34,20 +78,50 @@ export var getResourceListFromLocalStorage = /*#__PURE__*/function () {
34
78
  * @param ResourceList
35
79
  */
36
80
  export var getAllSchemaByResourceList = /*#__PURE__*/function () {
37
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(scenarioName, ResourceList) {
81
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(scenarioName, resourceList) {
38
82
  return _regeneratorRuntime.wrap(function (_context2) {
39
83
  while (1) switch (_context2.prev = _context2.next) {
40
84
  case 0:
41
- if (ResourceList) {
85
+ if (!(!Array.isArray(resourceList) || !resourceList.length)) {
42
86
  _context2.next = 1;
43
87
  break;
44
88
  }
45
- console.error('ResourceList is required!');
46
- return _context2.abrupt("return");
89
+ console.error('resourceList is required and should not be empty.');
90
+ return _context2.abrupt("return", []);
47
91
  case 1:
48
- return _context2.abrupt("return", ResourceList.map(function (item) {
49
- var localSchema = window.localStorage.getItem(getLSName(scenarioName, item.id)) || '{}';
50
- return JSON.parse(localSchema);
92
+ return _context2.abrupt("return", resourceList.map(function (item) {
93
+ var storageKey = getLSName(scenarioName, item.id);
94
+ var localSchema = window.localStorage.getItem(storageKey);
95
+ if (!localSchema) {
96
+ console.error('no schema found for resource %s', storageKey);
97
+ return {
98
+ version: '1.0.0',
99
+ componentsTree: [],
100
+ componentsMap: []
101
+ };
102
+ }
103
+ try {
104
+ var parsed = JSON.parse(localSchema);
105
+ if (!parsed || typeof parsed !== 'object') {
106
+ console.error('invalid schema object for resource %s: %o', storageKey, parsed);
107
+ return {
108
+ version: '1.0.0',
109
+ componentsTree: [],
110
+ componentsMap: []
111
+ };
112
+ }
113
+ if (!Array.isArray(parsed.componentsMap)) {
114
+ parsed.componentsMap = [];
115
+ }
116
+ return parsed;
117
+ } catch (error) {
118
+ console.error('failed to parse schema for resource %s', storageKey, error);
119
+ return {
120
+ version: '1.0.0',
121
+ componentsTree: [],
122
+ componentsMap: []
123
+ };
124
+ }
51
125
  }));
52
126
  case 2:
53
127
  case "end":
@@ -30,85 +30,108 @@ function CodeGenActionBtn(_ref) {
30
30
  setState = _useState[1];
31
31
  var handleClick = /*#__PURE__*/function () {
32
32
  var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
33
- var name, resourceList, allSchema, resultSchema, result, _t;
33
+ var _sanitizedSchemas$, name, resourceList, allSchema, invalidIndex, resource, sanitizedSchemas, primarySchema, originalPrimarySchema, result, error, _t;
34
34
  return _regenerator["default"].wrap(function (_context) {
35
35
  while (1) switch (_context.prev = _context.next) {
36
36
  case 0:
37
37
  _context.prev = 0;
38
- // 打开基于 Gravity 的编辑器/出码预览器
39
38
  setState(function (prev) {
40
39
  return (0, _extends2["default"])({}, prev, {
41
40
  loading: true,
42
41
  visible: true,
43
- hasError: false
42
+ hasError: false,
43
+ error: null
44
44
  });
45
45
  });
46
-
47
- // 获取 schema,并修正
48
- // const originalSchema = await project.exportSchema();
49
46
  name = (0, _utils.getProjectId)();
50
- _context.next = 1;
51
- return (0, _utils.getResourceListFromLocalStorage)(name);
47
+ if (name) {
48
+ _context.next = 1;
49
+ break;
50
+ }
51
+ throw new Error('无法获取 projectId,请确认已在低代码编辑器内打开该插件。');
52
52
  case 1:
53
- resourceList = _context.sent;
54
53
  _context.next = 2;
55
- return (0, _utils.getAllSchemaByResourceList)(name, resourceList);
54
+ return (0, _utils.getResourceListFromLocalStorage)(name);
56
55
  case 2:
56
+ resourceList = _context.sent;
57
+ if (resourceList.length) {
58
+ _context.next = 3;
59
+ break;
60
+ }
61
+ throw new Error('未找到页面配置,请先保存页面后再尝试出码。');
62
+ case 3:
63
+ _context.next = 4;
64
+ return (0, _utils.getAllSchemaByResourceList)(name, resourceList);
65
+ case 4:
57
66
  allSchema = _context.sent;
58
- _context.next = 3;
67
+ if (allSchema.length) {
68
+ _context.next = 5;
69
+ break;
70
+ }
71
+ throw new Error('未找到页面 schema,请先保存页面后再尝试出码。');
72
+ case 5:
73
+ if (!(allSchema.length !== resourceList.length)) {
74
+ _context.next = 6;
75
+ break;
76
+ }
77
+ throw new Error('页面 schema 数量异常,请刷新页面后重试。');
78
+ case 6:
79
+ invalidIndex = allSchema.findIndex(function (schema) {
80
+ return !schema || typeof schema !== 'object';
81
+ });
82
+ if (!(invalidIndex !== -1)) {
83
+ _context.next = 7;
84
+ break;
85
+ }
86
+ resource = resourceList[invalidIndex];
87
+ throw new Error("\u9875\u9762 \"" + ((resource === null || resource === void 0 ? void 0 : resource.title) || (resource === null || resource === void 0 ? void 0 : resource.id)) + "\" \u7F3A\u5C11\u6709\u6548 schema\uFF0C\u8BF7\u5148\u5728\u8BBE\u8BA1\u5668\u4E2D\u4FDD\u5B58\u8BE5\u9875\u9762\u3002");
88
+ case 7:
89
+ _context.next = 8;
59
90
  return Promise.all(allSchema.map(function (item) {
60
91
  return fixSchema(item);
61
92
  }));
62
- case 3:
63
- resultSchema = _context.sent;
64
- // console.log('ctx ', ctx)
65
- // console.log('isActive ', ctx.workspace.isActive)
66
- // console.log('window.exportSchema ', ctx.workspace.window.exportSchema())
67
- // console.log('skeleton ', ctx.workspace.skeleton)
68
- // console.log('windows ', ctx.workspace.windows)
69
- // const originalSchema2 = await ctx.project.exportSchema();
70
- // const schema = await fixSchema(originalSchema);
71
- // console.log('got schema:222222 ', schema);
72
- // console.log('got schema:33333333 ', originalSchema2);
73
-
74
- setState(function (prev) {
75
- return (0, _extends2["default"])({}, prev);
76
- });
77
-
78
- // 出码...
79
- _context.next = 4;
93
+ case 8:
94
+ sanitizedSchemas = _context.sent;
95
+ primarySchema = (_sanitizedSchemas$ = sanitizedSchemas[0]) !== null && _sanitizedSchemas$ !== void 0 ? _sanitizedSchemas$ : null;
96
+ originalPrimarySchema = allSchema[0] ? deepClone(allSchema[0]) : null; // 出码...
97
+ _context.next = 9;
80
98
  return CodeGenerator.generateCode({
81
99
  solution: 'vuejs3',
82
- schema: resultSchema,
100
+ schema: sanitizedSchemas,
83
101
  flattenResult: true,
84
102
  resourceList: resourceList
85
103
  });
86
- case 4:
104
+ case 9:
87
105
  result = _context.sent;
88
106
  console.log('generated: ', result);
89
107
  setState(function (prev) {
90
108
  return (0, _extends2["default"])({}, prev, {
91
109
  loading: false,
92
- result: result
110
+ result: result,
111
+ schema: primarySchema,
112
+ originalSchema: originalPrimarySchema
93
113
  });
94
114
  });
95
- _context.next = 6;
115
+ _context.next = 11;
96
116
  break;
97
- case 5:
98
- _context.prev = 5;
117
+ case 10:
118
+ _context.prev = 10;
99
119
  _t = _context["catch"](0);
100
120
  console.error('failed to run code generator: ', _t);
121
+ error = _t instanceof Error ? _t : new Error("" + ((_t === null || _t === void 0 ? void 0 : _t.message) || _t));
101
122
  setState(function (prev) {
102
123
  return (0, _extends2["default"])({}, prev, {
124
+ loading: false,
103
125
  hasError: true,
104
- error: _t instanceof Error ? _t : new Error("" + ((_t === null || _t === void 0 ? void 0 : _t.message) || _t))
126
+ error: error
105
127
  });
106
128
  });
107
- case 6:
129
+ _next.Message.error(error.message);
130
+ case 11:
108
131
  case "end":
109
132
  return _context.stop();
110
133
  }
111
- }, _callee, null, [[0, 5]]);
134
+ }, _callee, null, [[0, 10]]);
112
135
  }));
113
136
  return function handleClick() {
114
137
  return _ref2.apply(this, arguments);
@@ -156,14 +179,18 @@ function fixSchema(_x) {
156
179
  }
157
180
  function _fixSchema() {
158
181
  _fixSchema = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(schema) {
182
+ var componentsMap;
159
183
  return _regenerator["default"].wrap(function (_context2) {
160
184
  while (1) switch (_context2.prev = _context2.next) {
161
185
  case 0:
186
+ componentsMap = Array.isArray(schema.componentsMap) ? schema.componentsMap : [];
187
+ if (!Array.isArray(schema.componentsMap)) {
188
+ console.warn('schema.componentsMap 缺失,已回退为空数组。');
189
+ }
162
190
  return _context2.abrupt("return", deepClone((0, _extends2["default"])({}, schema, {
163
- componentsMap: schema.componentsMap.filter(function (c) {
164
- return c["package"];
165
- }) // 去掉没有 package 的组件
166
- .map(function (c) {
191
+ componentsMap: componentsMap.filter(function (c) {
192
+ return c && typeof c === 'object' && c["package"];
193
+ }).map(function (c) {
167
194
  // 修正版本号(对于没有有效版本号的组件,默认使用 latest)
168
195
  if (!isValidVersion(c.version)) {
169
196
  console.warn('[WARN] got invalid version "%o" for component "%s", use "latest" as fallback', c.version, c);
@@ -8,12 +8,23 @@ exports.getResourceName = exports.getResourceListFromLocalStorage = void 0;
8
8
  exports.getValueFromQueryByName = getValueFromQueryByName;
9
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var DEFAULT_RESOURCE_LIST = [{
12
+ title: '首页',
13
+ slug: 'index',
14
+ id: 'index',
15
+ firstPage: 'true'
16
+ }];
17
+ var toFirstPageFlag = function toFirstPageFlag(value) {
18
+ return value === 'true' ? 'true' : 'false';
19
+ };
20
+
11
21
  /**
12
22
  * 从缓存获取ResourceList
13
23
  * @param scenarioName
14
24
  */
15
25
  var getResourceListFromLocalStorage = exports.getResourceListFromLocalStorage = /*#__PURE__*/function () {
16
26
  var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(scenarioName) {
27
+ var raw, parsed, normalized, _t;
17
28
  return _regenerator["default"].wrap(function (_context) {
18
29
  while (1) switch (_context.prev = _context.next) {
19
30
  case 0:
@@ -22,14 +33,47 @@ var getResourceListFromLocalStorage = exports.getResourceListFromLocalStorage =
22
33
  break;
23
34
  }
24
35
  console.error('scenarioName is required!');
25
- return _context.abrupt("return");
36
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
26
37
  case 1:
27
- return _context.abrupt("return", JSON.parse(window.localStorage.getItem(getResourceName(scenarioName)) || '[{"title":"首页","slug":"index","id": "index"}]'));
38
+ raw = window.localStorage.getItem(getResourceName(scenarioName));
39
+ if (raw) {
40
+ _context.next = 2;
41
+ break;
42
+ }
43
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
28
44
  case 2:
45
+ _context.prev = 2;
46
+ parsed = JSON.parse(raw);
47
+ if (Array.isArray(parsed)) {
48
+ _context.next = 3;
49
+ break;
50
+ }
51
+ console.error('resourceList should be an array, got: %o', parsed);
52
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
53
+ case 3:
54
+ normalized = parsed.filter(function (item) {
55
+ return !!item && typeof item === 'object';
56
+ }).map(function (item) {
57
+ return {
58
+ title: typeof item.title === 'string' ? item.title : '',
59
+ slug: typeof item.slug === 'string' ? item.slug : '',
60
+ id: typeof item.id === 'string' ? item.id : '',
61
+ firstPage: toFirstPageFlag(item.firstPage)
62
+ };
63
+ }).filter(function (item) {
64
+ return item.id;
65
+ });
66
+ return _context.abrupt("return", normalized.length ? normalized : DEFAULT_RESOURCE_LIST);
67
+ case 4:
68
+ _context.prev = 4;
69
+ _t = _context["catch"](2);
70
+ console.error('failed to parse resourceList from localStorage', _t);
71
+ return _context.abrupt("return", DEFAULT_RESOURCE_LIST);
72
+ case 5:
29
73
  case "end":
30
74
  return _context.stop();
31
75
  }
32
- }, _callee);
76
+ }, _callee, null, [[2, 4]]);
33
77
  }));
34
78
  return function getResourceListFromLocalStorage(_x) {
35
79
  return _ref.apply(this, arguments);
@@ -42,20 +86,50 @@ var getResourceListFromLocalStorage = exports.getResourceListFromLocalStorage =
42
86
  * @param ResourceList
43
87
  */
44
88
  var getAllSchemaByResourceList = exports.getAllSchemaByResourceList = /*#__PURE__*/function () {
45
- var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(scenarioName, ResourceList) {
89
+ var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(scenarioName, resourceList) {
46
90
  return _regenerator["default"].wrap(function (_context2) {
47
91
  while (1) switch (_context2.prev = _context2.next) {
48
92
  case 0:
49
- if (ResourceList) {
93
+ if (!(!Array.isArray(resourceList) || !resourceList.length)) {
50
94
  _context2.next = 1;
51
95
  break;
52
96
  }
53
- console.error('ResourceList is required!');
54
- return _context2.abrupt("return");
97
+ console.error('resourceList is required and should not be empty.');
98
+ return _context2.abrupt("return", []);
55
99
  case 1:
56
- return _context2.abrupt("return", ResourceList.map(function (item) {
57
- var localSchema = window.localStorage.getItem(getLSName(scenarioName, item.id)) || '{}';
58
- return JSON.parse(localSchema);
100
+ return _context2.abrupt("return", resourceList.map(function (item) {
101
+ var storageKey = getLSName(scenarioName, item.id);
102
+ var localSchema = window.localStorage.getItem(storageKey);
103
+ if (!localSchema) {
104
+ console.error('no schema found for resource %s', storageKey);
105
+ return {
106
+ version: '1.0.0',
107
+ componentsTree: [],
108
+ componentsMap: []
109
+ };
110
+ }
111
+ try {
112
+ var parsed = JSON.parse(localSchema);
113
+ if (!parsed || typeof parsed !== 'object') {
114
+ console.error('invalid schema object for resource %s: %o', storageKey, parsed);
115
+ return {
116
+ version: '1.0.0',
117
+ componentsTree: [],
118
+ componentsMap: []
119
+ };
120
+ }
121
+ if (!Array.isArray(parsed.componentsMap)) {
122
+ parsed.componentsMap = [];
123
+ }
124
+ return parsed;
125
+ } catch (error) {
126
+ console.error('failed to parse schema for resource %s', storageKey, error);
127
+ return {
128
+ version: '1.0.0',
129
+ componentsTree: [],
130
+ componentsMap: []
131
+ };
132
+ }
59
133
  }));
60
134
  case 2:
61
135
  case "end":
package/package.json CHANGED
@@ -1,94 +1,95 @@
1
- {
2
- "name": "@dckj-npm/lowcode-plugin-code-generator",
3
- "version": "1.3.5",
4
- "description": "集团低代码引擎 - 浏览器出码插件",
5
- "main": "lib/index.js",
6
- "module": "es/index.js",
7
- "types": "es/index.d.ts",
8
- "files": [
9
- "lib",
10
- "es",
11
- "README.md"
12
- ],
13
- "scripts": {
14
- "start": "npm run dev",
15
- "dev": "cross-env NODE_ENV=development build-scripts start --config build.dev.json --host localhost",
16
- "build": "build-scripts build --skip-demo",
17
- "clean": "rimraf es lib dist",
18
- "prettier": "prettier --write 'src/**/*.{js,jsx,tsx,ts,less,md,json}'",
19
- "prepablishOnly": "npm run clean && npm run build"
20
- },
21
- "repository": {
22
- "type": "git",
23
- "url": "git@gitlab.alibaba-inc.com:ali-lowcode/code-generator-demo.git"
24
- },
25
- "keywords": [
26
- "出码"
27
- ],
28
- "authors": [
29
- {
30
- "name": "zgm"
31
- }
32
- ],
33
- "license": "MIT",
34
- "dependencies": {
35
- "@alilc/lowcode-code-generator": "^1.0.4",
36
- "@alilc/lowcode-plugin-base-monaco-editor": "^1.0.0",
37
- "@alilc/lowcode-types": "^1.0.0",
38
- "@dckj-npm/lowcode-code-generator": "^1.2.22",
39
- "@types/file-saver": "^2.0.4",
40
- "@types/js-base64": "^3.3.1",
41
- "@types/string-natural-compare": "^3.0.2",
42
- "codesandbox": "^2.2.3",
43
- "file-saver": "^2.0.5",
44
- "js-base64": "^3.6.1",
45
- "jszip": "^3.7.1",
46
- "semver": "^7.3.5",
47
- "string-natural-compare": "^3.0.1",
48
- "tslib": "^2.3.1"
49
- },
50
- "peerDependencies": {
51
- "@alilc/lowcode-engine": "^1.0.0",
52
- "react": "16.x || 17.x"
53
- },
54
- "devDependencies": {
55
- "@alib/build-scripts": "^0.1.18",
56
- "@alifd/theme-lowcode-light": "^0.2.1",
57
- "@alilc/lowcode-engine": "^1.0.0",
58
- "@alilc/lowcode-engine-ext": "^1.0.0",
59
- "@alilc/lowcode-plugin-code-editor": "^1.0.1",
60
- "@alilc/lowcode-plugin-components-pane": "^1.0.2",
61
- "@alilc/lowcode-plugin-datasource-pane": "^1.0.3",
62
- "@alilc/lowcode-plugin-inject": "^1.0.0",
63
- "@alilc/lowcode-plugin-manual": "^1.0.3",
64
- "@alilc/lowcode-plugin-schema": "^1.0.0",
65
- "@alilc/lowcode-plugin-simulator-select": "^1.0.0",
66
- "@alilc/lowcode-plugin-undo-redo": "^1.0.0",
67
- "@alilc/lowcode-plugin-zh-en": "^1.0.0",
68
- "@alilc/lowcode-react-renderer": "^1.0.0",
69
- "@alilc/lowcode-setter-behavior": "^1.0.0",
70
- "@alilc/lowcode-setter-title": "^1.0.2",
71
- "@alilc/lowcode-types": "^1.0.0",
72
- "@types/classnames": "^2.2.7",
73
- "@types/events": "^3.0.0",
74
- "@types/node": "^13.7.1",
75
- "@types/react": "^16.8.3",
76
- "@types/react-dom": "^16.8.2",
77
- "@types/streamsaver": "^2.0.0",
78
- "build-plugin-component": "^0.2.10",
79
- "build-plugin-fusion": "^0.1.0",
80
- "build-plugin-moment-locales": "^0.1.0",
81
- "build-plugin-react-app": "^1.1.2",
82
- "cross-env": "^7.0.3",
83
- "prettier": "^2.5.1",
84
- "react": "^16.8.3",
85
- "react-dom": "^16.8.3",
86
- "rimraf": "^3.0.2",
87
- "tsconfig-paths-webpack-plugin": "^3.2.0",
88
- "typescript": "^4.5.4"
89
- },
90
- "publishConfig": {
91
- "access": "public",
92
- "registry": "https://registry.npmjs.org/"
93
- }
94
- }
1
+ {
2
+ "name": "@dckj-npm/lowcode-plugin-code-generator",
3
+ "version": "1.3.7",
4
+ "description": "集团低代码引擎 - 浏览器出码插件",
5
+ "main": "lib/index.js",
6
+ "module": "es/index.js",
7
+ "types": "es/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "es",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "start": "npm run dev",
15
+ "dev": "cross-env NODE_ENV=development build-scripts start --config build.dev.json --host localhost",
16
+ "build": "build-scripts build --skip-demo",
17
+ "clean": "rimraf es lib dist",
18
+ "prettier": "prettier --write 'src/**/*.{js,jsx,tsx,ts,less,md,json}'",
19
+ "prepablishOnly": "npm run clean && npm run build"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git@gitlab.alibaba-inc.com:ali-lowcode/code-generator-demo.git"
24
+ },
25
+ "keywords": [
26
+ "出码"
27
+ ],
28
+ "authors": [
29
+ {
30
+ "name": "zgm"
31
+ }
32
+ ],
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "@alilc/lowcode-code-generator": "^1.0.4",
36
+ "@alilc/lowcode-plugin-base-monaco-editor": "^1.0.0",
37
+ "@alilc/lowcode-types": "^1.0.0",
38
+ "@dckj-npm/lowcode-code-generator": "^1.2.24",
39
+ "@types/file-saver": "^2.0.4",
40
+ "@types/js-base64": "^3.3.1",
41
+ "@types/string-natural-compare": "^3.0.2",
42
+ "codesandbox": "^2.2.3",
43
+ "file-saver": "^2.0.5",
44
+ "js-base64": "^3.6.1",
45
+ "jszip": "^3.7.1",
46
+ "regenerator-runtime": "^0.13.11",
47
+ "semver": "^7.3.5",
48
+ "string-natural-compare": "^3.0.1",
49
+ "tslib": "^2.3.1"
50
+ },
51
+ "peerDependencies": {
52
+ "@alilc/lowcode-engine": "^1.0.0",
53
+ "react": "16.x || 17.x"
54
+ },
55
+ "devDependencies": {
56
+ "@alib/build-scripts": "^0.1.18",
57
+ "@alifd/theme-lowcode-light": "^0.2.1",
58
+ "@alilc/lowcode-engine": "^1.0.0",
59
+ "@alilc/lowcode-engine-ext": "^1.0.0",
60
+ "@alilc/lowcode-plugin-code-editor": "^1.0.1",
61
+ "@alilc/lowcode-plugin-components-pane": "^1.0.2",
62
+ "@alilc/lowcode-plugin-datasource-pane": "^1.0.3",
63
+ "@alilc/lowcode-plugin-inject": "^1.0.0",
64
+ "@alilc/lowcode-plugin-manual": "^1.0.3",
65
+ "@alilc/lowcode-plugin-schema": "^1.0.0",
66
+ "@alilc/lowcode-plugin-simulator-select": "^1.0.0",
67
+ "@alilc/lowcode-plugin-undo-redo": "^1.0.0",
68
+ "@alilc/lowcode-plugin-zh-en": "^1.0.0",
69
+ "@alilc/lowcode-react-renderer": "^1.0.0",
70
+ "@alilc/lowcode-setter-behavior": "^1.0.0",
71
+ "@alilc/lowcode-setter-title": "^1.0.2",
72
+ "@alilc/lowcode-types": "^1.0.0",
73
+ "@types/classnames": "^2.2.7",
74
+ "@types/events": "^3.0.0",
75
+ "@types/node": "^13.7.1",
76
+ "@types/react": "^16.8.3",
77
+ "@types/react-dom": "^16.8.2",
78
+ "@types/streamsaver": "^2.0.0",
79
+ "build-plugin-component": "^0.2.10",
80
+ "build-plugin-fusion": "^0.1.0",
81
+ "build-plugin-moment-locales": "^0.1.0",
82
+ "build-plugin-react-app": "^1.1.2",
83
+ "cross-env": "^7.0.3",
84
+ "prettier": "^2.5.1",
85
+ "react": "^16.8.3",
86
+ "react-dom": "^16.8.3",
87
+ "rimraf": "^3.0.2",
88
+ "tsconfig-paths-webpack-plugin": "^3.2.0",
89
+ "typescript": "^4.5.4"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public",
93
+ "registry": "https://registry.npmjs.org/"
94
+ }
95
+ }