Skip to content

Commit a24bc46

Browse files
committed
chore: update agora-electron-sdk config
1 parent 024ae22 commit a24bc46

11 files changed

Lines changed: 67 additions & 161 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,5 @@ $RECYCLE.BIN/
194194
# IDE
195195
.idea/
196196
.vscode/
197+
198+
.npmrc

package.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "root",
33
"private": true,
44
"scripts": {
5-
"preinstall": "node ./scripts/Build-agora-sdk.js"
5+
"preinstall": "node ./scripts/preinstall"
66
},
77
"workspaces": {
88
"packages": [
@@ -13,15 +13,6 @@
1313
"**"
1414
]
1515
},
16-
"agora_electron": {
17-
"platform": "darwin",
18-
"arch": "x64",
19-
"electron_version": "7.1.2",
20-
"msvs_version": "2017",
21-
"silent": false,
22-
"debug": false,
23-
"prebuilt": true
24-
},
2516
"license": "MIT",
2617
"dependencies": {}
27-
}
18+
}

scripts/Build-agora-sdk.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/agora-electron-options.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// see: https://github.com/AgoraIO/Electron-SDK/wiki/Installation-Configuration-in-package.json
2+
const agoraSdkOptions = {
3+
arch: process.platform === "win32" ? "ia32" : "x64",
4+
platform: process.platform === "win32" ? "win32" : "darwin",
5+
// agora-electron-sdk currently only supports 7.1.2 pre-compilation, but supports 7.1.14 version of electron
6+
electron_version: "7.1.2",
7+
msvs_version: "2017",
8+
silent: false,
9+
debug: false,
10+
// Please do not set to false unless you know what you are doing.
11+
prebuilt: true,
12+
};
13+
14+
module.exports = agoraSdkOptions;

scripts/package.json

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require("fs").promises;
2+
const path = require("path");
3+
const agoraSdkOptions = require("../agora-electron-options");
4+
5+
const npmrcPath = path.join(__dirname, "..", "..", ".npmrc");
6+
7+
writeAgoraToNpmrc().catch(console.error);
8+
9+
async function writeAgoraToNpmrc() {
10+
const agoraOptions = addAgoraNpmrcPrefix(agoraSdkOptions);
11+
const options = await readNpmrc(npmrcPath);
12+
Object.keys(agoraOptions).forEach(key => {
13+
options[key] = agoraOptions[key];
14+
});
15+
await writeNpmrc(npmrcPath, options);
16+
}
17+
18+
function addAgoraNpmrcPrefix(agoraSdkOptions) {
19+
return Object.keys(agoraSdkOptions).reduce((npmrcOptions, key) => {
20+
if (key === "electron_version") {
21+
npmrcOptions[`agora_electron_dependent`] = `${agoraSdkOptions[key]}`;
22+
}
23+
npmrcOptions[`agora_electron_${key}`] = `${agoraSdkOptions[key]}`;
24+
return npmrcOptions;
25+
}, {});
26+
}
27+
28+
async function readNpmrc(npmrcPath) {
29+
const npmrcOptions = {};
30+
try {
31+
const str = await fs.readFile(npmrcPath, "utf8");
32+
const optMatcher = /^([^=]+)=([^=]*)$/gm;
33+
for (let matchResult; (matchResult = optMatcher.exec(str)) !== null; ) {
34+
npmrcOptions[matchResult[1].trim()] = matchResult[2].trim();
35+
}
36+
} catch (e) {
37+
// empty file
38+
}
39+
return npmrcOptions;
40+
}
41+
42+
async function writeNpmrc(npmrcPath, options) {
43+
const str = Object.keys(options)
44+
.map(key => `${key}=${options[key]}`)
45+
.join("\n");
46+
await fs.writeFile(npmrcPath, str);
47+
}

scripts/preinstall/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./configure-agora-sdk");

scripts/src/Utils.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

scripts/src/index.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/yarn.lock

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)