Files
blitzkit/scripts/setupDepotDownloader.ts
T

33 lines
1.0 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
if (!existsSync('temp')) {
console.log('Creating temp directory...');
await mkdir('temp');
}
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-02-19 21:10:13 -06:00
const asset = assets.find(({ name }) => name.includes('windows-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) =>
writeFile('temp/depotDownloader.zip', Buffer.from(arrayBuffer)),
);
console.log('Unzipping...');
2024-02-19 20:37:34 -06:00
await decompress('temp/depotDownloader.zip', 'temp/depotDownloader');
2024-02-19 20:32:12 -06:00
2024-02-19 20:44:44 -06:00
console.log('Download complete; files:', await readdir('temp/depotDownloader'));