freeschema 1.0.2 → 1.0.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.
package/bin/freeschema.js CHANGED
@@ -114,7 +114,14 @@ function generateJwt() {
114
114
  return crypto.randomBytes(32).toString('hex');
115
115
  }
116
116
 
117
- function httpsDownload(url, destStream) {
117
+ function fmtBytes(b) {
118
+ if (b >= 1073741824) return (b / 1073741824).toFixed(1) + ' GB';
119
+ if (b >= 1048576) return (b / 1048576).toFixed(1) + ' MB';
120
+ if (b >= 1024) return (b / 1024).toFixed(1) + ' KB';
121
+ return b + ' B';
122
+ }
123
+
124
+ function httpsDownload(url, destStream, onProgress) {
118
125
  return new Promise((resolve, reject) => {
119
126
  const follow = (u, redirects) => {
120
127
  if (redirects > 10) return reject(new Error('Too many redirects'));
@@ -123,6 +130,12 @@ function httpsDownload(url, destStream) {
123
130
  return follow(res.headers.location, redirects + 1);
124
131
  }
125
132
  if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
133
+ const total = parseInt(res.headers['content-length'], 10) || 0;
134
+ let received = 0;
135
+ res.on('data', chunk => {
136
+ received += chunk.length;
137
+ if (onProgress) onProgress(received, total);
138
+ });
126
139
  res.pipe(destStream);
127
140
  destStream.on('finish', resolve);
128
141
  destStream.on('error', reject);
@@ -132,6 +145,22 @@ function httpsDownload(url, destStream) {
132
145
  });
133
146
  }
134
147
 
148
+ function makeProgressBar(label) {
149
+ const BAR = 25;
150
+ return function onProgress(received, total) {
151
+ let line;
152
+ if (total) {
153
+ const pct = Math.min(100, Math.floor((received / total) * 100));
154
+ const filled = Math.floor((pct / 100) * BAR);
155
+ const bar = '█'.repeat(filled) + '░'.repeat(BAR - filled);
156
+ line = ` ${label} [${bar}] ${pct}% ${fmtBytes(received)} / ${fmtBytes(total)}`;
157
+ } else {
158
+ line = ` ${label} ${fmtBytes(received)} downloaded`;
159
+ }
160
+ process.stdout.write(`\r${line.padEnd(72)}`);
161
+ };
162
+ }
163
+
135
164
  function runCompose(composeArgs, opts = {}) {
136
165
  const cwd = process.cwd();
137
166
  if (!fs.existsSync(path.join(cwd, 'docker-compose.yml'))) {
@@ -338,9 +367,11 @@ async function cmdInit() {
338
367
  const dest = path.join(seedDir, seedFileName);
339
368
  console.log(` Downloading → seed-db/${seedFileName}…`);
340
369
  try {
341
- await httpsDownload(seedUrl, fs.createWriteStream(dest));
370
+ await httpsDownload(seedUrl, fs.createWriteStream(dest), makeProgressBar('Downloading'));
371
+ process.stdout.write('\n');
342
372
  console.log(` Seed data seed-db/${seedFileName} ✓`);
343
373
  } catch (e) {
374
+ process.stdout.write('\n');
344
375
  try { fs.unlinkSync(dest); } catch {}
345
376
  console.log(` Seed data download failed (${e.message}) — skipped`);
346
377
  seedFileName = null;
@@ -536,9 +567,9 @@ function cmdDbSeed() {
536
567
  const name = path.basename(new URL(url.replace('%2540', '%40')).pathname) || 'seed.sql';
537
568
  const dest = path.join(seedDir, name);
538
569
  console.log(`Downloading → seed-db/${name}…`);
539
- httpsDownload(url, fs.createWriteStream(dest))
540
- .then(() => console.log('Done. Run `freeschema start --local-db` to apply on first boot.'))
541
- .catch(e => { try { fs.unlinkSync(dest); } catch {} die(e.message); });
570
+ httpsDownload(url, fs.createWriteStream(dest), makeProgressBar('Downloading'))
571
+ .then(() => { process.stdout.write('\n'); console.log('Done. Run `freeschema start --local-db` to apply on first boot.'); })
572
+ .catch(e => { process.stdout.write('\n'); try { fs.unlinkSync(dest); } catch {} die(e.message); });
542
573
  return;
543
574
  }
544
575
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freeschema",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "FreeSchema — self-hosted deployment CLI",
5
5
  "keywords": [
6
6
  "freeschema",
@@ -54,7 +54,7 @@ services:
54
54
  ports:
55
55
  - "${MQTT_EXTERNAL_PORT:-1884}:1883"
56
56
  volumes:
57
- - ./mosquitto/config:/mosquitto/config:ro
57
+ - ./mosquitto/config:/mosquitto/config
58
58
  - ./mosquitto/data:/mosquitto/data
59
59
  - ./mosquitto/log:/mosquitto/log
60
60
  networks: