All files / src load-sprints.ts

82.22% Statements 37/45
47.82% Branches 11/23
100% Functions 8/8
82.22% Lines 37/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x     2x 2x 2x     2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x  
import * as fs from "node:fs"
import * as path from "node:path"
 
import { parseFrontmatterRecord, parseStringList } from "./load-frontmatter.js"
import { sortByIdAsc } from "./domain/sort-by-id.js"
 
export type SprintSummary = {
  id: string
  title: string
  version: string
  status: string
  goal: string
  doneWhen: string
  storyIds: string[]
}
 
export function loadSprintSummaries(docsRoot: string): SprintSummary[] {
  const dir = path.join(docsRoot, "sprints")
  if (!fs.existsSync(dir)) {
    return []
  }
  const out: SprintSummary[] = []
  for (const name of fs.readdirSync(dir)) {
    if (!name.endsWith(".md")) {
      continue
    }
    const raw = fs.readFileSync(path.join(dir, name), "utf-8")
    const record = parseFrontmatterRecord(raw)
    if (!record) {
      continue
    }
    const id = typeof record.id === "string" ? record.id : name.replace(/\.md$/i, "")
    const title = typeof record.title === "string" ? record.title : id
    const version = typeof record.version === "string" ? record.version : ""
    const status = typeof record.status === "string" ? record.status : "planned"
    const goal = typeof record.goal === "string" ? record.goal : ""
    const doneWhen = typeof record.done_when === "string" ? record.done_when : ""
    const storyIds = parseStringList(record.stories)
    if (!version) {
      continue
    }
    out.push({ id, title, version, status, goal, doneWhen, storyIds })
  }
  return sortByIdAsc(out)
}