@e-mc/file-manager 0.9.3 → 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 +48 -48
  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.3/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.3/lib/squared.d.ts
290
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/asset.d.ts
291
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/core.d.ts
292
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/filemanager.d.ts
293
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/logger.d.ts
294
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/module.d.ts
295
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/node.d.ts
296
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/request.d.ts
297
- - https://www.unpkg.com/@e-mc/types@0.9.3/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
  }
@@ -1693,25 +1684,8 @@ class FileManager extends core_1.Host {
1693
1684
  if (state === 0 && (this.cleared && this[kDelayed] <= 0 || override) || (this.aborted || state === 3) && override) {
1694
1685
  this.clearProcessTimeout();
1695
1686
  this[kDelayed] = Infinity;
1696
- const resetState = () => {
1697
- this.finalizeState = 2;
1698
- this._pendingResult = null;
1699
- };
1700
- const aborted = (err) => {
1701
- if (!this.restarting) {
1702
- this.writeFail(["Transaction was not completed", this.baseDirectory], err);
1703
- resetState();
1704
- }
1705
- else {
1706
- this.finalizeState = 4;
1707
- }
1708
- this.emit('end', [], collectErrors.call(this), this.collectLog());
1709
- if (!this.restarting) {
1710
- this.done = true;
1711
- }
1712
- };
1713
1687
  if (this.aborted) {
1714
- aborted((0, types_1.createAbortError)());
1688
+ this.abortFinalize((0, types_1.createAbortError)());
1715
1689
  return;
1716
1690
  }
1717
1691
  this.finalizeState = 1;
@@ -1731,7 +1705,7 @@ class FileManager extends core_1.Host {
1731
1705
  if (LOG_TIMEELAPSED) {
1732
1706
  this.writeTimeElapsed('END', this.baseDirectory, this.startTime, errors.length > 0 ? { failed: true, ...core_1.Host.LOG_STYLE_FAIL } : { ...core_1.Host.LOG_STYLE_SUCCESS });
1733
1707
  }
1734
- resetState();
1708
+ this.resetState();
1735
1709
  const log = this.config.log;
1736
1710
  let useNumeric, showSize;
1737
1711
  if ((0, types_1.isObject)(log)) {
@@ -1744,7 +1718,7 @@ class FileManager extends core_1.Host {
1744
1718
  this.emit('end', items, errors, this.collectLog());
1745
1719
  this.done = true;
1746
1720
  })
1747
- .catch((err) => aborted(err));
1721
+ .catch((err) => this.abortFinalize(err));
1748
1722
  }
1749
1723
  }
1750
1724
  hasDocument(instance, document) {
@@ -2321,12 +2295,14 @@ class FileManager extends core_1.Host {
2321
2295
  return 0;
2322
2296
  }
2323
2297
  const stat = this[kDownloadStats][type];
2324
- stat[0] += result;
2325
- stat[1]++;
2298
+ if (stat) {
2299
+ stat[0] += result;
2300
+ stat[1]++;
2301
+ }
2326
2302
  return result;
2327
2303
  }
2328
2304
  getDownload(type = 0) {
2329
- return this[kDownloadStats][type];
2305
+ return this[kDownloadStats][type] || [NaN, 0];
2330
2306
  }
2331
2307
  async fetchObject(uri, options = {}) {
2332
2308
  if (typeof options === 'string') {
@@ -3212,7 +3188,7 @@ class FileManager extends core_1.Host {
3212
3188
  request.httpVersion = (originCount[request.url.origin] || 0) <= 1 ? 1 : undefined;
3213
3189
  request.connected = headers => {
3214
3190
  applyHeaders(item, headers, true, mainEtag);
3215
- 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');
3216
3192
  };
3217
3193
  }
3218
3194
  else {
@@ -3517,13 +3493,14 @@ class FileManager extends core_1.Host {
3517
3493
  }
3518
3494
  const length = status.length;
3519
3495
  const logCurrent = (0, types_1.getLogCurrent)();
3520
- const redraw = processTask.logCurrent !== logCurrent;
3521
3496
  const formatSegment = (endTime, value) => endTime ? value : chalk.bgGray.black(value);
3497
+ let redraw = processTask.logCurrent !== logCurrent;
3522
3498
  if (redraw || length > processTask.length) {
3523
3499
  this.pauseLog();
3524
3500
  processTask.logCurrent = logCurrent;
3525
3501
  PROCESS_STDOUT.write('\n'.repeat(redraw ? length : length - processTask.length));
3526
3502
  processTask.length = length;
3503
+ redraw = true;
3527
3504
  }
3528
3505
  PROCESS_STDOUT.moveCursor(0, -length);
3529
3506
  processTask.updated = currentTime;
@@ -3535,11 +3512,12 @@ class FileManager extends core_1.Host {
3535
3512
  if (!endTime) {
3536
3513
  finished = false;
3537
3514
  }
3538
- if (item.previousBytes === receivedBytes && !redraw) {
3515
+ if (!redraw && item.previousBytes === receivedBytes) {
3539
3516
  PROCESS_STDOUT.moveCursor(0, 1);
3540
3517
  continue;
3541
3518
  }
3542
3519
  if (item.output) {
3520
+ PROCESS_STDOUT.clearLine(0);
3543
3521
  PROCESS_STDOUT.write(item.output);
3544
3522
  continue;
3545
3523
  }
@@ -3561,9 +3539,14 @@ class FileManager extends core_1.Host {
3561
3539
  }
3562
3540
  const diffTime = currentTime - item.startTime;
3563
3541
  const time = formatSegment(endTime, formatMinutes(diffTime).padStart(titleWidth));
3564
- 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));
3565
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));
3566
- 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);
3567
3550
  PROCESS_STDOUT.write(output);
3568
3551
  if (endTime) {
3569
3552
  item.output = output;
@@ -3625,7 +3608,7 @@ class FileManager extends core_1.Host {
3625
3608
  }
3626
3609
  else {
3627
3610
  if (data instanceof URL && data.protocol === 'file:') {
3628
- data = require('url').fileURLToPath(data);
3611
+ data = core_1.Host.resolveFile(data);
3629
3612
  }
3630
3613
  if ((0, types_1.isString)(data) && core_1.Host.isPath(data, true) && this.canRead(data)) {
3631
3614
  data = fs.createReadStream(data);
@@ -3891,6 +3874,23 @@ class FileManager extends core_1.Host {
3891
3874
  close() {
3892
3875
  this.Request.close();
3893
3876
  }
3877
+ resetState() {
3878
+ this.finalizeState = 2;
3879
+ this._pendingResult = null;
3880
+ }
3881
+ abortFinalize(err) {
3882
+ if (!this.restarting) {
3883
+ this.writeFail(["Transaction was not completed", this.baseDirectory], err);
3884
+ this.resetState();
3885
+ }
3886
+ else {
3887
+ this.finalizeState = 4;
3888
+ }
3889
+ this.emit('end', [], collectErrors.call(this), this.collectLog());
3890
+ if (!this.restarting) {
3891
+ this.done = true;
3892
+ }
3893
+ }
3894
3894
  set restarting(value) {
3895
3895
  this.finalizeState = (this[kRestarting] = value) ? 3 : 0;
3896
3896
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/file-manager",
3
- "version": "0.9.3",
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.3",
24
- "@e-mc/compress": "0.9.3",
25
- "@e-mc/core": "0.9.3",
26
- "@e-mc/document": "0.9.3",
27
- "@e-mc/image": "0.9.3",
28
- "@e-mc/request": "0.9.3",
29
- "@e-mc/task": "0.9.3",
30
- "@e-mc/types": "0.9.3",
31
- "@e-mc/watch": "0.9.3",
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
  }