@fern-api/generator-cli 0.10.4 → 0.11.0

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