@blocklet/meta 1.8.3 → 1.8.6
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/constants.js +0 -1
- package/lib/file.js +2 -2
- package/lib/parse-navigation.js +42 -4
- package/lib/parse.js +11 -25
- package/package.json +12 -12
package/lib/constants.js
CHANGED
package/lib/file.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const yaml = require('js-yaml');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
|
-
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
4
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = require('./constants');
|
|
5
5
|
|
|
6
|
-
const list = [BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
6
|
+
const list = [BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT];
|
|
7
7
|
|
|
8
8
|
const select = (dir, { throwOnError = true } = {}) => {
|
|
9
9
|
const metaFile = path.join(dir, BLOCKLET_META_FILE);
|
package/lib/parse-navigation.js
CHANGED
|
@@ -7,13 +7,13 @@ const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
|
|
|
7
7
|
* @param {*} prefix prefix of link
|
|
8
8
|
* @param {*} _level 1: primary menu, >2: secondary menu
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
11
11
|
const result = [];
|
|
12
12
|
|
|
13
13
|
(navigation || []).forEach((nav) => {
|
|
14
14
|
if (!nav.child) {
|
|
15
15
|
if (_level > 1 && nav.items?.length) {
|
|
16
|
-
const list =
|
|
16
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
17
17
|
result.push(...list);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -37,7 +37,7 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (nav.items?.length) {
|
|
40
|
-
const list =
|
|
40
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
41
41
|
if (list.length) {
|
|
42
42
|
item.items = list;
|
|
43
43
|
}
|
|
@@ -82,7 +82,7 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
82
82
|
result.push(item);
|
|
83
83
|
} else {
|
|
84
84
|
// child declares multiple menus
|
|
85
|
-
const list =
|
|
85
|
+
const list = doParseNavigation(
|
|
86
86
|
childNavigation,
|
|
87
87
|
child,
|
|
88
88
|
normalizePathPrefix(`${prefix}${child.mountPoint}`),
|
|
@@ -105,4 +105,42 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
105
105
|
return result;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
const markDuplicate = (navigation, urls = []) => {
|
|
109
|
+
navigation.forEach((item) => {
|
|
110
|
+
if (item.link && urls.includes(item.link)) {
|
|
111
|
+
item.duplicate = true;
|
|
112
|
+
}
|
|
113
|
+
if (item.link) {
|
|
114
|
+
urls.push(item.link);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (item.items) {
|
|
118
|
+
markDuplicate(item.items, urls);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return navigation;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const filterDuplicate = (navigation) => {
|
|
126
|
+
const res = navigation.filter((x) => !x.duplicate);
|
|
127
|
+
res.forEach((item) => {
|
|
128
|
+
if (item.items) {
|
|
129
|
+
item.items = filterDuplicate(item.items);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return res;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const uniq = (navigation) => {
|
|
137
|
+
return filterDuplicate(markDuplicate(navigation));
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const parseNavigation = (...args) => {
|
|
141
|
+
const res = doParseNavigation(...args);
|
|
142
|
+
|
|
143
|
+
return uniq(res);
|
|
144
|
+
};
|
|
145
|
+
|
|
108
146
|
module.exports = parseNavigation;
|
package/lib/parse.js
CHANGED
|
@@ -4,14 +4,14 @@ const yaml = require('js-yaml');
|
|
|
4
4
|
const camelCase = require('lodash/camelCase');
|
|
5
5
|
const debug = require('debug')('@blocklet/meta:parse');
|
|
6
6
|
|
|
7
|
-
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
7
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = require('./constants');
|
|
8
8
|
|
|
9
9
|
const toBlockletDid = require('./did');
|
|
10
10
|
const { createBlockletSchema } = require('./schema');
|
|
11
11
|
const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, fixService } = require('./fix');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Get blocklet meta from blocklet.yml
|
|
14
|
+
* Get blocklet meta from blocklet.yml
|
|
15
15
|
* @param {string} dir blocklet directory
|
|
16
16
|
* @param {object} options.extraRawAttrs extra attributes, will be used as base attributes
|
|
17
17
|
* @param {boolean} options.ensureMain should we verify that main exists
|
|
@@ -21,30 +21,16 @@ const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, f
|
|
|
21
21
|
*/
|
|
22
22
|
const parse = (
|
|
23
23
|
dir,
|
|
24
|
-
{
|
|
24
|
+
{
|
|
25
|
+
ensureMain = false,
|
|
26
|
+
ensureFiles = false,
|
|
27
|
+
ensureDist = false,
|
|
28
|
+
extraRawAttrs = {},
|
|
29
|
+
serviceMetas,
|
|
30
|
+
schemaOptions = {},
|
|
31
|
+
} = {}
|
|
25
32
|
) => {
|
|
26
33
|
let result = {};
|
|
27
|
-
const packageFile = path.join(dir, 'package.json');
|
|
28
|
-
if (fs.existsSync(packageFile)) {
|
|
29
|
-
try {
|
|
30
|
-
const packageJson = JSON.parse(fs.readFileSync(packageFile).toString());
|
|
31
|
-
delete packageJson.scripts;
|
|
32
|
-
result = Object.assign(result, packageJson, packageJson.blocklet || {});
|
|
33
|
-
debug('parse package.json', result);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error('parse_blocklet_meta from package.json failed', err);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const blockletMetaFileOld = path.join(dir, BLOCKLET_META_FILE_OLD);
|
|
40
|
-
if (fs.existsSync(blockletMetaFileOld)) {
|
|
41
|
-
try {
|
|
42
|
-
result = Object.assign(result, JSON.parse(fs.readFileSync(blockletMetaFileOld).toString()));
|
|
43
|
-
debug(`parse ${BLOCKLET_META_FILE_OLD}`, result);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE_OLD} failed`, err);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
34
|
|
|
49
35
|
const blockletMetaFile = path.join(dir, BLOCKLET_META_FILE);
|
|
50
36
|
const blockletMetaFileAlt = path.join(dir, BLOCKLET_META_FILE_ALT);
|
|
@@ -90,7 +76,7 @@ const parse = (
|
|
|
90
76
|
}, {});
|
|
91
77
|
|
|
92
78
|
// Validate and cleanup
|
|
93
|
-
const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist });
|
|
79
|
+
const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist, ...schemaOptions });
|
|
94
80
|
const { value, error } = schema.validate(result);
|
|
95
81
|
if (error) {
|
|
96
82
|
throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.6",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/util": "1.8.
|
|
23
|
-
"@arcblock/did": "1.17.
|
|
24
|
-
"@arcblock/did-ext": "1.17.
|
|
25
|
-
"@arcblock/did-util": "1.17.
|
|
26
|
-
"@arcblock/jwt": "1.17.
|
|
27
|
-
"@ocap/asset": "1.17.
|
|
28
|
-
"@ocap/mcrypto": "1.17.
|
|
29
|
-
"@ocap/util": "1.17.
|
|
30
|
-
"@ocap/wallet": "1.17.
|
|
21
|
+
"@abtnode/constant": "1.8.6",
|
|
22
|
+
"@abtnode/util": "1.8.6",
|
|
23
|
+
"@arcblock/did": "1.17.6",
|
|
24
|
+
"@arcblock/did-ext": "1.17.6",
|
|
25
|
+
"@arcblock/did-util": "1.17.6",
|
|
26
|
+
"@arcblock/jwt": "1.17.6",
|
|
27
|
+
"@ocap/asset": "1.17.6",
|
|
28
|
+
"@ocap/mcrypto": "1.17.6",
|
|
29
|
+
"@ocap/util": "1.17.6",
|
|
30
|
+
"@ocap/wallet": "1.17.6",
|
|
31
31
|
"ajv": "^8.11.0",
|
|
32
32
|
"cjk-length": "^1.0.0",
|
|
33
33
|
"debug": "^4.3.3",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"jest": "^27.4.5"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "070dad4ce5e12c8961399788f9d206bf7d9d263f"
|
|
50
50
|
}
|