-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.mjs
82 lines (65 loc) · 2.29 KB
/
install.mjs
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
import {configurePlatformBinaries, getPkg, allToolInfo} from './src/lib/tools.js';
import {fixPerms, allFilesExist, downloadFile, downloadProgress,
checkMakeFolder, unzipAndDelete} from './src/lib/download.js';
import * as path from 'path';
const fatalError = (err) => {
console.error(err);
console.error(`Installing required binary tools failed.`);
console.error(`\n** Manual Khronos tool installation required **\n\n${allToolInfo()}`);
installStatus.message = err;
installStatus.error = true;
installStatus.done = true;
process.exitCode = 0; // Allow npm install to proceed
};
// For test instrumentation
export const installStatus = {
done: false,
installed: false,
error: false,
message: undefined,
};
(async function main() {
const binSource = configurePlatformBinaries();
if (!binSource || !binSource.tag) {
fatalError('Prebuilt binaries not available for this platform');
return;
}
if (allFilesExist(binSource.fileList)) {
console.info('All binaries already installed');
fixPerms(binSource.fileList);
installStatus.done = true;
return;
}
const downloadBaseURL = getPkg()?.installBinaries?.url;
const downloadTag = getPkg()?.installBinaries?.tag;
if (!downloadBaseURL || !downloadTag) {
fatalError('No configured download URL');
return;
}
try {
checkMakeFolder(binSource.folderPath);
} catch (err) {
fatalError('Failed to create output folder');
return;
}
const downloadArchiveName = `${binSource.tag}.zip`;
const downloadURL = new URL(`${downloadTag}/${downloadArchiveName}`, downloadBaseURL).toString();
const downloadArchivePath = path.join(binSource.folderPath, downloadArchiveName);
try {
await downloadFile(downloadURL, downloadArchivePath, downloadProgress(`binaries for ${binSource.tag}`));
const unzippedFiles = unzipAndDelete(downloadArchivePath, binSource.folderPath);
if (allFilesExist(binSource.fileList)) {
fixPerms(binSource.fileList);
} else {
fatalError('Downloaded archive did not include the expected binaries');
return;
}
} catch (err) {
console.log(err);
fatalError(`Failed to download binaries for ${binSource.tag}\n${err.message}`);
return;
}
installStatus.installed = true;
console.log('Install completed');
installStatus.done = true;
})();