@jolibox/implement 1.1.46 → 1.1.47
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/.rush/temp/package-deps_build.json +6 -3
- package/dist/index.js +1 -1
- package/dist/index.native.js +32 -32
- package/dist/native/api/__tests__/convertVersionCodeToVString.test.d.ts +1 -0
- package/dist/native/api/base.d.ts +1 -0
- package/dist/native/api/index.d.ts +1 -0
- package/dist/native/api/is-native-support.d.ts +1 -0
- package/dist/native/api/utils.d.ts +6 -0
- package/implement.build.log +2 -2
- package/package.json +5 -5
- package/src/native/api/__tests__/convertVersionCodeToVString.test.ts +28 -0
- package/src/native/api/base.ts +1 -0
- package/src/native/api/index.ts +1 -0
- package/src/native/api/is-native-support.ts +38 -0
- package/src/native/api/utils.ts +35 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -12,3 +12,4 @@ export declare const registerCanIUse: (name: string, config: import("@jolibox/co
|
|
|
12
12
|
import { t } from '@/common/api-factory/validator';
|
|
13
13
|
export { t };
|
|
14
14
|
export declare const canIUseNative: (schema: string) => boolean;
|
|
15
|
+
export { convertVersionCodeToVString } from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.1.
|
|
3
|
+
> @jolibox/implement@1.1.47 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.
|
|
7
|
+
> @jolibox/implement@1.1.47 build:esm
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.47",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.1.
|
|
10
|
-
"@jolibox/types": "1.1.
|
|
11
|
-
"@jolibox/native-bridge": "1.1.
|
|
12
|
-
"@jolibox/ads": "1.1.
|
|
9
|
+
"@jolibox/common": "1.1.47",
|
|
10
|
+
"@jolibox/types": "1.1.47",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.47",
|
|
12
|
+
"@jolibox/ads": "1.1.47",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { convertVersionCodeToVString } from '../utils';
|
|
2
|
+
|
|
3
|
+
describe('convertVersionCodeToVString', () => {
|
|
4
|
+
it('应该正确转换版本码为版本号', () => {
|
|
5
|
+
expect(convertVersionCodeToVString(1030000)).toBe('1.3.0');
|
|
6
|
+
expect(convertVersionCodeToVString(1030100)).toBe('1.3.1');
|
|
7
|
+
expect(convertVersionCodeToVString(1020000)).toBe('1.2.0');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('应该处理不同长度的版本码', () => {
|
|
11
|
+
expect(convertVersionCodeToVString(1000000)).toBe('1.0.0');
|
|
12
|
+
expect(convertVersionCodeToVString(1010000)).toBe('1.1.0');
|
|
13
|
+
expect(convertVersionCodeToVString(1100000)).toBe('1.10.0');
|
|
14
|
+
expect(convertVersionCodeToVString(2000000)).toBe('2.0.0');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('应该处理边界情况', () => {
|
|
18
|
+
expect(convertVersionCodeToVString(0)).toBe('0.0.0');
|
|
19
|
+
expect(convertVersionCodeToVString(-1)).toBe('0.0.0');
|
|
20
|
+
expect(convertVersionCodeToVString(9999999)).toBe('9.99.99');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('应该处理补丁版本', () => {
|
|
24
|
+
expect(convertVersionCodeToVString(1030200)).toBe('1.3.2');
|
|
25
|
+
expect(convertVersionCodeToVString(1030500)).toBe('1.3.5');
|
|
26
|
+
expect(convertVersionCodeToVString(1030900)).toBe('1.3.9');
|
|
27
|
+
});
|
|
28
|
+
});
|
package/src/native/api/base.ts
CHANGED
package/src/native/api/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { compareVersion, createCommands } from '@jolibox/common';
|
|
2
|
+
import { convertVersionCodeToVString, createSyncAPI, registerCanIUse, t } from './base';
|
|
3
|
+
import { context } from '@/common/context';
|
|
4
|
+
|
|
5
|
+
const commands = createCommands();
|
|
6
|
+
|
|
7
|
+
const API_IS_NATIVE_SUPPORT = 'isNativeSupport';
|
|
8
|
+
|
|
9
|
+
const isNativeSupport = createSyncAPI(API_IS_NATIVE_SUPPORT, {
|
|
10
|
+
paramsSchema: t.tuple(
|
|
11
|
+
t.object({
|
|
12
|
+
version: t.string()
|
|
13
|
+
})
|
|
14
|
+
),
|
|
15
|
+
implement: (params) => {
|
|
16
|
+
const nativeCode = context.sdkInfo.nativeSDKVersionCode;
|
|
17
|
+
const { version } = params;
|
|
18
|
+
if (version) {
|
|
19
|
+
const isSupport = compareVersion(convertVersionCodeToVString(nativeCode ?? 0), version, '>=');
|
|
20
|
+
return {
|
|
21
|
+
code: 'SUCCESS',
|
|
22
|
+
data: isSupport
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
code: 'FAILURE',
|
|
28
|
+
message: `[Jolibox SDK] api or versionCode is required`,
|
|
29
|
+
data: false
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
commands.registerCommand('API.isNativeSupport', isNativeSupport);
|
|
35
|
+
|
|
36
|
+
registerCanIUse('isNativeSupport', {
|
|
37
|
+
version: '1.1.46'
|
|
38
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将nativeVersionCode转换成版本号形式
|
|
3
|
+
* @param versionCode 版本码,如1030000, 1030100, 1020000
|
|
4
|
+
* @returns 版本号字符串,如"1.3.0", "1.3.1", "1.2.0"
|
|
5
|
+
*/
|
|
6
|
+
export function convertVersionCodeToVString(versionCode: number): string {
|
|
7
|
+
if (typeof versionCode !== 'number' || versionCode <= 0) {
|
|
8
|
+
return '0.0.0';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 将版本码转换为字符串
|
|
12
|
+
const versionStr = versionCode.toString();
|
|
13
|
+
|
|
14
|
+
// 版本码格式:Mmmpp00 (主版本.次版本.补丁版本.00)
|
|
15
|
+
// 例如:1030000 = 1.03.00.00 = 1.3.0
|
|
16
|
+
// 例如:1030100 = 1.03.01.00 = 1.3.1
|
|
17
|
+
|
|
18
|
+
let major = 0;
|
|
19
|
+
let minor = 0;
|
|
20
|
+
let patch = 0;
|
|
21
|
+
|
|
22
|
+
if (versionStr.length >= 1) {
|
|
23
|
+
major = parseInt(versionStr.substring(0, 1), 10);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (versionStr.length >= 3) {
|
|
27
|
+
minor = parseInt(versionStr.substring(1, 3), 10);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (versionStr.length >= 5) {
|
|
31
|
+
patch = parseInt(versionStr.substring(3, 5), 10);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return `${major}.${minor}.${patch}`;
|
|
35
|
+
}
|