@blocklet/env 1.16.11-beta-0ae58a71 → 1.16.11-beta-f9719c31

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/lib/index.d.ts CHANGED
@@ -11,8 +11,10 @@ declare const _default: Readonly<{
11
11
  mode: string;
12
12
  appStorageEndpoint: string;
13
13
  serverVersion: string;
14
- preferences: {
15
- [key: string]: any;
16
- };
14
+ languages: {
15
+ code: string;
16
+ name: string;
17
+ }[];
18
+ preferences: Record<string, any>;
17
19
  }>;
18
20
  export = _default;
package/lib/util.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- /// <reference types="node" />
2
- type BlockletPreferences = {
3
- [key: string]: any;
4
- };
5
- export declare function parseEnv(env?: NodeJS.ProcessEnv): Readonly<{
1
+ export declare function getBlockletLanguages(langs?: string): Array<{
2
+ code: string;
3
+ name: string;
4
+ }>;
5
+ export declare function getBlockletPreferences(env: Record<string, string>): Record<string, any>;
6
+ export declare function parseEnv(env?: Record<string, string>): Readonly<{
6
7
  appId: string;
7
8
  appPid: string;
8
9
  appIds: string[];
@@ -15,6 +16,9 @@ export declare function parseEnv(env?: NodeJS.ProcessEnv): Readonly<{
15
16
  mode: string;
16
17
  appStorageEndpoint: string;
17
18
  serverVersion: string;
18
- preferences: BlockletPreferences;
19
+ languages: {
20
+ code: string;
21
+ name: string;
22
+ }[];
23
+ preferences: Record<string, any>;
19
24
  }>;
20
- export {};
package/lib/util.js CHANGED
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEnv = void 0;
3
+ exports.parseEnv = exports.getBlockletPreferences = exports.getBlockletLanguages = void 0;
4
4
  const constant_1 = require("@blocklet/constant");
5
- function parseEnv(env = process.env) {
6
- const preferences = Object.keys(env)
5
+ function getBlockletLanguages(langs = 'en') {
6
+ const languages = (langs || 'en')
7
+ .split(',')
8
+ .map((x) => x.trim())
9
+ .filter(Boolean)
10
+ .filter((x) => !!constant_1.SUPPORTED_LANGUAGES[x]);
11
+ return languages.map((x) => ({ code: x, name: constant_1.SUPPORTED_LANGUAGES[x].nativeName }));
12
+ }
13
+ exports.getBlockletLanguages = getBlockletLanguages;
14
+ function getBlockletPreferences(env) {
15
+ return Object.keys(env)
7
16
  .filter((x) => x.startsWith(constant_1.BLOCKLET_PREFERENCE_PREFIX))
8
17
  .reduce((acc, x) => {
9
18
  const key = x.replace(constant_1.BLOCKLET_PREFERENCE_PREFIX, '');
@@ -15,6 +24,10 @@ function parseEnv(env = process.env) {
15
24
  }
16
25
  return acc;
17
26
  }, {});
27
+ }
28
+ exports.getBlockletPreferences = getBlockletPreferences;
29
+ // eslint-disable-next-line import/prefer-default-export
30
+ function parseEnv(env = process.env) {
18
31
  return Object.freeze({
19
32
  appId: env.BLOCKLET_APP_ID,
20
33
  appPid: env.BLOCKLET_APP_PID,
@@ -27,8 +40,9 @@ function parseEnv(env = process.env) {
27
40
  cacheDir: env.BLOCKLET_CACHE_DIR,
28
41
  mode: env.BLOCKLET_MODE,
29
42
  appStorageEndpoint: env.BLOCKLET_APP_SPACE_ENDPOINT,
30
- serverVersion: env.ABT_NODE,
31
- preferences,
43
+ serverVersion: env.ABT_NODE_VERSION || env.ABT_NODE,
44
+ languages: getBlockletLanguages(env.BLOCKLET_APP_LANGUAGES),
45
+ preferences: getBlockletPreferences(env),
32
46
  });
33
47
  }
34
48
  exports.parseEnv = parseEnv;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-beta-0ae58a71",
6
+ "version": "1.16.11-beta-f9719c31",
7
7
  "description": "Blocklet environment parser and provider",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
@@ -23,10 +23,10 @@
23
23
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
- "@blocklet/constant": "1.16.11-beta-0ae58a71"
26
+ "@blocklet/constant": "1.16.11-beta-f9719c31"
27
27
  },
28
28
  "devDependencies": {
29
- "@arcblock/eslint-config-ts": "^0.2.3",
29
+ "@arcblock/eslint-config-ts": "^0.2.4",
30
30
  "@types/jest": "^29.2.0",
31
31
  "@types/node": "^18.11.0",
32
32
  "@typescript-eslint/eslint-plugin": "^5.40.1",
@@ -37,5 +37,5 @@
37
37
  "ts-jest": "^27.1.5",
38
38
  "typescript": "^5.0.4"
39
39
  },
40
- "gitHead": "5d044a08b4399eb855563e670af7cbd0d3851e94"
40
+ "gitHead": "2d88c5df1a414e5b6a8d575984e1940de7573976"
41
41
  }