Files
MD-to-Prrint/Makefile

111 lines
3.1 KiB
Makefile

.PHONY: build run shell test clean install uninstall help
# Variables
IMAGE_NAME=md-to-print
IMAGE_TAG=latest
SCRIPT_NAME=md_to_print.sh
INSTALL_DIR=/usr/local/bin
CONFIG_DIR=/etc/md-to-print
# Couleurs
GREEN=\033[0;32m
YELLOW=\033[1;33m
NC=\033[0m
help:
@echo "Commandes disponibles:"
@echo " make build - Construire l'image Docker"
@echo " make shell - Ouvrir un shell interactif dans le conteneur"
@echo " make test - Tester avec un fichier markdown exemple"
@echo " make clean - Nettoyer les fichiers générés (PDFs, logs)"
@echo " make install - Installer le script localement"
@echo " make uninstall - Désinstaller le script"
@echo " make help - Afficher cette aide"
# Construction de l'image Docker
build:
@echo "$(GREEN)Construction de l'image Docker...$(NC)"
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
@echo "$(GREEN)Image construite avec succès$(NC)"
# Exécution interactive avec shell
shell: build
@echo "$(GREEN)Ouverture d'un shell dans le conteneur...$(NC)"
docker run --rm -it \
-v $(PWD)/documents:/workspace/documents:ro \
-v $(PWD)/output:/workspace/output \
-v $(PWD)/logs:/workspace/logs \
--network host \
$(IMAGE_NAME):$(IMAGE_TAG) \
/bin/bash
# Test avec un fichier exemple
test: build
@echo "$(GREEN)Création d'un fichier markdown de test...$(NC)"
@mkdir -p documents output logs
@cat > documents/test.md << 'EOF'
# Test Markdown
Ceci est un test de conversion Markdown vers PDF.
## Fonctionnalités
- Conversion automatique
- Impression
- Prévisualisation
- Options avancées
## Exemple de code
\`\`\`bash
echo "Hello World"
\`\`\`
## Liste numérotée
1. Premier élément
2. Deuxième élément
3. Troisième élément
**Texte en gras** et *texte en italique*.
EOF
@echo "$(GREEN)Exécution du test...$(NC)"
docker run --rm -it \
-v $(PWD)/documents:/workspace/documents:ro \
-v $(PWD)/output:/workspace/output \
-v $(PWD)/logs:/workspace/logs \
--network host \
$(IMAGE_NAME):$(IMAGE_TAG) \
/workspace/documents/test.md --preview --keep-pdf --verbose
@echo "$(GREEN)Test terminé. Vérifiez le fichier output/test.pdf$(NC)"
# Nettoyage
clean:
@echo "$(YELLOW)Nettoyage des fichiers générés...$(NC)"
@rm -rf output/*.pdf logs/*.log 2>/dev/null || true
@rm -f documents/test.md 2>/dev/null || true
@echo "$(GREEN)Nettoyage terminé$(NC)"
# Installation locale
install:
@echo "$(GREEN)Installation du script...$(NC)"
@if [ ! -f "$(SCRIPT_NAME)" ]; then \
echo "Erreur: $(SCRIPT_NAME) introuvable"; \
exit 1; \
fi
@sudo mkdir -p $(INSTALL_DIR) $(CONFIG_DIR)
@sudo cp $(SCRIPT_NAME) $(INSTALL_DIR)/$(SCRIPT_NAME)
@sudo chmod +x $(INSTALL_DIR)/$(SCRIPT_NAME)
@sudo cp config.example.conf $(CONFIG_DIR)/config.example.conf
@echo "$(GREEN)Script installé dans $(INSTALL_DIR)/$(SCRIPT_NAME)$(NC)"
@echo "$(GREEN)Configuration exemple dans $(CONFIG_DIR)/config.example.conf$(NC)"
@echo "$(YELLOW)Créez $(CONFIG_DIR)/config.conf pour personnaliser la configuration$(NC)"
# Désinstallation
uninstall:
@echo "$(YELLOW)Désinstallation du script...$(NC)"
@sudo rm -f $(INSTALL_DIR)/$(SCRIPT_NAME)
@sudo rm -rf $(CONFIG_DIR)
@echo "$(GREEN)Désinstallation terminée$(NC)"