Skip to content

Commit c2038d6

Browse files
committed
Install script
1 parent 201bdbf commit c2038d6

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

build.binaries.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "glslangValidator LICENSE",
55
"url": "https://raw.githubusercontent.com/KhronosGroup/glslang/master/LICENSE.txt",
66
"fileList": [
7-
"glslangValidator-LICENSE.txt"
7+
"glslangValidator-LICENSE"
88
]
99
},
1010
{

install.mjs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {configurePlatformBinaries, getPkg, allToolInfo} from './lib/tools.js';
2+
import {fixPerms, allFilesExist, downloadFile, downloadProgress,
3+
checkMakeFolder, unzipAndDelete} from './lib/download.js';
4+
import * as path from 'path';
5+
6+
const fatalError = (err) => {
7+
console.error(err);
8+
console.error(`Installing required binary tools failed.`);
9+
console.error(`\n** Manual Khronos tool installation required **\n\n${allToolInfo()}`);
10+
process.exit(0); // Allow npm install to proceed
11+
};
12+
13+
(async function main() {
14+
const binSource = configurePlatformBinaries();
15+
16+
if (!binSource || !binSource.tag) {
17+
fatalError('Prebuilt binaries not available for this platform');
18+
}
19+
20+
if (allFilesExist(binSource.fileList)) {
21+
console.info('All binaries already installed');
22+
fixPerms(binSource.fileList);
23+
process.exit(0);
24+
}
25+
26+
const downloadBaseURL = getPkg()?.installBinaries?.url;
27+
const downloadTag = getPkg()?.installBinaries?.tag;
28+
29+
if (!downloadBaseURL || !downloadTag) {
30+
fatalError('No configured download URL');
31+
}
32+
33+
try {
34+
checkMakeFolder(binSource.folderPath);
35+
} catch (err) {
36+
fatalError('Failed to create output folder');
37+
}
38+
39+
const downloadArchiveName = `${binSource.tag}.zip`;
40+
const downloadURL = new URL(`${downloadTag}/${downloadArchiveName}`, downloadBaseURL).toString();
41+
42+
const downloadArchivePath = path.join(binSource.folderPath, downloadArchiveName);
43+
44+
try {
45+
await downloadFile(downloadURL, downloadArchivePath, downloadProgress(`binaries for ${binSource.tag}`));
46+
47+
const unzippedFiles = unzipAndDelete(downloadArchivePath, binSource.folderPath);
48+
49+
console.log(unzippedFiles.join('\n'));
50+
51+
if (allFilesExist(binSource.fileList)) {
52+
fixPerms(binSource.fileList);
53+
} else {
54+
fatalError('Downloaded archive did not include the expected binaries');
55+
}
56+
57+
} catch (err) {
58+
console.log(err);
59+
fatalError(`Failed to download binaries for ${binSource.tag}\n${err.message}`);
60+
}
61+
62+
console.log('Install completed');
63+
process.exit(0);
64+
})();

lib/download.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import * as fsSync from 'fs';
22
import {default as createHttpsProxyAgent} from 'https-proxy-agent';
3-
import {default as FileCache} from '@derhuerst/http-basic/lib/FileCache.js';
3+
import {default as TFileCache} from '@derhuerst/http-basic/lib/FileCache.js';
44
import * as querystring from 'querystring';
55
import {default as request} from '@derhuerst/http-basic';
6-
import * as ProgressBar from 'progress';
7-
import * as AdmZip from 'adm-zip';
6+
import {default as ProgressBar} from 'progress';
7+
import {default as AdmZip} from 'adm-zip';
88

99
import {URL} from 'url';
1010
import {argQuote, getCachePath, launchToolPath, runTool} from './tools.js';
1111

12+
/**
13+
* @typedef {import('@derhuerst/http-basic/lib/FileCache.js').default} FileCacheInst
14+
* @type {typeof import('@derhuerst/http-basic/lib/FileCache.js').default} */
15+
const FileCache = (
16+
/** @type {any} */(TFileCache).default);
17+
1218
/**
1319
* @param {import('@derhuerst/http-basic').HttpVerb} method
1420
* @param {string | URL} url
@@ -31,7 +37,7 @@ const normalizeS3Url = (url) => {
3137
return url.href;
3238
};
3339

34-
/** @type {{proxyAgent: false|import('https-proxy-agent').HttpsProxyAgent, cache: FileCache}} */
40+
/** @type {{proxyAgent: false|import('https-proxy-agent').HttpsProxyAgent, cache: FileCacheInst}} */
3541
let httpHelpers = null;
3642
function initHTTP() {
3743
if (httpHelpers) return;

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
"main": "index.js",
2424
"type": "module",
2525
"scripts": {
26+
"install": "node install.mjs",
2627
"lint": "eslint .",
2728
"test": "node ./test/index.js"
2829
},
30+
"installBinaries": {
31+
"url": "https://github.com/docd27/rollup-plugin-glsl-optimize/releases/download/",
32+
"tag": "b0.0.1"
33+
},
2934
"dependencies": {
3035
"@derhuerst/http-basic": "^8.2.1",
3136
"@rollup/pluginutils": "^4.1.0",

0 commit comments

Comments
 (0)