@hylid/env 3.0.0-alpha.4 → 3.0.0-alpha.9
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 +5 -2
- package/lib/index.js +28 -19
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ClientEnv, PlatformEnv } from './types';
|
|
2
|
-
declare
|
|
3
|
-
|
|
2
|
+
export declare function getDefaultDiscernEnv(): {
|
|
3
|
+
client: string | undefined;
|
|
4
|
+
platform: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
declare let client: string | undefined, platform: string | undefined;
|
|
4
7
|
interface CustomEnv {
|
|
5
8
|
client?: string;
|
|
6
9
|
platform?: string;
|
package/lib/index.js
CHANGED
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
import { createCommonEnv, getSettingName, isMP, notice } from "./utils";
|
|
2
2
|
import { getName4MP, getName4MpWeb, getName4Web } from "./getClientName";
|
|
3
3
|
import { CLIENT, PLATFORM } from "./constants";
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var setting = getSettingName();
|
|
11
|
-
if (setting.platform) {
|
|
12
|
-
platform = setting.platform;
|
|
13
|
-
client = setting.client || (platform === 'mpweb' ? getName4MpWeb() : getName4Web());
|
|
4
|
+
export function getDefaultDiscernEnv() {
|
|
5
|
+
var client;
|
|
6
|
+
var platform;
|
|
7
|
+
if (isMP()) {
|
|
8
|
+
client = getName4MP();
|
|
9
|
+
platform = PLATFORM.MP;
|
|
14
10
|
} else {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
var setting = getSettingName();
|
|
12
|
+
if (setting.platform) {
|
|
13
|
+
platform = setting.platform;
|
|
14
|
+
client = setting.client || (platform === 'mpweb' ? getName4MpWeb() : getName4Web());
|
|
19
15
|
} else {
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
// 如果只设置了 client,默认是套壳场景
|
|
17
|
+
client = setting.client || getName4MpWeb();
|
|
18
|
+
if (client) {
|
|
19
|
+
platform = PLATFORM.MPWEB;
|
|
20
|
+
} else {
|
|
21
|
+
client = getName4Web();
|
|
22
|
+
platform = PLATFORM.WEB;
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
26
|
+
if (!platform || !client) {
|
|
27
|
+
notice('Cannot identify your client.');
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
client: client,
|
|
31
|
+
platform: platform
|
|
32
|
+
};
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
var _a = getDefaultDiscernEnv(),
|
|
35
|
+
client = _a.client,
|
|
36
|
+
platform = _a.platform;
|
|
28
37
|
export function customEnv(config) {
|
|
29
38
|
var custom = typeof config === 'function' ? config({
|
|
30
39
|
client: client,
|