@gmb/bitmark-parser-generator 4.0.2 → 4.1.2

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/index.cjs CHANGED
@@ -8939,7 +8939,7 @@ var instance2 = new Config();
8939
8939
  // src/generated/package_info.ts
8940
8940
  var PACKAGE_INFO = {
8941
8941
  "name": "@gmb/bitmark-parser-generator",
8942
- "version": "4.0.2",
8942
+ "version": "4.1.2",
8943
8943
  "author": "Get More Brain Ltd",
8944
8944
  "license": "ISC",
8945
8945
  "description": "A bitmark parser and generator using Peggy.js"
@@ -20642,7 +20642,7 @@ var NodeValidator = class {
20642
20642
  }
20643
20643
  validateResource(resource) {
20644
20644
  if (!resource) return void 0;
20645
- let ret = resource;
20645
+ const ret = resource;
20646
20646
  let valid = false;
20647
20647
  switch (resource.type) {
20648
20648
  case ResourceType.image:
@@ -20704,12 +20704,7 @@ var NodeValidator = class {
20704
20704
  }
20705
20705
  if (!valid) {
20706
20706
  if (resource.type) {
20707
- ret = {
20708
- type: resource.type,
20709
- __typeAlias: resource.type,
20710
- __configKey: resource.__configKey,
20711
- __invalid: true
20712
- };
20707
+ resource.__invalid = true;
20713
20708
  }
20714
20709
  }
20715
20710
  return ret;
@@ -31251,7 +31246,6 @@ function buildResources(context, resourceTypeAttachment, resources) {
31251
31246
  const countsMax = resourcesConfig.getCountsMax();
31252
31247
  if (resources) {
31253
31248
  for (const r of resources.reverse()) {
31254
- if (r.__invalid) continue;
31255
31249
  const configKey = r.__configKey;
31256
31250
  let countMin = countsMin.get(configKey) ?? 0;
31257
31251
  let countMax = countsMax.get(configKey) ?? 0;
@@ -31266,6 +31260,9 @@ function buildResources(context, resourceTypeAttachment, resources) {
31266
31260
  }
31267
31261
  countsMin.set(configKey, countMin);
31268
31262
  countsMax.set(configKey, countMax);
31263
+ if (r.__invalid) {
31264
+ context.addWarning(`Resource type [&${r.type}] is not valid`);
31265
+ }
31269
31266
  }
31270
31267
  }
31271
31268
  if (!resourceAttachmentAllowed && resourceTypeAttachment) {
@@ -35125,9 +35122,10 @@ var BitmarkParser = class {
35125
35122
 
35126
35123
  // src/BitmarkParserGenerator.ts
35127
35124
  var import_node_path4 = __toESM(require("path"), 1);
35128
- var import_fs_extra6 = __toESM(require("fs-extra"), 1);
35125
+ var import_fs_extra4 = __toESM(require("fs-extra"), 1);
35129
35126
 
35130
35127
  // src/ast/writer/FileWriter.ts
35128
+ var import_node_fs = require("fs");
35131
35129
  var import_node_path = __toESM(require("path"), 1);
35132
35130
  var import_fs_extra = __toESM(require("fs-extra"), 1);
35133
35131
 
@@ -35266,9 +35264,10 @@ var FileWriter = class extends StreamWriter {
35266
35264
  };
35267
35265
 
35268
35266
  // src/generator/bitmark/BitmarkFileGenerator.ts
35269
- var import_fs_extra3 = require("fs-extra");
35267
+ var import_node_fs3 = require("fs");
35270
35268
 
35271
35269
  // src/ast/writer/SyncFileWriter.ts
35270
+ var import_node_fs2 = require("fs");
35272
35271
  var import_node_path2 = __toESM(require("path"), 1);
35273
35272
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
35274
35273
  var import_os2 = __toESM(require("os"), 1);
@@ -35415,7 +35414,7 @@ var BitmarkFileGenerator = class {
35415
35414
  };
35416
35415
 
35417
35416
  // src/generator/json/JsonFileGenerator.ts
35418
- var import_fs_extra4 = require("fs-extra");
35417
+ var import_node_fs4 = require("fs");
35419
35418
  var JsonFileGenerator = class {
35420
35419
  /**
35421
35420
  * Generate bitmark JSON from a bitmark AST as a file
@@ -35455,7 +35454,7 @@ var JsonFileGenerator = class {
35455
35454
 
35456
35455
  // src/info/ConfigBuilder.ts
35457
35456
  var import_node_path3 = __toESM(require("path"), 1);
35458
- var import_fs_extra5 = __toESM(require("fs-extra"), 1);
35457
+ var import_fs_extra3 = __toESM(require("fs-extra"), 1);
35459
35458
  var ConfigBuilder = class {
35460
35459
  build(options) {
35461
35460
  const opts = Object.assign({}, options);
@@ -35471,7 +35470,7 @@ var ConfigBuilder = class {
35471
35470
  }
35472
35471
  const outputFolder = opts.outputDir ?? "assets/config";
35473
35472
  const outputFolderBits = import_node_path3.default.join(outputFolder, "bits_flat");
35474
- import_fs_extra5.default.ensureDirSync(outputFolderBits);
35473
+ import_fs_extra3.default.ensureDirSync(outputFolderBits);
35475
35474
  for (const b of bitConfigs) {
35476
35475
  const inherits = [];
35477
35476
  const tags2 = [];
@@ -35606,7 +35605,7 @@ var ConfigBuilder = class {
35606
35605
  };
35607
35606
  const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
35608
35607
  const str = JSON.stringify(bitJson, null, 2);
35609
- import_fs_extra5.default.writeFileSync(output, str);
35608
+ import_fs_extra3.default.writeFileSync(output, str);
35610
35609
  }
35611
35610
  }
35612
35611
  };
@@ -35760,13 +35759,14 @@ var BitmarkParserGenerator = class {
35760
35759
  const outputAst = outputFormat === Output.ast;
35761
35760
  const bitmarkParserType = BitmarkParserType.peggy;
35762
35761
  let inStr = input;
35762
+ const inputIsString = typeof input === "string";
35763
35763
  if (env.isBrowser && opts.outputFile) {
35764
35764
  throw new Error("Cannot write to file in browser environment");
35765
35765
  }
35766
35766
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
35767
35767
  if (env.isNode) {
35768
- if (import_fs_extra6.default.existsSync(inStr)) {
35769
- inStr = import_fs_extra6.default.readFileSync(inStr, {
35768
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
35769
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
35770
35770
  encoding: "utf8"
35771
35771
  });
35772
35772
  }
@@ -35778,7 +35778,7 @@ var BitmarkParserGenerator = class {
35778
35778
  ast = this.jsonParser.toAst(inStr);
35779
35779
  }
35780
35780
  const isJson = !!ast?.bits;
35781
- const isBitmark = !isJson && !isAst;
35781
+ const isBitmark = inputIsString && !isJson && !isAst;
35782
35782
  const bitmarkToBitmark = (bitmarkStr) => {
35783
35783
  bitmarkToAst(bitmarkStr);
35784
35784
  astToBitmark(res);
@@ -35857,7 +35857,7 @@ var BitmarkParserGenerator = class {
35857
35857
  } else {
35858
35858
  astToBitmark(ast);
35859
35859
  }
35860
- } else {
35860
+ } else if (isJson) {
35861
35861
  ast = ast;
35862
35862
  if (outputJson) {
35863
35863
  jsonToJson(ast);
@@ -35866,6 +35866,8 @@ var BitmarkParserGenerator = class {
35866
35866
  } else {
35867
35867
  jsonToBitmark(ast);
35868
35868
  }
35869
+ } else {
35870
+ res = "";
35869
35871
  }
35870
35872
  return res;
35871
35873
  }
@@ -35900,13 +35902,14 @@ var BitmarkParserGenerator = class {
35900
35902
  const jsonOptions = Object.assign({}, opts.jsonOptions);
35901
35903
  const bitmarkParserType = opts.bitmarkParserType;
35902
35904
  let inStr = input;
35905
+ const inputIsString = typeof input === "string";
35903
35906
  if (env.isBrowser && opts.outputFile) {
35904
35907
  throw new Error("Cannot write to file in browser environment");
35905
35908
  }
35906
35909
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
35907
35910
  if (env.isNode) {
35908
- if (import_fs_extra6.default.existsSync(inStr)) {
35909
- inStr = import_fs_extra6.default.readFileSync(inStr, {
35911
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
35912
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
35910
35913
  encoding: "utf8"
35911
35914
  });
35912
35915
  }
@@ -35914,7 +35917,7 @@ var BitmarkParserGenerator = class {
35914
35917
  }
35915
35918
  let ast = this.jsonParser.toAst(inStr);
35916
35919
  const isJson = !!ast?.bits;
35917
- const isBitmark = !isJson;
35920
+ const isBitmark = inputIsString && !isJson;
35918
35921
  const bitmarkToBitmark = (bitmarkStr) => {
35919
35922
  const astJson = this.bitmarkParser.toAst(bitmarkStr, {
35920
35923
  parserType: bitmarkParserType
@@ -35939,9 +35942,11 @@ var BitmarkParserGenerator = class {
35939
35942
  };
35940
35943
  if (isBitmark) {
35941
35944
  bitmarkToBitmark(inStr);
35942
- } else {
35945
+ } else if (isJson) {
35943
35946
  ast = ast;
35944
35947
  jsonToJson(ast);
35948
+ } else {
35949
+ return;
35945
35950
  }
35946
35951
  return res;
35947
35952
  }
@@ -35958,11 +35963,12 @@ var BitmarkParserGenerator = class {
35958
35963
  createAst(input, options) {
35959
35964
  let res;
35960
35965
  let inStr = input;
35966
+ const inputIsString = typeof input === "string";
35961
35967
  const opts = Object.assign({}, options);
35962
35968
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
35963
35969
  if (env.isNode) {
35964
- if (import_fs_extra6.default.existsSync(inStr)) {
35965
- inStr = import_fs_extra6.default.readFileSync(inStr, {
35970
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
35971
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
35966
35972
  encoding: "utf8"
35967
35973
  });
35968
35974
  }
@@ -35974,11 +35980,13 @@ var BitmarkParserGenerator = class {
35974
35980
  ast = this.jsonParser.toAst(inStr);
35975
35981
  }
35976
35982
  const isJson = !!ast?.bits;
35977
- const isBitmark = !isJson && !isAst;
35983
+ const isBitmark = inputIsString && !isJson && !isAst;
35978
35984
  if (isBitmark) {
35979
35985
  res = this.bitmarkParser.toAst(inStr);
35980
- } else {
35986
+ } else if (isJson) {
35981
35987
  res = ast;
35988
+ } else {
35989
+ res = {};
35982
35990
  }
35983
35991
  return res;
35984
35992
  }
@@ -36014,13 +36022,14 @@ var BitmarkParserGenerator = class {
36014
36022
  const textFormat = TextFormat.fromValue(opts.textFormat) ?? TextFormat.bitmarkText;
36015
36023
  const textLocation = opts.textLocation ?? TextLocation.body;
36016
36024
  let inStr = input;
36025
+ const inputIsString = typeof input === "string";
36017
36026
  if (env.isBrowser && opts.outputFile) {
36018
36027
  throw new Error("Cannot write to file in browser environment");
36019
36028
  }
36020
36029
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
36021
36030
  if (env.isNode) {
36022
- if (import_fs_extra6.default.existsSync(inStr)) {
36023
- inStr = import_fs_extra6.default.readFileSync(inStr, {
36031
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
36032
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
36024
36033
  encoding: "utf8"
36025
36034
  });
36026
36035
  }
@@ -36043,8 +36052,8 @@ var BitmarkParserGenerator = class {
36043
36052
  strRes = this.jsonStringifyPrettify(preRes, jsonOptions, true);
36044
36053
  }
36045
36054
  const flag = fileOptions.append ? "a" : "w";
36046
- import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
36047
- import_fs_extra6.default.writeFileSync(output, strRes, {
36055
+ import_fs_extra4.default.ensureDirSync(import_node_path4.default.dirname(output));
36056
+ import_fs_extra4.default.writeFileSync(output, strRes, {
36048
36057
  flag
36049
36058
  });
36050
36059
  } else {
@@ -36081,13 +36090,14 @@ var BitmarkParserGenerator = class {
36081
36090
  const textFormat = TextFormat.fromValue(opts.textFormat) ?? TextFormat.bitmarkText;
36082
36091
  const textLocation = opts.textLocation ?? TextLocation.body;
36083
36092
  let inStr = input;
36093
+ const inputIsString = typeof input === "string";
36084
36094
  if (env.isBrowser && opts.outputFile) {
36085
36095
  throw new Error("Cannot write to file in browser environment");
36086
36096
  }
36087
36097
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
36088
36098
  if (env.isNode) {
36089
- if (import_fs_extra6.default.existsSync(inStr)) {
36090
- inStr = import_fs_extra6.default.readFileSync(inStr, {
36099
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
36100
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
36091
36101
  encoding: "utf8"
36092
36102
  });
36093
36103
  }
@@ -36100,8 +36110,8 @@ var BitmarkParserGenerator = class {
36100
36110
  if (opts.outputFile) {
36101
36111
  const output = opts.outputFile.toString();
36102
36112
  const flag = fileOptions.append ? "a" : "w";
36103
- import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
36104
- import_fs_extra6.default.writeFileSync(output, res, {
36113
+ import_fs_extra4.default.ensureDirSync(import_node_path4.default.dirname(output));
36114
+ import_fs_extra4.default.writeFileSync(output, res, {
36105
36115
  flag
36106
36116
  });
36107
36117
  } else {
@@ -36133,13 +36143,14 @@ var BitmarkParserGenerator = class {
36133
36143
  const textFormat = TextFormat.fromValue(opts.textFormat) ?? TextFormat.bitmarkText;
36134
36144
  const textLocation = opts.textLocation ?? TextLocation.body;
36135
36145
  let inStr = input;
36146
+ const inputIsString = typeof input === "string";
36136
36147
  if (env.isBrowser && opts.outputFile) {
36137
36148
  throw new Error("Cannot write to file in browser environment");
36138
36149
  }
36139
36150
  if (!opts.inputFormat || opts.inputFormat === Input.file) {
36140
36151
  if (env.isNode) {
36141
- if (import_fs_extra6.default.existsSync(inStr)) {
36142
- inStr = import_fs_extra6.default.readFileSync(inStr, {
36152
+ if (inputIsString && import_fs_extra4.default.existsSync(inStr)) {
36153
+ inStr = import_fs_extra4.default.readFileSync(inStr, {
36143
36154
  encoding: "utf8"
36144
36155
  });
36145
36156
  }
@@ -36152,8 +36163,8 @@ var BitmarkParserGenerator = class {
36152
36163
  if (opts.outputFile) {
36153
36164
  const output = opts.outputFile.toString();
36154
36165
  const flag = fileOptions.append ? "a" : "w";
36155
- import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
36156
- import_fs_extra6.default.writeFileSync(output, res, {
36166
+ import_fs_extra4.default.ensureDirSync(import_node_path4.default.dirname(output));
36167
+ import_fs_extra4.default.writeFileSync(output, res, {
36157
36168
  flag
36158
36169
  });
36159
36170
  } else {