Files
blitzkit/packages/scripts/src/setupDepotDownloader.ts
T

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-01-22 13:40:37 -06:00
import decompress from 'decompress';
import { existsSync } from 'fs';
2024-02-19 20:32:12 -06:00
import { mkdir, readdir, writeFile } from 'fs/promises';
2024-01-22 13:40:37 -06:00
2024-10-21 11:11:25 -05:00
if (!existsSync('../../temp')) {
2024-01-22 13:40:37 -06:00
console.log('Creating temp directory...');
2024-10-21 11:11:25 -05:00
await mkdir('../../temp');
2024-01-22 13:40:37 -06:00
}
console.log('Downloading depot downloader...');
await fetch(
'https://api.github.com/repos/SteamRE/DepotDownloader/releases/latest',
)
.then(
(response) =>
response.json() as Promise<{
2024-02-19 20:42:30 -06:00
assets: { browser_download_url: string; name: string }[];
2024-01-22 13:40:37 -06:00
}>,
)
2024-02-19 20:42:30 -06:00
.then(({ assets }) => {
2024-08-23 19:50:48 -05:00
const asset = assets.find(({ name }) => name.includes('linux-x64'));
2024-02-19 20:42:30 -06:00
if (!asset) throw new Error('No asset found');
return fetch(asset.browser_download_url);
})
2024-01-22 13:40:37 -06:00
.then((response) => response.arrayBuffer())
.then((arrayBuffer) =>
2024-10-21 11:11:25 -05:00
writeFile('../../temp/depotDownloader.zip', new Uint8Array(arrayBuffer)),
2024-01-22 13:40:37 -06:00
);
console.log('Unzipping...');
2024-10-21 11:11:25 -05:00
await decompress(
'../../temp/depotDownloader.zip',
'../../temp/depotDownloader',
);
2024-02-19 20:32:12 -06:00
2024-10-21 11:11:25 -05:00
console.log(
'Download complete; files:',
await readdir('../../temp/depotDownloader'),
);