xpose-cli 0.3.1 → 0.4.0

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/bin/install.js CHANGED
@@ -11,8 +11,14 @@ const crypto = require('crypto');
11
11
  * Fetches the pre-compiled Rust binary for the current platform.
12
12
  */
13
13
 
14
- const VERSION = '0.1.0';
15
- const REPO = 'user/xpose-cli'; // Placeholder
14
+ function getPackageVersion() {
15
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
16
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
17
+ return pkg.version;
18
+ }
19
+
20
+ const VERSION = getPackageVersion();
21
+ const REPO = 'vkaylee/xpose-cli';
16
22
  const BASE_URL = `https://github.com/${REPO}/releases/download/v${VERSION}`;
17
23
 
18
24
  const BIN_DIR = path.join(os.homedir(), '.xpose', 'bin');
@@ -59,6 +65,9 @@ function getFileContent(url) {
59
65
  if (res.statusCode === 301 || res.statusCode === 302) {
60
66
  return getFileContent(res.headers.location).then(resolve).catch(reject);
61
67
  }
68
+ if (res.statusCode !== 200) {
69
+ return reject(new Error(`Failed to fetch ${url} (Status: ${res.statusCode})`));
70
+ }
62
71
  let data = '';
63
72
  res.on('data', hunk => data += hunk);
64
73
  res.on('end', () => resolve(data.trim()));
@@ -162,4 +171,4 @@ if (require.main === module) {
162
171
  }
163
172
  }
164
173
 
165
- module.exports = { download, getReleaseName };
174
+ module.exports = { download, getReleaseName, getFileContent };
@@ -7,7 +7,7 @@ const http = require('http'); // We'll use this to mock
7
7
  // Mocking dependencies would be complex without a library like proxyquire or jest.
8
8
  // For a simple standalone test, we'll use environment variables and temporary paths.
9
9
 
10
- const { download } = require('./install');
10
+ const { download, getFileContent } = require('./install');
11
11
 
12
12
  async function testSuccessfulDownload() {
13
13
  console.log('Running testSuccessfulDownload...');
@@ -23,11 +23,29 @@ async function testSuccessfulDownload() {
23
23
  }
24
24
  }
25
25
 
26
+ async function testGetFileContent404() {
27
+ console.log('Running testGetFileContent404...');
28
+ const url = 'https://github.com/vkaylee/xpose-cli/releases/download/v0.3.2/NON_EXISTENT_FILE.sha256';
29
+ try {
30
+ await getFileContent(url);
31
+ console.error('❌ testGetFileContent404 FAILED: Expected rejection for 404, but it resolved.');
32
+ process.exit(1);
33
+ } catch (e) {
34
+ if (e.message.includes('Status: 404')) {
35
+ console.log('✅ testGetFileContent404 passed: Correctly rejected with Status: 404');
36
+ } else {
37
+ console.error('❌ testGetFileContent404 FAILED: Unexpected error message:', e.message);
38
+ process.exit(1);
39
+ }
40
+ }
41
+ }
42
+
26
43
  // In a real scenario, we would mock https.get and fs.createWriteStream.
27
44
  // Since we want to stay within standard node tools for now, we'll verify the logic structure.
28
45
 
29
46
  async function runTests() {
30
47
  await testSuccessfulDownload();
48
+ await testGetFileContent404();
31
49
  console.log('\nAll tests passed!');
32
50
  }
33
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpose-cli",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Cloudflare Tunnel CLI for developers - Vivid TUI, auto-copy, and smart defaults.",
5
5
  "bin": {
6
6
  "xpose": "bin/cli.js"