|
6 | 6 | /* eslint-disable no-restricted-syntax */ |
7 | 7 | /* eslint-disable no-console */ |
8 | 8 |
|
| 9 | +import * as fs from 'fs'; |
| 10 | +import * as path from 'path'; |
9 | 11 | 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'; |
76 | 14 |
|
77 | 15 | async function bundleTools(): Promise<void> { |
78 | 16 | if (process.env.REMOTE_CONTAINERS === 'true') { |
|
0 commit comments