@gmb/bitmark-parser-generator 3.38.0 → 4.0.1
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 +61 -56
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +24 -8
- package/dist/browser/esm/index.d.ts +24 -8
- package/dist/browser/esm/index.js +61 -56
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/index.cjs +245 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -8
- package/dist/index.d.ts +24 -8
- package/dist/index.js +243 -118
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1463,12 +1463,12 @@ var StringUtils = class {
|
|
|
1463
1463
|
subLength = width;
|
|
1464
1464
|
rangeStartNext = rangeStart + width;
|
|
1465
1465
|
}
|
|
1466
|
-
subString = str.
|
|
1466
|
+
subString = str.slice(rangeStart, rangeStart + subLength);
|
|
1467
1467
|
rangeStart = rangeStartNext;
|
|
1468
1468
|
result.push(subString.trim());
|
|
1469
1469
|
}
|
|
1470
1470
|
if (rangeStart < len) {
|
|
1471
|
-
subString = str.
|
|
1471
|
+
subString = str.slice(rangeStart);
|
|
1472
1472
|
result.push(subString);
|
|
1473
1473
|
}
|
|
1474
1474
|
return result;
|
|
@@ -1480,6 +1480,7 @@ var StringUtils = class {
|
|
|
1480
1480
|
* @returns the camelCase version of the string
|
|
1481
1481
|
*/
|
|
1482
1482
|
kebabToCamel(str) {
|
|
1483
|
+
if (!str) return str;
|
|
1483
1484
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1484
1485
|
}
|
|
1485
1486
|
};
|
|
@@ -1635,13 +1636,13 @@ var ObjectUtils = class {
|
|
|
1635
1636
|
* @param path the path to the property to set as a dotted string or array or a mix of both
|
|
1636
1637
|
* @returns the value of the property, or undefined if the property does not exist
|
|
1637
1638
|
*/
|
|
1638
|
-
getViaPath(obj,
|
|
1639
|
+
getViaPath(obj, path5) {
|
|
1639
1640
|
if (!obj) return void 0;
|
|
1640
|
-
if (!
|
|
1641
|
-
if (!Array.isArray(
|
|
1642
|
-
|
|
1641
|
+
if (!path5) return void 0;
|
|
1642
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1643
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1643
1644
|
let node = obj;
|
|
1644
|
-
for (const key of
|
|
1645
|
+
for (const key of path5) {
|
|
1645
1646
|
if (node == null) return void 0;
|
|
1646
1647
|
node = node[key];
|
|
1647
1648
|
}
|
|
@@ -1657,14 +1658,14 @@ var ObjectUtils = class {
|
|
|
1657
1658
|
* @param create - if true, create plain objects in the path if they do not exist
|
|
1658
1659
|
* @returns true if the value was set, false if the value was not set
|
|
1659
1660
|
*/
|
|
1660
|
-
setViaPath(obj,
|
|
1661
|
+
setViaPath(obj, path5, value, create) {
|
|
1661
1662
|
if (!obj) return false;
|
|
1662
|
-
if (!
|
|
1663
|
-
if (!Array.isArray(
|
|
1664
|
-
|
|
1663
|
+
if (!path5) return false;
|
|
1664
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1665
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1665
1666
|
let node = obj;
|
|
1666
|
-
for (let i = 0; i <
|
|
1667
|
-
const key =
|
|
1667
|
+
for (let i = 0; i < path5.length - 1; i++) {
|
|
1668
|
+
const key = path5[i];
|
|
1668
1669
|
if (node[key] == void 0) {
|
|
1669
1670
|
if (create) {
|
|
1670
1671
|
node[key] = {};
|
|
@@ -1674,7 +1675,7 @@ var ObjectUtils = class {
|
|
|
1674
1675
|
}
|
|
1675
1676
|
node = node[key];
|
|
1676
1677
|
}
|
|
1677
|
-
node[
|
|
1678
|
+
node[path5[path5.length - 1]] = value;
|
|
1678
1679
|
return true;
|
|
1679
1680
|
}
|
|
1680
1681
|
/**
|
|
@@ -1721,19 +1722,19 @@ var ObjectUtils = class {
|
|
|
1721
1722
|
* @param path
|
|
1722
1723
|
* @returns
|
|
1723
1724
|
*/
|
|
1724
|
-
flatMapPath(obj,
|
|
1725
|
+
flatMapPath(obj, path5) {
|
|
1725
1726
|
if (!obj) return [];
|
|
1726
|
-
if (!
|
|
1727
|
-
if (!Array.isArray(
|
|
1727
|
+
if (!path5) return [];
|
|
1728
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1728
1729
|
const node = obj;
|
|
1729
|
-
const key =
|
|
1730
|
+
const key = path5.shift();
|
|
1730
1731
|
if (key == null) return node;
|
|
1731
1732
|
const data = node[key];
|
|
1732
1733
|
if (!data) return [];
|
|
1733
1734
|
if (Array.isArray(data)) {
|
|
1734
|
-
return data.flatMap((d) => this.flatMapPath(d,
|
|
1735
|
+
return data.flatMap((d) => this.flatMapPath(d, path5.slice()));
|
|
1735
1736
|
} else {
|
|
1736
|
-
return [this.flatMapPath(data,
|
|
1737
|
+
return [this.flatMapPath(data, path5)].flat();
|
|
1737
1738
|
}
|
|
1738
1739
|
}
|
|
1739
1740
|
// testFlatMapPath() {
|
|
@@ -8879,7 +8880,7 @@ var instance2 = new Config();
|
|
|
8879
8880
|
// src/generated/package_info.ts
|
|
8880
8881
|
var PACKAGE_INFO = {
|
|
8881
8882
|
"name": "@gmb/bitmark-parser-generator",
|
|
8882
|
-
"version": "
|
|
8883
|
+
"version": "4.0.1",
|
|
8883
8884
|
"author": "Get More Brain Ltd",
|
|
8884
8885
|
"license": "ISC",
|
|
8885
8886
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -20645,8 +20646,10 @@ var NodeValidator = class {
|
|
|
20645
20646
|
if (!valid) {
|
|
20646
20647
|
if (resource.type) {
|
|
20647
20648
|
ret = {
|
|
20648
|
-
type: resource.type
|
|
20649
|
-
|
|
20649
|
+
type: resource.type,
|
|
20650
|
+
__typeAlias: resource.type,
|
|
20651
|
+
__configKey: resource.__configKey,
|
|
20652
|
+
__invalid: true
|
|
20650
20653
|
};
|
|
20651
20654
|
}
|
|
20652
20655
|
}
|
|
@@ -24124,14 +24127,14 @@ var Builder = class extends BaseBuilder {
|
|
|
24124
24127
|
* @param path path for the value
|
|
24125
24128
|
* @param value the value to push down
|
|
24126
24129
|
*/
|
|
24127
|
-
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath,
|
|
24130
|
+
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath, path5, value) {
|
|
24128
24131
|
if (value === void 0) return;
|
|
24129
24132
|
if (cardNode && cardNodePath) {
|
|
24130
24133
|
if (!Array.isArray(cardNodePath)) cardNodePath = [cardNodePath];
|
|
24131
24134
|
const data = objectUtils.flatMapPath(cardNode, cardNodePath);
|
|
24132
24135
|
for (const d of data) {
|
|
24133
|
-
if (d[
|
|
24134
|
-
d[
|
|
24136
|
+
if (d[path5] == null) {
|
|
24137
|
+
d[path5] = value;
|
|
24135
24138
|
}
|
|
24136
24139
|
}
|
|
24137
24140
|
}
|
|
@@ -24145,8 +24148,8 @@ var Builder = class extends BaseBuilder {
|
|
|
24145
24148
|
if (part) {
|
|
24146
24149
|
if (bodyBitTypes.indexOf(part.type) !== -1) {
|
|
24147
24150
|
const data = part;
|
|
24148
|
-
if (data[
|
|
24149
|
-
data[
|
|
24151
|
+
if (data[path5] == null) {
|
|
24152
|
+
data[path5] = value;
|
|
24150
24153
|
}
|
|
24151
24154
|
}
|
|
24152
24155
|
}
|
|
@@ -24339,13 +24342,14 @@ var StringWriter = class {
|
|
|
24339
24342
|
}
|
|
24340
24343
|
writeLine(value) {
|
|
24341
24344
|
if (!this._buffer) return this;
|
|
24345
|
+
let line;
|
|
24342
24346
|
if (value != null) {
|
|
24343
|
-
|
|
24344
|
-
this.lastWrite = value + this.endOfLineString;
|
|
24347
|
+
line = value + this.endOfLineString;
|
|
24345
24348
|
} else {
|
|
24346
|
-
this.
|
|
24347
|
-
this.lastWrite = this.endOfLineString;
|
|
24349
|
+
line = this.endOfLineString;
|
|
24348
24350
|
}
|
|
24351
|
+
this._buffer.push(line);
|
|
24352
|
+
this.lastWrite = line;
|
|
24349
24353
|
return this;
|
|
24350
24354
|
}
|
|
24351
24355
|
writeLines(values, delimiter) {
|
|
@@ -26633,6 +26637,7 @@ var JsonGenerator = class extends AstWalkerGenerator {
|
|
|
26633
26637
|
this.resetState();
|
|
26634
26638
|
this.writer.openSync();
|
|
26635
26639
|
this.walkAndWrite(ast);
|
|
26640
|
+
this.write(JSON.stringify(this.json, null, this.jsonPrettifySpace));
|
|
26636
26641
|
this.writer.closeSync();
|
|
26637
26642
|
}
|
|
26638
26643
|
resetState() {
|
|
@@ -31187,7 +31192,8 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31187
31192
|
const countsMax = resourcesConfig.getCountsMax();
|
|
31188
31193
|
if (resources) {
|
|
31189
31194
|
for (const r of resources.reverse()) {
|
|
31190
|
-
|
|
31195
|
+
if (r.__invalid) continue;
|
|
31196
|
+
const configKey = r.__configKey;
|
|
31191
31197
|
let countMin = countsMin.get(configKey) ?? 0;
|
|
31192
31198
|
let countMax = countsMax.get(configKey) ?? 0;
|
|
31193
31199
|
countMin = Math.max(0, countMin - 1);
|
|
@@ -31208,7 +31214,7 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31208
31214
|
context.addWarning(warningMsg);
|
|
31209
31215
|
} else if (filteredResources.length === 0 && resourceTypeAttachment) {
|
|
31210
31216
|
context.addWarning(
|
|
31211
|
-
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such
|
|
31217
|
+
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such resource is present`
|
|
31212
31218
|
);
|
|
31213
31219
|
}
|
|
31214
31220
|
if (excessResources.length > 0) {
|
|
@@ -35059,8 +35065,8 @@ var BitmarkParser = class {
|
|
|
35059
35065
|
};
|
|
35060
35066
|
|
|
35061
35067
|
// src/BitmarkParserGenerator.ts
|
|
35062
|
-
import
|
|
35063
|
-
import
|
|
35068
|
+
import path4 from "path";
|
|
35069
|
+
import fs6 from "fs-extra";
|
|
35064
35070
|
|
|
35065
35071
|
// src/ast/writer/FileWriter.ts
|
|
35066
35072
|
import path from "path";
|
|
@@ -35148,13 +35154,13 @@ var FileWriter = class extends StreamWriter {
|
|
|
35148
35154
|
* @param path - path of file to write
|
|
35149
35155
|
* @param options - options for file writing
|
|
35150
35156
|
*/
|
|
35151
|
-
constructor(
|
|
35157
|
+
constructor(path5, options) {
|
|
35152
35158
|
super();
|
|
35153
35159
|
__publicField(this, "_path");
|
|
35154
35160
|
__publicField(this, "_append");
|
|
35155
35161
|
__publicField(this, "_encoding");
|
|
35156
35162
|
const opts = Object.assign({}, options);
|
|
35157
|
-
this._path =
|
|
35163
|
+
this._path = path5;
|
|
35158
35164
|
this._append = !!opts.append;
|
|
35159
35165
|
this._encoding = opts.encoding ?? "utf8";
|
|
35160
35166
|
}
|
|
@@ -35202,6 +35208,118 @@ var FileWriter = class extends StreamWriter {
|
|
|
35202
35208
|
|
|
35203
35209
|
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35204
35210
|
import "fs-extra";
|
|
35211
|
+
|
|
35212
|
+
// src/ast/writer/SyncFileWriter.ts
|
|
35213
|
+
import path2 from "path";
|
|
35214
|
+
import fs2 from "fs-extra";
|
|
35215
|
+
import os2 from "os";
|
|
35216
|
+
var SyncFileWriter = class {
|
|
35217
|
+
/**
|
|
35218
|
+
* Create a writer to write to a file.
|
|
35219
|
+
*
|
|
35220
|
+
* @param path - path of file to write
|
|
35221
|
+
* @param options - options for file writing
|
|
35222
|
+
*/
|
|
35223
|
+
constructor(path5, options) {
|
|
35224
|
+
__publicField(this, "_path");
|
|
35225
|
+
__publicField(this, "_append");
|
|
35226
|
+
__publicField(this, "_encoding");
|
|
35227
|
+
__publicField(this, "_open");
|
|
35228
|
+
__publicField(this, "endOfLineString", os2.EOL);
|
|
35229
|
+
__publicField(this, "lastWrite", "");
|
|
35230
|
+
const opts = Object.assign({}, options);
|
|
35231
|
+
this._path = path5;
|
|
35232
|
+
this._append = !!opts.append;
|
|
35233
|
+
this._encoding = opts.encoding ?? "utf8";
|
|
35234
|
+
this._open = false;
|
|
35235
|
+
}
|
|
35236
|
+
get isSync() {
|
|
35237
|
+
return true;
|
|
35238
|
+
}
|
|
35239
|
+
get path() {
|
|
35240
|
+
return this._path;
|
|
35241
|
+
}
|
|
35242
|
+
get append() {
|
|
35243
|
+
return this._append;
|
|
35244
|
+
}
|
|
35245
|
+
get encoding() {
|
|
35246
|
+
return this._encoding;
|
|
35247
|
+
}
|
|
35248
|
+
async open() {
|
|
35249
|
+
this.openSync();
|
|
35250
|
+
return Promise.resolve();
|
|
35251
|
+
}
|
|
35252
|
+
async close() {
|
|
35253
|
+
try {
|
|
35254
|
+
this.closeSync();
|
|
35255
|
+
} catch (e) {
|
|
35256
|
+
return Promise.reject(e);
|
|
35257
|
+
}
|
|
35258
|
+
return Promise.resolve();
|
|
35259
|
+
}
|
|
35260
|
+
openSync() {
|
|
35261
|
+
const flag = this._append ? "a" : "w";
|
|
35262
|
+
fs2.ensureDirSync(path2.dirname(this._path.toString()));
|
|
35263
|
+
fs2.writeFileSync(this._path, "", {
|
|
35264
|
+
flag,
|
|
35265
|
+
encoding: this._encoding
|
|
35266
|
+
});
|
|
35267
|
+
this._open = true;
|
|
35268
|
+
}
|
|
35269
|
+
closeSync() {
|
|
35270
|
+
this._open = false;
|
|
35271
|
+
}
|
|
35272
|
+
writeLine(value) {
|
|
35273
|
+
if (!this._open) return this;
|
|
35274
|
+
let line;
|
|
35275
|
+
if (value != null) {
|
|
35276
|
+
line = value + this.endOfLineString;
|
|
35277
|
+
} else {
|
|
35278
|
+
line = this.endOfLineString;
|
|
35279
|
+
}
|
|
35280
|
+
fs2.appendFileSync(this._path, line, {
|
|
35281
|
+
encoding: this._encoding
|
|
35282
|
+
});
|
|
35283
|
+
this.lastWrite = line;
|
|
35284
|
+
return this;
|
|
35285
|
+
}
|
|
35286
|
+
writeLines(values, delimiter) {
|
|
35287
|
+
if (!this._open) return this;
|
|
35288
|
+
if (!values) return this;
|
|
35289
|
+
let str = "";
|
|
35290
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
35291
|
+
const value = values[i];
|
|
35292
|
+
str += value;
|
|
35293
|
+
if (delimiter && i < len - 1) {
|
|
35294
|
+
str += delimiter;
|
|
35295
|
+
}
|
|
35296
|
+
str += this.endOfLineString;
|
|
35297
|
+
}
|
|
35298
|
+
fs2.appendFileSync(this._path, str, {
|
|
35299
|
+
encoding: this._encoding
|
|
35300
|
+
});
|
|
35301
|
+
this.lastWrite = str;
|
|
35302
|
+
return this;
|
|
35303
|
+
}
|
|
35304
|
+
write(value) {
|
|
35305
|
+
if (!this._open) return this;
|
|
35306
|
+
if (value == null) return this;
|
|
35307
|
+
if (value) this.lastWrite = value;
|
|
35308
|
+
fs2.appendFileSync(this._path, value, {
|
|
35309
|
+
encoding: this._encoding
|
|
35310
|
+
});
|
|
35311
|
+
return this;
|
|
35312
|
+
}
|
|
35313
|
+
writeWhiteSpace() {
|
|
35314
|
+
this.write(" ");
|
|
35315
|
+
return this;
|
|
35316
|
+
}
|
|
35317
|
+
getLastWrite() {
|
|
35318
|
+
return this.lastWrite;
|
|
35319
|
+
}
|
|
35320
|
+
};
|
|
35321
|
+
|
|
35322
|
+
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35205
35323
|
var BitmarkFileGenerator = class {
|
|
35206
35324
|
/**
|
|
35207
35325
|
* Generate bitmark markup from a bitmark AST as a file
|
|
@@ -35209,9 +35327,11 @@ var BitmarkFileGenerator = class {
|
|
|
35209
35327
|
* @param path - path of file to generate
|
|
35210
35328
|
* @param options - bitmark generation options
|
|
35211
35329
|
*/
|
|
35212
|
-
constructor(
|
|
35330
|
+
constructor(path5, options) {
|
|
35213
35331
|
__publicField(this, "generator");
|
|
35214
|
-
|
|
35332
|
+
__publicField(this, "async");
|
|
35333
|
+
this.async = options?.async ?? false;
|
|
35334
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35215
35335
|
this.generator = new BitmarkGenerator(writer, options);
|
|
35216
35336
|
}
|
|
35217
35337
|
/**
|
|
@@ -35228,7 +35348,10 @@ var BitmarkFileGenerator = class {
|
|
|
35228
35348
|
* @param ast bitmark AST
|
|
35229
35349
|
*/
|
|
35230
35350
|
generateSync(_ast) {
|
|
35231
|
-
|
|
35351
|
+
if (this.async) {
|
|
35352
|
+
throw new Error("Sync operation not supported");
|
|
35353
|
+
}
|
|
35354
|
+
this.generator.generateSync(_ast);
|
|
35232
35355
|
}
|
|
35233
35356
|
};
|
|
35234
35357
|
|
|
@@ -35243,9 +35366,11 @@ var JsonFileGenerator = class {
|
|
|
35243
35366
|
* @param fileOptions - file options
|
|
35244
35367
|
* @param bitmarkOptions - bitmark generation options
|
|
35245
35368
|
*/
|
|
35246
|
-
constructor(
|
|
35369
|
+
constructor(path5, options) {
|
|
35247
35370
|
__publicField(this, "generator");
|
|
35248
|
-
|
|
35371
|
+
__publicField(this, "async");
|
|
35372
|
+
this.async = options?.async ?? false;
|
|
35373
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35249
35374
|
this.generator = new JsonGenerator(writer, options);
|
|
35250
35375
|
}
|
|
35251
35376
|
/**
|
|
@@ -35262,19 +35387,22 @@ var JsonFileGenerator = class {
|
|
|
35262
35387
|
* @param ast bitmark AST
|
|
35263
35388
|
*/
|
|
35264
35389
|
generateSync(_ast) {
|
|
35265
|
-
|
|
35390
|
+
if (this.async) {
|
|
35391
|
+
throw new Error("Sync operation not supported");
|
|
35392
|
+
}
|
|
35393
|
+
this.generator.generateSync(_ast);
|
|
35266
35394
|
}
|
|
35267
35395
|
};
|
|
35268
35396
|
|
|
35269
35397
|
// src/info/ConfigBuilder.ts
|
|
35270
|
-
import
|
|
35271
|
-
import
|
|
35398
|
+
import path3 from "path";
|
|
35399
|
+
import fs5 from "fs-extra";
|
|
35272
35400
|
var ConfigBuilder = class {
|
|
35273
|
-
|
|
35401
|
+
build(options) {
|
|
35274
35402
|
const opts = Object.assign({}, options);
|
|
35275
|
-
|
|
35403
|
+
this.buildFlat(opts);
|
|
35276
35404
|
}
|
|
35277
|
-
|
|
35405
|
+
buildFlat(options) {
|
|
35278
35406
|
const opts = Object.assign({}, options);
|
|
35279
35407
|
const bitConfigs = [];
|
|
35280
35408
|
for (const bt of BitType.values()) {
|
|
@@ -35283,9 +35411,8 @@ var ConfigBuilder = class {
|
|
|
35283
35411
|
if (bitConfig) bitConfigs.push(bitConfig);
|
|
35284
35412
|
}
|
|
35285
35413
|
const outputFolder = opts.outputDir ?? "assets/config";
|
|
35286
|
-
const outputFolderBits =
|
|
35287
|
-
|
|
35288
|
-
const fileWrites = [];
|
|
35414
|
+
const outputFolderBits = path3.join(outputFolder, "bits_flat");
|
|
35415
|
+
fs5.ensureDirSync(outputFolderBits);
|
|
35289
35416
|
for (const b of bitConfigs) {
|
|
35290
35417
|
const inherits = [];
|
|
35291
35418
|
const tags2 = [];
|
|
@@ -35418,11 +35545,10 @@ var ConfigBuilder = class {
|
|
|
35418
35545
|
resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
|
|
35419
35546
|
tags: tags2
|
|
35420
35547
|
};
|
|
35421
|
-
const output =
|
|
35548
|
+
const output = path3.join(outputFolderBits, `${b.bitType}.jsonc`);
|
|
35422
35549
|
const str = JSON.stringify(bitJson, null, 2);
|
|
35423
|
-
|
|
35550
|
+
fs5.writeFileSync(output, str);
|
|
35424
35551
|
}
|
|
35425
|
-
await Promise.all(fileWrites);
|
|
35426
35552
|
}
|
|
35427
35553
|
};
|
|
35428
35554
|
|
|
@@ -35534,11 +35660,10 @@ var BitmarkParserGenerator = class {
|
|
|
35534
35660
|
/**
|
|
35535
35661
|
* Generate the new configuration for the bitmark parser.
|
|
35536
35662
|
*/
|
|
35537
|
-
|
|
35663
|
+
generateConfig(options) {
|
|
35538
35664
|
const opts = Object.assign({}, options);
|
|
35539
35665
|
const builder3 = new ConfigBuilder();
|
|
35540
|
-
|
|
35541
|
-
return void 0;
|
|
35666
|
+
builder3.build(opts);
|
|
35542
35667
|
}
|
|
35543
35668
|
/**
|
|
35544
35669
|
* Convert bitmark from bitmark to JSON, or JSON to bitmark.
|
|
@@ -35562,11 +35687,11 @@ var BitmarkParserGenerator = class {
|
|
|
35562
35687
|
* @param input - bitmark or JSON or AST as a string, JSON or AST as plain JS object, or path to a file containing
|
|
35563
35688
|
* bitmark, JSON, or AST.
|
|
35564
35689
|
* @param options - the conversion options
|
|
35565
|
-
* @returns
|
|
35690
|
+
* @returns A string if converting to bitmark, a plain JS object if converting to JSON, or
|
|
35566
35691
|
* void if writing to a file
|
|
35567
35692
|
* @throws Error if any error occurs
|
|
35568
35693
|
*/
|
|
35569
|
-
|
|
35694
|
+
convert(input, options) {
|
|
35570
35695
|
let res;
|
|
35571
35696
|
const opts = Object.assign({}, options);
|
|
35572
35697
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35581,8 +35706,8 @@ var BitmarkParserGenerator = class {
|
|
|
35581
35706
|
}
|
|
35582
35707
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35583
35708
|
if (env.isNode) {
|
|
35584
|
-
if (
|
|
35585
|
-
inStr =
|
|
35709
|
+
if (fs6.existsSync(inStr)) {
|
|
35710
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35586
35711
|
encoding: "utf8"
|
|
35587
35712
|
});
|
|
35588
35713
|
}
|
|
@@ -35595,92 +35720,92 @@ var BitmarkParserGenerator = class {
|
|
|
35595
35720
|
}
|
|
35596
35721
|
const isJson = !!ast?.bits;
|
|
35597
35722
|
const isBitmark = !isJson && !isAst;
|
|
35598
|
-
const bitmarkToBitmark =
|
|
35599
|
-
|
|
35600
|
-
|
|
35723
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35724
|
+
bitmarkToAst(bitmarkStr);
|
|
35725
|
+
astToBitmark(res);
|
|
35601
35726
|
};
|
|
35602
|
-
const bitmarkToAst =
|
|
35727
|
+
const bitmarkToAst = (bitmarkStr) => {
|
|
35603
35728
|
res = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35604
35729
|
parserType: bitmarkParserType
|
|
35605
35730
|
});
|
|
35606
35731
|
};
|
|
35607
|
-
const bitmarkToJson =
|
|
35732
|
+
const bitmarkToJson = (bitmarkStr) => {
|
|
35608
35733
|
if (bitmarkParserType === BitmarkParserType.peggy) {
|
|
35609
35734
|
ast = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35610
35735
|
parserType: bitmarkParserType
|
|
35611
35736
|
});
|
|
35612
35737
|
if (opts.outputFile) {
|
|
35613
35738
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35614
|
-
|
|
35739
|
+
generator.generateSync(ast);
|
|
35615
35740
|
} else {
|
|
35616
35741
|
const generator = new JsonObjectGenerator(opts);
|
|
35617
|
-
const json =
|
|
35742
|
+
const json = generator.generateSync(ast);
|
|
35618
35743
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35619
35744
|
}
|
|
35620
35745
|
}
|
|
35621
35746
|
};
|
|
35622
|
-
const astToBitmark =
|
|
35747
|
+
const astToBitmark = (astJson) => {
|
|
35623
35748
|
if (opts.outputFile) {
|
|
35624
35749
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35625
|
-
|
|
35750
|
+
generator.generateSync(astJson);
|
|
35626
35751
|
} else {
|
|
35627
35752
|
const generator = new BitmarkStringGenerator(opts);
|
|
35628
|
-
res =
|
|
35753
|
+
res = generator.generateSync(astJson);
|
|
35629
35754
|
}
|
|
35630
35755
|
};
|
|
35631
|
-
const astToAst =
|
|
35756
|
+
const astToAst = (astJson) => {
|
|
35632
35757
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35633
35758
|
};
|
|
35634
|
-
const astToJson =
|
|
35759
|
+
const astToJson = (astJson) => {
|
|
35635
35760
|
if (opts.outputFile) {
|
|
35636
35761
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35637
|
-
|
|
35762
|
+
generator.generateSync(astJson);
|
|
35638
35763
|
} else {
|
|
35639
35764
|
const generator = new JsonObjectGenerator(opts);
|
|
35640
|
-
const json =
|
|
35765
|
+
const json = generator.generateSync(astJson);
|
|
35641
35766
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35642
35767
|
}
|
|
35643
35768
|
};
|
|
35644
|
-
const jsonToBitmark =
|
|
35769
|
+
const jsonToBitmark = (astJson) => {
|
|
35645
35770
|
if (opts.outputFile) {
|
|
35646
35771
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35647
|
-
|
|
35772
|
+
generator.generateSync(astJson);
|
|
35648
35773
|
} else {
|
|
35649
35774
|
const generator = new BitmarkStringGenerator(opts);
|
|
35650
|
-
res =
|
|
35775
|
+
res = generator.generateSync(astJson);
|
|
35651
35776
|
}
|
|
35652
35777
|
};
|
|
35653
|
-
const jsonToAst =
|
|
35778
|
+
const jsonToAst = (astJson) => {
|
|
35654
35779
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35655
35780
|
};
|
|
35656
|
-
const jsonToJson =
|
|
35657
|
-
|
|
35781
|
+
const jsonToJson = (astJson) => {
|
|
35782
|
+
astToJson(astJson);
|
|
35658
35783
|
};
|
|
35659
35784
|
if (isBitmark) {
|
|
35660
35785
|
if (outputBitmark) {
|
|
35661
|
-
|
|
35786
|
+
bitmarkToBitmark(inStr);
|
|
35662
35787
|
} else if (outputAst) {
|
|
35663
|
-
|
|
35788
|
+
bitmarkToAst(inStr);
|
|
35664
35789
|
} else {
|
|
35665
|
-
|
|
35790
|
+
bitmarkToJson(inStr);
|
|
35666
35791
|
}
|
|
35667
35792
|
} else if (isAst) {
|
|
35668
35793
|
ast = ast;
|
|
35669
35794
|
if (outputAst) {
|
|
35670
|
-
|
|
35795
|
+
astToAst(ast);
|
|
35671
35796
|
} else if (outputJson) {
|
|
35672
|
-
|
|
35797
|
+
astToJson(ast);
|
|
35673
35798
|
} else {
|
|
35674
|
-
|
|
35799
|
+
astToBitmark(ast);
|
|
35675
35800
|
}
|
|
35676
35801
|
} else {
|
|
35677
35802
|
ast = ast;
|
|
35678
35803
|
if (outputJson) {
|
|
35679
|
-
|
|
35804
|
+
jsonToJson(ast);
|
|
35680
35805
|
} else if (outputAst) {
|
|
35681
|
-
|
|
35806
|
+
jsonToAst(ast);
|
|
35682
35807
|
} else {
|
|
35683
|
-
|
|
35808
|
+
jsonToBitmark(ast);
|
|
35684
35809
|
}
|
|
35685
35810
|
}
|
|
35686
35811
|
return res;
|
|
@@ -35710,7 +35835,7 @@ var BitmarkParserGenerator = class {
|
|
|
35710
35835
|
* void if writing to a file
|
|
35711
35836
|
* @throws Error if any error occurs
|
|
35712
35837
|
*/
|
|
35713
|
-
|
|
35838
|
+
upgrade(input, options) {
|
|
35714
35839
|
let res;
|
|
35715
35840
|
const opts = Object.assign({}, options);
|
|
35716
35841
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35721,8 +35846,8 @@ var BitmarkParserGenerator = class {
|
|
|
35721
35846
|
}
|
|
35722
35847
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35723
35848
|
if (env.isNode) {
|
|
35724
|
-
if (
|
|
35725
|
-
inStr =
|
|
35849
|
+
if (fs6.existsSync(inStr)) {
|
|
35850
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35726
35851
|
encoding: "utf8"
|
|
35727
35852
|
});
|
|
35728
35853
|
}
|
|
@@ -35731,33 +35856,33 @@ var BitmarkParserGenerator = class {
|
|
|
35731
35856
|
let ast = this.jsonParser.toAst(inStr);
|
|
35732
35857
|
const isJson = !!ast?.bits;
|
|
35733
35858
|
const isBitmark = !isJson;
|
|
35734
|
-
const bitmarkToBitmark =
|
|
35859
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35735
35860
|
const astJson = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35736
35861
|
parserType: bitmarkParserType
|
|
35737
35862
|
});
|
|
35738
35863
|
if (opts.outputFile) {
|
|
35739
35864
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35740
|
-
|
|
35865
|
+
generator.generateSync(astJson);
|
|
35741
35866
|
} else {
|
|
35742
35867
|
const generator = new BitmarkStringGenerator(opts);
|
|
35743
|
-
res =
|
|
35868
|
+
res = generator.generateSync(astJson);
|
|
35744
35869
|
}
|
|
35745
35870
|
};
|
|
35746
|
-
const jsonToJson =
|
|
35871
|
+
const jsonToJson = (astJson) => {
|
|
35747
35872
|
if (opts.outputFile) {
|
|
35748
35873
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35749
|
-
|
|
35874
|
+
generator.generateSync(astJson);
|
|
35750
35875
|
} else {
|
|
35751
35876
|
const generator = new JsonObjectGenerator(opts);
|
|
35752
|
-
const json =
|
|
35877
|
+
const json = generator.generateSync(astJson);
|
|
35753
35878
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35754
35879
|
}
|
|
35755
35880
|
};
|
|
35756
35881
|
if (isBitmark) {
|
|
35757
|
-
|
|
35882
|
+
bitmarkToBitmark(inStr);
|
|
35758
35883
|
} else {
|
|
35759
35884
|
ast = ast;
|
|
35760
|
-
|
|
35885
|
+
jsonToJson(ast);
|
|
35761
35886
|
}
|
|
35762
35887
|
return res;
|
|
35763
35888
|
}
|
|
@@ -35777,8 +35902,8 @@ var BitmarkParserGenerator = class {
|
|
|
35777
35902
|
const opts = Object.assign({}, options);
|
|
35778
35903
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35779
35904
|
if (env.isNode) {
|
|
35780
|
-
if (
|
|
35781
|
-
inStr =
|
|
35905
|
+
if (fs6.existsSync(inStr)) {
|
|
35906
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35782
35907
|
encoding: "utf8"
|
|
35783
35908
|
});
|
|
35784
35909
|
}
|
|
@@ -35821,7 +35946,7 @@ var BitmarkParserGenerator = class {
|
|
|
35821
35946
|
* void if writing to a file
|
|
35822
35947
|
* @throws Error if any error occurs
|
|
35823
35948
|
*/
|
|
35824
|
-
|
|
35949
|
+
convertText(input, options) {
|
|
35825
35950
|
let res;
|
|
35826
35951
|
let preRes;
|
|
35827
35952
|
const opts = Object.assign({}, options);
|
|
@@ -35835,8 +35960,8 @@ var BitmarkParserGenerator = class {
|
|
|
35835
35960
|
}
|
|
35836
35961
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35837
35962
|
if (env.isNode) {
|
|
35838
|
-
if (
|
|
35839
|
-
inStr =
|
|
35963
|
+
if (fs6.existsSync(inStr)) {
|
|
35964
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35840
35965
|
encoding: "utf8"
|
|
35841
35966
|
});
|
|
35842
35967
|
}
|
|
@@ -35850,7 +35975,7 @@ var BitmarkParserGenerator = class {
|
|
|
35850
35975
|
location: TextLocation.body
|
|
35851
35976
|
});
|
|
35852
35977
|
} else {
|
|
35853
|
-
preRes =
|
|
35978
|
+
preRes = this.textGenerator.generateSync(ast, textFormat, textLocation);
|
|
35854
35979
|
}
|
|
35855
35980
|
if (opts.outputFile) {
|
|
35856
35981
|
const output = opts.outputFile.toString();
|
|
@@ -35859,8 +35984,8 @@ var BitmarkParserGenerator = class {
|
|
|
35859
35984
|
strRes = this.jsonStringifyPrettify(preRes, jsonOptions, true);
|
|
35860
35985
|
}
|
|
35861
35986
|
const flag = fileOptions.append ? "a" : "w";
|
|
35862
|
-
|
|
35863
|
-
|
|
35987
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
35988
|
+
fs6.writeFileSync(output, strRes, {
|
|
35864
35989
|
flag
|
|
35865
35990
|
});
|
|
35866
35991
|
} else {
|
|
@@ -35902,8 +36027,8 @@ var BitmarkParserGenerator = class {
|
|
|
35902
36027
|
}
|
|
35903
36028
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35904
36029
|
if (env.isNode) {
|
|
35905
|
-
if (
|
|
35906
|
-
inStr =
|
|
36030
|
+
if (fs6.existsSync(inStr)) {
|
|
36031
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35907
36032
|
encoding: "utf8"
|
|
35908
36033
|
});
|
|
35909
36034
|
}
|
|
@@ -35916,8 +36041,8 @@ var BitmarkParserGenerator = class {
|
|
|
35916
36041
|
if (opts.outputFile) {
|
|
35917
36042
|
const output = opts.outputFile.toString();
|
|
35918
36043
|
const flag = fileOptions.append ? "a" : "w";
|
|
35919
|
-
|
|
35920
|
-
|
|
36044
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
36045
|
+
fs6.writeFileSync(output, res, {
|
|
35921
36046
|
flag
|
|
35922
36047
|
});
|
|
35923
36048
|
} else {
|
|
@@ -35954,8 +36079,8 @@ var BitmarkParserGenerator = class {
|
|
|
35954
36079
|
}
|
|
35955
36080
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35956
36081
|
if (env.isNode) {
|
|
35957
|
-
if (
|
|
35958
|
-
inStr =
|
|
36082
|
+
if (fs6.existsSync(inStr)) {
|
|
36083
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35959
36084
|
encoding: "utf8"
|
|
35960
36085
|
});
|
|
35961
36086
|
}
|
|
@@ -35968,8 +36093,8 @@ var BitmarkParserGenerator = class {
|
|
|
35968
36093
|
if (opts.outputFile) {
|
|
35969
36094
|
const output = opts.outputFile.toString();
|
|
35970
36095
|
const flag = fileOptions.append ? "a" : "w";
|
|
35971
|
-
|
|
35972
|
-
|
|
36096
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
36097
|
+
fs6.writeFileSync(output, res, {
|
|
35973
36098
|
flag
|
|
35974
36099
|
});
|
|
35975
36100
|
} else {
|