#!/usr/bin/env node
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/changelog-formatter.ts
var changelog_formatter_exports = {};
__export(changelog_formatter_exports, {
  default: () => changelog_formatter_default
});
module.exports = __toCommonJS(changelog_formatter_exports);
var typeMap = {
  build: "Build System",
  chore: "Miscellaneous Chores",
  ci: "Continuous Integration",
  docs: "Documentation",
  feat: "Features",
  fix: "Bug Fixes",
  perf: "Performance Improvements",
  refactor: "Code Refactoring",
  style: "Styles",
  styles: "Styles",
  test: "Tests"
};
var changelogFunctions = {
  getDependencyReleaseLine: (_changesets, dependenciesUpdated, options) => {
    if (!options.repo) {
      throw new Error(
        'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]'
      );
    }
    if (dependenciesUpdated.length === 0) {
      return "";
    }
    const deps = dependenciesUpdated.map((d) => d.name).join(", ");
    return `### Miscellaneous Chores
* **deps:** update dependencies [${deps}]`;
  },
  getReleaseLine: (changeset, _type, options) => {
    if (!options?.repo) {
      throw new Error(
        'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]'
      );
    }
    let commitFromSummary;
    const cleanedSummary = changeset.summary.split("\n").filter((line2) => !line2.trim().toLowerCase().startsWith("signed-off-by:")).join("\n").replace(/^\s*commit:\s*([^\s]+)/im, (_, commit2) => {
      commitFromSummary = commit2;
      return "";
    }).trim();
    const prMatch = cleanedSummary.match(/\(#(\d+)\)/);
    const prNumber = prMatch?.[1];
    const typeMatch = cleanedSummary.match(
      /^(feat|fix|refactor|chore|perf|test|docs|styles?|ci|build)\s*(\(.+?\))?!?:\s*/i
    );
    const conventionalType = typeMatch?.[1]?.toLowerCase();
    const scope = typeMatch?.[2]?.replace("(", "").replace(")", "");
    const isBreaking = cleanedSummary.includes("!:") || cleanedSummary.toLowerCase().includes("breaking");
    const summary = cleanedSummary.replace(
      /^(feat|fix|refactor|chore|perf|test|docs|styles?|ci|build)\s*(\(.+?\))?!?:\s*/i,
      ""
    ).replace(/\s*\(#\d+\)\s*$/, "").trim();
    const section = isBreaking ? "BREAKING CHANGES" : typeMap[conventionalType ?? ""] || "Miscellaneous";
    let line = `### ${section}
* ${scope ? `[${scope}]: ` : ""}${summary}`;
    if (prNumber) {
      line += ` ([#${prNumber}](${options.repo}/issues/${prNumber}))`;
    }
    const commit = commitFromSummary || changeset.commit;
    if (commit) {
      const shortCommit = commit.slice(0, 7);
      line += ` ([${shortCommit}](${options.repo}/commit/${commit}))`;
    }
    return line;
  }
};
var changelog_formatter_default = changelogFunctions;
//# sourceMappingURL=changelog-formatter.cjs.map
