update CLI cp services_reference
EBO <eric.bouhana@softalys.com> committé le 2026-05-15 21:44
0b8a83b8d79a45b44e84dc201e05f96e34718574
1 parent(s)
2 fichiers modifiés
+85
-3
M
tools/rustwarden-cli/src/start_project.rs
+12
-3
@@ -89,7 +89,8 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | copy_resources(&rustwarden_root, &project_dir, with_ui)?; |
| 92 | - copy_docs(&rustwarden_root, &project_dir)?; | |
| 92 | + let fediverse_active = !matches!(cfg.fediverse_mode, FediverseMode::None); | |
| 93 | + copy_docs(&rustwarden_root, &project_dir, fediverse_active)?; | |
| 93 | 94 | generate_files(&project_dir, &cfg)?; |
| 94 | 95 | rebrand_templates(&project_dir, &app_display_name)?; |
| 95 | 96 |
@@ -635,8 +636,16 @@ fn copy_resources(
| 635 | 636 | } |
| 636 | 637 | |
| 637 | 638 | /// Copy framework documentation relevant to consumer projects. |
| 638 | -fn copy_docs(rustwarden_root: &Path, project_dir: &Path) -> Result<(), Box<dyn std::error::Error>> { | |
| 639 | - let docs_to_copy = ["docs/SERVICES_REFERENCE.md", "docs/MIGRATION_GUIDE.md"]; | |
| 639 | +fn copy_docs( | |
| 640 | + rustwarden_root: &Path, | |
| 641 | + project_dir: &Path, | |
| 642 | + fediverse_active: bool, | |
| 643 | +) -> Result<(), Box<dyn std::error::Error>> { | |
| 644 | + let mut docs_to_copy: Vec<&str> = | |
| 645 | + vec!["docs/SERVICES_REFERENCE.md", "docs/MIGRATION_GUIDE.md"]; | |
| 646 | + if fediverse_active { | |
| 647 | + docs_to_copy.push("docs/fediverse-consumer-guide.md"); | |
| 648 | + } | |
| 640 | 649 | |
| 641 | 650 | let dst_dir = project_dir.join("docs"); |
| 642 | 651 | fs::create_dir_all(&dst_dir)?; |
M
tools/rustwarden-cli/src/update_project.rs
+73
-0
@@ -97,6 +97,9 @@ pub fn run() -> Result<(), Box<dyn std::error::Error>> {
| 97 | 97 | &custom_templates, |
| 98 | 98 | )?; |
| 99 | 99 | |
| 100 | + // --- Resync des docs framework-owned (SERVICES_REFERENCE, MIGRATION_GUIDE, …) --- | |
| 101 | + refresh_docs(&rustwarden_root, &project_dir, has_fediverse)?; | |
| 102 | + | |
| 100 | 103 | // --- Reecrire le fichier de version --- |
| 101 | 104 | version::write_version(&project_dir, &new_version)?; |
| 102 | 105 |
@@ -689,6 +692,76 @@ fn update_crates(
| 689 | 692 | Ok(stats) |
| 690 | 693 | } |
| 691 | 694 | |
| 695 | +/// Resynchronise les documents framework-owned dans `<project>/docs/`. | |
| 696 | +/// | |
| 697 | +/// Ces fichiers ne sont jamais customisés par le consommateur ; ils sont | |
| 698 | +/// systématiquement réécrits à l'identique de l'upstream à chaque update, | |
| 699 | +/// afin que la documentation de référence reste alignée avec la version | |
| 700 | +/// installée des crates. Le contenu fediverse n'est copié que si le projet | |
| 701 | +/// utilise effectivement la fédération. | |
| 702 | +fn refresh_docs( | |
| 703 | + rustwarden_root: &Path, | |
| 704 | + project_dir: &Path, | |
| 705 | + has_fediverse: bool, | |
| 706 | +) -> Result<(), Box<dyn std::error::Error>> { | |
| 707 | + let mut docs_to_copy: Vec<&str> = | |
| 708 | + vec!["docs/SERVICES_REFERENCE.md", "docs/MIGRATION_GUIDE.md"]; | |
| 709 | + if has_fediverse { | |
| 710 | + docs_to_copy.push("docs/fediverse-consumer-guide.md"); | |
| 711 | + } | |
| 712 | + | |
| 713 | + let dst_dir = project_dir.join("docs"); | |
| 714 | + fs::create_dir_all(&dst_dir)?; | |
| 715 | + | |
| 716 | + println!( | |
| 717 | + "\n{}", | |
| 718 | + style("── Resync des docs framework ──").cyan().bold() | |
| 719 | + ); | |
| 720 | + | |
| 721 | + for doc in &docs_to_copy { | |
| 722 | + let src = rustwarden_root.join(doc); | |
| 723 | + let Some(filename) = Path::new(doc).file_name() else { | |
| 724 | + continue; | |
| 725 | + }; | |
| 726 | + let dst = dst_dir.join(filename); | |
| 727 | + | |
| 728 | + if !src.exists() { | |
| 729 | + println!( | |
| 730 | + " {} {} (source manquante, ignoré)", | |
| 731 | + style("!").yellow(), | |
| 732 | + style(format!("docs/{}", filename.to_string_lossy())).dim() | |
| 733 | + ); | |
| 734 | + continue; | |
| 735 | + } | |
| 736 | + | |
| 737 | + // Si le fichier existe et a le même contenu, ne rien faire ; | |
| 738 | + // sinon overwrite. Pas de notion de "custom" : ces docs sont | |
| 739 | + // framework-owned, jamais éditées par le consommateur. | |
| 740 | + let need_write = match (fs::read(&src), fs::read(&dst)) { | |
| 741 | + (Ok(s), Ok(d)) => s != d, | |
| 742 | + (Ok(_), Err(_)) => true, // dst missing | |
| 743 | + _ => false, | |
| 744 | + }; | |
| 745 | + | |
| 746 | + if need_write { | |
| 747 | + fs::copy(&src, &dst)?; | |
| 748 | + println!( | |
| 749 | + " {} docs/{}", | |
| 750 | + style("✓").green().bold(), | |
| 751 | + style(filename.to_string_lossy()).cyan() | |
| 752 | + ); | |
| 753 | + } else { | |
| 754 | + println!( | |
| 755 | + " {} docs/{} (déjà à jour)", | |
| 756 | + style("=").dim(), | |
| 757 | + style(filename.to_string_lossy()).dim() | |
| 758 | + ); | |
| 759 | + } | |
| 760 | + } | |
| 761 | + | |
| 762 | + Ok(()) | |
| 763 | +} | |
| 764 | + | |
| 692 | 765 | /// Synchronise un crate du framework fichier par fichier. |
| 693 | 766 | /// - Fichiers identiques : ignores |
| 694 | 767 | /// - Fichiers modifies dans le framework : mis a jour |
GitRust