|
1 |
| -import path from "node:path" |
2 |
| -import os from 'node:os' |
3 |
| -import fs from 'fs-extra' |
4 |
| -import axios from 'axios' |
5 |
| -import * as tar from 'tar' |
6 |
| -import extractZip from 'extract-zip' |
7 |
| -import packageJson from './getPackage.js' |
| 1 | +import path from 'node:path'; |
| 2 | +import os from 'node:os'; |
| 3 | +import fs from 'fs-extra'; |
| 4 | +import axios from 'axios'; |
| 5 | +import * as tar from 'tar'; |
| 6 | +import extractZip from 'extract-zip'; |
| 7 | +import packageJson from './getPackage.js'; |
8 | 8 |
|
9 | 9 | const uvVer = packageJson.config.uvVersion;
|
10 | 10 |
|
11 | 11 | /** @typedef {{ [key]: { zipFile: string, uvOutputFolderName: string, zip: boolean } }} UvDownloadOptions */
|
12 | 12 | const options = {
|
13 |
| - win32: { |
14 |
| - zipFile: 'uv-x86_64-pc-windows-msvc.zip', |
15 |
| - uvOutputFolderName: 'win', |
16 |
| - zip: true, |
17 |
| - }, |
18 |
| - darwin: { |
19 |
| - zipFile: 'uv-aarch64-apple-darwin.tar.gz', |
20 |
| - uvOutputFolderName: 'macos', |
21 |
| - zip: false, |
22 |
| - }, |
23 |
| - linux: { |
24 |
| - zipFile: 'uv-x86_64-unknown-linux-gnu.tar.gz', |
25 |
| - uvOutputFolderName: 'linux', |
26 |
| - zip: false, |
27 |
| - } |
28 |
| -} |
| 13 | + win32: { |
| 14 | + zipFile: 'uv-x86_64-pc-windows-msvc.zip', |
| 15 | + uvOutputFolderName: 'win', |
| 16 | + zip: true, |
| 17 | + }, |
| 18 | + darwin: { |
| 19 | + zipFile: 'uv-aarch64-apple-darwin.tar.gz', |
| 20 | + uvOutputFolderName: 'macos', |
| 21 | + zip: false, |
| 22 | + }, |
| 23 | + linux: { |
| 24 | + zipFile: 'uv-x86_64-unknown-linux-gnu.tar.gz', |
| 25 | + uvOutputFolderName: 'linux', |
| 26 | + zip: false, |
| 27 | + }, |
| 28 | +}; |
29 | 29 |
|
30 | 30 | async function downloadUV() {
|
31 |
| - |
32 | 31 | const allFlag = process.argv[2];
|
33 | 32 | const baseDownloadURL = `https://github.com/astral-sh/uv/releases/download/${uvVer}/`;
|
34 |
| - if (allFlag) |
35 |
| - { |
36 |
| - if (allFlag === 'all') { |
37 |
| - await downloadAndExtract(baseDownloadURL, options.win32); |
38 |
| - await downloadAndExtract(baseDownloadURL, options.darwin); |
39 |
| - await downloadAndExtract(baseDownloadURL, options.linux); |
40 |
| - return; |
41 |
| - } |
42 |
| - if (allFlag === 'none') { |
43 |
| - return; |
44 |
| - } |
| 33 | + if (allFlag) { |
| 34 | + if (allFlag === 'all') { |
| 35 | + await downloadAndExtract(baseDownloadURL, options.win32); |
| 36 | + await downloadAndExtract(baseDownloadURL, options.darwin); |
| 37 | + await downloadAndExtract(baseDownloadURL, options.linux); |
| 38 | + return; |
| 39 | + } |
| 40 | + if (allFlag === 'none') { |
| 41 | + return; |
| 42 | + } |
45 | 43 | }
|
46 | 44 |
|
47 | 45 | const uvDownloaded = fs.existsSync(path.join('./assets', 'uv'));
|
48 | 46 | if (!uvDownloaded) {
|
49 |
| - await downloadAndExtract(baseDownloadURL, options[os.platform()]); |
50 |
| - return; |
| 47 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 48 | + await downloadAndExtract(baseDownloadURL, options[os.platform()]); |
| 49 | + return; |
51 | 50 | }
|
52 | 51 | console.log('< UV Folder Exists, Skipping >');
|
53 |
| - |
54 |
| -}; |
| 52 | +} |
55 | 53 |
|
56 | 54 | /** @param {UvDownloadOptions[any]} options */
|
57 | 55 | async function downloadAndExtract(baseURL, options) {
|
58 |
| - const { |
59 |
| - zipFile, |
60 |
| - uvOutputFolderName, |
61 |
| - zip |
62 |
| - } = options; |
63 |
| - const zipFilePath = path.join('./assets', zipFile); |
64 |
| - const outputUVFolder = path.join('./assets', 'uv', uvOutputFolderName); |
65 |
| - await fs.mkdir(outputUVFolder, { |
66 |
| - recursive: true |
| 56 | + const { zipFile, uvOutputFolderName, zip } = options; |
| 57 | + const zipFilePath = path.join('./assets', zipFile); |
| 58 | + const outputUVFolder = path.join('./assets', 'uv', uvOutputFolderName); |
| 59 | + await fs.mkdir(outputUVFolder, { |
| 60 | + recursive: true, |
| 61 | + }); |
| 62 | + const downloadedFile = await axios({ |
| 63 | + method: 'GET', |
| 64 | + url: baseURL + zipFile, |
| 65 | + responseType: 'arraybuffer', |
| 66 | + }); |
| 67 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 68 | + fs.writeFileSync(zipFilePath, downloadedFile.data); |
| 69 | + if (zip) { |
| 70 | + await extractZip(zipFilePath, { dir: path.resolve(outputUVFolder) }); |
| 71 | + } else { |
| 72 | + tar.extract({ |
| 73 | + sync: true, |
| 74 | + file: zipFilePath, |
| 75 | + C: outputUVFolder, |
| 76 | + 'strip-components': 1, |
67 | 77 | });
|
68 |
| - const downloadedFile = await axios({ |
69 |
| - method: 'GET', |
70 |
| - url: baseURL + zipFile, |
71 |
| - responseType: 'arraybuffer' |
72 |
| - }); |
73 |
| - fs.writeFileSync(zipFilePath, downloadedFile.data); |
74 |
| - zip ? await extractZip(zipFilePath, { |
75 |
| - dir: path.resolve(outputUVFolder) |
76 |
| - }) : tar.extract({ |
77 |
| - sync: true, |
78 |
| - file: zipFilePath, |
79 |
| - C: outputUVFolder, |
80 |
| - "strip-components": 1 |
81 |
| - }); |
82 |
| - await fs.unlink(zipFilePath); |
83 |
| - console.log(`FINISHED DOWNLOAD AND EXTRACT UV ${uvOutputFolderName}`); |
| 78 | + } |
| 79 | + await fs.unlink(zipFilePath); |
| 80 | + console.log(`FINISHED DOWNLOAD AND EXTRACT UV ${uvOutputFolderName}`); |
84 | 81 | }
|
85 | 82 |
|
86 | 83 | //** Download and Extract UV. Default uses OS.Platfrom. Add 'all' will download all. Add 'none' will skip */
|
|
0 commit comments