Skip to content

Commit 7a904cc

Browse files
committed
adds caching
1 parent 87aa8a8 commit 7a904cc

6 files changed

Lines changed: 22 additions & 49 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
},
2828
"dependencies": {
2929
"7zip-min": "^1.1.1",
30-
"mkdirp": "^1.0.3",
30+
"env-paths": "^2.2.0",
31+
"make-dir": "^3.0.0",
3132
"node-fetch": "^2.6.0",
32-
"progress": "^2.0.3",
33-
"tempy": "^0.3.0"
33+
"progress": "^2.0.3"
3434
}
3535
}

src/downloader.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import util from 'util';
33
import fs from 'fs';
44
import path from 'path';
55
import stream from 'stream';
6-
import mkdirp from 'mkdirp';
6+
import mkdirp from 'make-dir';
77
import Progress from 'progress';
88

99
const streamPipeline = util.promisify(stream.pipeline);
10+
const fsExist = util.promisify(fs.exists);
1011

1112
function progressBar(tokens: string, total: number): stream.PassThrough {
1213
const pt = new stream.PassThrough();
@@ -21,6 +22,11 @@ export async function download(link: string, outPath: string, options: DownloadO
2122
if (!response.ok) {
2223
throw new Error(`Error while downloading ${name}:${link}. ${response.statusText}`);
2324
}
25+
if (options.skipIfCached) {
26+
if (await fsExist(outPath)) {
27+
return console.warn(`Archive already exists at ${outPath}. Skipping download....`);
28+
}
29+
}
2430
await mkdirp(path.dirname(outPath));
2531
const total = parseInt(`${response.headers.get('content-length')}`, 10);
2632
const totalInMb = (total / 1024 / 1024).toFixed(2);
@@ -31,4 +37,4 @@ export async function download(link: string, outPath: string, options: DownloadO
3137
);
3238
}
3339

34-
type DownloadOptions = { name?: string };
40+
type DownloadOptions = { name?: string; skipIfCached?: boolean };

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import './types';
21
export { setupQt } from './setup';

src/setup.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { download } from './downloader';
22
import { extract } from './extractor';
3+
import path from 'path';
34
import metadata from './metadata.json';
4-
import tempy from 'tempy';
5+
import envPaths from 'env-paths';
6+
7+
const appPaths = envPaths('nodegui-qt');
58

69
type SupportedOs = 'linux' | 'win32' | 'darwin';
710
type SetupOptions = {
@@ -12,9 +15,9 @@ type SetupOptions = {
1215

1316
export async function setupQt(options: SetupOptions): Promise<string> {
1417
const downloadLink = options.downloadLink || metadata[options.osType];
15-
const archivePath = tempy.file({ extension: '7z' });
18+
const archivePath = path.resolve(appPaths.cache, path.basename(downloadLink));
1619
const extractDir = options.qtDir;
17-
await download(downloadLink, archivePath, { name: 'Qt for Mac' });
20+
await download(downloadLink, archivePath, { name: 'Qt for Mac', skipIfCached: true });
1821
await extract(archivePath, extractDir);
1922
console.log(`Mini Qt was setup successfully. QtDir: ${extractDir}`);
2023
return extractDir;

src/types.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

yarn.lock

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,6 @@ cross-spawn@^7.0.0:
992992
shebang-command "^2.0.0"
993993
which "^2.0.1"
994994

995-
crypto-random-string@^1.0.0:
996-
version "1.0.0"
997-
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
998-
integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=
999-
1000995
cssom@^0.4.1:
1001996
version "0.4.4"
1002997
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.4.4.tgz#5a66cf93d2d0b661d80bf6a44fb65f5c2e4e0a10"
@@ -1142,6 +1137,11 @@ end-of-stream@^1.1.0:
11421137
dependencies:
11431138
once "^1.4.0"
11441139

1140+
env-paths@^2.2.0:
1141+
version "2.2.0"
1142+
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-2.2.0.tgz#cdca557dc009152917d6166e2febe1f039685e43"
1143+
integrity sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA==
1144+
11451145
es-abstract@^1.17.0-next.1, es-abstract@^1.17.2:
11461146
version "1.17.4"
11471147
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.4.tgz#e3aedf19706b20e7c2594c35fc0d57605a79e184"
@@ -2651,11 +2651,6 @@ mkdirp@0.x, mkdirp@^0.5.1:
26512651
dependencies:
26522652
minimist "0.0.8"
26532653

2654-
mkdirp@^1.0.3:
2655-
version "1.0.3"
2656-
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.3.tgz#4cf2e30ad45959dddea53ad97d518b6c8205e1ea"
2657-
integrity sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==
2658-
26592654
ms@2.0.0:
26602655
version "2.0.0"
26612656
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
@@ -3551,20 +3546,6 @@ table@^5.2.3:
35513546
slice-ansi "^2.1.0"
35523547
string-width "^3.0.0"
35533548

3554-
temp-dir@^1.0.0:
3555-
version "1.0.0"
3556-
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-1.0.0.tgz#0a7c0ea26d3a39afa7e0ebea9c1fc0bc4daa011d"
3557-
integrity sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=
3558-
3559-
tempy@^0.3.0:
3560-
version "0.3.0"
3561-
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.3.0.tgz#6f6c5b295695a16130996ad5ab01a8bd726e8bf8"
3562-
integrity sha512-WrH/pui8YCwmeiAoxV+lpRH9HpRtgBhSR2ViBPgpGb/wnYDzp21R4MN45fsCGvLROvY67o3byhJRYRONJyImVQ==
3563-
dependencies:
3564-
temp-dir "^1.0.0"
3565-
type-fest "^0.3.1"
3566-
unique-string "^1.0.0"
3567-
35683549
terminal-link@^2.0.0:
35693550
version "2.1.1"
35703551
resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.1.1.tgz#14a64a27ab3c0df933ea546fba55f2d078edc994"
@@ -3730,11 +3711,6 @@ type-detect@4.0.8:
37303711
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
37313712
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
37323713

3733-
type-fest@^0.3.1:
3734-
version "0.3.1"
3735-
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"
3736-
integrity sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==
3737-
37383714
type-fest@^0.8.1:
37393715
version "0.8.1"
37403716
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
@@ -3762,13 +3738,6 @@ union-value@^1.0.0:
37623738
is-extendable "^0.1.1"
37633739
set-value "^2.0.1"
37643740

3765-
unique-string@^1.0.0:
3766-
version "1.0.0"
3767-
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
3768-
integrity sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo=
3769-
dependencies:
3770-
crypto-random-string "^1.0.0"
3771-
37723741
unset-value@^1.0.0:
37733742
version "1.0.0"
37743743
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"

0 commit comments

Comments
 (0)