Description
The project currently has hundreds of source files, and the order of top-level import statements is inconsistent. Manually sorting them is time-consuming and error-prone. A consistent import order improves code readability and maintainability.
This task is to create a Node.js script inside the /buildScripts directory to automate the sorting of ES module imports.
Requirements
- The script should be able to parse
.mjs files.
- It should read all top-level
import statements within a file.
- It must sort the imports alphabetically based on their file path (e.g.,
'../core/Base.mjs' comes before '../manager/Component.mjs').
- The script should then overwrite the original file with the newly sorted imports, leaving the rest of the file content unchanged.
- It should be designed to run across the entire
/src directory or on specific sub-directories.
Future Enhancements
- Integrate the script into a pre-commit hook to automatically format files.
- Add the script to a CI/CD pipeline to enforce the standard.
Description
The project currently has hundreds of source files, and the order of top-level
importstatements is inconsistent. Manually sorting them is time-consuming and error-prone. A consistent import order improves code readability and maintainability.This task is to create a Node.js script inside the
/buildScriptsdirectory to automate the sorting of ES module imports.Requirements
.mjsfiles.importstatements within a file.'../core/Base.mjs'comes before'../manager/Component.mjs')./srcdirectory or on specific sub-directories.Future Enhancements