@fern-api/generator-cli 0.10.4 → 0.10.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +113 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -42811,8 +42811,8 @@ ${body}` : `${COMMIT_MARKER} ${subject}`;
42811
42811
  analysis: {
42812
42812
  versionBump: bestBump,
42813
42813
  message: bestMessage,
42814
- changelogEntry: changelogEntries.length > 0 ? changelogEntries.join("\n\n") : void 0,
42815
- prDescription: prDescriptions.length > 0 ? prDescriptions.join("\n\n") : void 0,
42814
+ changelogEntry: changelogEntries.length > 0 ? mergeMarkdownSections(changelogEntries) : void 0,
42815
+ prDescription: prDescriptions.length > 0 ? mergeMarkdownSections(prDescriptions) : void 0,
42816
42816
  versionBumpReason: bestVersionBumpReason
42817
42817
  },
42818
42818
  analysisWarning
@@ -42928,6 +42928,117 @@ function aggregateChunkAnalyses(chunkAnalyses) {
42928
42928
  }
42929
42929
  return { bestBump, bestMessage, bestVersionBumpReason, changelogEntries, usedBumpReasonAsEntry };
42930
42930
  }
42931
+ var MARKDOWN_HEADING = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
42932
+ var MARKDOWN_FENCE = /^\s*(`{3,}|~{3,})(.*)$/;
42933
+ var MARKDOWN_LIST_ITEM = /^\s*(?:[-*+]|\d+[.)])\s/;
42934
+ function parseMarkdownSections(text) {
42935
+ const sections = [];
42936
+ const stack = [];
42937
+ let intro = "";
42938
+ let current;
42939
+ let fence;
42940
+ let buffer = [];
42941
+ const closeBody = () => {
42942
+ const body = buffer.join("\n").trim();
42943
+ buffer = [];
42944
+ if (current != null) {
42945
+ current.body = body;
42946
+ } else {
42947
+ intro = body;
42948
+ }
42949
+ };
42950
+ for (const line of text.trim().split("\n")) {
42951
+ const fenceMatch = MARKDOWN_FENCE.exec(line);
42952
+ if (fenceMatch != null) {
42953
+ const marker = fenceMatch[1] ?? "";
42954
+ if (fence == null) {
42955
+ fence = marker;
42956
+ } else if (marker[0] === fence[0] && marker.length >= fence.length && (fenceMatch[2] ?? "").trim() === "") {
42957
+ fence = void 0;
42958
+ }
42959
+ }
42960
+ const match2 = fence == null ? MARKDOWN_HEADING.exec(line) : null;
42961
+ if (match2 == null) {
42962
+ buffer.push(line);
42963
+ continue;
42964
+ }
42965
+ closeBody();
42966
+ const level = match2[1]?.length ?? 1;
42967
+ const section = {
42968
+ heading: `${match2[1]} ${match2[2]?.trim()}`,
42969
+ level,
42970
+ body: "",
42971
+ children: []
42972
+ };
42973
+ while (stack.length > 0 && (stack[stack.length - 1]?.level ?? 0) >= level) {
42974
+ stack.pop();
42975
+ }
42976
+ const parent = stack[stack.length - 1];
42977
+ (parent != null ? parent.children : sections).push(section);
42978
+ stack.push(section);
42979
+ current = section;
42980
+ }
42981
+ closeBody();
42982
+ return { intro, sections };
42983
+ }
42984
+ function mergeParsedSections(target, parsed, intro) {
42985
+ parsed.forEach((section, index) => {
42986
+ const key = `${section.level} ${section.heading.toLowerCase().replace(/\s+/g, " ")}`;
42987
+ let node = target.get(key);
42988
+ if (node == null) {
42989
+ node = { heading: section.heading, bodies: [], children: /* @__PURE__ */ new Map() };
42990
+ target.set(key, node);
42991
+ }
42992
+ if (index === 0 && hasText(intro)) {
42993
+ node.bodies.push(intro);
42994
+ }
42995
+ if (section.body.length > 0) {
42996
+ node.bodies.push(section.body);
42997
+ }
42998
+ mergeParsedSections(node.children, section.children, "");
42999
+ });
43000
+ }
43001
+ function renderMergedSection(node) {
43002
+ return [
43003
+ node.heading,
43004
+ ...node.bodies.length > 0 ? [joinSectionBodies(node.bodies)] : [],
43005
+ ...[...node.children.values()].map(renderMergedSection)
43006
+ ].join("\n\n");
43007
+ }
43008
+ function mergeMarkdownSections(texts) {
43009
+ const order = [];
43010
+ const roots = /* @__PURE__ */ new Map();
43011
+ for (const text of texts) {
43012
+ const { intro, sections } = parseMarkdownSections(text);
43013
+ if (sections.length === 0) {
43014
+ if (hasText(intro)) {
43015
+ order.push(intro);
43016
+ }
43017
+ continue;
43018
+ }
43019
+ mergeParsedSections(roots, sections, intro);
43020
+ for (const node of roots.values()) {
43021
+ if (!order.includes(node)) {
43022
+ order.push(node);
43023
+ }
43024
+ }
43025
+ }
43026
+ return order.map((item) => typeof item === "string" ? item : renderMergedSection(item)).join("\n\n");
43027
+ }
43028
+ function joinSectionBodies(bodies) {
43029
+ let joined = "";
43030
+ for (const body of bodies) {
43031
+ if (joined.length === 0) {
43032
+ joined = body;
43033
+ continue;
43034
+ }
43035
+ const lastLine = joined.slice(joined.lastIndexOf("\n") + 1);
43036
+ const firstLine = body.slice(0, body.indexOf("\n") === -1 ? body.length : body.indexOf("\n"));
43037
+ const bothLists = MARKDOWN_LIST_ITEM.test(lastLine) && MARKDOWN_LIST_ITEM.test(firstLine);
43038
+ joined += `${bothLists ? "\n" : "\n\n"}${body}`;
43039
+ }
43040
+ return joined;
43041
+ }
42931
43042
  function hasText(value) {
42932
43043
  return value != null && value.trim().length > 0;
42933
43044
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fern-api/generator-cli",
3
- "version": "0.10.4",
3
+ "version": "0.10.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fern-api/fern.git",