How flinedev/bartycrouch works
Main Components
• Command-Line Interface / Entry Point: Represented by the main.swift in Sources/BartyCrouch, which parses command-line arguments and determines whether to run “update” or “lint” (or other) commands.
• Configuration Module: The configuration is loaded from a TOML file (usually generated by “bartycrouch init”) and managed by modules under Sources/BartyCrouchConfiguration (e.g. Configuration.swift, Options, and Extensions). This component defines which tasks to run and paths to scan.
• Command Modules: Under Sources/BartyCrouchKit/Commands there are several command handlers (InitCommand, LintCommand, UpdateCommand). They act as controllers that orchestrate the process.
• Task Handlers: Each update task (interfaces, code, transform, normalize, translate) has its own implementation under Sources/BartyCrouchKit/TaskHandlers. They encapsulate the logic for updating localized strings, scanning files, and applying transformations.
• File Handling Components: Modules in Sources/BartyCrouchKit/FileHandling (e.g. CodeFileHandler, StringsFileUpdater, TranslateTransformer) are responsible for scanning directories (including ignoring certain subpaths) and processing code/IB files.
• Translation and External Services: The translator modules under Sources/BartyCrouchTranslator integrate with external services (such as DeepLApi and MicrosoftTranslatorApi) to support machine translation. These components connect via their respective API clients.
• Utility and Global Modules: Provide common helpers, global options, extensions, and constants (think Sources/BartyCrouchUtility and files under Globals) that support the above operations.
• Build Integration: The Demo project and the build script serve as an example of how BartyCrouch is integrated into Xcode build phases, triggering the update and lint commands automatically.
Relationships and Interactions
• The main CLI parses user input, reads in configuration data, and passes control to one or more command modules.
• Each command (e.g., update) further delegates to several Task Handlers; for instance, the "update" task is broken into sub-tasks (interfaces, code, transform, normalize, and possibly translate).
• The Task Handlers use File Handling components to scan the project directories (as specified by the configuration) for resources like Swift code files, storyboard files, or .strings files.
• When machine translation is enabled, the translator components call out to external APIs (encapsulated in the MicrosoftTranslatorApi or DeepLApi modules) and then update the localizable resources.
• Utility modules support these tasks with helper functions and extension methods for better string and file manipulation.
• Tests and Demo components validate and showcase the usage of these modules.
Architectural Patterns/Design Principles
• Modularity: The project is clearly divided into modules (Command, Configuration, File Handling, Task Handling, Translator) to separate concerns.
• Command Pattern: Handling “update” and “lint” via separate commands.
• Dependency Inversion: Higher-level tasks depend on abstract file operations and translator services (allowing for easy extensions or replacements).
• Extension and Configurability: The configuration file (.bartycrouch.toml) drives behavior, making it flexible for different project setups.