Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Reorganize utilities into 'utils' directory and separate concerns #52

Merged
merged 6 commits into from
Sep 21, 2024

Conversation

mitsuki31
Copy link
Owner

Overview

This pull request refactors the utility modules to enhance code organization, readability, and maintainability. The changes involve moving and separating utility functions into specific files within a new utils directory, updating import paths, and adjusting relevant code to align with these structural changes.

Changes Made

  • Move utility modules to utils directory:

    • Relocated the utility files into a new utils directory to improve code organization.
      • utils.js was moved to utils/index.js.
      • url-utils.js was moved to utils/url-utils.js.
      • yt-urlfmt.js was moved to utils/yt-urlfmt.js.
  • Separate type and logger utilities:

    • Introduced new utility modules for cleaner separation of concerns:
      • Created utils/type-utils.js to house type checking and utility functions.
      • Created utils/logger.js to manage logging functionalities.
    • Renamed the logger object to Logger while keeping the old name (logger) as an alias for backward compatibility.
    • Added circular references within the Logger object:
      • log as an alias for Logger.
      • logger retained as a backward compatibility reference.
  • Correct import path for utils module:

    • Updated all references and import paths across the codebase to align with the new structure of the utils directory.
  • Update @module tag description in documentation:

    • Refined and updated the @module JSDoc tags in affected files to reflect the new paths and module structure accurately.
  • Correct the ROOTDIR path in utils module:

    • Adjusted the ROOTDIR constant to ensure it correctly points to the project’s root directory after the module reorganization.
  • Correct import paths in test files:

    • Updated the test suites to use the correct import paths for the refactored utils module, ensuring all tests reference the new directory structure.

Impact

  • Enhances code organization by clearly separating utility functions into dedicated modules.
  • Improves maintainability and readability of the codebase.
  • Maintains backward compatibility with the legacy logger naming convention to avoid breaking changes.
  • Corrects all necessary paths in production and test code to reflect the updated structure.

Summary

This refactoring effort significantly improves the project’s structure by organizing utility functions into a utils directory. The changes maintain backward compatibility where necessary, correct paths across the codebase, and update documentation to align with the new structure, resulting in a more maintainable and readable codebase.

This includes:
  - `utils.js` -> `utils/index.js`
  - `url-utils.js` -> `utils/url-utils.js`
  - `yt-urlfmt.js` -> `utils/yt-urlfmt.js`
* Added a new module called `utils/type-utils` to separate type checking and utility functions.
* Added a new module called `utils/logger` to separate logger namespace and its functions.
* Renamed the `logger` object to `Logger`, but still have the old name for backward compatibility.
* Added two circular references in `Logger` object, one for alias (`log`) and one for backward compatibility (`logger`).
Due to displacement of `utils` module, we need to ensure that the `ROOTDIR` constant value is refer to correct project's root directory path as previous.
@mitsuki31 mitsuki31 added refactor Refactor and enhancement changes minor Minor changes labels Sep 21, 2024
@mitsuki31 mitsuki31 self-assigned this Sep 21, 2024
@mitsuki31 mitsuki31 added the chore Maintenance updates to improve project maintainability label Sep 21, 2024
@mitsuki31 mitsuki31 merged commit 87d92d0 into master Sep 21, 2024
24 checks passed
@mitsuki31 mitsuki31 deleted the refactor/restructure-and-reorganize-util-modules branch September 21, 2024 12:22
mitsuki31 added a commit that referenced this pull request Sep 21, 2024
This file was unchecked when developing on #52. I apologize for inconvenience due to this issue.

Signed-off-by: Ryuu Mitsuki <dhefam31@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance updates to improve project maintainability minor Minor changes refactor Refactor and enhancement changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant