@gmb/bitmark-parser-generator 4.7.0 → 4.8.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/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/browser/cjs/index.cjs +26 -1
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +9 -0
- package/dist/browser/esm/index.d.ts +9 -0
- package/dist/browser/esm/index.js +26 -1
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/index.cjs +284 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +284 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1297,6 +1297,7 @@ var propertyKeys = {
|
|
|
1297
1297
|
property_reference: "@reference",
|
|
1298
1298
|
property_refPublicationYear: "@refPublicationYear",
|
|
1299
1299
|
property_refPublisher: "@refPublisher",
|
|
1300
|
+
property_relatedBook: "@relatedBook",
|
|
1300
1301
|
property_releaseDate: "@releaseDate",
|
|
1301
1302
|
property_releaseKind: "@releaseKind",
|
|
1302
1303
|
property_releaseVersion: "@releaseVersion",
|
|
@@ -1572,6 +1573,16 @@ var StringUtils = class {
|
|
|
1572
1573
|
if (!str) return str;
|
|
1573
1574
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1574
1575
|
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Convert a camelCase string to kebab-case.
|
|
1578
|
+
*
|
|
1579
|
+
* @param str the string to convert
|
|
1580
|
+
* @returns the kebab-case version of the string
|
|
1581
|
+
*/
|
|
1582
|
+
camelToKebab(str) {
|
|
1583
|
+
if (!str) return str;
|
|
1584
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
1585
|
+
}
|
|
1575
1586
|
};
|
|
1576
1587
|
var stringUtils = new StringUtils();
|
|
1577
1588
|
|
|
@@ -3246,6 +3257,12 @@ var GROUPS = {
|
|
|
3246
3257
|
format: TagFormat.plainText,
|
|
3247
3258
|
maxCount: Count.infinity
|
|
3248
3259
|
},
|
|
3260
|
+
{
|
|
3261
|
+
key: ConfigKey.property_relatedBook,
|
|
3262
|
+
description: "Books related to this book",
|
|
3263
|
+
format: TagFormat.plainText,
|
|
3264
|
+
maxCount: Count.infinity
|
|
3265
|
+
},
|
|
3249
3266
|
{
|
|
3250
3267
|
key: ConfigKey.property_duration,
|
|
3251
3268
|
description: "The duration of the book",
|
|
@@ -9130,7 +9147,7 @@ var instance2 = new Config();
|
|
|
9130
9147
|
// src/generated/package_info.ts
|
|
9131
9148
|
var PACKAGE_INFO = {
|
|
9132
9149
|
"name": "@gmb/bitmark-parser-generator",
|
|
9133
|
-
"version": "4.
|
|
9150
|
+
"version": "4.8.0",
|
|
9134
9151
|
"author": "Get More Brain Ltd",
|
|
9135
9152
|
"license": "ISC",
|
|
9136
9153
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -9874,6 +9891,8 @@ var NodeType = (0, import_superenum20.superenum)({
|
|
|
9874
9891
|
referencePropertyValue: "referencePropertyValue",
|
|
9875
9892
|
refPublicationYear: "refPublicationYear",
|
|
9876
9893
|
refPublisher: "refPublisher",
|
|
9894
|
+
relatedBook: "relatedBook",
|
|
9895
|
+
relatedBookValue: "relatedBookValue",
|
|
9877
9896
|
releaseDate: "releaseDate",
|
|
9878
9897
|
releaseDateValue: "releaseDateValue",
|
|
9879
9898
|
releaseKind: "releaseKind",
|
|
@@ -22402,6 +22421,12 @@ var Builder = class extends BaseBuilder {
|
|
|
22402
22421
|
data.publications,
|
|
22403
22422
|
options
|
|
22404
22423
|
),
|
|
22424
|
+
relatedBook: this.toAstProperty(
|
|
22425
|
+
bitType,
|
|
22426
|
+
ConfigKey.property_relatedBook,
|
|
22427
|
+
data.relatedBook,
|
|
22428
|
+
options
|
|
22429
|
+
),
|
|
22405
22430
|
author: this.toAstProperty(bitType, ConfigKey.property_author, data.author, options),
|
|
22406
22431
|
subject: this.toAstProperty(bitType, ConfigKey.property_subject, data.subject, options),
|
|
22407
22432
|
date: this.toAstProperty(bitType, ConfigKey.property_date, data.date, options),
|
|
@@ -35812,6 +35837,264 @@ var ConfigBuilder = class {
|
|
|
35812
35837
|
build(options) {
|
|
35813
35838
|
const opts = Object.assign({}, options);
|
|
35814
35839
|
this.buildFlat(opts);
|
|
35840
|
+
const bitConfigs = [];
|
|
35841
|
+
const groupConfigs = [];
|
|
35842
|
+
for (const bt of BitType.values()) {
|
|
35843
|
+
const bitType = instance2.getBitType(bt);
|
|
35844
|
+
const _bitConfig = BITS[bitType];
|
|
35845
|
+
if (_bitConfig) {
|
|
35846
|
+
_bitConfig.bitType = bitType;
|
|
35847
|
+
bitConfigs.push(_bitConfig);
|
|
35848
|
+
}
|
|
35849
|
+
}
|
|
35850
|
+
for (const [k, g] of Object.entries(GROUPS)) {
|
|
35851
|
+
const g2 = g;
|
|
35852
|
+
let k2 = k;
|
|
35853
|
+
if (k.startsWith("group_")) k2 = k2.substring(6);
|
|
35854
|
+
k2 = /*'_' +*/
|
|
35855
|
+
stringUtils.camelToKebab(k2);
|
|
35856
|
+
g2.key = k2;
|
|
35857
|
+
groupConfigs.push(g2);
|
|
35858
|
+
}
|
|
35859
|
+
const outputFolder = opts.outputDir ?? "assets/config";
|
|
35860
|
+
const outputFolderBits = import_node_path3.default.join(outputFolder, "bits");
|
|
35861
|
+
const outputFolderGroups = import_node_path3.default.join(outputFolder, "partials");
|
|
35862
|
+
import_fs_extra3.default.ensureDirSync(outputFolderBits);
|
|
35863
|
+
import_fs_extra3.default.ensureDirSync(outputFolderGroups);
|
|
35864
|
+
const fileWrites = [];
|
|
35865
|
+
for (const b of bitConfigs) {
|
|
35866
|
+
const inherits = [];
|
|
35867
|
+
const tags2 = [];
|
|
35868
|
+
const tagEntriesTypeOrder = [
|
|
35869
|
+
BitTagConfigKeyType.tag,
|
|
35870
|
+
BitTagConfigKeyType.property,
|
|
35871
|
+
BitTagConfigKeyType.resource,
|
|
35872
|
+
BitTagConfigKeyType.group,
|
|
35873
|
+
BitTagConfigKeyType.unknown
|
|
35874
|
+
];
|
|
35875
|
+
const tagEntries = Object.entries(b.tags ?? []).sort((a, b2) => {
|
|
35876
|
+
const tagA = a[1];
|
|
35877
|
+
const tagB = b2[1];
|
|
35878
|
+
const typeA = typeFromConfigKey(tagA.key);
|
|
35879
|
+
const typeB = typeFromConfigKey(tagB.key);
|
|
35880
|
+
const typeOrder = tagEntriesTypeOrder.indexOf(typeA) - tagEntriesTypeOrder.indexOf(typeB);
|
|
35881
|
+
return typeOrder;
|
|
35882
|
+
});
|
|
35883
|
+
if (b.baseBitType) inherits.push(b.baseBitType);
|
|
35884
|
+
for (const [_tagKey, tag] of tagEntries) {
|
|
35885
|
+
const tagName = tag.key;
|
|
35886
|
+
let format = "";
|
|
35887
|
+
let chain = void 0;
|
|
35888
|
+
const tagType = typeFromConfigKey(tag.key);
|
|
35889
|
+
if (tagType === BitTagConfigKeyType.tag) {
|
|
35890
|
+
if (tagName === "%") {
|
|
35891
|
+
chain = {
|
|
35892
|
+
key: "%",
|
|
35893
|
+
format,
|
|
35894
|
+
min: tag.minCount,
|
|
35895
|
+
max: tag.maxCount,
|
|
35896
|
+
description: "Lead",
|
|
35897
|
+
chain: {
|
|
35898
|
+
key: "%",
|
|
35899
|
+
format,
|
|
35900
|
+
min: tag.minCount,
|
|
35901
|
+
max: tag.maxCount,
|
|
35902
|
+
description: "Page number",
|
|
35903
|
+
chain: {
|
|
35904
|
+
key: "%",
|
|
35905
|
+
format,
|
|
35906
|
+
min: tag.minCount,
|
|
35907
|
+
max: tag.maxCount,
|
|
35908
|
+
description: "Margin number"
|
|
35909
|
+
}
|
|
35910
|
+
}
|
|
35911
|
+
};
|
|
35912
|
+
}
|
|
35913
|
+
format = "bitmark--";
|
|
35914
|
+
} else if (tagType === BitTagConfigKeyType.property) {
|
|
35915
|
+
if (tag.format === TagFormat.plainText) {
|
|
35916
|
+
format = "string";
|
|
35917
|
+
} else if (tag.format === TagFormat.boolean) {
|
|
35918
|
+
format = "bool";
|
|
35919
|
+
} else if (tag.format === TagFormat.bitmarkText) {
|
|
35920
|
+
format = "bitmark";
|
|
35921
|
+
} else if (tag.format === TagFormat.number) {
|
|
35922
|
+
format = "number";
|
|
35923
|
+
}
|
|
35924
|
+
} else if (tagType === BitTagConfigKeyType.resource) {
|
|
35925
|
+
} else if (tagType === BitTagConfigKeyType.group) {
|
|
35926
|
+
let k = tag.key;
|
|
35927
|
+
if (k.startsWith("group_")) k = k.substring(6);
|
|
35928
|
+
k = "_" + k;
|
|
35929
|
+
inherits.push(k);
|
|
35930
|
+
continue;
|
|
35931
|
+
}
|
|
35932
|
+
const t = {
|
|
35933
|
+
key: tagName,
|
|
35934
|
+
format,
|
|
35935
|
+
default: null,
|
|
35936
|
+
alwaysInclude: false,
|
|
35937
|
+
min: tag.minCount == null ? 0 : tag.minCount,
|
|
35938
|
+
max: tag.maxCount == null ? 1 : tag.maxCount,
|
|
35939
|
+
description: tag.description ?? "",
|
|
35940
|
+
chain
|
|
35941
|
+
// raw: {
|
|
35942
|
+
// ...tag,
|
|
35943
|
+
// },
|
|
35944
|
+
};
|
|
35945
|
+
tags2.push(t);
|
|
35946
|
+
}
|
|
35947
|
+
const bitJson = {
|
|
35948
|
+
name: b.bitType,
|
|
35949
|
+
description: b.description ?? "",
|
|
35950
|
+
since: b.since,
|
|
35951
|
+
deprecated: b.deprecated,
|
|
35952
|
+
history: [
|
|
35953
|
+
{
|
|
35954
|
+
version: b.since,
|
|
35955
|
+
changes: ["Initial version"]
|
|
35956
|
+
}
|
|
35957
|
+
],
|
|
35958
|
+
format: b.textFormatDefault ?? "bitmark--",
|
|
35959
|
+
bodyAllowed: b.bodyAllowed ?? true,
|
|
35960
|
+
bodyRequired: b.bodyRequired ?? false,
|
|
35961
|
+
footerAllowed: b.footerAllowed ?? true,
|
|
35962
|
+
footerRequired: b.footerRequired ?? false,
|
|
35963
|
+
resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
|
|
35964
|
+
inherits,
|
|
35965
|
+
tags: tags2
|
|
35966
|
+
};
|
|
35967
|
+
const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
|
|
35968
|
+
const str = JSON.stringify(bitJson, null, 2);
|
|
35969
|
+
fileWrites.push(import_fs_extra3.default.writeFile(output, str));
|
|
35970
|
+
}
|
|
35971
|
+
const writeGroupConfigs = (groupConfigs2) => {
|
|
35972
|
+
for (const g of groupConfigs2) {
|
|
35973
|
+
const inherits = [];
|
|
35974
|
+
const tags2 = [];
|
|
35975
|
+
const groupKey = stringUtils.camelToKebab(g.key);
|
|
35976
|
+
const tagEntriesTypeOrder = [
|
|
35977
|
+
BitTagConfigKeyType.tag,
|
|
35978
|
+
BitTagConfigKeyType.property,
|
|
35979
|
+
BitTagConfigKeyType.resource,
|
|
35980
|
+
BitTagConfigKeyType.group
|
|
35981
|
+
];
|
|
35982
|
+
const tagEntries = Object.entries(g.tags ?? []).sort((a, b) => {
|
|
35983
|
+
const tagA = a[1];
|
|
35984
|
+
const tagB = b[1];
|
|
35985
|
+
const typeOrder = tagEntriesTypeOrder.indexOf(tagA.type) - tagEntriesTypeOrder.indexOf(tagB.type);
|
|
35986
|
+
return typeOrder;
|
|
35987
|
+
});
|
|
35988
|
+
for (const [_tagKey, tag] of tagEntries) {
|
|
35989
|
+
let tagName = tag.key;
|
|
35990
|
+
const tagType = typeFromConfigKey(tag.key);
|
|
35991
|
+
let format = "";
|
|
35992
|
+
let chain = void 0;
|
|
35993
|
+
if (tagType === BitTagConfigKeyType.tag) {
|
|
35994
|
+
tagName = tag.name;
|
|
35995
|
+
if (tagName === "%") {
|
|
35996
|
+
chain = {
|
|
35997
|
+
key: "%",
|
|
35998
|
+
format,
|
|
35999
|
+
min: tag.minCount,
|
|
36000
|
+
max: tag.maxCount,
|
|
36001
|
+
description: "Lead",
|
|
36002
|
+
chain: {
|
|
36003
|
+
key: "%",
|
|
36004
|
+
format,
|
|
36005
|
+
min: tag.minCount,
|
|
36006
|
+
max: tag.maxCount,
|
|
36007
|
+
description: "Page number",
|
|
36008
|
+
chain: {
|
|
36009
|
+
key: "%",
|
|
36010
|
+
format,
|
|
36011
|
+
min: tag.minCount,
|
|
36012
|
+
max: tag.maxCount,
|
|
36013
|
+
description: "Margin number"
|
|
36014
|
+
}
|
|
36015
|
+
}
|
|
36016
|
+
};
|
|
36017
|
+
}
|
|
36018
|
+
format = "bitmark--";
|
|
36019
|
+
} else if (tagType === BitTagConfigKeyType.property) {
|
|
36020
|
+
tagName = tag.key;
|
|
36021
|
+
if (tag.format === TagFormat.plainText) {
|
|
36022
|
+
format = "string";
|
|
36023
|
+
} else if (tag.format === TagFormat.boolean) {
|
|
36024
|
+
format = "bool";
|
|
36025
|
+
} else if (tag.format === TagFormat.bitmarkText) {
|
|
36026
|
+
format = "bitmark";
|
|
36027
|
+
} else if (tag.format === TagFormat.number) {
|
|
36028
|
+
format = "number";
|
|
36029
|
+
}
|
|
36030
|
+
} else if (tagType === BitTagConfigKeyType.resource) {
|
|
36031
|
+
format = "string";
|
|
36032
|
+
} else if (tagType === BitTagConfigKeyType.group) {
|
|
36033
|
+
let k = tag.key;
|
|
36034
|
+
if (k.startsWith("group_")) k = k.substring(6);
|
|
36035
|
+
k = /*'_' +*/
|
|
36036
|
+
stringUtils.camelToKebab(k);
|
|
36037
|
+
inherits.push(k);
|
|
36038
|
+
continue;
|
|
36039
|
+
}
|
|
36040
|
+
const t = {
|
|
36041
|
+
key: tagName,
|
|
36042
|
+
format,
|
|
36043
|
+
default: null,
|
|
36044
|
+
alwaysInclude: false,
|
|
36045
|
+
min: tag.minCount == null ? 0 : tag.minCount,
|
|
36046
|
+
max: tag.maxCount == null ? 1 : tag.maxCount,
|
|
36047
|
+
description: tag.description ?? "",
|
|
36048
|
+
chain
|
|
36049
|
+
// raw: {
|
|
36050
|
+
// ...tag,
|
|
36051
|
+
// },
|
|
36052
|
+
};
|
|
36053
|
+
tags2.push(t);
|
|
36054
|
+
}
|
|
36055
|
+
const bitJson = {
|
|
36056
|
+
name: groupKey,
|
|
36057
|
+
description: g.description ?? "",
|
|
36058
|
+
since: "UNKNOWN",
|
|
36059
|
+
deprecated: g.deprecated,
|
|
36060
|
+
history: [
|
|
36061
|
+
{
|
|
36062
|
+
version: "UNKNOWN",
|
|
36063
|
+
changes: ["Initial version"]
|
|
36064
|
+
}
|
|
36065
|
+
],
|
|
36066
|
+
inherits,
|
|
36067
|
+
tags: tags2
|
|
36068
|
+
// cards: [
|
|
36069
|
+
// {
|
|
36070
|
+
// card: null,
|
|
36071
|
+
// side: 1,
|
|
36072
|
+
// variant: null,
|
|
36073
|
+
// description: '',
|
|
36074
|
+
// tags: [],
|
|
36075
|
+
// },
|
|
36076
|
+
// {
|
|
36077
|
+
// card: null,
|
|
36078
|
+
// side: 2,
|
|
36079
|
+
// variant: 1,
|
|
36080
|
+
// description: '',
|
|
36081
|
+
// tags: [],
|
|
36082
|
+
// },
|
|
36083
|
+
// {
|
|
36084
|
+
// card: null,
|
|
36085
|
+
// side: 2,
|
|
36086
|
+
// variant: null,
|
|
36087
|
+
// description: '',
|
|
36088
|
+
// tags: [],
|
|
36089
|
+
// },
|
|
36090
|
+
// ],
|
|
36091
|
+
};
|
|
36092
|
+
const output = import_node_path3.default.join(outputFolderGroups, `${groupKey}.jsonc`);
|
|
36093
|
+
const str = JSON.stringify(bitJson, null, 2);
|
|
36094
|
+
import_fs_extra3.default.writeFileSync(output, str);
|
|
36095
|
+
}
|
|
36096
|
+
};
|
|
36097
|
+
writeGroupConfigs(groupConfigs);
|
|
35815
36098
|
}
|
|
35816
36099
|
buildFlat(options) {
|
|
35817
36100
|
const opts = Object.assign({}, options);
|