Aller au contenu

Développement

Prérequis

Outil Version Installation
Rust stable rustup.rs
Podman latest sudo apt install podman
wasm-pack latest curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf \| sh

Structure du projet

rust-vlatex/
├── Cargo.toml                 # Workspace root + crate vlatex
├── src/                       # Crate vlatex (bibliothèque)
│   ├── lib.rs
│   ├── latex/
│   │   ├── converter.rs       # Moteur principal
│   │   ├── packages.rs        # Preamble LaTeX
│   │   ├── bibliography.rs    # Citations
│   │   ├── docx.rs            # Post-traitement DOCX
│   │   └── tables.rs          # Tableaux
│   ├── images.rs              # Images
│   ├── mermaid/               # Mermaid → PNG
│   └── ...
├── vlatex-desktop/            # Crate desktop (binaire)
│   ├── Cargo.toml
│   ├── src/
│   │   ├── main.rs            # CLI + dispatcher
│   │   ├── tui.rs             # TUI (ratatui)
│   │   └── gui.rs             # GUI (egui)
│   └── web/                   # Frontend web (obsolète)
├── obsidian-plugin/           # Plugin Obsidian (JS + WASM)
├── example_vault/             # Vault de démonstration
├── Dockerfile.vlatex          # Image de compilation
├── .github/workflows/
│   └── release.yml            # CI/CD
└── docs/                      # Documentation MkDocs

Commandes utiles

Build

# Debug
cargo build

# Release
cargo build --release

# Sans TUI
cargo build --release --no-default-features --features gui

# Sans GUI
cargo build --release --no-default-features --features tui

# WASM
wasm-pack build --target web --out-dir wasm-pkg

Tests

# Tous les tests
cargo test

# Tests du crate vlatex
cargo test -p vlatex

# Tests du desktop
cargo test -p vlatex-desktop

# Avec logs
RUST_LOG=debug cargo test

Lint

# Clippy
cargo clippy -- -D warnings

# Format
cargo fmt

Image Docker

# Construire
podman build -t vlatex-env -f Dockerfile.vlatex .

# Tester
podman run --rm vlatex-env pdflatex --version

Ajouter une fonctionnalité

1. Comprendre le pipeline

La conversion suit le pipeline dans src/latex/converter.rs. Chaque étape est une méthode de Converter.

2. Modifier le converter

// src/latex/converter.rs
impl Converter {
    fn ma_fonction(&self, text: &str) -> String {
        // Logique de conversion
        text.replace("avant", "après")
    }

    pub fn convert(&mut self, content: &str) -> String {
        let mut text = content.to_string();
        // ... étapes précédentes ...
        text = self.ma_fonction(&text);
        // ... étapes suivantes ...
        text
    }
}

3. Ajouter des tests

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ma_fonction() {
        let converter = Converter::new(/* ... */);
        let input = "avant";
        let expected = "après";
        assert_eq!(converter.ma_fonction(input), expected);
    }
}

4. Mettre à jour le WASM

wasm-pack build --target web --out-dir wasm-pkg
cp wasm-pkg/vlatex_bg.wasm obsidian-plugin/
cp wasm-pkg/vlatex.js obsidian-plugin/

Architecture GUI

La GUI utilise egui (immediate mode) :

VlatexApp
├── update()           → Render loop
├── render_main_panel() → Editor + preview + buttons
├── render_config_panel() → Settings
├── handle_messages()  → Worker thread responses
└── send_convert()     → Send commands to worker

Le worker tourne dans un thread séparé :

Main Thread ←→ mpsc::channel ←→ Worker Thread
                              cli_convert()
                              cli_compile()

Déployer une release

  1. Mettre à jour la version dans Cargo.toml
  2. Commit
  3. Créer un tag :
git tag v0.3.0
git push origin main --tags
  1. GitHub Actions build les binaires et crée la release

Contribuer

  1. Fork le repository
  2. Créer une branche (git checkout -b feature/ma-fonctionnalite)
  3. Commit (git commit -m 'Add ma fonctionnalité')
  4. Push (git push origin feature/ma-fonctionnalite)
  5. Ouvrir une Pull Request