Skip to content

Commit 8398ad0

Browse files
authoredJan 28, 2024
chore(get): factor out nw download logic (#1020)
### Description of Changes - Factor out NW.js download logic
1 parent d04d5a0 commit 8398ad0

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed
 

‎README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ nwbuild({
293293
- chore(cicd): use `google-github-actions/release-please-action` to automate publishing to npm, updating changelog and creating releases
294294
- chore(cli): migrate from `yargs` to `commander`
295295
- chore(get): verify sha checksum for downloads
296-
- chore(util): factor out nw file paths finder
297-
- chore(get): factor out nwjs downloader
296+
- chore(util): factor out file paths as constant variables
298297
- chore(get): factor out ffmpeg downloader
299298
- chore(get): factor out node headers downloader
300299
- chore(bld): factor out core build step

‎src/get/nw.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

‎src/get/nw.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from "node:fs";
2+
import process from "node:process";
3+
4+
import { afterEach, describe, expect, it } from "vitest";
5+
6+
import util from "../util.js";
7+
8+
import nw from "./nw.js";
9+
10+
describe("get/nw", function () {
11+
12+
let nwFile = '';
13+
14+
afterEach(function () {
15+
fs.promises.rm(nwFile, { recursive: true, force: true });
16+
});
17+
18+
it("downloades a NW.js Linux tarball or Windows/MacOS zip", async function () {
19+
nwFile = await nw(
20+
"https://dl.nwjs.io",
21+
"0.83.0",
22+
"sdk",
23+
util.PLATFORM_KV[process.platform],
24+
util.ARCH_KV[process.arch],
25+
"./test/fixture"
26+
);
27+
expect(util.fileExists(nwFile)).resolves.toBe(true);
28+
}, Infinity);
29+
});

0 commit comments

Comments
 (0)