@paimaexample/npm-midnight-node 0.3.20 → 0.3.21
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 +11 -0
- package/index.js +0 -1
- package/package.json +1 -1
- package/run_midnight_node.js +37 -30
package/binary.js
CHANGED
|
@@ -24,6 +24,8 @@ function getBinaryUrl() {
|
|
|
24
24
|
async function downloadAndSaveBinary() {
|
|
25
25
|
const url = getBinaryUrl();
|
|
26
26
|
try {
|
|
27
|
+
console.error(`Downloading... ${url}`);
|
|
28
|
+
|
|
27
29
|
const response = await axios.get(url, { responseType: "stream" });
|
|
28
30
|
const writer = fs.createWriteStream(
|
|
29
31
|
path.join(__dirname, "midnight-node.zip"),
|
|
@@ -45,6 +47,14 @@ async function unzipBinary() {
|
|
|
45
47
|
await extract(path.join(__dirname, "midnight-node.zip"), {
|
|
46
48
|
dir: path.join(__dirname, "midnight-node"),
|
|
47
49
|
});
|
|
50
|
+
const platform = getPlatform();
|
|
51
|
+
const parts = platform.split("-");
|
|
52
|
+
if (parts[0] === "linux") {
|
|
53
|
+
fs.chmodSync(
|
|
54
|
+
path.join(__dirname, "midnight-node", `midnight-node-${platform}`),
|
|
55
|
+
0o755,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
48
58
|
fs.unlinkSync(path.join(__dirname, "midnight-node.zip"));
|
|
49
59
|
}
|
|
50
60
|
|
|
@@ -55,4 +65,5 @@ async function binary() {
|
|
|
55
65
|
|
|
56
66
|
module.exports = {
|
|
57
67
|
binary,
|
|
68
|
+
getPlatform,
|
|
58
69
|
};
|
package/index.js
CHANGED
package/package.json
CHANGED
package/run_midnight_node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { spawn } = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
|
|
1
|
+
const { spawn } = require("child_process");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { getPlatform } = require("./binary");
|
|
4
4
|
/**
|
|
5
5
|
* Executes the midnight-node binary as a child process
|
|
6
6
|
* @param {Object} env - Environment variables to pass to the child process
|
|
@@ -8,33 +8,40 @@ const path = require('path');
|
|
|
8
8
|
* @returns {ChildProcess} The spawned child process
|
|
9
9
|
*/
|
|
10
10
|
function runMidnightNode(env = process.env, args = []) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
const platform = getPlatform();
|
|
12
|
+
const parts = platform.split("-");
|
|
13
|
+
const binaryName = (parts[0] === "linux")
|
|
14
|
+
? `midnight-node-${platform}`
|
|
15
|
+
: "midnight-node";
|
|
16
|
+
const binaryPath = path.join(__dirname, "midnight-node", binaryName);
|
|
17
|
+
|
|
18
|
+
console.log(
|
|
19
|
+
`Starting midnight-node binary at: ${binaryPath} ${args.join(" ")}`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const childProcess = spawn(binaryPath, args, {
|
|
23
|
+
env: env,
|
|
24
|
+
stdio: "inherit", // Inherit stdin, stdout, stderr from parent process
|
|
25
|
+
cwd: path.join(__dirname, "midnight-node"), // Run from inside the midnight-node directory
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
childProcess.on("spawn", () => {
|
|
29
|
+
console.log(`midnight-node process spawned with PID: ${childProcess.pid}`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
childProcess.on("error", (error) => {
|
|
33
|
+
console.error("Failed to start midnight-node:", error);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
childProcess.on("exit", (code, signal) => {
|
|
37
|
+
if (code !== null) {
|
|
38
|
+
console.log(`midnight-node process exited with code: ${code}`);
|
|
39
|
+
} else {
|
|
40
|
+
console.log(`midnight-node process terminated by signal: ${signal}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return childProcess;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
module.exports = { runMidnightNode };
|