@blocklet/meta 1.8.34 → 1.8.35
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/lib/channel.d.ts +27 -0
- package/lib/channel.js +32 -32
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +6 -3
- package/lib/did.d.ts +10 -0
- package/lib/did.js +18 -24
- package/lib/engine.d.ts +7 -0
- package/lib/engine.js +21 -25
- package/lib/entry.d.ts +3 -0
- package/lib/entry.js +51 -64
- package/lib/extension.d.ts +10 -0
- package/lib/extension.js +78 -77
- package/lib/file.d.ts +21 -0
- package/lib/file.js +44 -39
- package/lib/fix.d.ts +33 -0
- package/lib/fix.js +218 -208
- package/lib/get-component-process-id.d.ts +5 -0
- package/lib/get-component-process-id.js +13 -14
- package/lib/has-reserved-key.d.ts +3 -0
- package/lib/has-reserved-key.js +10 -9
- package/lib/index.d.ts +82 -0
- package/lib/index.js +51 -34
- package/lib/info.d.ts +13 -0
- package/lib/info.js +58 -60
- package/lib/name.d.ts +5 -0
- package/lib/name.js +14 -7
- package/lib/nft-templates.d.ts +86 -0
- package/lib/nft-templates.js +47 -42
- package/lib/parse-navigation.d.ts +3 -0
- package/lib/parse-navigation.js +167 -228
- package/lib/parse.d.ts +22 -0
- package/lib/parse.js +71 -82
- package/lib/payment/index.d.ts +254 -0
- package/lib/payment/index.js +13 -6
- package/lib/payment/v1.d.ts +185 -0
- package/lib/payment/v1.js +80 -81
- package/lib/payment/v2.d.ts +242 -0
- package/lib/payment/v2.js +453 -531
- package/lib/schema.d.ts +50 -0
- package/lib/schema.js +405 -402
- package/lib/service-configs/auth.json +61 -61
- package/lib/service.d.ts +26 -0
- package/lib/service.js +69 -85
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +18 -0
- package/lib/types/schema.d.ts +241 -0
- package/lib/types/schema.js +3 -0
- package/lib/util-meta.d.ts +42 -0
- package/lib/util-meta.js +138 -158
- package/lib/util.d.ts +185 -0
- package/lib/util.js +359 -414
- package/lib/validate.d.ts +10 -0
- package/lib/validate.js +28 -34
- package/lib/verify-multi-sig.d.ts +3 -0
- package/lib/verify-multi-sig.js +94 -101
- package/lib/wallet.d.ts +9 -0
- package/lib/wallet.js +17 -27
- package/package.json +40 -18
package/lib/parse-navigation.js
CHANGED
|
@@ -1,249 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
6
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
7
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
8
|
+
const normalize_path_prefix_1 = __importDefault(require("@abtnode/util/lib/normalize-path-prefix"));
|
|
9
|
+
const parseLinkString = (link, prefix = '') => link.startsWith('/') ? (0, normalize_path_prefix_1.default)(`${prefix}${link || '/'}`) : link;
|
|
9
10
|
const parseLink = (input, prefix) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return parseLinkString(input, prefix);
|
|
11
|
+
if (Object.prototype.toString.call(input) === '[object Object]') {
|
|
12
|
+
return Object.entries(input).reduce((o, [key, value]) => {
|
|
13
|
+
o[key] = parseLinkString(value, prefix);
|
|
14
|
+
return o;
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
return parseLinkString(input, prefix);
|
|
18
18
|
};
|
|
19
|
-
|
|
20
19
|
const getGroups = (navigation) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
item.section = sec === '__undefined__' ? [] : [sec];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
groups[sec].push(item);
|
|
20
|
+
const groups = {};
|
|
21
|
+
for (const nav of navigation) {
|
|
22
|
+
const sections = !nav.section || !nav.section.length ? ['__undefined__'] : nav.section;
|
|
23
|
+
for (const sec of sections) {
|
|
24
|
+
if (!groups[sec]) {
|
|
25
|
+
groups[sec] = [];
|
|
26
|
+
}
|
|
27
|
+
const item = Object.assign({}, nav);
|
|
28
|
+
if (nav.section) {
|
|
29
|
+
item.section = sec === '__undefined__' ? [] : [sec];
|
|
30
|
+
}
|
|
31
|
+
groups[sec].push(item);
|
|
32
|
+
}
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
return Object.values(groups);
|
|
34
|
+
return Object.values(groups);
|
|
41
35
|
};
|
|
42
|
-
|
|
43
36
|
const getChildName = (nav) => nav.component || nav.child;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @param {*} navigation src
|
|
47
|
-
* @param {*} blocklet
|
|
48
|
-
* @param {*} prefix prefix of link
|
|
49
|
-
* @param {*} _level 1: primary menu, >2: secondary menu
|
|
50
|
-
*/
|
|
51
37
|
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
item.items = list;
|
|
38
|
+
const result = [];
|
|
39
|
+
(navigation || []).forEach((nav) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
if (!getChildName(nav)) {
|
|
42
|
+
if (_level > 1 && ((_a = nav.items) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
43
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
44
|
+
result.push(...list);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const item = {
|
|
48
|
+
title: nav.title,
|
|
49
|
+
};
|
|
50
|
+
if (nav.section) {
|
|
51
|
+
item.section = nav.section;
|
|
52
|
+
}
|
|
53
|
+
if (nav.icon) {
|
|
54
|
+
item.icon = nav.icon;
|
|
55
|
+
}
|
|
56
|
+
if (nav.link) {
|
|
57
|
+
item.link = parseLink(nav.link, prefix);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
item.link = '';
|
|
61
|
+
}
|
|
62
|
+
if (nav.role) {
|
|
63
|
+
item.role = nav.role;
|
|
64
|
+
}
|
|
65
|
+
if ((_b = nav.items) === null || _b === void 0 ? void 0 : _b.length) {
|
|
66
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
67
|
+
if (list.length) {
|
|
68
|
+
item.items = list;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
result.push(item);
|
|
72
|
+
return;
|
|
88
73
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (nav.role) {
|
|
119
|
-
itemProto.role = nav.role;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// get groups by section
|
|
123
|
-
const groups = getGroups(get(child, 'meta.navigation', []));
|
|
124
|
-
|
|
125
|
-
if (!groups.length) {
|
|
126
|
-
// child does not declares menu
|
|
127
|
-
const item = cloneDeep(itemProto);
|
|
128
|
-
item.link = parseLink(child.mountPoint || '/', prefix);
|
|
129
|
-
result.push(item);
|
|
130
|
-
} else {
|
|
131
|
-
for (const childNavigation of groups) {
|
|
132
|
-
if (childNavigation.length === 1) {
|
|
133
|
-
// child declares one menu
|
|
134
|
-
const childNav = childNavigation[0];
|
|
135
|
-
|
|
136
|
-
const item = cloneDeep(itemProto);
|
|
137
|
-
|
|
138
|
-
item.title = nav.title || childNav.title || childTitle;
|
|
139
|
-
|
|
140
|
-
if (childNav.icon) {
|
|
141
|
-
item.icon = item.icon || childNav.icon;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (childNav.role) {
|
|
145
|
-
item.role = item.role || childNav.role;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (childNav.section) {
|
|
149
|
-
item.section = item.section || childNav.section;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
item.link = parseLink(childNavigation[0].link || '/', normalizePathPrefix(`${prefix}${child.mountPoint}`));
|
|
153
|
-
|
|
154
|
-
// doParseNavigation because child nav depth may be > 1
|
|
155
|
-
const list = doParseNavigation(
|
|
156
|
-
childNavigation,
|
|
157
|
-
child,
|
|
158
|
-
normalizePathPrefix(`${prefix}${child.mountPoint}`),
|
|
159
|
-
_level + 1
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
if (list.length > 1) {
|
|
163
|
-
// more than 1 child nav
|
|
164
|
-
delete item.link;
|
|
165
|
-
result.push({
|
|
166
|
-
...item,
|
|
167
|
-
items: list,
|
|
168
|
-
});
|
|
169
|
-
} else {
|
|
170
|
-
// only 1 child nav
|
|
171
|
-
item.link = list[0].link;
|
|
74
|
+
if (!blocklet) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// parse child
|
|
78
|
+
const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(getChildName(nav)));
|
|
79
|
+
if (!child) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const childTitle = child.meta.title || child.meta.name;
|
|
83
|
+
const itemProto = {
|
|
84
|
+
title: nav.title || childTitle,
|
|
85
|
+
};
|
|
86
|
+
if (nav.section) {
|
|
87
|
+
itemProto.section = nav.section;
|
|
88
|
+
}
|
|
89
|
+
if (nav.icon) {
|
|
90
|
+
itemProto.icon = nav.icon;
|
|
91
|
+
}
|
|
92
|
+
if (nav.role) {
|
|
93
|
+
itemProto.role = nav.role;
|
|
94
|
+
}
|
|
95
|
+
// get groups by section
|
|
96
|
+
const groups = getGroups((0, get_1.default)(child, 'meta.navigation', []));
|
|
97
|
+
if (!groups.length) {
|
|
98
|
+
// child does not declares menu
|
|
99
|
+
const item = (0, cloneDeep_1.default)(itemProto);
|
|
100
|
+
item.link = parseLink(child.mountPoint || '/', prefix);
|
|
172
101
|
result.push(item);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
for (const childNavigation of groups) {
|
|
105
|
+
if (childNavigation.length === 1) {
|
|
106
|
+
// child declares one menu
|
|
107
|
+
const childNav = childNavigation[0];
|
|
108
|
+
const item = (0, cloneDeep_1.default)(itemProto);
|
|
109
|
+
item.title = nav.title || childNav.title || childTitle;
|
|
110
|
+
if (childNav.icon) {
|
|
111
|
+
item.icon = item.icon || childNav.icon;
|
|
112
|
+
}
|
|
113
|
+
if (childNav.role) {
|
|
114
|
+
item.role = item.role || childNav.role;
|
|
115
|
+
}
|
|
116
|
+
if (childNav.section) {
|
|
117
|
+
item.section = item.section || childNav.section;
|
|
118
|
+
}
|
|
119
|
+
item.link = parseLink(childNavigation[0].link || '/', (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`));
|
|
120
|
+
// doParseNavigation because child nav depth may be > 1
|
|
121
|
+
const list = doParseNavigation(childNavigation, child, (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`), _level + 1);
|
|
122
|
+
if (list.length > 1) {
|
|
123
|
+
// more than 1 child nav
|
|
124
|
+
delete item.link;
|
|
125
|
+
result.push(Object.assign(Object.assign({}, item), { items: list }));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// only 1 child nav
|
|
129
|
+
item.link = list[0].link;
|
|
130
|
+
result.push(item);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// child declares multiple menus
|
|
135
|
+
const groupSection = childNavigation[0].section || [];
|
|
136
|
+
const list = doParseNavigation(childNavigation, child, (0, normalize_path_prefix_1.default)(`${prefix}${child.mountPoint}`), _level + 1);
|
|
137
|
+
if (_level === 1) {
|
|
138
|
+
// primary menu
|
|
139
|
+
const item = (0, cloneDeep_1.default)(itemProto);
|
|
140
|
+
if (groupSection.length) {
|
|
141
|
+
item.section = item.section || groupSection;
|
|
142
|
+
}
|
|
143
|
+
item.items = list;
|
|
144
|
+
result.push(Object.assign(Object.assign({}, item), { items: list }));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// secondary menu
|
|
148
|
+
result.push(...list);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
191
151
|
}
|
|
192
|
-
|
|
193
|
-
item.items = list;
|
|
194
|
-
result.push({
|
|
195
|
-
...item,
|
|
196
|
-
items: list,
|
|
197
|
-
});
|
|
198
|
-
} else {
|
|
199
|
-
// secondary menu
|
|
200
|
-
result.push(...list);
|
|
201
|
-
}
|
|
202
152
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
return result;
|
|
153
|
+
});
|
|
154
|
+
return result;
|
|
208
155
|
};
|
|
209
|
-
|
|
210
156
|
const markDuplicate = (navigation, compares = []) => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return navigation;
|
|
157
|
+
navigation.forEach((item) => {
|
|
158
|
+
const compare = { link: item.link, section: item.section || [] };
|
|
159
|
+
if (item.link && compares.some((x) => (0, isEqual_1.default)(x, compare))) {
|
|
160
|
+
item.duplicate = true;
|
|
161
|
+
}
|
|
162
|
+
if (item.link) {
|
|
163
|
+
compares.push(compare);
|
|
164
|
+
}
|
|
165
|
+
if (item.items) {
|
|
166
|
+
markDuplicate(item.items, compares);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return navigation;
|
|
226
170
|
};
|
|
227
|
-
|
|
228
171
|
const filterDuplicate = (navigation) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return res;
|
|
172
|
+
const res = navigation.filter((x) => !x.duplicate);
|
|
173
|
+
res.forEach((item) => {
|
|
174
|
+
if (item.items) {
|
|
175
|
+
item.items = filterDuplicate(item.items);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return res;
|
|
237
179
|
};
|
|
238
|
-
|
|
239
180
|
const uniq = (navigation) => {
|
|
240
|
-
|
|
181
|
+
return filterDuplicate(markDuplicate(navigation));
|
|
241
182
|
};
|
|
242
|
-
|
|
243
183
|
const parseNavigation = (...args) => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
184
|
+
// @ts-expect-error
|
|
185
|
+
const res = doParseNavigation(...args);
|
|
186
|
+
return uniq(res).filter((x) => x.link || (x.items && x.items.length));
|
|
247
187
|
};
|
|
248
|
-
|
|
249
188
|
module.exports = parseNavigation;
|
package/lib/parse.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TBlockletMeta } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get blocklet meta from blocklet.yml
|
|
4
|
+
* @param {string} dir blocklet directory
|
|
5
|
+
* @param {object} options.extraRawAttrs extra attributes, will be used as base attributes
|
|
6
|
+
* @param {boolean} options.ensureMain should we verify that main exists
|
|
7
|
+
* @param {boolean} options.ensureDist should we verify that dist exists
|
|
8
|
+
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
9
|
+
* @param {Array} options.serviceMetas should we verify that each service is validate (using JSON Schema defined serviceMetas)
|
|
10
|
+
*/
|
|
11
|
+
declare const parse: (dir: string, { ensureMain, ensureFiles, ensureDist, extraRawAttrs, serviceMetas, schemaOptions, fix, }?: {
|
|
12
|
+
ensureMain?: boolean;
|
|
13
|
+
ensureFiles?: boolean;
|
|
14
|
+
ensureDist?: boolean;
|
|
15
|
+
extraRawAttrs?: any;
|
|
16
|
+
serviceMetas?: any;
|
|
17
|
+
schemaOptions?: any;
|
|
18
|
+
enableDefaults?: boolean;
|
|
19
|
+
extraAttrSpec?: any;
|
|
20
|
+
fix?: boolean;
|
|
21
|
+
}) => TBlockletMeta;
|
|
22
|
+
export = parse;
|
package/lib/parse.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const fs_1 = __importDefault(require("fs"));
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
8
|
+
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const constants_1 = __importDefault(require("./constants"));
|
|
11
|
+
const did_1 = __importDefault(require("./did"));
|
|
12
|
+
const schema_1 = require("./schema");
|
|
13
|
+
const fix_1 = require("./fix");
|
|
14
|
+
const debug = (0, debug_1.default)('@blocklet/meta:parse');
|
|
15
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
|
|
13
16
|
/**
|
|
14
17
|
* Get blocklet meta from blocklet.yml
|
|
15
18
|
* @param {string} dir blocklet directory
|
|
@@ -19,77 +22,63 @@ const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, f
|
|
|
19
22
|
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
20
23
|
* @param {Array} options.serviceMetas should we verify that each service is validate (using JSON Schema defined serviceMetas)
|
|
21
24
|
*/
|
|
22
|
-
const parse = (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, extraRawAttrs = {}, serviceMetas, schemaOptions = {}, fix = true, } = {}) => {
|
|
26
|
+
let result = {};
|
|
27
|
+
const blockletMetaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
|
|
28
|
+
const blockletMetaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
|
|
29
|
+
if (fs_1.default.existsSync(blockletMetaFile)) {
|
|
30
|
+
try {
|
|
31
|
+
result = Object.assign(result, js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFile).toString(), { json: true }));
|
|
32
|
+
debug(`parse ${blockletMetaFile}`, result);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE} failed`, err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (fs_1.default.existsSync(blockletMetaFileAlt)) {
|
|
39
|
+
try {
|
|
40
|
+
result = Object.assign(result, js_yaml_1.default.load(fs_1.default.readFileSync(blockletMetaFileAlt).toString(), { json: true }));
|
|
41
|
+
debug(`parse ${blockletMetaFileAlt}`, result);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE_ALT} failed`, err);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(`no ${BLOCKLET_META_FILE} or ${BLOCKLET_META_FILE_ALT} found`);
|
|
49
|
+
}
|
|
50
|
+
// User Can override with extra meta attrs: useful for registry
|
|
51
|
+
if (extraRawAttrs) {
|
|
52
|
+
result = Object.assign(result, extraRawAttrs);
|
|
53
|
+
}
|
|
54
|
+
if (!fix) {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
return result;
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
// Fix
|
|
59
|
+
(0, fix_1.fixRequired)(result, dir);
|
|
60
|
+
(0, fix_1.fixRepository)(result);
|
|
61
|
+
(0, fix_1.fixFiles)(result);
|
|
62
|
+
(0, fix_1.fixKeywords)(result);
|
|
63
|
+
(0, fix_1.fixTags)(result);
|
|
64
|
+
(0, fix_1.fixPerson)(result);
|
|
65
|
+
// @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 2.
|
|
66
|
+
(0, fix_1.fixService)(result, serviceMetas);
|
|
67
|
+
debug('fix', result);
|
|
68
|
+
// We will overwrite did anyway
|
|
69
|
+
result.path = `/${result.group}/${result.name}`;
|
|
70
|
+
result.did = (0, did_1.default)(Buffer.from(result.name, 'utf8'));
|
|
71
|
+
// Ensure camelCase
|
|
72
|
+
result = Object.keys(result).reduce((acc, k) => {
|
|
73
|
+
acc[(0, camelCase_1.default)(k)] = result[k];
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
76
|
+
// Validate and cleanup
|
|
77
|
+
const schema = (0, schema_1.createBlockletSchema)(dir, Object.assign({ ensureMain, ensureFiles, ensureDist }, schemaOptions));
|
|
78
|
+
const { value, error } = schema.validate(result);
|
|
79
|
+
if (error) {
|
|
80
|
+
throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
|
|
51
81
|
}
|
|
52
|
-
|
|
53
|
-
throw new Error(`no ${BLOCKLET_META_FILE} or ${BLOCKLET_META_FILE_ALT} found`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// User Can override with extra meta attrs: useful for registry
|
|
57
|
-
if (extraRawAttrs) {
|
|
58
|
-
result = Object.assign(result, extraRawAttrs);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!fix) {
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Fix
|
|
66
|
-
fixRequired(result, dir);
|
|
67
|
-
fixRepository(result);
|
|
68
|
-
fixFiles(result);
|
|
69
|
-
fixKeywords(result);
|
|
70
|
-
fixTags(result);
|
|
71
|
-
fixPerson(result);
|
|
72
|
-
fixService(result, serviceMetas);
|
|
73
|
-
debug('fix', result);
|
|
74
|
-
|
|
75
|
-
// We will overwrite did anyway
|
|
76
|
-
result.path = `/${result.group}/${result.name}`;
|
|
77
|
-
result.did = toBlockletDid(Buffer.from(result.name, 'utf8'));
|
|
78
|
-
|
|
79
|
-
// Ensure camelCase
|
|
80
|
-
result = Object.keys(result).reduce((acc, k) => {
|
|
81
|
-
acc[camelCase(k)] = result[k];
|
|
82
|
-
return acc;
|
|
83
|
-
}, {});
|
|
84
|
-
|
|
85
|
-
// Validate and cleanup
|
|
86
|
-
const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist, ...schemaOptions });
|
|
87
|
-
const { value, error } = schema.validate(result);
|
|
88
|
-
if (error) {
|
|
89
|
-
throw new Error(`Invalid blocklet.yml: ${error.details.map((x) => x.message).join(', ')}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return value;
|
|
82
|
+
return value;
|
|
93
83
|
};
|
|
94
|
-
|
|
95
84
|
module.exports = parse;
|