Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 4 additions & 66 deletions build/bundle-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,11 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-console */

import * as fs from 'fs';
import * as path from 'path';
import { exit } from 'process';
import { Archive } from './archive';
import { DownloadUtil } from './download';

import hasha = require('hasha');
import mkdirp = require('mkdirp');
import path = require('path');
import fs = require('fs-extra');
import configData = require('../src/tools.json');

export interface PlatformData {
url: string;
sha256sum: string;
dlFileName: string;
cmdFileName: string;
filePrefix: string;
}

export async function isDownloadRequired(filePath: string, sha256: string): Promise<boolean> {
let result = true;
if (fs.existsSync(filePath)) {
const fileSha256 = await hasha.fromFile(filePath, { algorithm: 'sha256' });
result = fileSha256 !== sha256;
}
return result;
}

async function extractTool(toolsFolder: string, platform: PlatformData, currentFile: string): Promise<void> {
let toolLocation = toolsFolder;
if (process.env.REMOTE_CONTAINERS === undefined) {
toolLocation = path.join(toolsFolder, platform.cmdFileName);
}
console.log(`Extracting ${currentFile} to ${toolLocation}`);
if (!currentFile.endsWith('.exe') && currentFile.includes('.')) {
await Archive.extract(currentFile, toolsFolder, platform.cmdFileName, platform.filePrefix);
} else {
fs.copyFileSync(currentFile, toolLocation);
}
}

export async function downloadFileAndCreateSha256(
toolsCacheFolder: string,
toolsFolder: string,
platform: PlatformData,
): Promise<void> {
mkdirp.sync(toolsCacheFolder);
mkdirp.sync(toolsFolder);
const currentFile = path.join(toolsCacheFolder, platform.dlFileName);
if (await isDownloadRequired(currentFile, platform.sha256sum)) {
console.log(`Downloading ${platform.url} to ${currentFile}`);
await DownloadUtil.downloadFile(platform.url, currentFile, (current) =>
console.log(`${current}%`),
);
const currentSHA256 = await hasha.fromFile(currentFile, { algorithm: 'sha256' });
if (currentSHA256 === platform.sha256sum) {
console.log(`Download of ${currentFile} has finished and SHA256 is correct`);
} else {
throw Error(`${currentFile} is downloaded and SHA256 is not correct`);
}
if (process.env.REMOTE_CONTAINERS === 'true') {
await extractTool(toolsFolder, platform, currentFile);
}
} else {
console.log('Previously downloaded archive SHA256 is correct');
}
if (process.env.REMOTE_CONTAINERS === undefined) await extractTool(toolsFolder, platform, currentFile);
}
import { downloadFileAndCreateSha256 } from '../src/downloadBinaries/downloadBinaries';
import * as configData from '../src/tools.json';

async function bundleTools(): Promise<void> {
if (process.env.REMOTE_CONTAINERS === 'true') {
Expand Down
2 changes: 1 addition & 1 deletion build/verify-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
/* eslint-disable @typescript-eslint/no-misused-promises */

import { exit } from 'shelljs';
import { DownloadUtil } from '../src/downloadBinaries/download';
import hasha = require('hasha');
import mkdirp = require('mkdirp');
import fs = require('fs-extra');
import path = require('path');
import cp = require('child_process');
import os = require('os');
import { DownloadUtil } from './download';
import configData = require('../src/tools.json');

/**
Expand Down
Loading