@blocklet/env 1.8.68
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 +5 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +3 -0
- package/lib/util.d.ts +20 -0
- package/lib/util.js +34 -0
- package/package.json +41 -0
package/README.md
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const _default: Readonly<{
|
|
2
|
+
appId: string;
|
|
3
|
+
appPid: string;
|
|
4
|
+
appIds: string[];
|
|
5
|
+
appName: string;
|
|
6
|
+
appDescription: string;
|
|
7
|
+
appUrl: string;
|
|
8
|
+
isComponent: boolean;
|
|
9
|
+
dataDir: string;
|
|
10
|
+
cacheDir: string;
|
|
11
|
+
mode: string;
|
|
12
|
+
appStorageEndpoint: string;
|
|
13
|
+
serverVersion: string;
|
|
14
|
+
preferences: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
export = _default;
|
package/lib/index.js
ADDED
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare type BlockletPreferences = {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
5
|
+
export declare function parseEnv(env?: NodeJS.ProcessEnv): Readonly<{
|
|
6
|
+
appId: string;
|
|
7
|
+
appPid: string;
|
|
8
|
+
appIds: string[];
|
|
9
|
+
appName: string;
|
|
10
|
+
appDescription: string;
|
|
11
|
+
appUrl: string;
|
|
12
|
+
isComponent: boolean;
|
|
13
|
+
dataDir: string;
|
|
14
|
+
cacheDir: string;
|
|
15
|
+
mode: string;
|
|
16
|
+
appStorageEndpoint: string;
|
|
17
|
+
serverVersion: string;
|
|
18
|
+
preferences: BlockletPreferences;
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseEnv = void 0;
|
|
4
|
+
const constant_1 = require("@blocklet/constant");
|
|
5
|
+
function parseEnv(env = process.env) {
|
|
6
|
+
const preferences = Object.keys(env)
|
|
7
|
+
.filter((x) => x.startsWith(constant_1.BLOCKLET_PREFERENCE_PREFIX))
|
|
8
|
+
.reduce((acc, x) => {
|
|
9
|
+
const key = x.replace(constant_1.BLOCKLET_PREFERENCE_PREFIX, '');
|
|
10
|
+
try {
|
|
11
|
+
acc[key] = JSON.parse(env[x]);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
acc[key] = env[x];
|
|
15
|
+
}
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
appId: env.BLOCKLET_APP_ID,
|
|
20
|
+
appPid: env.BLOCKLET_APP_PID,
|
|
21
|
+
appIds: (env.BLOCKLET_APP_IDS || '').split(','),
|
|
22
|
+
appName: env.BLOCKLET_APP_NAME,
|
|
23
|
+
appDescription: env.BLOCKLET_APP_DESCRIPTION,
|
|
24
|
+
appUrl: env.BLOCKLET_APP_URL,
|
|
25
|
+
isComponent: env.BLOCKLET_DID !== env.BLOCKLET_REAL_DID,
|
|
26
|
+
dataDir: env.BLOCKLET_DATA_DIR,
|
|
27
|
+
cacheDir: env.BLOCKLET_CACHE_DIR,
|
|
28
|
+
mode: env.BLOCKLET_MODE,
|
|
29
|
+
appStorageEndpoint: env.BLOCKLET_APP_SPACE_ENDPOINT,
|
|
30
|
+
serverVersion: env.ABT_NODE,
|
|
31
|
+
preferences,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.parseEnv = parseEnv;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blocklet/env",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.8.68",
|
|
7
|
+
"description": "Blocklet environment parser and provider",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"typings": "lib/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"verify": "npm run lint:fix && npm run test && npm run build",
|
|
15
|
+
"lint": "eslint src tests",
|
|
16
|
+
"lint:fix": "npm run lint -- --fix",
|
|
17
|
+
"test": "jest --forceExit --detectOpenHandles",
|
|
18
|
+
"coverage": "npm run test -- --coverage",
|
|
19
|
+
"clean": "rm -fr lib",
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"build:watch": "npm run build -- -w"
|
|
22
|
+
},
|
|
23
|
+
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@blocklet/constant": "1.8.68"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
30
|
+
"@types/jest": "^29.2.0",
|
|
31
|
+
"@types/node": "^18.11.0",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
33
|
+
"@typescript-eslint/parser": "^5.40.1",
|
|
34
|
+
"eslint": "^8.25.0",
|
|
35
|
+
"jest": "^29.2.0",
|
|
36
|
+
"prettier": "^2.7.1",
|
|
37
|
+
"ts-jest": "^29.0.3",
|
|
38
|
+
"ts-node": "^10.9.1",
|
|
39
|
+
"typescript": "^4.8.4"
|
|
40
|
+
}
|
|
41
|
+
}
|