bau/nimble

Converts Nimble project files into Bau configuration.

Types

ConvertDiagnostic = object
  severity*: ConvertSeverity ## Diagnostic severity.
  line*: int                 ## Source line number, or zero when not tied to a line.
  message*: string           ## Human-readable diagnostic message.
Diagnostic produced while converting Nimble data.
ConvertSeverity = enum
  csInfo = "info",          ## Informational conversion note.
  csWarning = "warning"      ## Conversion warning that may need review.
Severity for Nimble conversion diagnostics.
NimbleConvertResult = object
  nimblePath*: string        ## Converted `.nimble` file path.
  configPath*: string        ## Target `bau.toml` path.
  cfg*: BauConfig            ## Converted Bau configuration.
  content*: string           ## Generated `bau.toml` content.
  diagnostics*: seq[ConvertDiagnostic] ## Diagnostics emitted during conversion.
  wrote*: bool               ## True when `content` was written to disk.
Result of converting a Nimble project.
NimbleProject = object
  nimblePath*: string        ## Absolute path to the parsed `.nimble` file.
  projectDir*: string        ## Project directory containing the `.nimble` file.
  packageName*: string       ## Inferred or declared package name.
  version*: string           ## Package version.
  authors*: seq[string]      ## Package authors.
  description*: string       ## Package description.
  license*: string           ## Package license.
  nimRequirement*: string    ## Nim version requirement.
  srcDir*: string            ## Nimble `srcDir` value.
  binDir*: string            ## Nimble `binDir` value.
  backend*: string           ## Compiler backend requested by Nimble metadata.
  bins*: seq[string]         ## Binary names declared by `bin`.
  namedBins*: Table[string, string] ## Binary names mapped to explicit source paths.
  skipDirs*: seq[string]     ## Nimble package directories to exclude.
  skipFiles*: seq[string]    ## Nimble package files to exclude.
  skipExt*: seq[string]      ## Nimble package extensions to exclude.
  installDirs*: seq[string]  ## Nimble package directories to include.
  installFiles*: seq[string] ## Nimble package files to include.
  installExt*: seq[string]   ## Nimble package extensions to include.
  deps*: Table[string, DepInfo] ## Dependencies parsed from `requires`.
  features*: Table[string, FeatureInfo] ## Features parsed from Nimble feature blocks.
  tasks*: seq[TaskInfo]      ## Tasks converted from Nimble task blocks.
  scripts*: ScriptInfo       ## Lifecycle hooks converted from Nimble hooks.
  diagnostics*: seq[ConvertDiagnostic] ## Conversion diagnostics.
Static facts extracted from a .nimble file.

Procs

proc bauTomlContent(cfg: BauConfig): string {....raises: [KeyError], tags: [],
    forbids: [].}
Render a Bau configuration as TOML generated by bau convert.
proc convertNimbleProject(projectDir: string = getCurrentDir();
                          nimblePath: string = ""; write = true; force = false): NimbleConvertResult {.
    ...raises: [ValueError, OSError, IOError, KeyError],
    tags: [ReadDirEffect, ReadIOEffect, WriteDirEffect, WriteIOEffect],
    forbids: [].}
Convert a Nimble project to Bau configuration and optionally write it.
proc convertResultJson(conversion: NimbleConvertResult): JsonNode {....raises: [],
    tags: [], forbids: [].}
Convert a Nimble conversion result to JSON.
proc findNimbleFile(projectDir: string; explicitPath = ""): string {.
    ...raises: [ValueError, OSError, IOError], tags: [ReadDirEffect], forbids: [].}

Locate the .nimble file to convert.

Raises when no file is found or multiple candidates require disambiguation.

proc findProjectConfig(startDir: string = getCurrentDir()): BauConfig {.
    ...raises: [ValueError, OSError, Exception, TomlError, KeyError],
    tags: [ReadDirEffect, ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].}
Find a Bau config, or fall back to parsing a nearby .nimble file.
proc parseNimbleFile(path: string): Option[BauConfig] {....raises: [],
    tags: [ReadDirEffect, ReadIOEffect], forbids: [].}
Parse a .nimble file into Bau config, returning none on failure.
proc parseNimbleProject(path: string): NimbleProject {.
    ...raises: [IOError, ValueError, OSError, KeyError],
    tags: [ReadDirEffect, ReadIOEffect], forbids: [].}

Parse static Nimble metadata from a .nimble file.

Dynamic NimScript control flow is skipped with warnings.

proc toBauConfig(project: var NimbleProject): BauConfig {....raises: [KeyError],
    tags: [ReadDirEffect], forbids: [].}
Convert parsed Nimble project metadata into a Bau configuration.