|
1 | 1 | import { download } from './downloader'; |
2 | 2 | import { extract } from './extractor'; |
3 | 3 | import path from 'path'; |
4 | | -import metadata from './metadata.json'; |
5 | 4 | import envPaths from 'env-paths'; |
| 5 | +import emptyDir from 'empty-dir'; |
| 6 | +import mkdirp from 'make-dir'; |
6 | 7 |
|
7 | | -const appPaths = envPaths('nodegui-qt'); |
8 | | - |
9 | | -type SupportedOs = 'linux' | 'win32' | 'darwin'; |
10 | 8 | type SetupOptions = { |
11 | | - qtDir: string; |
12 | | - downloadLink?: string; |
| 9 | + outDir: string; |
| 10 | + downloadLink: string; |
13 | 11 | cacheDir?: string; |
14 | | - osType: SupportedOs; |
| 12 | + force?: boolean; |
| 13 | + id: string; |
| 14 | + displayName?: string; |
15 | 15 | }; |
16 | 16 |
|
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; |
20 | 22 | 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; |
26 | 36 | } |
0 commit comments