@paimaexample/npm-midnight-node 0.3.43 → 0.3.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binary.js CHANGED
@@ -4,6 +4,11 @@ const axios = require("axios");
4
4
  const extract = require("extract-zip");
5
5
  const path = require("path");
6
6
 
7
+ const CURRENT_BINARY_VERSION = "0.12.0";
8
+
9
+ /*
10
+ @returns {string} The platform and architecture of the current machine.
11
+ */
7
12
  function getPlatform() {
8
13
  let platform = os.platform();
9
14
  let arch = os.arch();
@@ -12,15 +17,24 @@ function getPlatform() {
12
17
  return `${platform}-${arch}`;
13
18
  }
14
19
 
20
+ const FILE_NAME =
21
+ `midnight-node-${getPlatform()}-${CURRENT_BINARY_VERSION}.zip`;
22
+
23
+ /*
24
+ @returns {string} The URL to download the binary for the current platform.
25
+ */
15
26
  function getBinaryUrl() {
16
27
  const platform = getPlatform();
17
28
  const supportedPlatforms = require("./package.json").supportedPlatforms;
18
29
  if (!supportedPlatforms.includes(platform)) {
19
30
  throw new Error(`Unsupported platform: ${platform}`);
20
31
  }
21
- return `https://paima-midnight.nyc3.cdn.digitaloceanspaces.com/binaries/midnight-node-${platform}.zip`;
32
+ return `https://paima-midnight.nyc3.cdn.digitaloceanspaces.com/binaries/${FILE_NAME}`;
22
33
  }
23
34
 
35
+ /*
36
+ @returns {Promise<void>} Downloads and saves the binary for the current platform.
37
+ */
24
38
  async function downloadAndSaveBinary() {
25
39
  const url = getBinaryUrl();
26
40
  try {
@@ -28,7 +42,10 @@ async function downloadAndSaveBinary() {
28
42
 
29
43
  const response = await axios.get(url, { responseType: "stream" });
30
44
  const writer = fs.createWriteStream(
31
- path.join(__dirname, "midnight-node.zip"),
45
+ path.join(
46
+ __dirname,
47
+ FILE_NAME,
48
+ ),
32
49
  );
33
50
 
34
51
  response.data.pipe(writer);
@@ -43,22 +60,28 @@ async function downloadAndSaveBinary() {
43
60
  }
44
61
  }
45
62
 
63
+ /*
64
+ @returns {Promise<void>} Unzips the binary for the current platform.
65
+ */
46
66
  async function unzipBinary() {
47
- await extract(path.join(__dirname, "midnight-node.zip"), {
67
+ await extract(path.join(__dirname, FILE_NAME), {
48
68
  dir: path.join(__dirname, "midnight-node"),
49
69
  });
50
70
  const platform = getPlatform();
51
71
  const parts = platform.split("-");
52
- const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
53
- ? `midnight-node-${platform}`
54
- : "midnight-node";
72
+ const binaryName = `midnight-node-${platform}`;
55
73
  if (parts[0] === "linux") {
56
74
  fs.chmodSync(
57
75
  path.join(__dirname, "midnight-node", binaryName),
58
76
  0o755,
59
77
  );
60
78
  }
61
- fs.unlinkSync(path.join(__dirname, "midnight-node.zip"));
79
+ fs.unlinkSync(
80
+ path.join(
81
+ __dirname,
82
+ FILE_NAME,
83
+ ),
84
+ );
62
85
  }
63
86
 
64
87
  async function binary() {
package/index.js CHANGED
@@ -7,9 +7,7 @@ const path = require("path");
7
7
  function checkIfBinaryExists() {
8
8
  const platform = getPlatform();
9
9
  const parts = platform.split("-");
10
- const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
11
- ? `midnight-node-${platform}`
12
- : "midnight-node";
10
+ const binaryName = `midnight-node-${platform}`;
13
11
  return fs.existsSync(path.join(__dirname, "midnight-node", binaryName));
14
12
  }
15
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paimaexample/npm-midnight-node",
3
- "version": "0.3.43",
3
+ "version": "0.3.45",
4
4
  "description": "Downloads and starts the binary for Midnight Node",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,9 +10,7 @@ const { getPlatform } = require("./binary");
10
10
  function runMidnightNode(env = process.env, args = []) {
11
11
  const platform = getPlatform();
12
12
  const parts = platform.split("-");
13
- const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
14
- ? `midnight-node-${platform}`
15
- : "midnight-node";
13
+ const binaryName = `midnight-node-${platform}`;
16
14
  const binaryPath = path.join(__dirname, "midnight-node", binaryName);
17
15
 
18
16
  console.log(