1 | import path from "node:path";
|
2 |
|
3 | import request from "./request.js";
|
4 |
|
5 | /**
|
6 | * Download NW.js binary.
|
7 | *
|
8 | * @param {string} downloadUrl - Download server
|
9 | * @param {string} version - Runtime version
|
10 | * @param {string} flavor - Runtime build flavor
|
11 | * @param {string} platform - NW supported platform
|
12 | * @param {string} arch - NW supported architecture
|
13 | * @param {string} cacheDir - Directory to store NW binaries
|
14 | * @return {Promise<string>} - path of compressed file which contains NW.js binaries.
|
15 | */
|
16 | export default async function nw(downloadUrl, version, flavor, platform, arch, cacheDir) {
|
17 |
|
18 | /**
|
19 | * Name of directory which contains NW.js binaries.
|
20 | *
|
21 | * @type {string}
|
22 | */
|
23 | const nwDir = [
|
24 | `nwjs`,
|
25 | flavor === 'sdk' ? '-sdk' : '',
|
26 | `-v${version}-${platform}-${arch}`,
|
27 | ].join('');
|
28 |
|
29 | /**
|
30 | * Name of compressed file which contains NW.js binaries.
|
31 | *
|
32 | * @type {string}
|
33 | */
|
34 | const nwFile = [
|
35 | nwDir,
|
36 | platform === 'linux' ? "tar.gz" : "zip"
|
37 | ].join('.');
|
38 |
|
39 | /**
|
40 | * URL to download specific NW.js binary from.
|
41 | *
|
42 | * @type {string}
|
43 | */
|
44 | const url = [
|
45 | downloadUrl,
|
46 | `v${version}`,
|
47 | nwFile,
|
48 | ].join('/');
|
49 |
|
50 | /**
|
51 | * Absolute path of compressed file which contains NW.js binaries.
|
52 | */
|
53 | const nwFileAbs = path.resolve(
|
54 | cacheDir,
|
55 | nwFile
|
56 | );
|
57 | await request(url, nwFileAbs);
|
58 |
|
59 | return nwFileAbs;
|
60 | }
|