remix-flat-routes
remix-flat-routes copied to clipboard
Refactor cli script for better readability and separation of concerns
-
Error message handling: Previously, error messages were handled inline within the main function, making the code harder to read and maintain. This PR introduces a separate function, printErrorAndExit, which takes care of printing the error message and exiting the process. This helps keep the code clean and makes it easier to handle errors.
-
Option building: The process of building the options object was mixed with validating command line arguments. This PR introduces a separate function, buildOptions, which is responsible solely for creating the options object based on the provided arguments. This separation of concerns makes the code easier to understand and maintain.
-
Usage message: The usage function has been renamed to printUsageAndExit to better convey its purpose. Additionally, the usage message has been updated to use a template string, improving readability.
These changes not only make the code more readable but also follow best practices for separation of concerns, ensuring that each function has a single, clear responsibility. This will make the script easier to maintain and extend in the future.