@appsemble/node-utils 0.36.6-test.0 → 0.36.7-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.36.6-test.0/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.36.7-test.0/config/assets/logo.svg) Appsemble Node Utilities
2
2
 
3
3
  > NodeJS utilities used by Appsemble internally.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/node-utils)](https://www.npmjs.com/package/@appsemble/node-utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.36.6-test.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.36.6-test.0)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.36.7-test.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.36.7-test.0)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
8
8
 
9
9
  ## Table of Contents
@@ -26,5 +26,5 @@ compatibility is not guaranteed.
26
26
 
27
27
  ## License
28
28
 
29
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.36.6-test.0/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.36.7-test.0/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
@@ -1,9 +1,24 @@
1
1
  import { readdir, readFile } from 'node:fs/promises';
2
- import { defaultLocale } from '@appsemble/utils';
2
+ import { defaultLocale, normalizeLocale } from '@appsemble/utils';
3
+ import { AppsembleError } from './AppsembleError.js';
3
4
  const translationsDir = new URL('../../i18n/', import.meta.url);
4
- export async function getSupportedLanguages() {
5
+ async function getLanguageFiles() {
5
6
  const files = await readdir(translationsDir);
6
- return new Set(files.map((lang) => lang.split('.json')[0].toLowerCase()));
7
+ const result = new Map();
8
+ for (const file of files) {
9
+ if (!file.endsWith('.json')) {
10
+ continue;
11
+ }
12
+ const language = normalizeLocale(file.slice(0, -'.json'.length));
13
+ if (result.has(language)) {
14
+ throw new AppsembleError(`Found duplicate language codes: ‘${language}’`);
15
+ }
16
+ result.set(language, file);
17
+ }
18
+ return result;
19
+ }
20
+ export async function getSupportedLanguages() {
21
+ return new Set((await getLanguageFiles()).keys());
7
22
  }
8
23
  /**
9
24
  * Fetch and merge the Appsemble core messages based on a language and a base language.
@@ -13,21 +28,19 @@ export async function getSupportedLanguages() {
13
28
  * @returns The Appsemble core messages.
14
29
  */
15
30
  export async function getAppsembleMessages(language, baseLanguage) {
16
- const lang = language.toLowerCase();
17
- const baseLang = baseLanguage?.toLowerCase();
18
- const languages = await getSupportedLanguages();
31
+ const lang = normalizeLocale(language);
32
+ const baseLang = baseLanguage ? normalizeLocale(baseLanguage) : undefined;
33
+ const languages = await getLanguageFiles();
19
34
  const messages = {};
20
- // @ts-expect-error 2345 argument of type is not assignable to parameter of type
21
- // (strictNullChecks)
22
- if (baseLang && languages.has(baseLanguage)) {
23
- Object.assign(messages, JSON.parse(await readFile(new URL(`${baseLang}.json`, translationsDir), 'utf8')));
35
+ if (baseLang && languages.has(baseLang)) {
36
+ Object.assign(messages, JSON.parse(await readFile(new URL(languages.get(baseLang), translationsDir), 'utf8')));
24
37
  }
25
38
  if (languages.has(lang)) {
26
- Object.assign(messages, Object.fromEntries(Object.entries(JSON.parse(await readFile(new URL(`${lang}.json`, translationsDir), 'utf8'))).filter(([, value]) => Boolean(value))));
39
+ Object.assign(messages, Object.fromEntries(Object.entries(JSON.parse(await readFile(new URL(languages.get(lang), translationsDir), 'utf8'))).filter(([, value]) => Boolean(value))));
27
40
  }
28
- // Fall back to reading the default locale’s messages if no core messages were found.
29
41
  if (!languages.has(lang) && (!baseLang || !languages.has(baseLang))) {
30
- Object.assign(messages, JSON.parse(await readFile(new URL(`${defaultLocale}.json`, translationsDir), 'utf8')));
42
+ const defaultLanguage = normalizeLocale(defaultLocale);
43
+ Object.assign(messages, JSON.parse(await readFile(new URL(languages.get(defaultLanguage), translationsDir), 'utf8')));
31
44
  }
32
45
  return messages;
33
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/node-utils",
3
- "version": "0.36.6-test.0",
3
+ "version": "0.36.7-test.0",
4
4
  "description": "NodeJS utilities used by Appsemble internally.",
5
5
  "keywords": [
6
6
  "app",
@@ -40,9 +40,9 @@
40
40
  "test": "vitest"
41
41
  },
42
42
  "dependencies": {
43
- "@appsemble/lang-sdk": "0.36.6-test.0",
44
- "@appsemble/types": "0.36.6-test.0",
45
- "@appsemble/utils": "0.36.6-test.0",
43
+ "@appsemble/lang-sdk": "0.36.7-test.0",
44
+ "@appsemble/types": "0.36.7-test.0",
45
+ "@appsemble/utils": "0.36.7-test.0",
46
46
  "@formatjs/fast-memoize": "^2.0.0",
47
47
  "@fortawesome/fontawesome-free": "^6.0.0",
48
48
  "@kubernetes/client-node": "1.4.0",
@@ -50,7 +50,7 @@
50
50
  "@types/koa": "^2.0.0",
51
51
  "axios": "^1.0.0",
52
52
  "bcrypt": "^5.1.1",
53
- "bulma": "=0.9.3",
53
+ "bulma": "=0.9.4",
54
54
  "bulma-checkradio": "=2.1.1",
55
55
  "bulma-slider": "=2.0.4",
56
56
  "bulma-switch": "^2.0.0",
package/readAsset.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const assetDir: import("url").URL;
1
+ export declare const assetDir: import("node:url").URL;
2
2
  /**
3
3
  * Read a file from the server assets directory.
4
4
  *