moledb 0.1.0 → 0.1.3

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.
Files changed (3) hide show
  1. package/bin/mole +0 -0
  2. package/install.js +52 -29
  3. package/package.json +1 -1
package/bin/mole CHANGED
Binary file
package/install.js CHANGED
@@ -37,45 +37,67 @@ const binaries = [
37
37
  { name: 'mole-cli', remote: `mole-cli-${platform}-${arch}${ext}` }
38
38
  ];
39
39
 
40
- console.log(`Installing Mole DB v${VERSION} for ${platform}/${arch}...`);
40
+ console.log(`\n📦 Installing Mole DB v${VERSION} for ${platform}/${arch}...\n`);
41
+
42
+ function formatBytes(bytes) {
43
+ if (bytes === 0) return '0 B';
44
+ const k = 1024;
45
+ const sizes = ['B', 'KB', 'MB', 'GB'];
46
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
47
+ return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
48
+ }
41
49
 
42
50
  function downloadBinary(binaryInfo) {
43
51
  return new Promise((resolve, reject) => {
44
52
  const downloadUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/${binaryInfo.remote}`;
45
53
  const dest = path.join(binDir, `${binaryInfo.name}${ext}`);
46
54
 
47
- console.log(`Downloading ${binaryInfo.name}...`);
55
+ process.stdout.write(`⬇️ Downloading ${binaryInfo.name}... `);
48
56
 
49
57
  const file = fs.createWriteStream(dest);
58
+ let downloadedBytes = 0;
59
+ let totalBytes = 0;
60
+ let lastUpdate = Date.now();
61
+
62
+ const handleResponse = (response) => {
63
+ totalBytes = parseInt(response.headers['content-length'] || '0', 10);
64
+
65
+ response.on('data', (chunk) => {
66
+ downloadedBytes += chunk.length;
67
+ const now = Date.now();
68
+ if (now - lastUpdate > 500) {
69
+ const percent = totalBytes > 0 ? Math.round((downloadedBytes / totalBytes) * 100) : 0;
70
+ const downloaded = formatBytes(downloadedBytes);
71
+ const total = totalBytes > 0 ? formatBytes(totalBytes) : '?';
72
+ process.stdout.write(`\r⬇️ Downloading ${binaryInfo.name}... ${percent}% (${downloaded}/${total})`);
73
+ lastUpdate = now;
74
+ }
75
+ });
76
+
77
+ response.pipe(file);
78
+ file.on('finish', () => {
79
+ file.close();
80
+ if (!isWindows) {
81
+ fs.chmodSync(dest, 0o755);
82
+ }
83
+ const size = formatBytes(downloadedBytes);
84
+ console.log(`\r✅ ${binaryInfo.name} installed (${size}) `);
85
+ resolve();
86
+ });
87
+ };
50
88
 
51
89
  https.get(downloadUrl, (response) => {
52
90
  if (response.statusCode === 302 || response.statusCode === 301) {
53
- https.get(response.headers.location, (response) => {
54
- response.pipe(file);
55
- file.on('finish', () => {
56
- file.close();
57
- if (!isWindows) {
58
- fs.chmodSync(dest, 0o755);
59
- }
60
- console.log(`✓ ${binaryInfo.name} installed`);
61
- resolve();
62
- });
63
- }).on('error', reject);
91
+ https.get(response.headers.location, handleResponse).on('error', reject);
64
92
  } else if (response.statusCode !== 200) {
93
+ console.log(`\r❌ Failed to download ${binaryInfo.name} `);
65
94
  fs.unlink(dest, () => {});
66
95
  reject(new Error(`Failed to download ${binaryInfo.name}: HTTP ${response.statusCode}`));
67
96
  } else {
68
- response.pipe(file);
69
- file.on('finish', () => {
70
- file.close();
71
- if (!isWindows) {
72
- fs.chmodSync(dest, 0o755);
73
- }
74
- console.log(`✓ ${binaryInfo.name} installed`);
75
- resolve();
76
- });
97
+ handleResponse(response);
77
98
  }
78
99
  }).on('error', (err) => {
100
+ console.log(`\r❌ Download error `);
79
101
  fs.unlink(dest, () => {});
80
102
  reject(err);
81
103
  });
@@ -84,14 +106,15 @@ function downloadBinary(binaryInfo) {
84
106
 
85
107
  Promise.all(binaries.map(downloadBinary))
86
108
  .then(() => {
87
- console.log('\n✨ Mole DB installed successfully!');
88
- console.log('\nUsage:');
89
- console.log(' mole # Start the server');
90
- console.log(' mole-cli # Connect to the server');
109
+ console.log('\n✨ Mole DB installed successfully!\n');
110
+ console.log('Usage:');
111
+ console.log(' mole -i # Start server with interactive mode');
112
+ console.log(' mole # Start server only');
113
+ console.log(' mole-cli # Connect to running server\n');
91
114
  })
92
115
  .catch((err) => {
93
- console.error(`\nInstallation failed: ${err.message}`);
94
- console.error(`\nPlease try installing manually from:`);
95
- console.error(`https://github.com/${REPO}/releases/tag/v${VERSION}`);
116
+ console.error(`\n❌ Installation failed: ${err.message}\n`);
117
+ console.error('Please try installing manually from:');
118
+ console.error(`https://github.com/${REPO}/releases/tag/v${VERSION}\n`);
96
119
  process.exit(1);
97
120
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moledb",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Fast, lightweight in-memory database. Redis-compatible protocol with persistence, replication, and Sentinel support.",
5
5
  "keywords": [
6
6
  "database",