node-nim 10.8.10-beta.153 → 10.8.10-beta.161
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/dist/loader.js +1 -48
- package/dist/loader.js.map +1 -1
- package/package.json +1 -1
- package/script/download-sdk.js +55 -34
- package/types/loader.d.ts +2 -2
package/dist/loader.js
CHANGED
|
@@ -1,51 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
let sdk_path = '';
|
|
9
|
-
let debug_path = '';
|
|
10
|
-
// Add the compiled product path to the environment variable,
|
|
11
|
-
// so that the third party does not need to copy the
|
|
12
|
-
// dynamic library separately to the program directory when importing.
|
|
13
|
-
if (process.platform === 'win32') {
|
|
14
|
-
sdk_path = path_1.default.join(__dirname, '../sdk/bin');
|
|
15
|
-
debug_path = path_1.default.join(__dirname, '../../build/bin');
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
sdk_path = path_1.default.join(__dirname, '../sdk/lib');
|
|
19
|
-
debug_path = path_1.default.join(__dirname, '../../build/lib');
|
|
20
|
-
}
|
|
21
|
-
let relative_path = process.platform === 'win32'
|
|
22
|
-
? path_1.default.join(process.cwd(), 'node_modules/node-nim/sdk/bin')
|
|
23
|
-
: path_1.default.join(process.cwd(), 'node_modules/node-nim/sdk/lib');
|
|
24
|
-
let paths = [debug_path, sdk_path, process.cwd(), path_1.default.dirname(process.execPath), relative_path];
|
|
25
|
-
let node_nim_dir = '';
|
|
26
|
-
for (let current_path of paths) {
|
|
27
|
-
if (fs_1.default.existsSync(path_1.default.join(current_path, 'node-nim.node'))) {
|
|
28
|
-
node_nim_dir = current_path;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (node_nim_dir.length === 0) {
|
|
33
|
-
throw new Error('node-nim.node not found, tried: ' + paths.join(', '));
|
|
34
|
-
}
|
|
35
|
-
if (process.platform === 'win32') {
|
|
36
|
-
process.env.PATH = `${node_nim_dir};${process.env.PATH}`;
|
|
37
|
-
}
|
|
38
|
-
let object;
|
|
39
|
-
try {
|
|
40
|
-
object = require(path_1.default.join(node_nim_dir, 'node-nim.node'));
|
|
41
|
-
}
|
|
42
|
-
catch (exception) {
|
|
43
|
-
if (process.platform === 'win32') {
|
|
44
|
-
object = require('../sdk/bin/node-nim.node');
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
object = require('../sdk/lib/node-nim.node');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.default = object;
|
|
3
|
+
exports.default = require('../build/Release/node-nim.node');
|
|
51
4
|
//# sourceMappingURL=loader.js.map
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../ts/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../ts/loader.ts"],"names":[],"mappings":";;AAAA,kBAAe,OAAO,CAAC,gCAAgC,CAAC,CAAA"}
|
package/package.json
CHANGED
package/script/download-sdk.js
CHANGED
|
@@ -1,78 +1,99 @@
|
|
|
1
1
|
const fetch = require('node-fetch')
|
|
2
2
|
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
3
4
|
const compareVersions = require('compare-versions')
|
|
4
5
|
const download = require('download')
|
|
6
|
+
|
|
7
|
+
// Global variables
|
|
5
8
|
const arch = process.env.npm_config_arch || process.arch
|
|
6
9
|
const platform = process.env.npm_config_platform || process.platform
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
+
const channel = 'message'
|
|
11
|
+
const product = 'nim'
|
|
12
|
+
const savePath = path.join(__dirname, '..', 'temporary')
|
|
13
|
+
|
|
10
14
|
if (process.env.npm_config_ignoredownloadsdk) {
|
|
11
|
-
console.log('ignore download
|
|
15
|
+
console.log('ignore download product')
|
|
12
16
|
process.exit(0)
|
|
13
17
|
}
|
|
14
|
-
let
|
|
15
|
-
let
|
|
18
|
+
let version
|
|
19
|
+
let downloadUrl = process.env.npm_config_nimsdkurl
|
|
16
20
|
if (process.env.npm_package_version) {
|
|
17
|
-
|
|
21
|
+
version = process.env.npm_package_version.split('-')[0]
|
|
18
22
|
}
|
|
19
23
|
if (process.env.npm_config_nimsdkversion) {
|
|
20
|
-
|
|
24
|
+
version = process.env.npm_config_nimsdkversion
|
|
21
25
|
}
|
|
22
26
|
async function downloadSDK(custom_sdk_url) {
|
|
23
27
|
if (custom_sdk_url) {
|
|
24
|
-
|
|
28
|
+
downloadUrl = custom_sdk_url
|
|
25
29
|
}
|
|
26
30
|
// fetch publish list
|
|
27
31
|
const res = await fetch('https://admin.netease.im/public-service/free/publish/list')
|
|
28
32
|
const publish_json = await res.json()
|
|
29
33
|
// get sdk list
|
|
30
|
-
if (!
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
Object.keys(publish_json.data[
|
|
34
|
-
if (compareVersions.compare(
|
|
35
|
-
publish_json.data[
|
|
36
|
-
if (member.filename.includes(
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
if (!downloadUrl) {
|
|
35
|
+
let latestVersion = '0.0.0'
|
|
36
|
+
let latestDownloadUrl = ''
|
|
37
|
+
Object.keys(publish_json.data[channel]).forEach((temp) => {
|
|
38
|
+
if (compareVersions.compare(latestVersion, temp, '<')) {
|
|
39
|
+
publish_json.data[channel][temp].forEach((member) => {
|
|
40
|
+
if (member.filename.includes(product) && member.filename.includes(platform) && member.filename.includes(arch)) {
|
|
41
|
+
latestVersion = temp
|
|
42
|
+
latestDownloadUrl = member.cdnlink
|
|
39
43
|
}
|
|
40
44
|
})
|
|
41
45
|
}
|
|
42
|
-
if (
|
|
43
|
-
publish_json.data[
|
|
44
|
-
if (member.filename.includes(
|
|
45
|
-
|
|
46
|
+
if (version === temp) {
|
|
47
|
+
publish_json.data[channel][temp].forEach((member) => {
|
|
48
|
+
if (member.filename.includes(product) && member.filename.includes(platform) && member.filename.includes(arch)) {
|
|
49
|
+
downloadUrl = member.cdnlink
|
|
46
50
|
}
|
|
47
51
|
})
|
|
48
52
|
}
|
|
49
53
|
})
|
|
50
|
-
if (!
|
|
51
|
-
console.log(
|
|
52
|
-
|
|
54
|
+
if (!downloadUrl || downloadUrl.length === 0) {
|
|
55
|
+
console.log(`[node-nim] Product [${product}] version ${version} not found, use latest version ${latestVersion}`)
|
|
56
|
+
downloadUrl = latestDownloadUrl
|
|
53
57
|
}
|
|
54
|
-
console.log(`[node-nim]
|
|
58
|
+
console.log(`[node-nim] Downloading product: ${product}, platform: ${platform}, arch: ${arch}`)
|
|
55
59
|
}
|
|
56
|
-
if (!
|
|
57
|
-
console.error(`[node-nim]
|
|
60
|
+
if (!downloadUrl) {
|
|
61
|
+
console.error(`[node-nim] Downloading product: ${product}, platform: ${platform}, arch: ${arch} not found`)
|
|
58
62
|
return
|
|
59
63
|
}
|
|
60
|
-
console.info(`[node-nim] Downloading prebuilt
|
|
61
|
-
// remove
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
console.info(`[node-nim] Downloading prebuilt SDK from ${downloadUrl} to ${savePath}`)
|
|
65
|
+
// remove temporary download folder and target folder
|
|
66
|
+
const target = path.join(__dirname, '..', 'build', 'Release')
|
|
67
|
+
if (fs.existsSync(savePath)) {
|
|
68
|
+
fs.rmSync(savePath, { recursive: true })
|
|
69
|
+
}
|
|
70
|
+
if (fs.existsSync(target)) {
|
|
71
|
+
fs.rmSync(target, { recursive: true })
|
|
64
72
|
}
|
|
65
73
|
// download sdk
|
|
66
74
|
try {
|
|
67
|
-
await download(
|
|
75
|
+
await download(downloadUrl, savePath, {
|
|
68
76
|
extract: true,
|
|
69
77
|
filter: (file) => {
|
|
70
78
|
return !file.path.includes('._')
|
|
71
79
|
}
|
|
72
80
|
})
|
|
81
|
+
// create build/Release folder
|
|
82
|
+
if (!fs.existsSync(target)) {
|
|
83
|
+
fs.mkdirSync(target, { recursive: true })
|
|
84
|
+
}
|
|
85
|
+
// move sdk/* files to build/Release
|
|
86
|
+
const from = path.join(savePath, platform === 'win32' ? 'bin' : 'lib')
|
|
87
|
+
const files = fs.readdirSync(from)
|
|
88
|
+
files.forEach((file) => {
|
|
89
|
+
console.info(`[node-nim] move ${file} to ${target}`)
|
|
90
|
+
fs.renameSync(path.join(from, file), path.join(target, file))
|
|
91
|
+
})
|
|
92
|
+
// remove temporary download folder
|
|
93
|
+
fs.rmSync(savePath, { recursive: true })
|
|
73
94
|
console.info(`[node-nim] Downloading prebuilt sdk complete`)
|
|
74
95
|
} catch (err) {
|
|
75
|
-
console.error(`[node-nim]
|
|
96
|
+
console.error(`[node-nim] Failed to download, error: ${err}`)
|
|
76
97
|
}
|
|
77
98
|
}
|
|
78
99
|
exports.downloadSDK = downloadSDK
|
package/types/loader.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare
|
|
2
|
-
export default
|
|
1
|
+
declare const _default: any;
|
|
2
|
+
export default _default;
|