Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up build scripts #914

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
"eslint": "8.47.0",
"eslint-config-prettier": "9.1.0",
"execa": "8.0.1",
"glob": "10.3.15",
"husky": "8.0.3",
"jest": "29.7.0",
"jest-expo": "50.0.4",
Expand All @@ -161,7 +160,6 @@
"prettier": "3.2.5",
"react-native-svg-transformer": "1.3.0",
"react-test-renderer": "18.2.0",
"rimraf": "5.0.5",
"semver": "7.6.0",
"type-fest": "4.26.0",
"typescript": "5.3.3"
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-intl-polyfills.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import fs from 'node:fs';
import {supportedLocales as relativeTimeFormatSupportedLocales} from '@formatjs/intl-relativetimeformat/supported-locales.generated.js';
import {supportedLocales as pluralRulesSupportedLocales} from '@formatjs/intl-pluralrules/supported-locales.generated.js';

import languages from '../src/frontend/languages.json' assert {type: 'json'};
import messages from '../translations/messages.json' assert {type: 'json'};
import languages from '../src/frontend/languages.json' with {type: 'json'};
import messages from '../translations/messages.json' with {type: 'json'};

build();

Expand Down
22 changes: 8 additions & 14 deletions scripts/build-translations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import path from 'node:path';
import fs from 'node:fs';
import {readFile, writeFile} from 'node:fs/promises';
import {glob} from 'glob';
import {rimraf} from 'rimraf';

import LANGUAGE_NAME_TRANSLATIONS from '../src/frontend/languages.json' assert {type: 'json'};
import LANGUAGE_NAME_TRANSLATIONS from '../src/frontend/languages.json' with {type: 'json'};

const PROJECT_ROOT_DIR_PATH = new URL('../', import.meta.url).pathname;
const TRANSLATIONS_DIR_PATH = path.join(PROJECT_ROOT_DIR_PATH, 'translations');
Expand All @@ -19,14 +17,8 @@ const TRANSLATIONS_OUTPUT_PATH = path.join(
await run();

async function run() {
// We want to preserve the translations/ directory
await rimraf(`${TRANSLATIONS_DIR_PATH}/*`, {glob: true, preserveRoot: true});

try {
fs.mkdirSync(TRANSLATIONS_DIR_PATH);
} catch (_) {
// Translations directory already exists
}
fs.rmSync(TRANSLATIONS_DIR_PATH, {force: true, recursive: true});
fs.mkdirSync(TRANSLATIONS_DIR_PATH);

const messages = await loadMessages();
const translations = convertMessagesToTranslations(messages);
Expand All @@ -45,13 +37,15 @@ async function run() {
* @returns {Promise<{ [lang: string]: unknown }>}
*/
async function loadMessages() {
const files = await glob(`${PROJECT_ROOT_DIR_PATH}/messages/**/*.json`);
const files = fs.readdirSync(path.join(PROJECT_ROOT_DIR_PATH, 'messages'), {
withFileTypes: true,
});

/** @type {Array<[string, any]>} */
const loadedMessages = await Promise.all(
files.map(async file => {
const lang = path.parse(file).name;
const msgs = JSON.parse(await readFile(file));
const lang = path.parse(file.name).name;
const msgs = JSON.parse(await readFile(path.join(file.path, file.name)));
return [lang, msgs];
}),
);
Expand Down
Loading