-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
101 lines (84 loc) · 2.89 KB
/
install.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
const { version } = require('./package');
const fs = require('fs');
const os = require('os');
const path = require('path');
const extract = require('extract-zip');
const { downloadArtifact } = require('@electron/get');
if (process.env.ELECTRON_SKIP_BINARY_DOWNLOAD) {
process.exit(0)
}
const platformPath = getPlatformPath()
if (isInstalled()) {
process.exit(0);
}
const platform = process.env.npm_config_platform || process.platform;
const arch = process.env.npm_config_arch || process.arch;
// downloads if not cached
const electroniteRepoUrl = 'https://github.com/unfoldingWord/electronite/releases/download/';
const electroniteVersion = 'v' + version;
const artifactName = 'electronite-v' + version + '-' + platform + '-' + arch + '.zip';
console.log('Downloading Electronite if not loaded: ');
console.log('electroniteRepoUrl:', electroniteRepoUrl);
console.log('electroniteVersion:', electroniteVersion);
console.log('artifactName:', artifactName);
downloadArtifact({
version,
artifactName: 'electron',
force: process.env.force_no_cache === 'true',
cacheRoot: process.env.electron_config_cache,
platform,
arch,
// electronite specific configuration
unsafelyDisableChecksums: true,
mirrorOptions: {
mirror: electroniteRepoUrl,
customDir: electroniteVersion,
customFilename: artifactName
}
}).then(extractFile).catch(err => {
console.error(err.stack);
process.exit(1);
});
function isInstalled () {
try {
if (fs.readFileSync(path.join(__dirname, 'dist', 'version'), 'utf-8').replace(/^v/, '') !== version) {
return false;
}
if (fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8') !== platformPath) {
return false;
}
} catch (ignored) {
return false;
}
const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist', platformPath);
return fs.existsSync(electronPath);
}
// unzips and makes path.txt point at the correct executable
function extractFile (zipPath) {
return new Promise((resolve, reject) => {
extract(zipPath, { dir: path.join(__dirname, 'dist') }, err => {
if (err) return reject(err);
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, err => {
if (err) return reject(err);
resolve();
});
});
});
}
function getPlatformPath () {
const platform = process.env.npm_config_platform || os.platform();
switch (platform) {
case 'mas':
case 'darwin':
return 'Electron.app/Contents/MacOS/Electron';
case 'freebsd':
case 'openbsd':
case 'linux':
return 'electron';
case 'win32':
return 'electron.exe';
default:
throw new Error('Electron builds are not available on platform: ' + platform);
}
}