Skip to content

Commit

Permalink
chore: sort i18n files in format task (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Jun 21, 2024
1 parent 4095379 commit f671eb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"e2e": "cd e2e && npm install && node open-cypress",
"lint": "ng lint",
"lint-hard": "node scripts/eslint-hard",
"format": "node docs/check-sentence-newline && stylelint \"**/*.{css,scss}\" --fix && prettier --loglevel warn --write \"**/*.*\"",
"sort-i18n": "node scripts/sort-i18n.mjs",
"format": "node docs/check-sentence-newline && stylelint \"**/*.{css,scss}\" --fix && prettier --loglevel warn --write \"**/*.*\" && npm run sort-i18n",
"compile": "tsc --project tsconfig.all.json --noEmit",
"dead-code": "npx ts-node scripts/find-dead-code.ts",
"clean-localizations": "node scripts/clean-up-localizations",
Expand Down Expand Up @@ -218,7 +219,7 @@
"jest --ci --bail --findRelatedTests --passWithNoTests"
],
"src/assets/i18n/*.json": [
"sort-json --indent-size=2"
"npm run sort-i18n"
]
},
"commitlint": {
Expand Down
20 changes: 20 additions & 0 deletions scripts/sort-i18n.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as fs from 'fs';
import * as glob from 'glob';
import sort from 'sort-json';

/** @type string[] */
let files;

if (process.argv.length > 2) {
files = process.argv.slice(2);
} else {
files = glob.sync('src/assets/i18n/*.json');
}

files.forEach(file => {
console.log('sorting', file);

const content = JSON.parse(fs.readFileSync(file, { encoding: 'utf-8' }));
const sorted = sort(content);
fs.writeFileSync(file, `${JSON.stringify(sorted, undefined, 2)}\n`);
});

0 comments on commit f671eb8

Please sign in to comment.