ai-ops-cli 1.0.2 → 1.0.3

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/dist/bin/index.js CHANGED
@@ -866,14 +866,45 @@ var parseProjectLayerDocument = (path, rawContent) => {
866
866
  content
867
867
  };
868
868
  };
869
+ var parseMarkdownTableCells = (line) => {
870
+ const trimmed = line.trim();
871
+ if (!trimmed.startsWith("|") || !trimmed.endsWith("|")) {
872
+ return null;
873
+ }
874
+ return trimmed.slice(1, -1).split("|").map((cell) => cell.trim());
875
+ };
876
+ var isDocsStatusHeaderLine = (line) => {
877
+ const cells = parseMarkdownTableCells(line);
878
+ return cells !== null && cells.length === 3 && cells[0] === "path" && cells[1] === "status" && cells[2] === "owner";
879
+ };
880
+ var isMarkdownDividerCell = (cell) => /^:?-{3,}:?$/.test(cell);
881
+ var isDocsStatusDividerLine = (line) => {
882
+ const cells = parseMarkdownTableCells(line);
883
+ return cells !== null && cells.length === 3 && cells.every(isMarkdownDividerCell);
884
+ };
885
+ var findDocsStatusTableBounds = (lines) => {
886
+ const headerIndex = lines.findIndex(isDocsStatusHeaderLine);
887
+ const dividerIndex = headerIndex + 1;
888
+ if (headerIndex < 0 || !isDocsStatusDividerLine(lines[dividerIndex] ?? "")) {
889
+ return null;
890
+ }
891
+ let tableEndIndex = dividerIndex + 1;
892
+ while (tableEndIndex < lines.length && parseMarkdownTableCells(lines[tableEndIndex] ?? "") !== null) {
893
+ tableEndIndex += 1;
894
+ }
895
+ return { headerIndex, dividerIndex, tableEndIndex };
896
+ };
869
897
  var parseDocsStatusEntries = (content) => {
870
898
  const document = parseProjectLayerDocument("docs/docs-status.md", content);
871
- const rows = document.content.split("\n").filter((line) => line.trim().startsWith("|")).map((line) => line.trim());
899
+ const lines = document.content.split("\n");
900
+ const tableBounds = findDocsStatusTableBounds(lines);
901
+ if (tableBounds === null) {
902
+ return [];
903
+ }
904
+ const rows = lines.slice(tableBounds.dividerIndex + 1, tableBounds.tableEndIndex);
872
905
  return rows.flatMap((line) => {
873
- const cells = line.split("|").map((cell) => cell.trim()).filter((cell) => cell.length > 0);
874
- if (cells.length < 3) return [];
875
- if (cells[0] === "path") return [];
876
- if (cells[0].startsWith("---")) return [];
906
+ const cells = parseMarkdownTableCells(line);
907
+ if (cells === null || cells.length < 3) return [];
877
908
  return [
878
909
  {
879
910
  path: cells[0],
@@ -1050,16 +1081,11 @@ var buildDocsStatusRowsFromDisk = (params) => params.documentPaths.map((path) =>
1050
1081
  });
1051
1082
  var replaceDocsStatusRows = (content, rows) => {
1052
1083
  const lines = content.trimEnd().split("\n");
1053
- const headerIndex = lines.findIndex((line) => line.trim() === "| path | status | owner |");
1054
- const dividerIndex = headerIndex + 1;
1055
- if (headerIndex < 0 || !lines[dividerIndex]?.trim().startsWith("| ---")) {
1084
+ const tableBounds = findDocsStatusTableBounds(lines);
1085
+ if (tableBounds === null) {
1056
1086
  throw new Error("docs/docs-status.md table header not found");
1057
1087
  }
1058
- let tableEndIndex = dividerIndex + 1;
1059
- while (tableEndIndex < lines.length && lines[tableEndIndex]?.trim().startsWith("|")) {
1060
- tableEndIndex += 1;
1061
- }
1062
- return [...lines.slice(0, dividerIndex + 1), ...rows, ...lines.slice(tableEndIndex)].join("\n") + "\n";
1088
+ return [...lines.slice(0, tableBounds.dividerIndex + 1), ...rows, ...lines.slice(tableBounds.tableEndIndex)].join("\n") + "\n";
1063
1089
  };
1064
1090
  var updateDocsStatusTable = (basePath, documentPaths) => {
1065
1091
  const docsStatusPath = "docs/docs-status.md";