Created
June 13, 2025 09:17
-
-
Save muuvmuuv/e966c713a237d20f50dd7c015408fe89 to your computer and use it in GitHub Desktop.
Bulk re-order json file contents like dependencies in package.json or paths in tsconfig.json. It uses `jq` and can be expanded to re-order other paths as well!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
tsconfig_files=$( | |
find . -type d \( -path "*/node_modules" -o -path "*/dist" -o -path "*/tmp" -o -path '*/.*' \) -prune \ | |
-o -not -name '.*' \ | |
-type f -name "tsconfig*.json" \ | |
) | |
for tsconfig_file in $tsconfig_files; do | |
echo "Reordering paths in $tsconfig_file" | |
( | |
jq ' | |
if .compilerOptions.paths != null then | |
.compilerOptions.paths|=(to_entries|sort_by(.key)|from_entries) | |
end | | |
if .references != null then | |
.references|=sort_by(.path) | |
end | |
' $tsconfig_file >$tsconfig_file.tmp | |
mv $tsconfig_file.tmp $tsconfig_file | |
prettier --write --log-level=silent $tsconfig_file | |
) & | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment