Skip to content

Commit edd06b4

Browse files
committed
Change to artifact installer
1 parent 0efed7e commit edd06b4

10 files changed

Lines changed: 77 additions & 41 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Artifact installer
2+
3+
Artifact installer is used to setup Qt
4+
5+
This downloads prebuilt binary dependencies such as Qt binaries and sets it up.
6+
Supports caching the downloaded binaries so that its not downloaded again and again.
7+
8+
Currently support extraction only using 7zip.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@nodegui/qt-installer",
2+
"name": "@nodegui/artifact-installer",
33
"version": "1.0.0",
4-
"description": "A minimal qt installer for nodegui",
4+
"description": "An artifact or prebuilt binary installer for for nodegui",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "tsc",
@@ -15,6 +15,7 @@
1515
"license": "ISC",
1616
"devDependencies": {
1717
"@types/7zip-min": "^1.1.0",
18+
"@types/empty-dir": "^2.0.0",
1819
"@types/jest": "^25.1.2",
1920
"@types/node-fetch": "^2.5.4",
2021
"@types/progress": "^2.0.3",
@@ -30,6 +31,7 @@
3031
},
3132
"dependencies": {
3233
"7zip-min": "^1.1.1",
34+
"empty-dir": "^2.0.0",
3335
"env-paths": "^2.2.0",
3436
"make-dir": "^3.0.0",
3537
"node-fetch": "^2.6.0",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { download } from './downloader';
22
export { extract } from './extractor';
3-
export { setupQt } from './setup';
3+
export { setupArtifact } from './setup';

src/metadata.json

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

src/setup.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
import { download } from './downloader';
22
import { extract } from './extractor';
33
import path from 'path';
4-
import metadata from './metadata.json';
54
import envPaths from 'env-paths';
5+
import emptyDir from 'empty-dir';
6+
import mkdirp from 'make-dir';
67

7-
const appPaths = envPaths('nodegui-qt');
8-
9-
type SupportedOs = 'linux' | 'win32' | 'darwin';
108
type SetupOptions = {
11-
qtDir: string;
12-
downloadLink?: string;
9+
outDir: string;
10+
downloadLink: string;
1311
cacheDir?: string;
14-
osType: SupportedOs;
12+
force?: boolean;
13+
id: string;
14+
displayName?: string;
1515
};
1616

17-
export async function setupQt(options: SetupOptions): Promise<string> {
18-
const downloadLink = options.downloadLink || metadata[options.osType];
19-
const cacheDir = options.cacheDir || appPaths.cache;
17+
export async function setupArtifact(options: SetupOptions): Promise<string> {
18+
const downloadLink = options.downloadLink;
19+
const cacheDir = options.cacheDir || envPaths(`${options.id}`).cache;
20+
const force = Boolean(options.force);
21+
const displayName = options.displayName || options.id;
2022
const archivePath = path.resolve(cacheDir, path.basename(downloadLink));
21-
const extractDir = options.qtDir;
22-
await download(downloadLink, archivePath, { name: 'Mini Qt', skipIfExist: true });
23-
await extract(archivePath, extractDir);
24-
console.log(`Mini Qt was setup successfully. QtDir: ${extractDir}`);
25-
return extractDir;
23+
const outDir = options.outDir;
24+
25+
await mkdirp(outDir);
26+
27+
if (!(await emptyDir(outDir)) && !force) {
28+
console.log(`Skipping setup for ${displayName}...`);
29+
return outDir;
30+
}
31+
32+
await download(downloadLink, archivePath, { name: displayName, skipIfExist: !force });
33+
await extract(archivePath, outDir);
34+
console.log(`${displayName} was setup successfully. outDir: ${outDir}`);
35+
return outDir;
2636
}

src/tests/darwin.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import { setupQt } from '../index';
4-
import { outputDir, TIMEOUT } from './utils';
3+
import { setupArtifact } from '../index';
4+
import { outputDir, TIMEOUT, metadata } from './utils';
55

66
describe('Setup QT for darwin', () => {
77
const osType = 'darwin';
8-
const qtDir = outputDir(osType);
8+
const outDir = outputDir(osType);
99
let outPath = '';
1010

1111
beforeAll(async () => {
12-
outPath = await setupQt({ qtDir, osType });
12+
outPath = await setupArtifact({ outDir, downloadLink: metadata.darwin, id: 'nodeguiqt' });
1313
}, TIMEOUT);
1414

1515
test('check if output path is same as specified: ', () => {
16-
expect(outPath).toBe(qtDir);
16+
expect(outPath).toBe(outDir);
1717
});
1818

1919
test('check if qt exists', () => {
2020
const expectedPath = `5.13.0/clang_64`;
21-
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
21+
const doesQtExist = fs.existsSync(path.resolve(outDir, expectedPath));
2222
expect(doesQtExist).toBe(true);
2323
});
2424
});

src/tests/linux.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import { setupQt } from '../index';
4-
import { outputDir, TIMEOUT } from './utils';
3+
import { setupArtifact } from '../index';
4+
import { outputDir, TIMEOUT, metadata } from './utils';
55

66
describe('Setup QT for linux', () => {
77
const osType = 'linux';
8-
const qtDir = outputDir(osType);
8+
const outDir = outputDir(osType);
99
let outPath = '';
1010

1111
beforeAll(async () => {
12-
outPath = await setupQt({ qtDir, osType });
12+
outPath = await setupArtifact({ outDir, downloadLink: metadata.linux, id: 'nodeguiqt' });
1313
}, TIMEOUT);
1414

1515
test('check if output path is same as specified: ', () => {
16-
expect(outPath).toBe(qtDir);
16+
expect(outPath).toBe(outDir);
1717
});
1818

1919
test('check if qt exists', () => {
2020
const expectedPath = `5.13.0/gcc_64`;
21-
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
21+
const doesQtExist = fs.existsSync(path.resolve(outDir, expectedPath));
2222
expect(doesQtExist).toBe(true);
2323
});
2424
});

src/tests/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ import path from 'path';
22

33
export const TIMEOUT = 60000;
44
export const outputDir = (osName: string): string => path.resolve(__dirname, '..', '..', 'out', osName);
5+
6+
export const metadata = {
7+
darwin:
8+
'https://download.qt.io/online/qtsdkrepository/mac_x64/desktop/qt5_5130/qt.qt5.5130.clang_64/5.13.0-0-201906171525qtbase-MacOS-MacOS_10_13-Clang-MacOS-MacOS_10_13-X86_64.7z',
9+
win32:
10+
'https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt5_5130/qt.qt5.5130.win64_msvc2017_64/5.13.0-0-201906171525qtbase-Windows-Windows_10-MSVC2017-Windows-Windows_10-X86_64.7z',
11+
linux:
12+
'https://download.qt.io/online/qtsdkrepository/linux_x64/desktop/qt5_5130/qt.qt5.5130.gcc_64/5.13.0-0-201906171524qtbase-Linux-RHEL_7_6-GCC-Linux-RHEL_7_6-X86_64.7z',
13+
};

src/tests/win32.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import { setupQt } from '../index';
4-
import { outputDir, TIMEOUT } from './utils';
3+
import { setupArtifact } from '../index';
4+
import { outputDir, TIMEOUT, metadata } from './utils';
55

66
describe('Setup QT for win32', () => {
77
const osType = 'win32';
8-
const qtDir = outputDir(osType);
8+
const outDir = outputDir(osType);
99
let outPath = '';
1010

1111
beforeAll(async () => {
12-
outPath = await setupQt({ qtDir, osType });
12+
outPath = await setupArtifact({ outDir, downloadLink: metadata.win32, id: 'nodeguiqt' });
1313
}, TIMEOUT);
1414

1515
test('check if output path is same as specified: ', () => {
16-
expect(outPath).toBe(qtDir);
16+
expect(outPath).toBe(outDir);
1717
});
1818

1919
test('check if qt exists', () => {
2020
const expectedPath = `5.13.0/msvc2017_64`;
21-
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
21+
const doesQtExist = fs.existsSync(path.resolve(outDir, expectedPath));
2222
expect(doesQtExist).toBe(true);
2323
});
2424
});

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@
387387
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
388388
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
389389

390+
"@types/empty-dir@^2.0.0":
391+
version "2.0.0"
392+
resolved "https://registry.yarnpkg.com/@types/empty-dir/-/empty-dir-2.0.0.tgz#fc40e385727b1625c5cb5021ecf9cd28efeafe8a"
393+
integrity sha512-wyXug9Ay49frbC8fd+QDnoe1ByBk+wDz+acg+cacXWSnrph2v1wyLm3dSVnGLYAzMsfmga0asuBl2Da9IeQx2w==
394+
dependencies:
395+
"@types/node" "*"
396+
390397
"@types/eslint-visitor-keys@^1.0.0":
391398
version "1.0.0"
392399
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
@@ -1130,6 +1137,11 @@ emoji-regex@^8.0.0:
11301137
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
11311138
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
11321139

1140+
empty-dir@^2.0.0:
1141+
version "2.0.0"
1142+
resolved "https://registry.yarnpkg.com/empty-dir/-/empty-dir-2.0.0.tgz#c59b4e73b9909d3c4bd49c1fbdaea52031fe22ac"
1143+
integrity sha512-XAedXlNAQZxMmbllXY9cxuESlNVjZ8xd67bSIUZwbS7VoLyhlNehVN3Iy35yDTGFHKR1opBRgORkp3am0so+WQ==
1144+
11331145
end-of-stream@^1.1.0:
11341146
version "1.4.4"
11351147
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"

0 commit comments

Comments
 (0)