@e-mc/file-manager 0.9.4 → 0.9.5

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/README.md +10 -10
  2. package/index.js +28 -28
  3. package/package.json +10 -10
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.4/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.5/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
@@ -286,15 +286,15 @@ NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-
286
286
 
287
287
  ## References
288
288
 
289
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/squared.d.ts
290
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/asset.d.ts
291
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/core.d.ts
292
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/filemanager.d.ts
293
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/logger.d.ts
294
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/module.d.ts
295
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/node.d.ts
296
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/request.d.ts
297
- - https://www.unpkg.com/@e-mc/types@0.9.4/lib/settings.d.ts
289
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/squared.d.ts
290
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/asset.d.ts
291
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/core.d.ts
292
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/filemanager.d.ts
293
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/logger.d.ts
294
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/module.d.ts
295
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/node.d.ts
296
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/request.d.ts
297
+ - https://www.unpkg.com/@e-mc/types@0.9.5/lib/settings.d.ts
298
298
 
299
299
  * https://www.npmjs.com/package/@types/node
300
300
 
package/index.js CHANGED
@@ -1201,26 +1201,17 @@ class FileManager extends core_1.Host {
1201
1201
  }
1202
1202
  switch (name) {
1203
1203
  case 'cloud': {
1204
- const instance = new cloud_1(args[0]);
1205
- instance.host = this;
1206
- instance.init(this.config);
1207
- observeFile.call(this, instance);
1208
- return this.Cloud = instance;
1209
- }
1210
- case 'watch': {
1211
- const instance = new watch_1(...args);
1212
- instance.host = this;
1213
- instance.init(this.config);
1214
- observeFile.call(this, instance);
1215
- return this.Watch = instance;
1216
- }
1217
- case 'compress': {
1218
- const instance = new compress_1(args[0]);
1219
- instance.host = this;
1220
- instance.init();
1221
- observeFile.call(this, instance);
1222
- return this.Compress = instance;
1204
+ if ((0, types_1.isArray)(args[1])) {
1205
+ const instance = new cloud_1(args[0], args[1]);
1206
+ instance.host = this;
1207
+ instance.init(this.config);
1208
+ observeFile.call(this, instance);
1209
+ return this.Cloud = instance;
1210
+ }
1223
1211
  }
1212
+ case 'watch':
1213
+ case 'compress':
1214
+ return this.install(name, ...args);
1224
1215
  default:
1225
1216
  return null;
1226
1217
  }
@@ -2304,12 +2295,14 @@ class FileManager extends core_1.Host {
2304
2295
  return 0;
2305
2296
  }
2306
2297
  const stat = this[kDownloadStats][type];
2307
- stat[0] += result;
2308
- stat[1]++;
2298
+ if (stat) {
2299
+ stat[0] += result;
2300
+ stat[1]++;
2301
+ }
2309
2302
  return result;
2310
2303
  }
2311
2304
  getDownload(type = 0) {
2312
- return this[kDownloadStats][type];
2305
+ return this[kDownloadStats][type] || [NaN, 0];
2313
2306
  }
2314
2307
  async fetchObject(uri, options = {}) {
2315
2308
  if (typeof options === 'string') {
@@ -3195,7 +3188,7 @@ class FileManager extends core_1.Host {
3195
3188
  request.httpVersion = (originCount[request.url.origin] || 0) <= 1 ? 1 : undefined;
3196
3189
  request.connected = headers => {
3197
3190
  applyHeaders(item, headers, true, mainEtag);
3198
- return item.willChange || !!etagDir && (cacheDir || !item.contentLength || cacheToMemory.within(item.contentLength));
3191
+ return item.willChange || !!etagDir && (cacheDir || !item.contentLength || cacheToMemory.within(item.contentLength)) || this.hasLog('progress');
3199
3192
  };
3200
3193
  }
3201
3194
  else {
@@ -3500,13 +3493,14 @@ class FileManager extends core_1.Host {
3500
3493
  }
3501
3494
  const length = status.length;
3502
3495
  const logCurrent = (0, types_1.getLogCurrent)();
3503
- const redraw = processTask.logCurrent !== logCurrent;
3504
3496
  const formatSegment = (endTime, value) => endTime ? value : chalk.bgGray.black(value);
3497
+ let redraw = processTask.logCurrent !== logCurrent;
3505
3498
  if (redraw || length > processTask.length) {
3506
3499
  this.pauseLog();
3507
3500
  processTask.logCurrent = logCurrent;
3508
3501
  PROCESS_STDOUT.write('\n'.repeat(redraw ? length : length - processTask.length));
3509
3502
  processTask.length = length;
3503
+ redraw = true;
3510
3504
  }
3511
3505
  PROCESS_STDOUT.moveCursor(0, -length);
3512
3506
  processTask.updated = currentTime;
@@ -3518,11 +3512,12 @@ class FileManager extends core_1.Host {
3518
3512
  if (!endTime) {
3519
3513
  finished = false;
3520
3514
  }
3521
- if (item.previousBytes === receivedBytes && !redraw) {
3515
+ if (!redraw && item.previousBytes === receivedBytes) {
3522
3516
  PROCESS_STDOUT.moveCursor(0, 1);
3523
3517
  continue;
3524
3518
  }
3525
3519
  if (item.output) {
3520
+ PROCESS_STDOUT.clearLine(0);
3526
3521
  PROCESS_STDOUT.write(item.output);
3527
3522
  continue;
3528
3523
  }
@@ -3544,9 +3539,14 @@ class FileManager extends core_1.Host {
3544
3539
  }
3545
3540
  const diffTime = currentTime - item.startTime;
3546
3541
  const time = formatSegment(endTime, formatMinutes(diffTime).padStart(titleWidth));
3547
- const size = formatSegment(endTime, (0, types_1.formatSize)(receivedBytes, { unit: receivedBytes < 1048576 ? 'KB' : receivedBytes < 1073741824 ? 'MB' : 'GB', unitSeparator: ' ' }).padStart(9));
3542
+ const size = formatSegment(endTime, (0, types_1.formatSize)(receivedBytes, { unit: receivedBytes < 1048576 ? 'KB' : receivedBytes < 1073741824 ? 'MB' : 'GB', unitSeparator: ' ', fixedDecimals: true, decimalPlaces: 2 }).padStart(9));
3548
3543
  const speed = formatSegment(endTime, (0, util_1.getTransferRate)(receivedBytes, item.dataTime ? (0, types_1.convertTime)(process.hrtime(item.dataTime), false) * 1000 : diffTime, ' ').padStart(10));
3549
- const output = time + ` ${chalk.blackBright(':')} ${endTime && bars !== -1 ? chalk.bgBlack.gray(item.url) : item.url}| ${size} | ${speed} |${bars === -1 ? chalk.bgBlack.green.bold('>'.repeat(25)) : (bars > 0 ? chalk.yellow('>'.repeat(bars)) : '') + (25 - bars > 0 ? chalk.gray((endTime ? '#' : '-').repeat(25 - bars)) : '')}| ${endTime ? bars === -1 ? chalk.bold('100%') : chalk.red('ERR!') : Math.trunc(percent).toString().padStart(3) + '%'}\n`;
3544
+ let output = time + ` ${chalk.blackBright(':')} ${endTime && bars !== -1 ? chalk.bgBlack.gray(item.url) : item.url}| ${size} |`;
3545
+ if (!isNaN(percent)) {
3546
+ output += speed + ` |${bars === -1 ? chalk.bgBlack.green.bold('>'.repeat(25)) : (bars > 0 ? chalk.yellow('>'.repeat(bars)) : '') + (25 - bars > 0 ? chalk.gray((endTime ? '#' : '-').repeat(25 - bars)) : '')}| ` + (endTime ? bars === -1 ? chalk.bold('100%') : chalk.red('ERR!') : Math.trunc(percent).toString().padStart(3) + '%');
3547
+ }
3548
+ output += '\n';
3549
+ PROCESS_STDOUT.clearLine(0);
3550
3550
  PROCESS_STDOUT.write(output);
3551
3551
  if (endTime) {
3552
3552
  item.output = output;
@@ -3608,7 +3608,7 @@ class FileManager extends core_1.Host {
3608
3608
  }
3609
3609
  else {
3610
3610
  if (data instanceof URL && data.protocol === 'file:') {
3611
- data = require('url').fileURLToPath(data);
3611
+ data = core_1.Host.resolveFile(data);
3612
3612
  }
3613
3613
  if ((0, types_1.isString)(data) && core_1.Host.isPath(data, true) && this.canRead(data)) {
3614
3614
  data = fs.createReadStream(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "FileManager constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,15 +20,15 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "0.9.4",
24
- "@e-mc/compress": "0.9.4",
25
- "@e-mc/core": "0.9.4",
26
- "@e-mc/document": "0.9.4",
27
- "@e-mc/image": "0.9.4",
28
- "@e-mc/request": "0.9.4",
29
- "@e-mc/task": "0.9.4",
30
- "@e-mc/types": "0.9.4",
31
- "@e-mc/watch": "0.9.4",
23
+ "@e-mc/cloud": "0.9.5",
24
+ "@e-mc/compress": "0.9.5",
25
+ "@e-mc/core": "0.9.5",
26
+ "@e-mc/document": "0.9.5",
27
+ "@e-mc/image": "0.9.5",
28
+ "@e-mc/request": "0.9.5",
29
+ "@e-mc/task": "0.9.5",
30
+ "@e-mc/types": "0.9.5",
31
+ "@e-mc/watch": "0.9.5",
32
32
  "chalk": "4.1.2",
33
33
  "picomatch": "^4.0.2"
34
34
  }