@stryke/capnp 0.12.79 → 0.12.81

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
@@ -38,6 +38,7 @@ let typescript = require("typescript");
38
38
  typescript = __toESM(typescript);
39
39
  require("defu");
40
40
  let node_buffer = require("node:buffer");
41
+ let __stryke_fs = require("@stryke/fs");
41
42
  let __stryke_fs_json = require("@stryke/fs/json");
42
43
  let __stryke_fs_list_files = require("@stryke/fs/list-files");
43
44
 
@@ -86,6 +87,23 @@ var DEFAULT_COLOR_CONFIG = {
86
87
  ]
87
88
  }
88
89
  };
90
+ function getColors(config) {
91
+ if (!config?.colors || typeof config.colors !== "object" || !config.colors["dark"] && (!config.colors["base"] || typeof config.colors !== "object" || !config.colors["base"]?.["dark"])) return DEFAULT_COLOR_CONFIG;
92
+ if (config.colors["base"]) {
93
+ if (typeof config.colors["base"]["dark"] === "object") return config.colors["base"]["dark"];
94
+ else if (config.colors["base"]["dark"] === "string") return config.colors["base"];
95
+ }
96
+ if (typeof config.colors["dark"] === "object") return config.colors["dark"];
97
+ return config.colors ?? DEFAULT_COLOR_CONFIG;
98
+ }
99
+ function getColor(key, config) {
100
+ const colors = getColors(config);
101
+ const result = (typeof colors["dark"] === "object" ? colors["dark"][key] : colors[key]) || DEFAULT_COLOR_CONFIG["dark"][key] || DEFAULT_COLOR_CONFIG[key];
102
+ if (result) return result;
103
+ if (key === "link" || key === "debug") return getColor("info", config);
104
+ else if (key === "fatal") return getColor("danger", config);
105
+ return getColor("brand", config);
106
+ }
89
107
 
90
108
  //#endregion
91
109
  //#region ../../node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js
@@ -2911,6 +2929,7 @@ var _isFunction = (value) => {
2911
2929
  return false;
2912
2930
  }
2913
2931
  };
2932
+ var brandIcon = (config = {}, _chalk = getChalk()) => _chalk.hex(getColor("brand", config))("🗲");
2914
2933
 
2915
2934
  //#endregion
2916
2935
  //#region ../../node_modules/.pnpm/@storm-software+config-tools@1.189.21/node_modules/@storm-software/config-tools/dist/chunk-T4YVVO6G.js
@@ -11864,11 +11883,27 @@ function toArray(array) {
11864
11883
  */
11865
11884
  async function resolveOptions(options) {
11866
11885
  const tsconfigPath = options.tsconfigPath ? options.tsconfigPath.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "tsconfig.json");
11867
- const schemas = toArray(options.schemas ? options.schemas : (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "schemas/**/*.capnp")).filter(Boolean).map((schema) => schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot));
11886
+ const schemas = [];
11887
+ if (options.schemas) schemas.push(...toArray(options.schemas).filter(Boolean).map((schema) => schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot)).map((schema) => schema.includes("*") || schema.endsWith(".capnp") || (0, __stryke_fs_exists.existsSync)(schema) && (0, __stryke_fs_list_files.listSync)((0, __stryke_path_join_paths.joinPaths)(schema, "**/*.capnp")).length > 0 ? schema : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(options.projectRoot, schema)) && (0, __stryke_fs_list_files.listSync)((0, __stryke_path_join_paths.joinPaths)(options.projectRoot, schema, "**/*.capnp")).length > 0 ? (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, schema, "**/*.capnp") : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, schema)) && (0, __stryke_fs_list_files.listSync)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, schema, "**/*.capnp")).length > 0 ? (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, schema, "**/*.capnp") : schema));
11888
+ else schemas.push((0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "schemas/**/*.capnp")) && (0, __stryke_fs_list_files.listSync)((0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "schemas/**/*.capnp")).length > 0 ? (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "schemas/**/*.capnp") : (0, __stryke_fs_exists.existsSync)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "schemas/**/*.capnp")) && (0, __stryke_fs_list_files.listSync)((0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "schemas/**/*.capnp")).length > 0 ? (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "schemas/**/*.capnp") : "schemas/**/*.capnp");
11868
11889
  let resolvedTsconfig;
11869
11890
  if (options.tsconfig) resolvedTsconfig = options.tsconfig;
11870
11891
  else {
11871
- if (!tsconfigPath || !(0, __stryke_fs_exists.existsSync)(tsconfigPath)) {
11892
+ let resolvedTsconfigPath = tsconfigPath;
11893
+ if (!(0, __stryke_fs_exists.existsSync)(resolvedTsconfigPath)) {
11894
+ const found = [
11895
+ (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "tsconfig.json"),
11896
+ (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "tsconfig.lib.json"),
11897
+ (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "tsconfig.app.json"),
11898
+ (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, "tsconfig.capnp.json"),
11899
+ (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "tsconfig.json"),
11900
+ (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "tsconfig.lib.json"),
11901
+ (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "tsconfig.app.json"),
11902
+ (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, "tsconfig.capnp.json")
11903
+ ].find((path$1) => (0, __stryke_fs_exists.existsSync)(path$1));
11904
+ if (found) resolvedTsconfigPath = found;
11905
+ }
11906
+ if (!resolvedTsconfigPath || !(0, __stryke_fs_exists.existsSync)(resolvedTsconfigPath)) {
11872
11907
  const errorMessage = tsconfigPath ? `✖ The specified TypeScript configuration file "${tsconfigPath}" does not exist. Please provide a valid path.` : "✖ The specified TypeScript configuration file does not exist. Please provide a valid path.";
11873
11908
  writeFatal(errorMessage, { logLevel: "all" });
11874
11909
  throw new Error(errorMessage);
@@ -11895,6 +11930,15 @@ async function resolveOptions(options) {
11895
11930
  return null;
11896
11931
  }
11897
11932
  const output = options.output ? options.output.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : (0, __stryke_path_join_paths.joinPaths)(options.projectRoot, (0, __stryke_path_file_path_fns.relativePath)(tsconfigPath ? (0, __stryke_path_file_path_fns.findFilePath)(tsconfigPath) : options.projectRoot, (0, __stryke_path_join_paths.joinPaths)(options.workspaceRoot, resolvedSchemas[0].endsWith(".capnp") ? (0, __stryke_path_file_path_fns.findFilePath)(resolvedSchemas[0]) : resolvedSchemas[0])));
11933
+ if (!(0, __stryke_fs_exists.existsSync)(output)) {
11934
+ if ((0, __stryke_fs.isFile)(output)) {
11935
+ const errorMessage = `✖ The specified output path "${output}" is a file. Please provide a valid directory path.`;
11936
+ writeFatal(errorMessage, { logLevel: "all" });
11937
+ throw new Error(errorMessage);
11938
+ }
11939
+ writeInfo(`Output directory "${output}" does not exist. It will be created automatically.`, { logLevel: "all" });
11940
+ await (0, __stryke_fs.createDirectory)(output);
11941
+ }
11898
11942
  resolvedTsconfig.options.outDir = output;
11899
11943
  return {
11900
11944
  ...options,
@@ -11975,13 +12019,13 @@ const compileAction = (workspaceRoot) => async (options) => {
11975
12019
  writeWarning("✖ Unable to resolve Cap'n Proto compiler options - the program will terminate", { logLevel: "all" });
11976
12020
  return;
11977
12021
  }
11978
- writeInfo(`📦 Storm Cap'n Proto Compiler will output ${resolvedOptions.ts ? "TypeScript code" : ""}${resolvedOptions.js ? resolvedOptions.ts ? ", JavaScript code" : "JavaScript code" : ""}${resolvedOptions.dts ? resolvedOptions.ts || resolvedOptions.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${options.schema ? options.schema.replace("{projectRoot}", resolvedOptions.projectRoot).replace("{workspaceRoot}", resolvedOptions.workspaceRoot) : resolvedOptions.projectRoot} to ${resolvedOptions.tsconfig.options.outDir}...`, { logLevel: "all" });
12022
+ writeInfo(`Storm Cap'n Proto Compiler will output ${resolvedOptions.ts ? "TypeScript code" : ""}${resolvedOptions.js ? resolvedOptions.ts ? ", JavaScript code" : "JavaScript code" : ""}${resolvedOptions.dts ? resolvedOptions.ts || resolvedOptions.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${options.schema ? options.schema.replace("{projectRoot}", resolvedOptions.projectRoot).replace("{workspaceRoot}", resolvedOptions.workspaceRoot) : resolvedOptions.projectRoot} to ${resolvedOptions.tsconfig.options.outDir}...`, { logLevel: "all" });
11979
12023
  const result = await capnpc(resolvedOptions);
11980
12024
  if (result.files.size === 0) {
11981
- writeWarning("⚠️ No files were generated. Please check your schema files.", { logLevel: "all" });
12025
+ writeWarning("No files were generated. Please check your schema files.", { logLevel: "all" });
11982
12026
  return;
11983
12027
  }
11984
- writeInfo(`📋 Writing ${result.files.size} generated files to disk...`, { logLevel: "all" });
12028
+ writeInfo(`Writing ${result.files.size} generated files to disk...`, { logLevel: "all" });
11985
12029
  for (const [fileName, content] of result.files) {
11986
12030
  let filePath = fileName;
11987
12031
  if (!(0, __stryke_fs_exists.existsSync)((0, __stryke_path_file_path_fns.findFilePath)(filePath))) {
@@ -11994,10 +12038,10 @@ const compileAction = (workspaceRoot) => async (options) => {
11994
12038
  }
11995
12039
  await (0, node_fs_promises.writeFile)(filePath, content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2)));
11996
12040
  }
11997
- writeSuccess("⚡ Storm Cap'n Proto Compiler completed successfully.", { logLevel: "all" });
12041
+ writeSuccess(`✔ Storm Cap'n Proto Compiler completed successfully.`, { logLevel: "all" });
11998
12042
  };
11999
12043
  function createProgram() {
12000
- writeInfo("⚡ Running Storm Cap'n Proto Compiler Tools", { logLevel: "all" });
12044
+ writeInfo(`${brandIcon()} Running Storm Cap'n Proto Compiler Tools`, { logLevel: "all" });
12001
12045
  const root = findWorkspaceRootSafe(process.cwd());
12002
12046
  process.env.STORM_WORKSPACE_ROOT ??= root;
12003
12047
  process.env.NX_WORKSPACE_ROOT_PATH ??= root;
@@ -1 +1 @@
1
- {"version":3,"file":"capnpc.d.cts","names":[],"sources":["../../bin/capnpc.ts"],"sourcesContent":[],"mappings":";;;;iBA0IgB,aAAA,CAAA,GAAa"}
1
+ {"version":3,"file":"capnpc.d.cts","names":[],"sources":["../../bin/capnpc.ts"],"sourcesContent":[],"mappings":";;;;iBAwIgB,aAAA,CAAA,GAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"capnpc.d.mts","names":[],"sources":["../../bin/capnpc.ts"],"sourcesContent":[],"mappings":";;;;iBA0IgB,aAAA,CAAA,GAAa"}
1
+ {"version":3,"file":"capnpc.d.mts","names":[],"sources":["../../bin/capnpc.ts"],"sourcesContent":[],"mappings":";;;;iBAwIgB,aAAA,CAAA,GAAa"}
package/bin/capnpc.mjs CHANGED
@@ -10,8 +10,9 @@ import { joinPaths } from "@stryke/path/join-paths";
10
10
  import ts, { parseJsonConfigFileContent, sys } from "typescript";
11
11
  import "defu";
12
12
  import { Buffer as Buffer$1 } from "node:buffer";
13
+ import { createDirectory, isFile } from "@stryke/fs";
13
14
  import { readJsonFile } from "@stryke/fs/json";
14
- import { listFiles } from "@stryke/fs/list-files";
15
+ import { listFiles, listSync } from "@stryke/fs/list-files";
15
16
 
16
17
  //#region rolldown:runtime
17
18
  var __create = Object.create;
@@ -87,6 +88,23 @@ var DEFAULT_COLOR_CONFIG = {
87
88
  ]
88
89
  }
89
90
  };
91
+ function getColors(config) {
92
+ if (!config?.colors || typeof config.colors !== "object" || !config.colors["dark"] && (!config.colors["base"] || typeof config.colors !== "object" || !config.colors["base"]?.["dark"])) return DEFAULT_COLOR_CONFIG;
93
+ if (config.colors["base"]) {
94
+ if (typeof config.colors["base"]["dark"] === "object") return config.colors["base"]["dark"];
95
+ else if (config.colors["base"]["dark"] === "string") return config.colors["base"];
96
+ }
97
+ if (typeof config.colors["dark"] === "object") return config.colors["dark"];
98
+ return config.colors ?? DEFAULT_COLOR_CONFIG;
99
+ }
100
+ function getColor(key, config) {
101
+ const colors = getColors(config);
102
+ const result = (typeof colors["dark"] === "object" ? colors["dark"][key] : colors[key]) || DEFAULT_COLOR_CONFIG["dark"][key] || DEFAULT_COLOR_CONFIG[key];
103
+ if (result) return result;
104
+ if (key === "link" || key === "debug") return getColor("info", config);
105
+ else if (key === "fatal") return getColor("danger", config);
106
+ return getColor("brand", config);
107
+ }
90
108
 
91
109
  //#endregion
92
110
  //#region ../../node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js
@@ -2912,6 +2930,7 @@ var _isFunction = (value) => {
2912
2930
  return false;
2913
2931
  }
2914
2932
  };
2933
+ var brandIcon = (config = {}, _chalk = getChalk()) => _chalk.hex(getColor("brand", config))("🗲");
2915
2934
 
2916
2935
  //#endregion
2917
2936
  //#region ../../node_modules/.pnpm/@storm-software+config-tools@1.189.21/node_modules/@storm-software/config-tools/dist/chunk-T4YVVO6G.js
@@ -11865,11 +11884,27 @@ function toArray(array) {
11865
11884
  */
11866
11885
  async function resolveOptions(options) {
11867
11886
  const tsconfigPath = options.tsconfigPath ? options.tsconfigPath.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : joinPaths(options.projectRoot, "tsconfig.json");
11868
- const schemas = toArray(options.schemas ? options.schemas : joinPaths(options.projectRoot, "schemas/**/*.capnp")).filter(Boolean).map((schema) => schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot));
11887
+ const schemas = [];
11888
+ if (options.schemas) schemas.push(...toArray(options.schemas).filter(Boolean).map((schema) => schema.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot)).map((schema) => schema.includes("*") || schema.endsWith(".capnp") || existsSync$1(schema) && listSync(joinPaths(schema, "**/*.capnp")).length > 0 ? schema : existsSync$1(joinPaths(options.projectRoot, schema)) && listSync(joinPaths(options.projectRoot, schema, "**/*.capnp")).length > 0 ? joinPaths(options.projectRoot, schema, "**/*.capnp") : existsSync$1(joinPaths(options.workspaceRoot, schema)) && listSync(joinPaths(options.workspaceRoot, schema, "**/*.capnp")).length > 0 ? joinPaths(options.workspaceRoot, schema, "**/*.capnp") : schema));
11889
+ else schemas.push(existsSync$1(joinPaths(options.projectRoot, "schemas/**/*.capnp")) && listSync(joinPaths(options.projectRoot, "schemas/**/*.capnp")).length > 0 ? joinPaths(options.projectRoot, "schemas/**/*.capnp") : existsSync$1(joinPaths(options.workspaceRoot, "schemas/**/*.capnp")) && listSync(joinPaths(options.workspaceRoot, "schemas/**/*.capnp")).length > 0 ? joinPaths(options.workspaceRoot, "schemas/**/*.capnp") : "schemas/**/*.capnp");
11869
11890
  let resolvedTsconfig;
11870
11891
  if (options.tsconfig) resolvedTsconfig = options.tsconfig;
11871
11892
  else {
11872
- if (!tsconfigPath || !existsSync$1(tsconfigPath)) {
11893
+ let resolvedTsconfigPath = tsconfigPath;
11894
+ if (!existsSync$1(resolvedTsconfigPath)) {
11895
+ const found = [
11896
+ joinPaths(options.projectRoot, "tsconfig.json"),
11897
+ joinPaths(options.projectRoot, "tsconfig.lib.json"),
11898
+ joinPaths(options.projectRoot, "tsconfig.app.json"),
11899
+ joinPaths(options.projectRoot, "tsconfig.capnp.json"),
11900
+ joinPaths(options.workspaceRoot, "tsconfig.json"),
11901
+ joinPaths(options.workspaceRoot, "tsconfig.lib.json"),
11902
+ joinPaths(options.workspaceRoot, "tsconfig.app.json"),
11903
+ joinPaths(options.workspaceRoot, "tsconfig.capnp.json")
11904
+ ].find((path$1) => existsSync$1(path$1));
11905
+ if (found) resolvedTsconfigPath = found;
11906
+ }
11907
+ if (!resolvedTsconfigPath || !existsSync$1(resolvedTsconfigPath)) {
11873
11908
  const errorMessage = tsconfigPath ? `✖ The specified TypeScript configuration file "${tsconfigPath}" does not exist. Please provide a valid path.` : "✖ The specified TypeScript configuration file does not exist. Please provide a valid path.";
11874
11909
  writeFatal(errorMessage, { logLevel: "all" });
11875
11910
  throw new Error(errorMessage);
@@ -11896,6 +11931,15 @@ async function resolveOptions(options) {
11896
11931
  return null;
11897
11932
  }
11898
11933
  const output = options.output ? options.output.replace("{projectRoot}", options.projectRoot).replace("{workspaceRoot}", options.workspaceRoot) : joinPaths(options.projectRoot, relativePath(tsconfigPath ? findFilePath(tsconfigPath) : options.projectRoot, joinPaths(options.workspaceRoot, resolvedSchemas[0].endsWith(".capnp") ? findFilePath(resolvedSchemas[0]) : resolvedSchemas[0])));
11934
+ if (!existsSync$1(output)) {
11935
+ if (isFile(output)) {
11936
+ const errorMessage = `✖ The specified output path "${output}" is a file. Please provide a valid directory path.`;
11937
+ writeFatal(errorMessage, { logLevel: "all" });
11938
+ throw new Error(errorMessage);
11939
+ }
11940
+ writeInfo(`Output directory "${output}" does not exist. It will be created automatically.`, { logLevel: "all" });
11941
+ await createDirectory(output);
11942
+ }
11899
11943
  resolvedTsconfig.options.outDir = output;
11900
11944
  return {
11901
11945
  ...options,
@@ -11976,13 +12020,13 @@ const compileAction = (workspaceRoot) => async (options) => {
11976
12020
  writeWarning("✖ Unable to resolve Cap'n Proto compiler options - the program will terminate", { logLevel: "all" });
11977
12021
  return;
11978
12022
  }
11979
- writeInfo(`📦 Storm Cap'n Proto Compiler will output ${resolvedOptions.ts ? "TypeScript code" : ""}${resolvedOptions.js ? resolvedOptions.ts ? ", JavaScript code" : "JavaScript code" : ""}${resolvedOptions.dts ? resolvedOptions.ts || resolvedOptions.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${options.schema ? options.schema.replace("{projectRoot}", resolvedOptions.projectRoot).replace("{workspaceRoot}", resolvedOptions.workspaceRoot) : resolvedOptions.projectRoot} to ${resolvedOptions.tsconfig.options.outDir}...`, { logLevel: "all" });
12023
+ writeInfo(`Storm Cap'n Proto Compiler will output ${resolvedOptions.ts ? "TypeScript code" : ""}${resolvedOptions.js ? resolvedOptions.ts ? ", JavaScript code" : "JavaScript code" : ""}${resolvedOptions.dts ? resolvedOptions.ts || resolvedOptions.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${options.schema ? options.schema.replace("{projectRoot}", resolvedOptions.projectRoot).replace("{workspaceRoot}", resolvedOptions.workspaceRoot) : resolvedOptions.projectRoot} to ${resolvedOptions.tsconfig.options.outDir}...`, { logLevel: "all" });
11980
12024
  const result = await capnpc(resolvedOptions);
11981
12025
  if (result.files.size === 0) {
11982
- writeWarning("⚠️ No files were generated. Please check your schema files.", { logLevel: "all" });
12026
+ writeWarning("No files were generated. Please check your schema files.", { logLevel: "all" });
11983
12027
  return;
11984
12028
  }
11985
- writeInfo(`📋 Writing ${result.files.size} generated files to disk...`, { logLevel: "all" });
12029
+ writeInfo(`Writing ${result.files.size} generated files to disk...`, { logLevel: "all" });
11986
12030
  for (const [fileName, content] of result.files) {
11987
12031
  let filePath = fileName;
11988
12032
  if (!existsSync$1(findFilePath(filePath))) {
@@ -11995,10 +12039,10 @@ const compileAction = (workspaceRoot) => async (options) => {
11995
12039
  }
11996
12040
  await writeFile(filePath, content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2)));
11997
12041
  }
11998
- writeSuccess("⚡ Storm Cap'n Proto Compiler completed successfully.", { logLevel: "all" });
12042
+ writeSuccess(`✔ Storm Cap'n Proto Compiler completed successfully.`, { logLevel: "all" });
11999
12043
  };
12000
12044
  function createProgram() {
12001
- writeInfo("⚡ Running Storm Cap'n Proto Compiler Tools", { logLevel: "all" });
12045
+ writeInfo(`${brandIcon()} Running Storm Cap'n Proto Compiler Tools`, { logLevel: "all" });
12002
12046
  const root = findWorkspaceRootSafe(process.cwd());
12003
12047
  process.env.STORM_WORKSPACE_ROOT ??= root;
12004
12048
  process.env.NX_WORKSPACE_ROOT_PATH ??= root;