-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeDatachannelPlugin.js
63 lines (59 loc) · 2.09 KB
/
NodeDatachannelPlugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable @typescript-eslint/no-var-requires */
const { PluginBase } = require('@electron-forge/plugin-base');
const path = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
module.exports = class NodeDatachannelPlugin extends PluginBase {
name = 'plugin-node-datachannel';
getHooks() {
return {
generateAssets: this.generateAssets,
};
}
generateAssets(config) {
return new Promise((resolve, reject) => {
try {
// if there is no node-datachannel folder, then return
if (!fs.existsSync(path.join(__dirname, '..', 'node-datachannel'))) {
return resolve();
}
if (
fs.existsSync(
path.join(
__dirname,
'..',
'node-datachannel',
'build',
'Release',
'plugin-node-datachannel-ok',
),
)
) {
return resolve();
} else {
// if there is no node-datachannel-plugin-ok file, then we need to build the module
execSync(
`cd ${path.join(__dirname, '..', 'node-datachannel')} && npm run install --build-from-source`,
{
stdio: 'inherit',
},
);
fs.writeFileSync(
path.join(
__dirname,
'..',
'node-datachannel',
'build',
'Release',
'plugin-node-datachannel-ok',
),
'',
);
return resolve();
}
} catch (e) {
reject(e);
}
});
}
};