voidconnect 0.1.10

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/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # VoidConnect CLI Wrapper
2
+
3
+ This is an NPM wrapper for [voidconnect-cli](https://github.com/xptea/voidconnect-cli). It allows you to run the VoidConnect CLI seamlessly without manual installation.
4
+
5
+ ## Usage
6
+
7
+ You can use `bunx` (recommended) or `npx` to run commands directly:
8
+
9
+ ```bash
10
+ # Start the server in the background
11
+ bunx voidconnect run --bg
12
+
13
+ # Check status
14
+ bunx voidconnect status
15
+
16
+ # Initialize configuration
17
+ bunx voidconnect init
18
+ ```
19
+
20
+ ## How it works
21
+
22
+ When you run this package, it automatically:
23
+ 1. Detects your operating system and architecture.
24
+ 2. Downloads the matching `voidconnect` binary release from GitHub.
25
+ 3. Executes the command.
26
+
27
+ The binary handles the background server process, so `run --bg` works as expected even via `bunx`.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const os = require('os');
6
+ const fs = require('fs');
7
+ const { install } = require('../install.js');
8
+
9
+ const binaryName = os.platform() === 'win32' ? 'voidconnect.exe' : 'voidconnect';
10
+ const binaryPath = path.join(__dirname, binaryName);
11
+
12
+ async function run() {
13
+ // Ensure binary exists
14
+ if (!fs.existsSync(binaryPath)) {
15
+ try {
16
+ await install();
17
+ } catch (err) {
18
+ console.error('Failed to install voidconnect binary:', err);
19
+ process.exit(1);
20
+ }
21
+ }
22
+
23
+ // Spawn the binary processes
24
+ const child = spawn(binaryPath, process.argv.slice(2), {
25
+ stdio: 'inherit'
26
+ });
27
+
28
+ child.on('error', (err) => {
29
+ console.error('Failed to start subprocess:', err);
30
+ process.exit(1);
31
+ });
32
+
33
+ child.on('exit', (code) => {
34
+ if (code !== 0 && code !== null) {
35
+ process.exit(code);
36
+ }
37
+ process.exit(0);
38
+ });
39
+ }
40
+
41
+ run();
package/install.js ADDED
@@ -0,0 +1,117 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const https = require('https');
4
+ const { execSync } = require('child_process');
5
+ const os = require('os');
6
+ const packageJson = require('./package.json');
7
+
8
+ const VERSION = packageJson.version;
9
+ const REPO = 'xptea/voidconnect-cli';
10
+
11
+ function getTarget() {
12
+ const platform = os.platform();
13
+ const arch = os.arch();
14
+
15
+ if (platform === 'linux') {
16
+ if (arch === 'x64') return { target: 'x86_64-unknown-linux-gnu', binary: 'voidconnect', ext: '.tar.gz' };
17
+ if (arch === 'arm64') return { target: 'aarch64-unknown-linux-gnu', binary: 'voidconnect', ext: '.tar.gz' };
18
+ } else if (platform === 'darwin') {
19
+ if (arch === 'x64') return { target: 'x86_64-apple-darwin', binary: 'voidconnect', ext: '.tar.gz' };
20
+ if (arch === 'arm64') return { target: 'aarch64-apple-darwin', binary: 'voidconnect', ext: '.tar.gz' };
21
+ } else if (platform === 'win32') {
22
+ if (arch === 'x64') return { target: 'x86_64-pc-windows-msvc', binary: 'voidconnect.exe', ext: '.zip' };
23
+ }
24
+
25
+ throw new Error(`Unsupported platform: ${platform} ${arch}`);
26
+ }
27
+
28
+ async function install() {
29
+ const { target, binary, ext } = getTarget();
30
+ const assetName = `${binary}-${target}${ext}`;
31
+ const versionTag = `v${VERSION}`;
32
+ const downloadUrl = `https://github.com/${REPO}/releases/download/${versionTag}/${assetName}`;
33
+
34
+ const binDir = path.join(__dirname, 'bin');
35
+ if (!fs.existsSync(binDir)) {
36
+ fs.mkdirSync(binDir);
37
+ }
38
+
39
+ const destPath = path.join(binDir, binary);
40
+ if (fs.existsSync(destPath)) {
41
+ return;
42
+ }
43
+
44
+ console.log(`Downloading ${assetName} from ${downloadUrl}...`);
45
+ const tempFile = path.join(binDir, assetName);
46
+ const file = fs.createWriteStream(tempFile);
47
+
48
+ return new Promise((resolve, reject) => {
49
+ https.get(downloadUrl, (response) => {
50
+ if (response.statusCode === 302) {
51
+ https.get(response.headers.location, (response) => {
52
+ pipeToFile(response, file, tempFile, binDir, ext, binary, resolve, reject);
53
+ });
54
+ } else if (response.statusCode === 200) {
55
+ pipeToFile(response, file, tempFile, binDir, ext, binary, resolve, reject);
56
+ } else {
57
+ reject(new Error(`Failed to download: ${response.statusCode}`));
58
+ }
59
+ }).on('error', (err) => {
60
+ fs.unlink(tempFile, () => { });
61
+ reject(err);
62
+ });
63
+ });
64
+ }
65
+
66
+ function pipeToFile(response, file, tempFile, binDir, ext, binary, resolve, reject) {
67
+ response.pipe(file);
68
+ file.on('finish', () => {
69
+ file.close(() => {
70
+ console.log('Download complete. Extracting...');
71
+ try {
72
+ extract(tempFile, binDir, ext, binary);
73
+ resolve();
74
+ } catch (e) {
75
+ reject(e);
76
+ }
77
+ });
78
+ });
79
+ }
80
+
81
+ function extract(file, dest, extension, binary) {
82
+ try {
83
+ if (extension === '.zip') {
84
+ if (os.platform() === 'win32') {
85
+ execSync(`powershell -Command "Expand-Archive -Path '${file}' -DestinationPath '${dest}' -Force"`);
86
+ } else {
87
+ execSync(`unzip -o '${file}' -d '${dest}'`);
88
+ }
89
+ } else {
90
+ execSync(`tar -xzf '${file}' -C '${dest}'`);
91
+ }
92
+
93
+ fs.unlinkSync(file);
94
+
95
+ const binPath = path.join(dest, binary);
96
+ if (!fs.existsSync(binPath)) {
97
+ throw new Error(`Binary not found at ${binPath} after extraction.`);
98
+ }
99
+
100
+ if (os.platform() !== 'win32') {
101
+ execSync(`chmod +x '${binPath}'`);
102
+ }
103
+ console.log(`Successfully installed to ${binPath}`);
104
+
105
+ } catch (error) {
106
+ throw error;
107
+ }
108
+ }
109
+
110
+ if (require.main === module) {
111
+ install().catch(err => {
112
+ console.error(err);
113
+ process.exit(1);
114
+ });
115
+ }
116
+
117
+ module.exports = { install };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "voidconnect",
3
+ "version": "0.1.10",
4
+ "description": "NPM wrapper for voidconnect-cli",
5
+ "bin": {
6
+ "voidconnect": "bin/voidconnect.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/xptea/voidconnect-cli.git"
14
+ },
15
+ "keywords": [
16
+ "voidconnect",
17
+ "cli",
18
+ "tool"
19
+ ],
20
+ "author": "xptea",
21
+ "license": "MIT",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ }
25
+ }