trtc-electron-sdk 11.3.601-alpha.0 → 11.3.601-alpha.1
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/package.json +2 -1
- package/scripts/constant.js +9 -0
- package/scripts/copy-sdk.js +70 -0
- package/scripts/copy-types.js +3 -0
- package/scripts/download.js +205 -0
- package/scripts/prerelase.js +19 -0
- package/scripts/publish-doc.js +91 -0
- package/scripts/publish-npm.js +26 -0
- package/scripts/utils.js +86 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trtc-electron-sdk",
|
|
3
|
-
"version": "11.3.601-alpha.
|
|
3
|
+
"version": "11.3.601-alpha.1",
|
|
4
4
|
"description": "trtc electron sdk",
|
|
5
5
|
"main": "./liteav/trtc.js",
|
|
6
6
|
"types": "./liteav/trtc.d.ts",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"build",
|
|
66
66
|
"liteav",
|
|
67
67
|
"types",
|
|
68
|
+
"scripts",
|
|
68
69
|
"README.md",
|
|
69
70
|
"package.json"
|
|
70
71
|
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { removeSync, copySync } = require("fs-extra");
|
|
3
|
+
|
|
4
|
+
// npm run copy:sdk
|
|
5
|
+
const SDK_ROOT = path.resolve(__dirname, "../../");
|
|
6
|
+
const SDK_CPP_PATH = path.join(SDK_ROOT, "trtc-electron-cpp");
|
|
7
|
+
const SDK_JS_PATH = path.join(SDK_ROOT, "trtc-electron-sdk");
|
|
8
|
+
|
|
9
|
+
removeSync(path.join(SDK_JS_PATH, "build"));
|
|
10
|
+
|
|
11
|
+
copySync(
|
|
12
|
+
path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node"),
|
|
13
|
+
path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.node")
|
|
14
|
+
);
|
|
15
|
+
if (process.platform === "win32") {
|
|
16
|
+
let dllPrefix = "";
|
|
17
|
+
if (process.arch === "x64") {
|
|
18
|
+
dllPrefix = "Win64";
|
|
19
|
+
} else {
|
|
20
|
+
dllPrefix = "Win32";
|
|
21
|
+
}
|
|
22
|
+
copySync(
|
|
23
|
+
path.resolve(SDK_CPP_PATH, `v2/win/${dllPrefix}/lib/`),
|
|
24
|
+
path.resolve(SDK_JS_PATH, "build/Release/")
|
|
25
|
+
);
|
|
26
|
+
copySync(
|
|
27
|
+
path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.pdb"),
|
|
28
|
+
path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.pdb")
|
|
29
|
+
);
|
|
30
|
+
} else if (process.platform === 'darwin') {
|
|
31
|
+
copySync(
|
|
32
|
+
path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node"),
|
|
33
|
+
path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/trtc_electron_sdk.node`)
|
|
34
|
+
);
|
|
35
|
+
copySync(
|
|
36
|
+
path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node.dSYM"),
|
|
37
|
+
path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.node.dSYM")
|
|
38
|
+
);
|
|
39
|
+
copySync(
|
|
40
|
+
path.resolve(SDK_CPP_PATH, `v2/mac/Frameworks/${process.arch}/TXFFmpeg.framework`),
|
|
41
|
+
path.resolve(SDK_JS_PATH, `build/mac-framework/${process.arch}/TXFFmpeg.framework`)
|
|
42
|
+
);
|
|
43
|
+
copySync(
|
|
44
|
+
path.resolve(SDK_CPP_PATH, `v2/mac/Frameworks/${process.arch}/TXSoundTouch.framework`),
|
|
45
|
+
path.resolve(SDK_JS_PATH, `build/mac-framework/${process.arch}/TXSoundTouch.framework`)
|
|
46
|
+
);
|
|
47
|
+
} else {
|
|
48
|
+
// linux
|
|
49
|
+
let soPrefix = ""
|
|
50
|
+
if (process.arch === 'x64') {
|
|
51
|
+
soPrefix = "x86_64";
|
|
52
|
+
} else {
|
|
53
|
+
soPrefix = "arm64";
|
|
54
|
+
}
|
|
55
|
+
copySync(
|
|
56
|
+
path.resolve(SDK_CPP_PATH, 'build/Release/trtc_electron_sdk.node'),
|
|
57
|
+
path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/trtc_electron_sdk.node`)
|
|
58
|
+
);
|
|
59
|
+
copySync(
|
|
60
|
+
path.resolve(SDK_CPP_PATH, `v2/linux/libs/${soPrefix}/`),
|
|
61
|
+
path.resolve(SDK_JS_PATH, 'build/Release/')
|
|
62
|
+
);
|
|
63
|
+
copySync(
|
|
64
|
+
path.resolve(SDK_CPP_PATH, `v2/linux/libs/${soPrefix}/`),
|
|
65
|
+
path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/`)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
console.log("CopySDKManual.doCopy: 复制结束");
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
const download = require('download');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs-extra');
|
|
4
|
+
const rimraf = require('rimraf');
|
|
5
|
+
const signale = require('signale');
|
|
6
|
+
const { exec } = require('child_process');
|
|
7
|
+
const { HttpsProxyAgent } = require('hpagent');
|
|
8
|
+
|
|
9
|
+
const currentPath = path.join(__dirname, "../");
|
|
10
|
+
if (currentPath.indexOf("source-sdk/trtc-electron-sdk")) {
|
|
11
|
+
signale.info("trtc-electron-sdk: development mode, skip native sdk lib download");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
readCliArgv,
|
|
17
|
+
readArgvFromNpmEnv,
|
|
18
|
+
detectOS,
|
|
19
|
+
detectOwnVersion,
|
|
20
|
+
detectOwnName,
|
|
21
|
+
readProxyUrlFromEnv,
|
|
22
|
+
} = require('./utils');
|
|
23
|
+
const { Platform } = require('./constant');
|
|
24
|
+
|
|
25
|
+
const buildDownloadInfo = () => {
|
|
26
|
+
const configArgv = Object.assign({
|
|
27
|
+
arch: process.arch,
|
|
28
|
+
platform: process.platform,
|
|
29
|
+
}, readCliArgv(), readArgvFromNpmEnv());
|
|
30
|
+
|
|
31
|
+
// build os label
|
|
32
|
+
const osLabel = detectOS(configArgv.arch, configArgv.platform);
|
|
33
|
+
|
|
34
|
+
// build version label
|
|
35
|
+
const { version } = detectOwnVersion();
|
|
36
|
+
signale.info('buildDownloadInfo version=', version);
|
|
37
|
+
|
|
38
|
+
const name = detectOwnName();
|
|
39
|
+
signale.info('buildDownloadInfo name=', name);
|
|
40
|
+
|
|
41
|
+
// generate download url
|
|
42
|
+
return {
|
|
43
|
+
platform: osLabel,
|
|
44
|
+
downloadUrl: `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${osLabel}-${version}.zip`,
|
|
45
|
+
name,
|
|
46
|
+
version,
|
|
47
|
+
archType: configArgv.arch
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const main = () => {
|
|
52
|
+
const {
|
|
53
|
+
platform,
|
|
54
|
+
downloadUrl,
|
|
55
|
+
name,
|
|
56
|
+
version,
|
|
57
|
+
archType
|
|
58
|
+
} = buildDownloadInfo();
|
|
59
|
+
|
|
60
|
+
const outputDir = path.join(__dirname, '../temp');
|
|
61
|
+
const buildDir = path.join(__dirname, '../build');
|
|
62
|
+
|
|
63
|
+
rimraf.sync(outputDir);
|
|
64
|
+
rimraf(buildDir, err => {
|
|
65
|
+
if (err) {
|
|
66
|
+
signale.error(err);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// print download info
|
|
71
|
+
signale.info('removeDir =', buildDir);
|
|
72
|
+
signale.info('outputDir =', outputDir);
|
|
73
|
+
|
|
74
|
+
signale.info('Package Version =', version);
|
|
75
|
+
signale.info('Platform =', platform);
|
|
76
|
+
signale.info('Download Url =', downloadUrl, '\n');
|
|
77
|
+
|
|
78
|
+
signale.pending('Downloading C++ addon Electron SDK...\n');
|
|
79
|
+
const downloadOptions = {
|
|
80
|
+
strip: 0,
|
|
81
|
+
extract: true
|
|
82
|
+
};
|
|
83
|
+
const proxyUrl = readProxyUrlFromEnv(downloadUrl);
|
|
84
|
+
if (proxyUrl) {
|
|
85
|
+
downloadOptions.agent = {
|
|
86
|
+
https: new HttpsProxyAgent({
|
|
87
|
+
keepAlive: true,
|
|
88
|
+
keepAliveMsecs: 1000,
|
|
89
|
+
maxSockets: 256,
|
|
90
|
+
maxFreeSockets: 256,
|
|
91
|
+
scheduling: 'lifo',
|
|
92
|
+
proxy: proxyUrl
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
download(downloadUrl, outputDir, downloadOptions).then(() => {
|
|
97
|
+
signale.success(`Download finished - ${platform}`);
|
|
98
|
+
|
|
99
|
+
fs.copySync(
|
|
100
|
+
path.join(outputDir, './build/Release'),
|
|
101
|
+
path.join(buildDir, 'Release')
|
|
102
|
+
);
|
|
103
|
+
signale.success(`copy success! - ${platform}`);
|
|
104
|
+
|
|
105
|
+
if (platform === Platform.WINDOWS32 || platform === Platform.WINDOWS64) {
|
|
106
|
+
// windows 下
|
|
107
|
+
rimraf.sync(outputDir);
|
|
108
|
+
} else if (platform === 'mac' || platform === 'mac-arm64') {
|
|
109
|
+
// mac 下
|
|
110
|
+
const arch = archType;
|
|
111
|
+
fs.copySync(
|
|
112
|
+
path.join(outputDir, './build/Release/trtc_electron_sdk.node'),
|
|
113
|
+
path.join(buildDir, 'Release', arch, 'trtc_electron_sdk.node')
|
|
114
|
+
);
|
|
115
|
+
fs.copySync(
|
|
116
|
+
path.join(outputDir, './build/mac-framework', arch),
|
|
117
|
+
path.join(buildDir, 'mac-framework', arch)
|
|
118
|
+
);
|
|
119
|
+
signale.success(`copy success! - mac ${arch}`, '\n');
|
|
120
|
+
|
|
121
|
+
let anotherPlatform, anotherArch;
|
|
122
|
+
if (arch === 'x64') {
|
|
123
|
+
// download arm64
|
|
124
|
+
anotherPlatform = Platform.MACOS_ARM;
|
|
125
|
+
anotherArch = 'arm64';
|
|
126
|
+
} else {
|
|
127
|
+
// arch = arm64, download x64
|
|
128
|
+
anotherPlatform = Platform.MACOS;
|
|
129
|
+
anotherArch = 'x64';
|
|
130
|
+
}
|
|
131
|
+
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
132
|
+
signale.info('Download Url =', anotherDownloadUrl, '\n');
|
|
133
|
+
signale.pending(`Downloading C++ addon Electron SDK... ${anotherArch}\n`);
|
|
134
|
+
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
135
|
+
strip: 0,
|
|
136
|
+
extract: true
|
|
137
|
+
})
|
|
138
|
+
.then(() => {
|
|
139
|
+
signale.success(`Download finished - mac ${anotherArch}`);
|
|
140
|
+
|
|
141
|
+
fs.copySync(
|
|
142
|
+
path.join(outputDir, anotherPlatform, '/build/Release/trtc_electron_sdk.node'),
|
|
143
|
+
path.join(buildDir, 'Release', anotherArch, 'trtc_electron_sdk.node')
|
|
144
|
+
);
|
|
145
|
+
fs.copySync(
|
|
146
|
+
path.join(outputDir, anotherPlatform, '/build/mac-framework', anotherArch),
|
|
147
|
+
path.join(buildDir, 'mac-framework', anotherArch)
|
|
148
|
+
);
|
|
149
|
+
signale.success(`copy success! - mac ${anotherArch}`);
|
|
150
|
+
|
|
151
|
+
// Mac 下完成文件下载后,执行该命令,同步文件到 Electron 目录下
|
|
152
|
+
exec(`rsync -a ../../node_modules/trtc-electron-sdk/build/mac-framework/${archType}/ ../../node_modules/electron/dist/Electron.app/Contents/Frameworks`);
|
|
153
|
+
|
|
154
|
+
rimraf.sync(outputDir);
|
|
155
|
+
})
|
|
156
|
+
.catch(err => {
|
|
157
|
+
signale.error(`download error! - mac ${anotherPlatform}`, err);
|
|
158
|
+
});
|
|
159
|
+
} else if (platform === 'linux-x64' || platform === 'linux-arm64') {
|
|
160
|
+
// Linux 下
|
|
161
|
+
const arch = process.arch;
|
|
162
|
+
fs.copySync(
|
|
163
|
+
path.join(outputDir, './build/Release'),
|
|
164
|
+
path.join(buildDir, 'Release', arch)
|
|
165
|
+
);
|
|
166
|
+
signale.success(`copy success! - linux ${arch}`, '\n');
|
|
167
|
+
|
|
168
|
+
let anotherPlatform, anotherArch;
|
|
169
|
+
if (arch === 'x64') {
|
|
170
|
+
// download arm64
|
|
171
|
+
anotherPlatform = Platform.LINUX_ARM64;
|
|
172
|
+
anotherArch = 'arm64';
|
|
173
|
+
} else {
|
|
174
|
+
// arch = arm64, download x64
|
|
175
|
+
anotherPlatform = Platform.LINUX_X64;
|
|
176
|
+
anotherArch = 'x64';
|
|
177
|
+
}
|
|
178
|
+
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
179
|
+
signale.info('Download Url =', anotherDownloadUrl, '\n');
|
|
180
|
+
signale.pending(`Downloading C++ addon Electron SDK... ${anotherArch}\n`);
|
|
181
|
+
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
182
|
+
strip: 0,
|
|
183
|
+
extract: true
|
|
184
|
+
}).then(() => {
|
|
185
|
+
signale.success(`Download finished - linux ${anotherArch}`);
|
|
186
|
+
fs.copySync(
|
|
187
|
+
path.join(outputDir, anotherPlatform, '/build/Release'),
|
|
188
|
+
path.join(buildDir, 'Release', anotherArch)
|
|
189
|
+
);
|
|
190
|
+
signale.success(`copy success! - linux ${anotherArch}`);
|
|
191
|
+
|
|
192
|
+
rimraf.sync(outputDir);
|
|
193
|
+
}).catch(err => {
|
|
194
|
+
signale.error(`download error! - linux ${anotherPlatform}`, err);
|
|
195
|
+
})
|
|
196
|
+
} else {
|
|
197
|
+
signale.warn(`Not supported platform: ${platform}`);
|
|
198
|
+
}
|
|
199
|
+
}).catch(err => {
|
|
200
|
+
signale.error(`Failed! Download error - ${platform}`, err);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
main();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const {copy, remove} = require('fs-sync');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
const liteavPath = path.join(__dirname, '../liteav');
|
|
6
|
+
const liteavFiles = fs.readdirSync(liteavPath, {withFileTypes: true});
|
|
7
|
+
liteavFiles.forEach(file => {
|
|
8
|
+
if (file.isFile() && file.name.indexOf('_en.') !== -1) {
|
|
9
|
+
const filePath = path.join(liteavPath, file.name);
|
|
10
|
+
console.log(`Remove en files not to be published: `, filePath);
|
|
11
|
+
remove(filePath);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
remove('./npm');
|
|
16
|
+
copy(path.resolve('./liteav'), path.resolve('./npm/liteav'));
|
|
17
|
+
copy(path.resolve('./scripts'), path.resolve('./npm/scripts'));
|
|
18
|
+
copy(path.resolve('./package.json'), path.resolve('./npm/package.json'));
|
|
19
|
+
copy(path.resolve('./README.md'), path.resolve('./npm/README.md'));
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const COS = require('cos-nodejs-sdk-v5');
|
|
4
|
+
|
|
5
|
+
const cosConfig = {
|
|
6
|
+
SecretId: '',
|
|
7
|
+
SecretKey: ''
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
let enableWrite = false;
|
|
11
|
+
const myArgs = process.argv.slice(2);
|
|
12
|
+
myArgs.forEach(arg => {
|
|
13
|
+
if (arg.includes('=')) {
|
|
14
|
+
const [key, value] = arg.split('=');
|
|
15
|
+
if (key === 'SecretId' && value) {
|
|
16
|
+
// 注意: 确保在蓝盾运行时才打开, 真正上传文档到 cos
|
|
17
|
+
enableWrite = true;
|
|
18
|
+
cosConfig.SecretId = value;
|
|
19
|
+
}
|
|
20
|
+
if (key === 'SecretKey' && value) {
|
|
21
|
+
cosConfig.SecretKey = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!cosConfig.SecretId || !cosConfig.SecretKey) {
|
|
27
|
+
console.log('unable to upload doc');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const cos = new COS({
|
|
31
|
+
SecretId: cosConfig.SecretId,
|
|
32
|
+
SecretKey: cosConfig.SecretKey
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const bucket = 'sdk-web-1252463788';
|
|
36
|
+
const region = 'ap-hongkong';
|
|
37
|
+
const keyPrefix = 'trtc/electron/doc/';
|
|
38
|
+
const docPath = path.join(__dirname, '../_doc');
|
|
39
|
+
|
|
40
|
+
function walkSync(dir, filelist) {
|
|
41
|
+
const files = fs.readdirSync(dir);
|
|
42
|
+
filelist = filelist || [];
|
|
43
|
+
files.forEach(function(file) {
|
|
44
|
+
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
|
45
|
+
filelist = walkSync(path.join(dir, file), filelist);
|
|
46
|
+
} else {
|
|
47
|
+
filelist.push({
|
|
48
|
+
path: path.join(dir, file),
|
|
49
|
+
name: path.relative(docPath, path.join(dir, file))
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return filelist;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function getUploadFiles(docFileList) {
|
|
57
|
+
return docFileList.map(file => {
|
|
58
|
+
return {
|
|
59
|
+
Bucket: bucket,
|
|
60
|
+
Region: region,
|
|
61
|
+
Key: keyPrefix + file.name,
|
|
62
|
+
FilePath: file.path,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function uploadFiles() {
|
|
68
|
+
const docFileList = [];
|
|
69
|
+
walkSync(docPath, docFileList);
|
|
70
|
+
const fileList = getUploadFiles(docFileList);
|
|
71
|
+
if (enableWrite) {
|
|
72
|
+
cos.uploadFiles({
|
|
73
|
+
files: fileList,
|
|
74
|
+
SliceSize: 1024 * 1024,
|
|
75
|
+
onProgress: function (info) {
|
|
76
|
+
const percent = parseInt(info.percent * 10000) / 100;
|
|
77
|
+
const speed = parseInt((info.speed / 1024 / 1024) * 100) / 100;
|
|
78
|
+
console.log(`进度:${percent}%; 速度:${speed}Mb/s;`);
|
|
79
|
+
},
|
|
80
|
+
onFileFinish: function (err, data, options) {
|
|
81
|
+
console.log(`${options.Key}上传${err ? '失败' : '完成'}`);
|
|
82
|
+
},
|
|
83
|
+
}, function (err, data) {
|
|
84
|
+
if (err) {
|
|
85
|
+
console.log(JSON.stringify(err));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
uploadFiles();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
// trtc-electron-sdk 蓝盾地址: http://devops.oa.com/console/pipeline/ecc/p-b80c02872fad42dc9763c266593dfaed/history
|
|
6
|
+
// 因为需要去覆盖 ~/.npmrc 文件, 所以构建环境采用的是 macOS on DevCloud 云主机
|
|
7
|
+
|
|
8
|
+
let npmToken = '';
|
|
9
|
+
const myArgs = process.argv.slice(2);
|
|
10
|
+
myArgs.forEach(arg => {
|
|
11
|
+
if (arg.includes('=')) {
|
|
12
|
+
const [key, value] = arg.split('=');
|
|
13
|
+
if (key === 'npmToken' && value) {
|
|
14
|
+
npmToken = value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!npmToken) {
|
|
20
|
+
console.log('not publish npmToken, cant publish npm');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(path.resolve(os.homedir(), '.npmrc'), `//registry.npmjs.org/:_authToken=${npmToken}`);
|
|
24
|
+
|
|
25
|
+
const content = fs.readFileSync(path.resolve(os.homedir(), '.npmrc'), {encoding: 'utf8'});
|
|
26
|
+
console.log('content: ', content);
|
package/scripts/utils.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils for command line tools
|
|
3
|
+
*/
|
|
4
|
+
const semver = require('semver');
|
|
5
|
+
const pkg = require('../package.json');
|
|
6
|
+
|
|
7
|
+
const { Platform } = require('./constant');
|
|
8
|
+
|
|
9
|
+
module.exports.readCliArgv = function() {
|
|
10
|
+
const cliArgv = process.argv;
|
|
11
|
+
const newArgv = {};
|
|
12
|
+
let tmp = [];
|
|
13
|
+
console.log('readCliArgv',cliArgv);
|
|
14
|
+
for (let i = 0, len = cliArgv.length ; i < len ; i++) {
|
|
15
|
+
if (i === 0) {
|
|
16
|
+
newArgv.nodeDir = cliArgv[i];
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (i === 1) {
|
|
20
|
+
newArgv.scriptDir = cliArgv[i];
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
tmp = cliArgv[i].replace('--','').split('=');
|
|
24
|
+
newArgv[tmp[0]] = tmp[1];
|
|
25
|
+
tmp = [];
|
|
26
|
+
}
|
|
27
|
+
return newArgv;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports.readProxyUrlFromEnv = function(downloadUrl) {
|
|
31
|
+
if (downloadUrl.indexOf('https') === 0) {
|
|
32
|
+
return process.env.https_proxy || ''
|
|
33
|
+
}
|
|
34
|
+
return process.env.http_proxy || '';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports.readArgvFromNpmEnv = function() {
|
|
38
|
+
const result = {};
|
|
39
|
+
if (process.env.npm_config_trtc_electron_arch) {
|
|
40
|
+
result.arch = process.env.npm_config_trtc_electron_arch;
|
|
41
|
+
}
|
|
42
|
+
if (process.env.npm_config_trtc_electron_platform) {
|
|
43
|
+
result.platform = process.env.npm_config_trtc_electron_platform;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports.detectOS = (archType = '', platformType = '') => {
|
|
49
|
+
const platform = platformType !== '' ? platformType : process.platform;
|
|
50
|
+
const arch = archType !== '' ? archType : process.arch;
|
|
51
|
+
if (platform === 'darwin') {
|
|
52
|
+
if (arch === 'x64') {
|
|
53
|
+
return Platform.MACOS;
|
|
54
|
+
} else {
|
|
55
|
+
return Platform.MACOS_ARM;
|
|
56
|
+
}
|
|
57
|
+
} else if (platform === 'win32') {
|
|
58
|
+
if (arch === 'x64') {
|
|
59
|
+
return Platform.WINDOWS64;
|
|
60
|
+
} else {
|
|
61
|
+
return Platform.WINDOWS32;
|
|
62
|
+
}
|
|
63
|
+
} else if (platform === 'linux') {
|
|
64
|
+
if (arch === 'x64') {
|
|
65
|
+
return Platform.LINUX_X64;
|
|
66
|
+
} else if (arch === 'arm64') {
|
|
67
|
+
return Platform.LINUX_ARM64;
|
|
68
|
+
} else {
|
|
69
|
+
// unsupported
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Platform.UNSUPPORTED;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
module.exports.detectOwnVersion = () => {
|
|
76
|
+
const { major, minor, patch } = semver.coerce(pkg.version);
|
|
77
|
+
return {
|
|
78
|
+
major, minor, patch, version: pkg.version
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
module.exports.detectOwnName = () => {
|
|
83
|
+
const name = pkg.name;
|
|
84
|
+
return name;
|
|
85
|
+
};
|
|
86
|
+
|