Skip to content

Commit fbacd3f

Browse files
Move download scripts into ./src (#2950)
* Move download scripts into ./src - Also list packages that they require as runtime dependencies Fixes #2948 Signed-off-by: David Thompson <[email protected]> * folder renamed Signed-off-by: msivasubramaniaan <[email protected]> * made correct reference of the file Signed-off-by: msivasubramaniaan <[email protected]> * made correct reference of the file Signed-off-by: msivasubramaniaan <[email protected]> --------- Signed-off-by: David Thompson <[email protected]> Signed-off-by: msivasubramaniaan <[email protected]> Co-authored-by: msivasubramaniaan <[email protected]>
1 parent 40f068c commit fbacd3f

File tree

13 files changed

+165
-228
lines changed

13 files changed

+165
-228
lines changed

build/bundle-tools.ts

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,11 @@
66
/* eslint-disable no-restricted-syntax */
77
/* eslint-disable no-console */
88

9+
import * as fs from 'fs';
10+
import * as path from 'path';
911
import { exit } from 'process';
10-
import { Archive } from './archive';
11-
import { DownloadUtil } from './download';
12-
13-
import hasha = require('hasha');
14-
import mkdirp = require('mkdirp');
15-
import path = require('path');
16-
import fs = require('fs-extra');
17-
import configData = require('../src/tools.json');
18-
19-
export interface PlatformData {
20-
url: string;
21-
sha256sum: string;
22-
dlFileName: string;
23-
cmdFileName: string;
24-
filePrefix: string;
25-
}
26-
27-
export async function isDownloadRequired(filePath: string, sha256: string): Promise<boolean> {
28-
let result = true;
29-
if (fs.existsSync(filePath)) {
30-
const fileSha256 = await hasha.fromFile(filePath, { algorithm: 'sha256' });
31-
result = fileSha256 !== sha256;
32-
}
33-
return result;
34-
}
35-
36-
async function extractTool(toolsFolder: string, platform: PlatformData, currentFile: string): Promise<void> {
37-
let toolLocation = toolsFolder;
38-
if (process.env.REMOTE_CONTAINERS === undefined) {
39-
toolLocation = path.join(toolsFolder, platform.cmdFileName);
40-
}
41-
console.log(`Extracting ${currentFile} to ${toolLocation}`);
42-
if (!currentFile.endsWith('.exe') && currentFile.includes('.')) {
43-
await Archive.extract(currentFile, toolsFolder, platform.cmdFileName, platform.filePrefix);
44-
} else {
45-
fs.copyFileSync(currentFile, toolLocation);
46-
}
47-
}
48-
49-
export async function downloadFileAndCreateSha256(
50-
toolsCacheFolder: string,
51-
toolsFolder: string,
52-
platform: PlatformData,
53-
): Promise<void> {
54-
mkdirp.sync(toolsCacheFolder);
55-
mkdirp.sync(toolsFolder);
56-
const currentFile = path.join(toolsCacheFolder, platform.dlFileName);
57-
if (await isDownloadRequired(currentFile, platform.sha256sum)) {
58-
console.log(`Downloading ${platform.url} to ${currentFile}`);
59-
await DownloadUtil.downloadFile(platform.url, currentFile, (current) =>
60-
console.log(`${current}%`),
61-
);
62-
const currentSHA256 = await hasha.fromFile(currentFile, { algorithm: 'sha256' });
63-
if (currentSHA256 === platform.sha256sum) {
64-
console.log(`Download of ${currentFile} has finished and SHA256 is correct`);
65-
} else {
66-
throw Error(`${currentFile} is downloaded and SHA256 is not correct`);
67-
}
68-
if (process.env.REMOTE_CONTAINERS === 'true') {
69-
await extractTool(toolsFolder, platform, currentFile);
70-
}
71-
} else {
72-
console.log('Previously downloaded archive SHA256 is correct');
73-
}
74-
if (process.env.REMOTE_CONTAINERS === undefined) await extractTool(toolsFolder, platform, currentFile);
75-
}
12+
import { downloadFileAndCreateSha256 } from '../src/downloadUtil/downloadBinaries';
13+
import * as configData from '../src/tools.json';
7614

7715
async function bundleTools(): Promise<void> {
7816
if (process.env.REMOTE_CONTAINERS === 'true') {

build/verify-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
/* eslint-disable @typescript-eslint/no-misused-promises */
1111

1212
import { exit } from 'shelljs';
13+
import { DownloadUtil } from '../src/downloadUtil/download';
1314
import hasha = require('hasha');
1415
import mkdirp = require('mkdirp');
1516
import fs = require('fs-extra');
1617
import path = require('path');
1718
import cp = require('child_process');
1819
import os = require('os');
19-
import { DownloadUtil } from './download';
2020
import configData = require('../src/tools.json');
2121

2222
/**

0 commit comments

Comments
 (0)