@stryke/capnp 0.4.0 → 0.4.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/bin/capnpc.cjs CHANGED
@@ -657,11 +657,21 @@ async function readJsonFile(path, options) {
657
657
  }
658
658
  __name(readJsonFile, "readJsonFile");
659
659
 
660
+ // ../path/src/exists.ts
661
+ var import_node_fs2 = require("fs");
662
+ var import_promises2 = require("fs/promises");
663
+ var existsSync2 = /* @__PURE__ */ __name((filePath) => {
664
+ return (0, import_node_fs2.existsSync)(filePath);
665
+ }, "existsSync");
666
+ var exists = /* @__PURE__ */ __name(async (filePath) => {
667
+ return (0, import_promises2.access)(filePath, import_promises2.constants.F_OK).then(() => true).catch(() => false);
668
+ }, "exists");
669
+
660
670
  // ../path/src/file-path-fns.ts
661
671
  var import_node_path = require("path");
662
672
 
663
673
  // ../path/src/is-file.ts
664
- var import_node_fs2 = require("fs");
674
+ var import_node_fs3 = require("fs");
665
675
 
666
676
  // ../path/src/join-paths.ts
667
677
  var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
@@ -940,16 +950,6 @@ __name(findFilePath, "findFilePath");
940
950
  var import_commander = require("commander");
941
951
  var import_typescript = __toESM(require("typescript"), 1);
942
952
 
943
- // ../path/src/exists.ts
944
- var import_node_fs3 = require("fs");
945
- var import_promises2 = require("fs/promises");
946
- var existsSync2 = /* @__PURE__ */ __name((filePath) => {
947
- return (0, import_node_fs3.existsSync)(filePath);
948
- }, "existsSync");
949
- var exists = /* @__PURE__ */ __name(async (filePath) => {
950
- return (0, import_promises2.access)(filePath, import_promises2.constants.F_OK).then(() => true).catch(() => false);
951
- }, "exists");
952
-
953
953
  // ../fs/src/helpers.ts
954
954
  var import_nanotar = require("nanotar");
955
955
  var import_node_fs4 = require("fs");
@@ -989,39 +989,35 @@ var import_compiler = require("capnp-es/compiler");
989
989
  var import_node_buffer2 = require("buffer");
990
990
  var import_node_child_process = require("child_process");
991
991
  var import_node_fs6 = require("fs");
992
- async function readStdin() {
993
- if (process.stdin.isTTY) {
994
- return import_node_buffer2.Buffer.alloc(0);
995
- }
996
- const chunks = [];
997
- process.stdin.on("data", (chunk) => {
998
- chunks.push(chunk);
999
- });
1000
- await new Promise((resolve) => {
1001
- process.stdin.on("end", resolve);
1002
- });
1003
- const reqBuffer = import_node_buffer2.Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
1004
- let i = 0;
1005
- for (const chunk of chunks) {
1006
- chunk.copy(reqBuffer, i);
1007
- i += chunk.byteLength;
1008
- }
1009
- return reqBuffer;
1010
- }
1011
- __name(readStdin, "readStdin");
1012
992
  async function capnpc(options) {
1013
993
  try {
1014
- const { outputPath, tsconfig, sourcePath = [] } = options;
1015
- let dataBuf = await readStdin();
994
+ const { output, tsconfig, schema = [] } = options;
995
+ let dataBuf = import_node_buffer2.Buffer.alloc(0);
996
+ if (!process.stdin.isTTY) {
997
+ const chunks = [];
998
+ process.stdin.on("data", (chunk) => {
999
+ chunks.push(chunk);
1000
+ });
1001
+ await new Promise((resolve) => {
1002
+ process.stdin.on("end", resolve);
1003
+ });
1004
+ const reqBuffer = import_node_buffer2.Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
1005
+ let i = 0;
1006
+ for (const chunk of chunks) {
1007
+ chunk.copy(reqBuffer, i);
1008
+ i += chunk.byteLength;
1009
+ }
1010
+ dataBuf = reqBuffer;
1011
+ }
1016
1012
  if (dataBuf.byteLength === 0) {
1017
1013
  const opts = [];
1018
- if (outputPath) {
1019
- opts.push(`-o-:${outputPath}`);
1014
+ if (output) {
1015
+ opts.push(`-o-:${output}`);
1020
1016
  } else {
1021
1017
  opts.push("-o-");
1022
1018
  }
1023
1019
  dataBuf = await new Promise((resolve) => {
1024
- (0, import_node_child_process.exec)(`capnpc ${opts.join(" ")} ${sourcePath.join(" ")}`, {
1020
+ (0, import_node_child_process.exec)(`capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
1025
1021
  encoding: "buffer"
1026
1022
  }, (error, stdout, stderr) => {
1027
1023
  if (stderr.length > 0) {
@@ -1048,8 +1044,8 @@ async function capnpc(options) {
1048
1044
  filePath = fullPath;
1049
1045
  }
1050
1046
  }
1051
- if (outputPath) {
1052
- filePath = joinPaths(outputPath, fileName);
1047
+ if (output) {
1048
+ filePath = joinPaths(output, fileName);
1053
1049
  }
1054
1050
  if (!(0, import_node_fs6.existsSync)(findFilePath(filePath))) {
1055
1051
  await createDirectory(findFilePath(filePath));
@@ -1101,42 +1097,51 @@ function createProgram() {
1101
1097
  });
1102
1098
  const generateId = new import_commander.Option("-i --generate-id", "Generate a new 64-bit unique ID for use in a Cap'n Proto schema").default(true);
1103
1099
  const standardImportOption = new import_commander.Option("--standard-import", "Add default import paths; use only those specified by -I").default(true);
1104
- const outputPathOption = new import_commander.Option("-o --output-path <path>", "The directory to output the generated files to").default(process.cwd());
1105
- const sourceOption = new import_commander.Option("--source-path <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
1100
+ const schemaOption = new import_commander.Option("-s --schema <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
1106
1101
  joinPaths(process.cwd(), "**/*.capnp")
1107
1102
  ]).argParser((val) => {
1108
- if (val.startsWith("--source") || val.startsWith("-s")) {
1109
- return val.split(",").map((dir) => dir.trim());
1103
+ let result = [];
1104
+ if (val.startsWith("--schema") || val.startsWith("-s")) {
1105
+ result = val.split(",").map((dir) => dir.trim());
1110
1106
  }
1111
- return [
1107
+ result = [
1112
1108
  val.trim()
1113
1109
  ];
1110
+ return result.map((dir) => dir.endsWith(".capnp") ? dir : joinPaths(dir, "**/*.capnp"));
1114
1111
  });
1115
- const tsconfigPathOption = new import_commander.Option("--tsconfig-path <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths(process.cwd(), "tsconfig.json"));
1112
+ const outputOption = new import_commander.Option("-o --output <path>", "The directory to output the generated files to");
1113
+ const tsconfigOption = new import_commander.Option("-p --tsconfig <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths(process.cwd(), "tsconfig.json"));
1116
1114
  program.command("compile", {
1117
1115
  isDefault: true
1118
- }).description("Run the Storm Cap'n Proto compiler").addOption(sourceOption).addOption(outputPathOption).addOption(importPathOption).addOption(tsconfigPathOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(jsOption).addOption(dtsOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
1116
+ }).description("Run the Storm Cap'n Proto compiler").addOption(schemaOption).addOption(outputOption).addOption(importPathOption).addOption(tsconfigOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(jsOption).addOption(dtsOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
1119
1117
  return program;
1120
1118
  }
1121
1119
  __name(createProgram, "createProgram");
1122
1120
  async function compileAction(options) {
1123
- (0, import_console.writeInfo)(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files to ${options.outputPath}...`, {
1121
+ (0, import_console.writeInfo)(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files ${options.output ? `to ${options.output}...` : ""}`, {
1124
1122
  logLevel: "all"
1125
1123
  });
1126
- const resolvedTsconfig = await readJsonFile(options.tsconfigPath);
1127
- const tsconfig = import_typescript.default.parseJsonConfigFileContent(resolvedTsconfig, import_typescript.default.sys, findFilePath(options.tsconfigPath));
1128
- const sourcefiles = [];
1129
- for (const sourcePath of options.sourcePath) {
1130
- if (!sourcePath) {
1131
- (0, import_console.writeFatal)(`\u274C The source path "${sourcePath}" is invalid. Please provide a valid path.`, {
1124
+ if (!existsSync2(options.tsconfig)) {
1125
+ (0, import_console.writeFatal)(options.tsconfig ? `\u2716 The specified TypeScript configuration file "${options.tsconfig}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.", {
1126
+ logLevel: "all"
1127
+ });
1128
+ return;
1129
+ }
1130
+ const resolvedTsconfig = await readJsonFile(options.tsconfig);
1131
+ const tsconfig = import_typescript.default.parseJsonConfigFileContent(resolvedTsconfig, import_typescript.default.sys, findFilePath(options.tsconfig));
1132
+ tsconfig.options.configFilePath = options.tsconfig;
1133
+ const schema = [];
1134
+ for (const schemaPath of options.schema) {
1135
+ if (!schemaPath || !schemaPath.includes("*") && !existsSync2(schemaPath)) {
1136
+ (0, import_console.writeFatal)(`\u274C The schema path "${schemaPath}" is invalid. Please provide a valid path.`, {
1132
1137
  logLevel: "all"
1133
1138
  });
1134
1139
  return;
1135
1140
  }
1136
- sourcefiles.push(...await listFiles(sourcePath));
1141
+ schema.push(...await listFiles(schemaPath));
1137
1142
  }
1138
- if (sourcefiles.length === 0) {
1139
- (0, import_console.writeFatal)(`\u274C No Cap'n Proto schema files found in the specified source paths: ${options.sourcePath.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
1143
+ if (schema.length === 0) {
1144
+ (0, import_console.writeFatal)(`\u274C No Cap'n Proto schema files found in the specified source paths: ${options.schema.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
1140
1145
  logLevel: "all"
1141
1146
  });
1142
1147
  return;
@@ -1144,7 +1149,8 @@ async function compileAction(options) {
1144
1149
  const result = await capnpc({
1145
1150
  ...options,
1146
1151
  tsconfig,
1147
- sourcePath: sourcefiles
1152
+ schema,
1153
+ output: options.output ? options.output : schema.length > 0 && schema[0] ? findFilePath(schema[0]) : process.cwd()
1148
1154
  });
1149
1155
  if (result.files.size === 0) {
1150
1156
  (0, import_console.writeInfo)("\u26A0\uFE0F No files were generated. Please check your schema files.", {
package/bin/capnpc.js CHANGED
@@ -625,6 +625,16 @@ async function readJsonFile(path, options) {
625
625
  }
626
626
  __name(readJsonFile, "readJsonFile");
627
627
 
628
+ // ../path/src/exists.ts
629
+ import { existsSync as existsSyncFs } from "node:fs";
630
+ import { access, constants } from "node:fs/promises";
631
+ var existsSync2 = /* @__PURE__ */ __name((filePath) => {
632
+ return existsSyncFs(filePath);
633
+ }, "existsSync");
634
+ var exists = /* @__PURE__ */ __name(async (filePath) => {
635
+ return access(filePath, constants.F_OK).then(() => true).catch(() => false);
636
+ }, "exists");
637
+
628
638
  // ../path/src/file-path-fns.ts
629
639
  import { relative } from "node:path";
630
640
 
@@ -908,16 +918,6 @@ __name(findFilePath, "findFilePath");
908
918
  import { Command, Option } from "commander";
909
919
  import ts from "typescript";
910
920
 
911
- // ../path/src/exists.ts
912
- import { existsSync as existsSyncFs } from "node:fs";
913
- import { access, constants } from "node:fs/promises";
914
- var existsSync2 = /* @__PURE__ */ __name((filePath) => {
915
- return existsSyncFs(filePath);
916
- }, "existsSync");
917
- var exists = /* @__PURE__ */ __name(async (filePath) => {
918
- return access(filePath, constants.F_OK).then(() => true).catch(() => false);
919
- }, "exists");
920
-
921
921
  // ../fs/src/helpers.ts
922
922
  import { parseTar, parseTarGzip } from "nanotar";
923
923
  import { createWriteStream, mkdirSync, rmSync } from "node:fs";
@@ -957,39 +957,35 @@ import { compileAll } from "capnp-es/compiler";
957
957
  import { Buffer as Buffer3 } from "node:buffer";
958
958
  import { exec } from "node:child_process";
959
959
  import { existsSync as existsSync3 } from "node:fs";
960
- async function readStdin() {
961
- if (process.stdin.isTTY) {
962
- return Buffer3.alloc(0);
963
- }
964
- const chunks = [];
965
- process.stdin.on("data", (chunk) => {
966
- chunks.push(chunk);
967
- });
968
- await new Promise((resolve) => {
969
- process.stdin.on("end", resolve);
970
- });
971
- const reqBuffer = Buffer3.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
972
- let i = 0;
973
- for (const chunk of chunks) {
974
- chunk.copy(reqBuffer, i);
975
- i += chunk.byteLength;
976
- }
977
- return reqBuffer;
978
- }
979
- __name(readStdin, "readStdin");
980
960
  async function capnpc(options) {
981
961
  try {
982
- const { outputPath, tsconfig, sourcePath = [] } = options;
983
- let dataBuf = await readStdin();
962
+ const { output, tsconfig, schema = [] } = options;
963
+ let dataBuf = Buffer3.alloc(0);
964
+ if (!process.stdin.isTTY) {
965
+ const chunks = [];
966
+ process.stdin.on("data", (chunk) => {
967
+ chunks.push(chunk);
968
+ });
969
+ await new Promise((resolve) => {
970
+ process.stdin.on("end", resolve);
971
+ });
972
+ const reqBuffer = Buffer3.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
973
+ let i = 0;
974
+ for (const chunk of chunks) {
975
+ chunk.copy(reqBuffer, i);
976
+ i += chunk.byteLength;
977
+ }
978
+ dataBuf = reqBuffer;
979
+ }
984
980
  if (dataBuf.byteLength === 0) {
985
981
  const opts = [];
986
- if (outputPath) {
987
- opts.push(`-o-:${outputPath}`);
982
+ if (output) {
983
+ opts.push(`-o-:${output}`);
988
984
  } else {
989
985
  opts.push("-o-");
990
986
  }
991
987
  dataBuf = await new Promise((resolve) => {
992
- exec(`capnpc ${opts.join(" ")} ${sourcePath.join(" ")}`, {
988
+ exec(`capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
993
989
  encoding: "buffer"
994
990
  }, (error, stdout, stderr) => {
995
991
  if (stderr.length > 0) {
@@ -1016,8 +1012,8 @@ async function capnpc(options) {
1016
1012
  filePath = fullPath;
1017
1013
  }
1018
1014
  }
1019
- if (outputPath) {
1020
- filePath = joinPaths(outputPath, fileName);
1015
+ if (output) {
1016
+ filePath = joinPaths(output, fileName);
1021
1017
  }
1022
1018
  if (!existsSync3(findFilePath(filePath))) {
1023
1019
  await createDirectory(findFilePath(filePath));
@@ -1069,42 +1065,51 @@ function createProgram() {
1069
1065
  });
1070
1066
  const generateId = new Option("-i --generate-id", "Generate a new 64-bit unique ID for use in a Cap'n Proto schema").default(true);
1071
1067
  const standardImportOption = new Option("--standard-import", "Add default import paths; use only those specified by -I").default(true);
1072
- const outputPathOption = new Option("-o --output-path <path>", "The directory to output the generated files to").default(process.cwd());
1073
- const sourceOption = new Option("--source-path <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
1068
+ const schemaOption = new Option("-s --schema <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
1074
1069
  joinPaths(process.cwd(), "**/*.capnp")
1075
1070
  ]).argParser((val) => {
1076
- if (val.startsWith("--source") || val.startsWith("-s")) {
1077
- return val.split(",").map((dir) => dir.trim());
1071
+ let result = [];
1072
+ if (val.startsWith("--schema") || val.startsWith("-s")) {
1073
+ result = val.split(",").map((dir) => dir.trim());
1078
1074
  }
1079
- return [
1075
+ result = [
1080
1076
  val.trim()
1081
1077
  ];
1078
+ return result.map((dir) => dir.endsWith(".capnp") ? dir : joinPaths(dir, "**/*.capnp"));
1082
1079
  });
1083
- const tsconfigPathOption = new Option("--tsconfig-path <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths(process.cwd(), "tsconfig.json"));
1080
+ const outputOption = new Option("-o --output <path>", "The directory to output the generated files to");
1081
+ const tsconfigOption = new Option("-p --tsconfig <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths(process.cwd(), "tsconfig.json"));
1084
1082
  program.command("compile", {
1085
1083
  isDefault: true
1086
- }).description("Run the Storm Cap'n Proto compiler").addOption(sourceOption).addOption(outputPathOption).addOption(importPathOption).addOption(tsconfigPathOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(jsOption).addOption(dtsOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
1084
+ }).description("Run the Storm Cap'n Proto compiler").addOption(schemaOption).addOption(outputOption).addOption(importPathOption).addOption(tsconfigOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(jsOption).addOption(dtsOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
1087
1085
  return program;
1088
1086
  }
1089
1087
  __name(createProgram, "createProgram");
1090
1088
  async function compileAction(options) {
1091
- writeInfo(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files to ${options.outputPath}...`, {
1089
+ writeInfo(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files ${options.output ? `to ${options.output}...` : ""}`, {
1092
1090
  logLevel: "all"
1093
1091
  });
1094
- const resolvedTsconfig = await readJsonFile(options.tsconfigPath);
1095
- const tsconfig = ts.parseJsonConfigFileContent(resolvedTsconfig, ts.sys, findFilePath(options.tsconfigPath));
1096
- const sourcefiles = [];
1097
- for (const sourcePath of options.sourcePath) {
1098
- if (!sourcePath) {
1099
- writeFatal(`\u274C The source path "${sourcePath}" is invalid. Please provide a valid path.`, {
1092
+ if (!existsSync2(options.tsconfig)) {
1093
+ writeFatal(options.tsconfig ? `\u2716 The specified TypeScript configuration file "${options.tsconfig}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.", {
1094
+ logLevel: "all"
1095
+ });
1096
+ return;
1097
+ }
1098
+ const resolvedTsconfig = await readJsonFile(options.tsconfig);
1099
+ const tsconfig = ts.parseJsonConfigFileContent(resolvedTsconfig, ts.sys, findFilePath(options.tsconfig));
1100
+ tsconfig.options.configFilePath = options.tsconfig;
1101
+ const schema = [];
1102
+ for (const schemaPath of options.schema) {
1103
+ if (!schemaPath || !schemaPath.includes("*") && !existsSync2(schemaPath)) {
1104
+ writeFatal(`\u274C The schema path "${schemaPath}" is invalid. Please provide a valid path.`, {
1100
1105
  logLevel: "all"
1101
1106
  });
1102
1107
  return;
1103
1108
  }
1104
- sourcefiles.push(...await listFiles(sourcePath));
1109
+ schema.push(...await listFiles(schemaPath));
1105
1110
  }
1106
- if (sourcefiles.length === 0) {
1107
- writeFatal(`\u274C No Cap'n Proto schema files found in the specified source paths: ${options.sourcePath.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
1111
+ if (schema.length === 0) {
1112
+ writeFatal(`\u274C No Cap'n Proto schema files found in the specified source paths: ${options.schema.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
1108
1113
  logLevel: "all"
1109
1114
  });
1110
1115
  return;
@@ -1112,7 +1117,8 @@ async function compileAction(options) {
1112
1117
  const result = await capnpc({
1113
1118
  ...options,
1114
1119
  tsconfig,
1115
- sourcePath: sourcefiles
1120
+ schema,
1121
+ output: options.output ? options.output : schema.length > 0 && schema[0] ? findFilePath(schema[0]) : process.cwd()
1116
1122
  });
1117
1123
  if (result.files.size === 0) {
1118
1124
  writeInfo("\u26A0\uFE0F No files were generated. Please check your schema files.", {
@@ -886,39 +886,35 @@ import { compileAll } from "capnp-es/compiler";
886
886
  import { Buffer as Buffer2 } from "node:buffer";
887
887
  import { exec } from "node:child_process";
888
888
  import { existsSync as existsSync2 } from "node:fs";
889
- async function readStdin() {
890
- if (process.stdin.isTTY) {
891
- return Buffer2.alloc(0);
892
- }
893
- const chunks = [];
894
- process.stdin.on("data", (chunk) => {
895
- chunks.push(chunk);
896
- });
897
- await new Promise((resolve) => {
898
- process.stdin.on("end", resolve);
899
- });
900
- const reqBuffer = Buffer2.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
901
- let i = 0;
902
- for (const chunk of chunks) {
903
- chunk.copy(reqBuffer, i);
904
- i += chunk.byteLength;
905
- }
906
- return reqBuffer;
907
- }
908
- __name(readStdin, "readStdin");
909
889
  async function capnpc(options) {
910
890
  try {
911
- const { outputPath, tsconfig, sourcePath = [] } = options;
912
- let dataBuf = await readStdin();
891
+ const { output, tsconfig, schema = [] } = options;
892
+ let dataBuf = Buffer2.alloc(0);
893
+ if (!process.stdin.isTTY) {
894
+ const chunks = [];
895
+ process.stdin.on("data", (chunk) => {
896
+ chunks.push(chunk);
897
+ });
898
+ await new Promise((resolve) => {
899
+ process.stdin.on("end", resolve);
900
+ });
901
+ const reqBuffer = Buffer2.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
902
+ let i = 0;
903
+ for (const chunk of chunks) {
904
+ chunk.copy(reqBuffer, i);
905
+ i += chunk.byteLength;
906
+ }
907
+ dataBuf = reqBuffer;
908
+ }
913
909
  if (dataBuf.byteLength === 0) {
914
910
  const opts = [];
915
- if (outputPath) {
916
- opts.push(`-o-:${outputPath}`);
911
+ if (output) {
912
+ opts.push(`-o-:${output}`);
917
913
  } else {
918
914
  opts.push("-o-");
919
915
  }
920
916
  dataBuf = await new Promise((resolve) => {
921
- exec(`capnpc ${opts.join(" ")} ${sourcePath.join(" ")}`, {
917
+ exec(`capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
922
918
  encoding: "buffer"
923
919
  }, (error, stdout, stderr) => {
924
920
  if (stderr.length > 0) {
@@ -945,8 +941,8 @@ async function capnpc(options) {
945
941
  filePath = fullPath;
946
942
  }
947
943
  }
948
- if (outputPath) {
949
- filePath = joinPaths(outputPath, fileName);
944
+ if (output) {
945
+ filePath = joinPaths(output, fileName);
950
946
  }
951
947
  if (!existsSync2(findFilePath(filePath))) {
952
948
  await createDirectory(findFilePath(filePath));
@@ -886,39 +886,35 @@ var _compiler = require('capnp-es/compiler');
886
886
 
887
887
  var _child_process = require('child_process');
888
888
 
889
- async function readStdin() {
890
- if (process.stdin.isTTY) {
891
- return _buffer.Buffer.alloc(0);
892
- }
893
- const chunks = [];
894
- process.stdin.on("data", (chunk) => {
895
- chunks.push(chunk);
896
- });
897
- await new Promise((resolve) => {
898
- process.stdin.on("end", resolve);
899
- });
900
- const reqBuffer = _buffer.Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
901
- let i = 0;
902
- for (const chunk of chunks) {
903
- chunk.copy(reqBuffer, i);
904
- i += chunk.byteLength;
905
- }
906
- return reqBuffer;
907
- }
908
- _chunkUSNT2KNTcjs.__name.call(void 0, readStdin, "readStdin");
909
889
  async function capnpc(options) {
910
890
  try {
911
- const { outputPath, tsconfig, sourcePath = [] } = options;
912
- let dataBuf = await readStdin();
891
+ const { output, tsconfig, schema = [] } = options;
892
+ let dataBuf = _buffer.Buffer.alloc(0);
893
+ if (!process.stdin.isTTY) {
894
+ const chunks = [];
895
+ process.stdin.on("data", (chunk) => {
896
+ chunks.push(chunk);
897
+ });
898
+ await new Promise((resolve) => {
899
+ process.stdin.on("end", resolve);
900
+ });
901
+ const reqBuffer = _buffer.Buffer.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
902
+ let i = 0;
903
+ for (const chunk of chunks) {
904
+ chunk.copy(reqBuffer, i);
905
+ i += chunk.byteLength;
906
+ }
907
+ dataBuf = reqBuffer;
908
+ }
913
909
  if (dataBuf.byteLength === 0) {
914
910
  const opts = [];
915
- if (outputPath) {
916
- opts.push(`-o-:${outputPath}`);
911
+ if (output) {
912
+ opts.push(`-o-:${output}`);
917
913
  } else {
918
914
  opts.push("-o-");
919
915
  }
920
916
  dataBuf = await new Promise((resolve) => {
921
- _child_process.exec.call(void 0, `capnpc ${opts.join(" ")} ${sourcePath.join(" ")}`, {
917
+ _child_process.exec.call(void 0, `capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
922
918
  encoding: "buffer"
923
919
  }, (error, stdout, stderr) => {
924
920
  if (stderr.length > 0) {
@@ -945,8 +941,8 @@ async function capnpc(options) {
945
941
  filePath = fullPath;
946
942
  }
947
943
  }
948
- if (outputPath) {
949
- filePath = joinPaths(outputPath, fileName);
944
+ if (output) {
945
+ filePath = joinPaths(output, fileName);
950
946
  }
951
947
  if (!_fs.existsSync.call(void 0, findFilePath(filePath))) {
952
948
  await createDirectory(findFilePath(filePath));
package/dist/compile.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkPV3OG5H3cjs = require('./chunk-PV3OG5H3.cjs');
3
+ var _chunkWYA7EDMTcjs = require('./chunk-WYA7EDMT.cjs');
4
4
  require('./chunk-USNT2KNT.cjs');
5
5
 
6
6
 
7
- exports.capnpc = _chunkPV3OG5H3cjs.capnpc;
7
+ exports.capnpc = _chunkWYA7EDMTcjs.capnpc;
@@ -2,6 +2,12 @@ import { CapnpcOptions, CapnpcResult } from './types.cjs';
2
2
  import 'capnp-es/capnp/schema';
3
3
  import 'typescript';
4
4
 
5
+ /**
6
+ * Compiles Cap'n Proto schemas into TypeScript files.
7
+ *
8
+ * @param options - The options for the compilation process.
9
+ * @returns A promise that resolves to the compilation result.
10
+ */
5
11
  declare function capnpc(options: CapnpcOptions): Promise<CapnpcResult>;
6
12
 
7
13
  export { capnpc };
package/dist/compile.d.ts CHANGED
@@ -2,6 +2,12 @@ import { CapnpcOptions, CapnpcResult } from './types.js';
2
2
  import 'capnp-es/capnp/schema';
3
3
  import 'typescript';
4
4
 
5
+ /**
6
+ * Compiles Cap'n Proto schemas into TypeScript files.
7
+ *
8
+ * @param options - The options for the compilation process.
9
+ * @returns A promise that resolves to the compilation result.
10
+ */
5
11
  declare function capnpc(options: CapnpcOptions): Promise<CapnpcResult>;
6
12
 
7
13
  export { capnpc };
package/dist/compile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  capnpc
3
- } from "./chunk-LY3GWW4E.js";
3
+ } from "./chunk-BIIH7QKH.js";
4
4
  import "./chunk-SHUYVCID.js";
5
5
  export {
6
6
  capnpc
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkPV3OG5H3cjs = require('./chunk-PV3OG5H3.cjs');
3
+ var _chunkWYA7EDMTcjs = require('./chunk-WYA7EDMT.cjs');
4
4
  require('./chunk-USNT2KNT.cjs');
5
5
  require('./chunk-ORA4UQMU.cjs');
6
6
 
7
7
 
8
- exports.capnpc = _chunkPV3OG5H3cjs.capnpc;
8
+ exports.capnpc = _chunkWYA7EDMTcjs.capnpc;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  capnpc
3
- } from "./chunk-LY3GWW4E.js";
3
+ } from "./chunk-BIIH7QKH.js";
4
4
  import "./chunk-SHUYVCID.js";
5
5
  import "./chunk-OULCUN6I.js";
6
6
  export {
package/dist/types.d.cts CHANGED
@@ -16,18 +16,18 @@ interface CodeGeneratorContext {
16
16
  files: CodeGeneratorFileContext[];
17
17
  }
18
18
  interface CapnpcCLIOptions {
19
- ts: boolean;
20
- js: boolean;
21
- dts: boolean;
22
- sourcePath: string[];
23
- outputPath: string;
24
- importPath: string[];
25
- tsconfigPath: string;
26
- generateId: boolean;
27
- standardImport: boolean;
19
+ ts?: boolean;
20
+ js?: boolean;
21
+ dts?: boolean;
22
+ schema: string[];
23
+ output?: string;
24
+ importPath?: string[];
25
+ tsconfig: string;
26
+ generateId?: boolean;
27
+ standardImport?: boolean;
28
28
  }
29
- type CapnpcOptions = Omit<CapnpcCLIOptions, "tsconfigPath"> & {
30
- tsconfig?: ts.ParsedCommandLine;
29
+ type CapnpcOptions = Omit<CapnpcCLIOptions, "tsconfig"> & {
30
+ tsconfig: ts.ParsedCommandLine;
31
31
  };
32
32
  interface CapnpcResult {
33
33
  ctx: CodeGeneratorContext;
package/dist/types.d.ts CHANGED
@@ -16,18 +16,18 @@ interface CodeGeneratorContext {
16
16
  files: CodeGeneratorFileContext[];
17
17
  }
18
18
  interface CapnpcCLIOptions {
19
- ts: boolean;
20
- js: boolean;
21
- dts: boolean;
22
- sourcePath: string[];
23
- outputPath: string;
24
- importPath: string[];
25
- tsconfigPath: string;
26
- generateId: boolean;
27
- standardImport: boolean;
19
+ ts?: boolean;
20
+ js?: boolean;
21
+ dts?: boolean;
22
+ schema: string[];
23
+ output?: string;
24
+ importPath?: string[];
25
+ tsconfig: string;
26
+ generateId?: boolean;
27
+ standardImport?: boolean;
28
28
  }
29
- type CapnpcOptions = Omit<CapnpcCLIOptions, "tsconfigPath"> & {
30
- tsconfig?: ts.ParsedCommandLine;
29
+ type CapnpcOptions = Omit<CapnpcCLIOptions, "tsconfig"> & {
30
+ tsconfig: ts.ParsedCommandLine;
31
31
  };
32
32
  interface CapnpcResult {
33
33
  ctx: CodeGeneratorContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/capnp",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "A package to assist in running the Cap'n Proto compiler and creating Cap'n Proto serialization protocol schemas.",
6
6
  "repository": {