Update index.js #2
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I converted the script from a callback-based approach to one that uses fs/promises with async/await, which makes the code cleaner and easier to read. Instead of appending CSS files one by one using fs.appendFile—which can cause race conditions because file reads happen asynchronously—I updated the logic so that all CSS files are read first, combined into a single string using join("\n"), and then written to bundle.css in one go. This ensures the output is always consistent and avoids partial or out-of-order writes. I also added a step to automatically create the output directory with fs.mkdir(..., { recursive: true }) so the script will not fail if project-dist does not already exist. The file order is preserved based on how readdir returns them, but the code can easily be extended to sort alphabetically if needed. Finally, I wrapped the entire process in a try/catch block with a clear log message on success, which makes the script more robust and user-friendly.