diff --git a/admin/package.json b/admin/package.json index 062594ccc..e7c6e70d0 100644 --- a/admin/package.json +++ b/admin/package.json @@ -18,8 +18,8 @@ "test:coverage": "cross-env TZ=UTC vitest run --coverage", "test:debug": "cross-env TZ=UTC node --inspect-brk ./node_modules/vitest/vitest.mjs", "test:watch": "cross-env TZ=UTC vitest", - "locales": "scripts/sort.sh", - "locales:fix": "scripts/sort.sh --fix", + "locales": "bun scripts/sortLocales.ts", + "locales:fix": "bun scripts/sortLocales.ts --fix", "clear": "rm -rf node_modules && rm -rf build && rm -rf .turbo" }, "dependencies": { diff --git a/admin/scripts/sortLocales.ts b/admin/scripts/sortLocales.ts new file mode 100644 index 000000000..9b0ee74a0 --- /dev/null +++ b/admin/scripts/sortLocales.ts @@ -0,0 +1,51 @@ +#!/usr/bin/env bun +import { readdir, readFile, writeFile } from 'fs/promises' +import { join } from 'path' + +const ROOT_DIR = join(import.meta.dir, '..') +const LOCALES_DIR = join(ROOT_DIR, 'src', 'locales') + +const FIX = process.argv.includes('--fix') + +function sortObject(value: any): any { + if (Array.isArray(value)) { + return value.map(sortObject) + } + + if (value && typeof value === 'object') { + return Object.keys(value) + .sort() + .reduce>((acc, key) => { + acc[key] = sortObject(value[key]) + return acc + }, {}) + } + + return value +} + +let exitCode = 0 + +const files = (await readdir(LOCALES_DIR)) + .filter(f => f.endsWith('.json')) + +for (const file of files) { + const path = join(LOCALES_DIR, file) + + const originalText = await readFile(path, 'utf8') + const originalJson = JSON.parse(originalText) + + const sortedJson = sortObject(originalJson) + const sortedText = JSON.stringify(sortedJson, null, 2) + '\n' + + if (originalText !== sortedText) { + if (FIX) { + await writeFile(path, sortedText) + } else { + console.error(`${file} is not sorted by keys`) + exitCode = 1 + } + } +} + +process.exit(exitCode) \ No newline at end of file diff --git a/admin/src/components/Tables/OpenCreationsTable.vue b/admin/src/components/Tables/OpenCreationsTable.vue index d94f85bae..4e29b4241 100644 --- a/admin/src/components/Tables/OpenCreationsTable.vue +++ b/admin/src/components/Tables/OpenCreationsTable.vue @@ -14,7 +14,13 @@ - +