@paimaexample/npm-midnight-proof-server 0.6.1 → 0.7.1
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 +28 -1
- package/index.js +43 -9
- package/package.json +4 -2
package/binary.js
CHANGED
|
@@ -103,4 +103,31 @@ async function binary() {
|
|
|
103
103
|
await unzipBinary();
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
async function cleanBinaries() {
|
|
107
|
+
const binaryDir = path.join(__dirname, "proof-server");
|
|
108
|
+
const zipPath = path.join(__dirname, "proof-server.zip");
|
|
109
|
+
|
|
110
|
+
let deletedFiles = [];
|
|
111
|
+
|
|
112
|
+
if (fs.existsSync(binaryDir)) {
|
|
113
|
+
try {
|
|
114
|
+
fs.rmSync(binaryDir, { recursive: true, force: true });
|
|
115
|
+
deletedFiles.push(binaryDir);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(`Error removing directory ${binaryDir}:`, error.message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (fs.existsSync(zipPath)) {
|
|
122
|
+
try {
|
|
123
|
+
fs.unlinkSync(zipPath);
|
|
124
|
+
deletedFiles.push(zipPath);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(`Error removing file ${zipPath}:`, error.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return deletedFiles;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { binary, getPlatform, cleanBinaries };
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@ const fs = require("fs");
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const os = require("os");
|
|
5
5
|
|
|
6
|
-
const { binary, getPlatform } = require("./binary.js");
|
|
6
|
+
const { binary, getPlatform, cleanBinaries } = require("./binary.js");
|
|
7
7
|
const { runMidnightProofServer } = require("./run_midnight_proof_server.js");
|
|
8
8
|
const { checkIfDockerExists, pullDockerImage, runDockerContainer } = require(
|
|
9
9
|
"./docker.js",
|
|
@@ -25,30 +25,40 @@ function isBinarySupported() {
|
|
|
25
25
|
function showUsage() {
|
|
26
26
|
console.log(`\nUsage: npm-midnight-proof-server [options] [args...]\n
|
|
27
27
|
Options:
|
|
28
|
-
--docker
|
|
29
|
-
--binary
|
|
30
|
-
--
|
|
28
|
+
--docker Force use of Docker container
|
|
29
|
+
--binary Force binary execution (Linux only)
|
|
30
|
+
--clean-binaries Delete downloaded binaries and download them again
|
|
31
|
+
--only-clean Only delete downloaded binaries without downloading them again
|
|
32
|
+
--help, -h Show this help message\n`);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function parseFlags(argv) {
|
|
34
36
|
const flags = {
|
|
35
37
|
useDocker: false,
|
|
36
38
|
useBinary: false,
|
|
39
|
+
cleanBinaries: false,
|
|
40
|
+
onlyClean: false,
|
|
37
41
|
showHelp: false,
|
|
38
42
|
remaining: [],
|
|
39
43
|
};
|
|
40
44
|
for (const arg of argv) {
|
|
41
45
|
if (arg === "--docker") flags.useDocker = true;
|
|
42
46
|
else if (arg === "--binary") flags.useBinary = true;
|
|
47
|
+
else if (arg === "--clean-binaries") flags.cleanBinaries = true;
|
|
48
|
+
else if (arg === "--only-clean") flags.onlyClean = true;
|
|
43
49
|
else if (arg === "--help" || arg === "-h") flags.showHelp = true;
|
|
44
50
|
else flags.remaining.push(arg);
|
|
45
51
|
}
|
|
46
52
|
return flags;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
async function runWithBinary(env, args) {
|
|
50
|
-
if (!checkIfBinaryExists()) {
|
|
51
|
-
|
|
55
|
+
async function runWithBinary(env, args, forceClean = false) {
|
|
56
|
+
if (forceClean || !checkIfBinaryExists()) {
|
|
57
|
+
if (forceClean) {
|
|
58
|
+
console.log("Cleaning downloaded binaries...");
|
|
59
|
+
await cleanBinaries();
|
|
60
|
+
}
|
|
61
|
+
console.log("Downloading binary...");
|
|
52
62
|
await binary();
|
|
53
63
|
} else {
|
|
54
64
|
console.log("Using existing binary found in proof-server directory");
|
|
@@ -74,11 +84,31 @@ async function runWithDocker(env, args) {
|
|
|
74
84
|
process.exit(0);
|
|
75
85
|
}
|
|
76
86
|
|
|
87
|
+
// Handle --only-clean flag
|
|
88
|
+
if (flags.onlyClean) {
|
|
89
|
+
console.log("Cleaning downloaded binaries...");
|
|
90
|
+
const deletedFiles = await cleanBinaries();
|
|
91
|
+
if (deletedFiles.length > 0) {
|
|
92
|
+
console.log("Deleted:", deletedFiles.join(", "));
|
|
93
|
+
} else {
|
|
94
|
+
console.log("No downloaded binaries found to delete.");
|
|
95
|
+
}
|
|
96
|
+
process.exit(0);
|
|
97
|
+
}
|
|
98
|
+
|
|
77
99
|
if (flags.useDocker && flags.useBinary) {
|
|
78
100
|
console.error("Cannot use both --docker and --binary flags simultaneously");
|
|
79
101
|
process.exit(1);
|
|
80
102
|
}
|
|
81
103
|
|
|
104
|
+
// Validate clean flag usage
|
|
105
|
+
if (flags.cleanBinaries && flags.useDocker) {
|
|
106
|
+
console.error(
|
|
107
|
+
"Error: --clean-binaries flag cannot be used with --docker flag",
|
|
108
|
+
);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
82
112
|
if (flags.useDocker) {
|
|
83
113
|
await runWithDocker(env, flags.remaining);
|
|
84
114
|
return;
|
|
@@ -91,13 +121,13 @@ async function runWithDocker(env, args) {
|
|
|
91
121
|
);
|
|
92
122
|
process.exit(1);
|
|
93
123
|
}
|
|
94
|
-
await runWithBinary(env, flags.remaining);
|
|
124
|
+
await runWithBinary(env, flags.remaining, flags.cleanBinaries);
|
|
95
125
|
return;
|
|
96
126
|
}
|
|
97
127
|
|
|
98
128
|
// Automatic selection
|
|
99
129
|
if (isBinarySupported()) {
|
|
100
|
-
await runWithBinary(env, flags.remaining);
|
|
130
|
+
await runWithBinary(env, flags.remaining, flags.cleanBinaries);
|
|
101
131
|
} else {
|
|
102
132
|
console.log(
|
|
103
133
|
"Binary not supported on this platform, falling back to Docker...",
|
|
@@ -105,3 +135,7 @@ async function runWithDocker(env, args) {
|
|
|
105
135
|
await runWithDocker(env, flags.remaining);
|
|
106
136
|
}
|
|
107
137
|
})();
|
|
138
|
+
|
|
139
|
+
module.exports = {
|
|
140
|
+
cleanBinaries,
|
|
141
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paimaexample/npm-midnight-proof-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "A wrapper for the Midnight proof server binary",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"npm-midnight-proof-server": "index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"start": "node index.js"
|
|
10
|
+
"start": "node index.js",
|
|
11
|
+
"clean": "node index.js --clean-binaries",
|
|
12
|
+
"clean-only": "node index.js --only-clean"
|
|
11
13
|
},
|
|
12
14
|
"supportedPlatforms": [
|
|
13
15
|
"linux-amd64",
|