Integrate Prettier formatting in SVG icon generator script #419
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.
Problem:
The current SVG icon generator script produces code that doesn't adhere to the Prettier code style guidelines. As a result, users often face unexpected diffs when running the
build:icons
orformat
.Example:
One such inconsistency is that the
type IconName
is generated using double quotes ("
) and a semicolon - while Prettier enforces single quotes ('
) and no semicolon.Proposed Solution:
To ensure consistent formatting, I've updated the
writeIfChanged
function in the icon generator script. After writing the new content to a file, Prettier is invoked to format the file according to the project's Prettier configuration.async function writeIfChanged(filepath: string, newContent: string) { const currentContent = await fsExtra .readFile(filepath, 'utf8') .catch(() => '') if (currentContent === newContent) return false await fsExtra.writeFile(filepath, newContent, 'utf8') + await $`prettier --write ${filepath}` return true }
Considerations:
I realize that running Prettier for every file generation might seem excessive. However, this approach guarantees that the generated code will always comply with the project's Prettier configuration, preventing any unwanted diffs. An alternative approach is to adjust the code generation logic to produce Prettier-compliant code directly, but that would require manual adjustments if the Prettier configuration changes in the future.
I'm open to feedback and suggestions. If there's a preference to adjust the code generation logic instead, I'm happy to make that change.