markdown_parser/build.nim
Bruno Charest 18ee8a1cfd feat: Add report generation module for tracking metadata changes
- Implemented `report.nim` to create structured reports on metadata modifications.
- Added functionality to merge reports and convert them to formatted strings.

docs: Create prompt documentation for Markdown parser project

- Added `prompt.md` detailing the requirements and functionalities for the Markdown parser.
- Included specifications, usage examples, and testing guidelines.

docs: Generate code review report for Markdown parser

- Created `rapport_revue_code.md` outlining security vulnerabilities, code quality issues, and suggested improvements.
- Provided a detailed analysis of the codebase with actionable recommendations.

test: Add test data for Markdown parser

- Included various Markdown files and a JPG image in `test_data` to simulate different scenarios.
- Ensured that the parser can handle both valid and invalid metadata.

chore: Add version management file

- Created `version.nim` for automatic versioning of the Markdown parser.
- Established constants for major, minor, patch, and build versions.
2026-04-19 12:56:55 -04:00

149 lines
4.4 KiB
Nim

# build.nim
# Script de compilation pour markdown_parser
# Usage: nim c -r build.nim [major|minor|patch|build]
import std/[os, strutils, strformat, osproc, times]
type
VersionType = enum
vtMajor, vtMinor, vtPatch, vtBuild
proc getCurrentVersion(): tuple[major, minor, patch, build: int] =
## Récupère la version actuelle depuis le fichier version.nim
let versionContent = readFile("version.nim")
var major, minor, patch, build: int
for line in versionContent.splitLines():
if line.startsWith(" VERSION_MAJOR*"):
major = parseInt(line.split("=")[1].strip())
elif line.startsWith(" VERSION_MINOR*"):
minor = parseInt(line.split("=")[1].strip())
elif line.startsWith(" VERSION_PATCH*"):
patch = parseInt(line.split("=")[1].strip())
elif line.startsWith(" VERSION_BUILD*"):
let parts = line.split("=")[1].strip().split("#")[0].strip()
build = parseInt(parts)
return (major: major, minor: minor, patch: patch, build: build)
proc incrementVersion(versionType: VersionType) =
## Incrémente la partie spécifiée de la version
var version = getCurrentVersion()
case versionType
of vtMajor:
version.major += 1
version.minor = 0
version.patch = 0
version.build = 1
of vtMinor:
version.minor += 1
version.patch = 0
version.build = 1
of vtPatch:
version.patch += 1
version.build = 1
of vtBuild:
version.build += 1
# Mettre à jour le fichier version.nim
let newContent = fmt"""# version.nim
# Fichier de gestion de version automatique pour le parser Markdown
# Dernière mise à jour: {now().format("yyyy-MM-dd HH:mm:ss")}
const
VERSION_MAJOR* = {version.major}
VERSION_MINOR* = {version.minor}
VERSION_PATCH* = {version.patch}
VERSION_BUILD* = {version.build} # Sera incrémenté automatiquement par le script de build
VERSION_STRING* = $VERSION_MAJOR & "." & $VERSION_MINOR & "." & $VERSION_PATCH & "." & $VERSION_BUILD"""
writeFile("version.nim", newContent)
echo fmt"Version mise à jour: {version.major}.{version.minor}.{version.patch}.{version.build}"
proc createBinDirectory(version: tuple[major, minor, patch, build: int]): string =
## Crée le répertoire bin/<version>/ s'il n'existe pas
let versionStr = fmt"{version.major}.{version.minor}.{version.patch}.{version.build}"
let binDir = "bin" / versionStr
if not dirExists("bin"):
createDir("bin")
if not dirExists(binDir):
createDir(binDir)
return binDir
proc buildExecutable(binDir: string) =
## Compile l'exécutable en mode release et le place dans le répertoire bin
echo "Compilation de markdown_parser en mode release..."
let compileResult = execCmd("nim c -d:release markdown_parser.nim")
if compileResult != 0:
echo "Erreur lors de la compilation!"
quit(1)
# Copier l'exécutable dans le répertoire bin
let exeName = if defined(windows): "markdown_parser.exe" else: "markdown_parser"
try:
copyFile(exeName, binDir / exeName)
echo fmt"Exécutable copié dans {binDir}"
except:
echo "Erreur lors de la copie de l'exécutable!"
quit(1)
proc showHelp() =
echo """
Script de build pour markdown_parser
Usage:
nim c -r build.nim [command]
Commands:
major - Incrémente la version majeure, réinitialise mineure et patch
minor - Incrémente la version mineure, réinitialise patch
patch - Incrémente la version patch
build - Incrémente uniquement le numéro de build (défaut)
help - Affiche ce message d'aide
"""
proc main() =
# Récupérer le type d'incrémentation de version depuis les arguments
var versionType = vtBuild # Par défaut, incrémenter le build
if paramCount() > 0:
let arg = paramStr(1).toLowerAscii()
case arg
of "major": versionType = vtMajor
of "minor": versionType = vtMinor
of "patch": versionType = vtPatch
of "build": versionType = vtBuild
of "help":
showHelp()
quit(0)
else:
echo fmt"Commande inconnue: {arg}"
showHelp()
quit(1)
# Incrémenter la version
incrementVersion(versionType)
# Récupérer la version mise à jour
let version = getCurrentVersion()
# Créer le répertoire de destination
let binDir = createBinDirectory(version)
# Compiler l'exécutable et le placer dans le répertoire
buildExecutable(binDir)
echo "Build terminé!"
echo fmt"Version: {version.major}.{version.minor}.{version.patch}.{version.build}"
echo fmt"Emplacement: {binDir}"
when isMainModule:
main()