import fs from "node:fs";
import path from "node:path";

export const PACKAGE_ROOT = path.resolve(import.meta.dirname, "..");

export const ERP_KIT_PACKAGE_NAME = "@tailor-platform/erp-kit";

export function toErrorMessage(err: unknown): string {
  return err instanceof Error ? err.message : String(err);
}

export function readErpKitVersion(): string {
  const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf-8")) as {
    version: string;
  };
  return pkg.version;
}
