utiller 1.0.84 → 1.0.87

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.
@@ -59,6 +59,8 @@ var InfinitePool = /*#__PURE__*/function () {
59
59
 
60
60
  /** 如果要讓每個pool不會因為task掉進catch 而被中斷, 就必須加入taskFailHandler*/
61
61
 
62
+ /** 如果設定sleep interval, 可以加這個參數要不要先執行第一次 再開始 interval 機制*/
63
+
62
64
  /** 用於 runByParam */
63
65
 
64
66
  /** runByTimes 的次數 */
@@ -90,8 +92,8 @@ var InfinitePool = /*#__PURE__*/function () {
90
92
  (0, _defineProperty2["default"])(this, "enableOfTaskTimeout", _configerer.configerer.POOLLER_ENABLE_TIMEOUT);
91
93
  (0, _defineProperty2["default"])(this, "timeOfTaskTimeout", _configerer.configerer.POOLLER_TASK_TIMEOUT_DEFAULT);
92
94
  (0, _defineProperty2["default"])(this, "handlerOfAssignTaskFail", undefined);
93
- (0, _defineProperty2["default"])(this, "maxWorker", void 0);
94
- (0, _defineProperty2["default"])(this, "ignoreFirstRun", false);
95
+ (0, _defineProperty2["default"])(this, "maximumOfWorker", void 0);
96
+ (0, _defineProperty2["default"])(this, "disableFirstRun", false);
95
97
  (0, _defineProperty2["default"])(this, "queueOfWaitingParam", []);
96
98
  (0, _defineProperty2["default"])(this, "countsOfRunByTimes", -1);
97
99
  (0, _defineProperty2["default"])(this, "queueOfAssignTask", {});
@@ -348,7 +350,7 @@ var InfinitePool = /*#__PURE__*/function () {
348
350
  throw new _exceptioner["default"](4006, "type of task is ===> ".concat((0, _typeof2["default"])(task)));
349
351
 
350
352
  case 12:
351
- _this.enableTaskSleepInterval(!!interval, interval);
353
+ _this.enableTaskSleepInterval(_lodash["default"].isNumber(interval), interval);
352
354
 
353
355
  _this.setState(_configerer.configerer.POOLLER_STATE.RUN_INFINITE);
354
356
 
@@ -636,7 +638,7 @@ var InfinitePool = /*#__PURE__*/function () {
636
638
  return "TASK HASH: ".concat(hash);
637
639
  });
638
640
  (0, _defineProperty2["default"])(this, "showState", function () {
639
- _index2.utiller.appendInfo(_this.getPoollerLogFormat("workerCount: ".concat(_this.maxWorker)));
641
+ _index2.utiller.appendInfo(_this.getPoollerLogFormat("workerCount: ".concat(_this.maximumOfWorker)));
640
642
 
641
643
  _index2.utiller.appendInfo(_this.getPoollerLogFormat("taskQueue(\u9084\u5728\u6392\u968A\u7684Task): ".concat(_this.getCountOfAssignTaskInQueue())));
642
644
 
@@ -718,7 +720,7 @@ var InfinitePool = /*#__PURE__*/function () {
718
720
  _this.printLogMessage("4574152 \u4E0D\u61C9\u8A72\u8D70\u5230\u9019\u88CF,\u4F46\u662F minor issue", true);
719
721
 
720
722
  case 14:
721
- if (_this.queueOfExecutingTask.length > _this.maxWorker) _this.printLogMessage("4512214 \u4E00\u5B9A\u662F\u6539\u58DE\u4E86!!!!!!!!!!, ".concat(_this.getLogMessageOfExecutingTaskQueueCount, " "), true);
723
+ if (_this.queueOfExecutingTask.length > _this.maximumOfWorker) _this.printLogMessage("4512214 \u4E00\u5B9A\u662F\u6539\u58DE\u4E86!!!!!!!!!!, ".concat(_this.getLogMessageOfExecutingTaskQueueCount, " "), true);
722
724
 
723
725
  case 15:
724
726
  case "end":
@@ -825,7 +827,7 @@ var InfinitePool = /*#__PURE__*/function () {
825
827
 
826
828
  return _this;
827
829
  });
828
- this.maxWorker = maxWorkers;
830
+ this.maximumOfWorker = maxWorkers;
829
831
  this.setPoolId(_lodash["default"].toString(name));
830
832
 
831
833
  var _iterator4 = _createForOfIteratorHelper(_configerer.configerer.POOLLER_PRIORITY),
@@ -886,7 +888,7 @@ var InfinitePool = /*#__PURE__*/function () {
886
888
  }, {
887
889
  key: "setWorker",
888
890
  value: function setWorker(counts) {
889
- this.maxWorker = counts;
891
+ this.maximumOfWorker = counts;
890
892
  }
891
893
  }, {
892
894
  key: "cleanTaskInterval",
@@ -1042,10 +1044,10 @@ var InfinitePool = /*#__PURE__*/function () {
1042
1044
  /** 如果設定interval, 第一個run不要執行的話,就設定true, default是false */
1043
1045
 
1044
1046
  }, {
1045
- key: "setIgnoreFirstRun",
1046
- value: function setIgnoreFirstRun() {
1047
- var ignore = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1048
- this.ignoreFirstRun = ignore;
1047
+ key: "setDisableFirstRun",
1048
+ value: function setDisableFirstRun() {
1049
+ var disable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1050
+ this.disableFirstRun = disable;
1049
1051
  }
1050
1052
  /** 加上一個 被動式啟動, 不然一直while() run, 可能有效能上的問題,現階端只支援RUN_BY_TASK */
1051
1053
 
@@ -1070,7 +1072,7 @@ var InfinitePool = /*#__PURE__*/function () {
1070
1072
  }, {
1071
1073
  key: "isExecutingQueueFull",
1072
1074
  value: function isExecutingQueueFull() {
1073
- return _lodash["default"].size(this.queueOfExecutingTask) >= this.maxWorker;
1075
+ return _lodash["default"].size(this.queueOfExecutingTask) >= this.maximumOfWorker;
1074
1076
  }
1075
1077
  }, {
1076
1078
  key: "isTaskQueueEmpty",
@@ -1083,54 +1085,59 @@ var InfinitePool = /*#__PURE__*/function () {
1083
1085
  key: "syncTaskDispatcher",
1084
1086
  value: function () {
1085
1087
  var _syncTaskDispatcher = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
1086
- var initialTaskShouldNotRun, restInInterval, taskInfo, promise;
1088
+ var initialTaskShouldNotRun, isExecutingTaskAlmostFull, comparison, restInInterval, taskInfo, promise;
1087
1089
  return _regenerator["default"].wrap(function _callee10$(_context10) {
1088
1090
  while (1) {
1089
1091
  switch (_context10.prev = _context10.next) {
1090
1092
  case 0:
1091
- initialTaskShouldNotRun = this.ignoreFirstRun && !this.isFirstTaskCompleted();
1093
+ initialTaskShouldNotRun = this.disableFirstRun && !this.isFirstTaskCompleted();
1094
+ isExecutingTaskAlmostFull = this.queueOfExecutingTask.length >= this.maximumOfWorker - 1;
1095
+ /** 因為走能到syncTaskDispatcher表示其中一個工作完成了, 這個瞬間不可能 === maximumOfWorker,
1096
+ * 所以必須減1, 除非這個syncTaskDispatcher是單獨一個線程 */
1097
+
1098
+ comparison = this.isFirstTaskCompleted() && isExecutingTaskAlmostFull && this.enableOfTaskSleepByInterval;
1092
1099
 
1093
- if (!(initialTaskShouldNotRun || this.isFirstTaskCompleted() && this.isExecutingQueueFull() && this.enableOfTaskSleepByInterval)) {
1094
- _context10.next = 6;
1100
+ if (!(initialTaskShouldNotRun || comparison)) {
1101
+ _context10.next = 8;
1095
1102
  break;
1096
1103
  }
1097
1104
 
1098
- _context10.next = 4;
1105
+ _context10.next = 6;
1099
1106
  return _index2.utiller.syncDelayRandom(this.taskSleepInterval.min, this.taskSleepInterval.max);
1100
1107
 
1101
- case 4:
1108
+ case 6:
1102
1109
  restInInterval = _context10.sent;
1103
1110
  this.printLogMessage("4484121, \u8D70\u5230\u4E00\u5761\u7761\u89BA\u5340 enableOfTaskSleepByInterval:".concat(this.enableOfTaskSleepByInterval, " || ").concat(restInInterval, " ms"));
1104
1111
 
1105
- case 6:
1112
+ case 8:
1106
1113
  if (!this.rulesOfAppendToExecutingTask()) {
1107
- _context10.next = 18;
1114
+ _context10.next = 20;
1108
1115
  break;
1109
1116
  }
1110
1117
 
1111
1118
  taskInfo = this.getTaskInfoDependOnPriority();
1112
1119
 
1113
1120
  if (!taskInfo) {
1114
- _context10.next = 14;
1121
+ _context10.next = 16;
1115
1122
  break;
1116
1123
  }
1117
1124
 
1118
1125
  promise = this.taskWrapper(taskInfo.task, taskInfo.hash, this.queueOfWaitingParam.shift());
1119
1126
  this.removeTaskMapByHash(taskInfo.hash);
1120
1127
  this.appendTaskToExecuteQueue(taskInfo.hash, promise);
1121
- _context10.next = 16;
1128
+ _context10.next = 18;
1122
1129
  break;
1123
1130
 
1124
- case 14:
1131
+ case 16:
1125
1132
  /** 沒有taskInfo, 也許有未知的isssue,保險起見break */
1126
1133
  this.printLogMessage("848451 \u4E5F\u8A31\u6709\u672A\u77E5\u7684isssue,\u4FDD\u96AA\u8D77\u898Bbreak,\u662F\u4E0D\u662F\u5728\u9019\u88E1\u7121\u9650\u8FF4\u5708\u8DD1\u8DD1\u8DD1", true);
1127
- return _context10.abrupt("break", 18);
1134
+ return _context10.abrupt("break", 20);
1128
1135
 
1129
- case 16:
1130
- _context10.next = 6;
1136
+ case 18:
1137
+ _context10.next = 8;
1131
1138
  break;
1132
1139
 
1133
- case 18:
1140
+ case 20:
1134
1141
  case "end":
1135
1142
  return _context10.stop();
1136
1143
  }
@@ -1317,7 +1324,7 @@ var InfinitePool = /*#__PURE__*/function () {
1317
1324
 
1318
1325
  pool = new InfinitePool(2);
1319
1326
  pool.runInfiniteInBackground(myAsyncTask, 5000);
1320
- pool.setIgnoreFirstRun(true);
1327
+ pool.setDisableFirstRun(true);
1321
1328
  pool.setTaskFailHandler(function (error) {
1322
1329
  console.error(error.message);
1323
1330
  });
@@ -1647,7 +1654,7 @@ var InfinitePool = /*#__PURE__*/function () {
1647
1654
  case 0:
1648
1655
  _persistTone = function _persistTone3() {
1649
1656
  _persistTone = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee27() {
1650
- var sign;
1657
+ var sign, time;
1651
1658
  return _regenerator["default"].wrap(function _callee27$(_context27) {
1652
1659
  while (1) {
1653
1660
  switch (_context27.prev = _context27.next) {
@@ -1655,34 +1662,28 @@ var InfinitePool = /*#__PURE__*/function () {
1655
1662
  _context27.prev = 0;
1656
1663
  sign = _index2.utiller.getRandomHash(20);
1657
1664
  _context27.next = 4;
1658
- return _index2.utiller.syncDelay(1000);
1665
+ return _index2.utiller.syncDelayRandom(1, 10);
1659
1666
 
1660
1667
  case 4:
1661
- _context27.t0 = _index2.utiller;
1662
- _context27.t1 = "\u6C92\u6709TONE\u53EF\u4EE5\u4E0B\u8F09\u4E86....\u96A8\u6A5F\u7761\u500B";
1663
- _context27.next = 8;
1664
- return _index2.utiller.syncDelayRandom(1500, 3500);
1668
+ time = _context27.sent;
1665
1669
 
1666
- case 8:
1667
- _context27.t2 = _context27.sent;
1668
- _context27.t3 = _context27.t1.concat.call(_context27.t1, _context27.t2);
1670
+ _index2.utiller.appendInfo("".concat(time, " ms, yoyoyo ").concat(sign)); // Util.appendInfo(`沒有TONE可以下載了....隨機睡個${await Util.syncDelayRandom(1500, 3500)}`)
1669
1671
 
1670
- _context27.t0.appendInfo.call(_context27.t0, _context27.t3);
1671
1672
 
1672
1673
  return _context27.abrupt("return", "\u4EFB\u52D9ID:".concat(sign));
1673
1674
 
1674
- case 14:
1675
- _context27.prev = 14;
1676
- _context27.t4 = _context27["catch"](0);
1675
+ case 9:
1676
+ _context27.prev = 9;
1677
+ _context27.t0 = _context27["catch"](0);
1677
1678
 
1678
- _index2.utiller.appendError(_context27.t4.message);
1679
+ _index2.utiller.appendError(_context27.t0.message);
1679
1680
 
1680
- case 17:
1681
+ case 12:
1681
1682
  case "end":
1682
1683
  return _context27.stop();
1683
1684
  }
1684
1685
  }
1685
- }, _callee27, null, [[0, 14]]);
1686
+ }, _callee27, null, [[0, 9]]);
1686
1687
  }));
1687
1688
  return _persistTone.apply(this, arguments);
1688
1689
  };
@@ -1692,10 +1693,10 @@ var InfinitePool = /*#__PURE__*/function () {
1692
1693
  };
1693
1694
 
1694
1695
  poollers = [];
1695
- pool = new InfinitePool(2);
1696
+ pool = new InfinitePool(3);
1696
1697
  pool.setPoolId("tone fetch");
1697
- pool.setIgnoreFirstRun(false);
1698
- pool.runInfiniteInBackground(persistTone, 3000);
1698
+ pool.setDisableFirstRun(true);
1699
+ pool.runInfiniteInBackground(persistTone, 5000);
1699
1700
  pool.setTaskFailHandler(function (error) {
1700
1701
  return _index2.utiller.appendError("5165 error ".concat(error.message));
1701
1702
  });
@@ -1703,11 +1704,11 @@ var InfinitePool = /*#__PURE__*/function () {
1703
1704
  isRequiredTerminate = false;
1704
1705
  setTimeout(function () {
1705
1706
  isRequiredTerminate = true;
1706
- }, 10000);
1707
+ }, 20000);
1707
1708
 
1708
1709
  case 11:
1709
1710
  if (!true) {
1710
- _context28.next = 44;
1711
+ _context28.next = 43;
1711
1712
  break;
1712
1713
  }
1713
1714
 
@@ -1720,28 +1721,25 @@ var InfinitePool = /*#__PURE__*/function () {
1720
1721
 
1721
1722
  case 15:
1722
1723
  random = _context28.sent;
1723
-
1724
- _index2.utiller.appendInfo("\u4E3B\u7DDA\u7A0B\u9084\u5728\u52AA\u4E2D\u5DE5\u4F5C\u4E2D, \u4F11\u606F\u4E00\u6BC0\u5152 ".concat(random, " mms"));
1725
-
1726
- _context28.next = 19;
1724
+ _context28.next = 18;
1727
1725
  return _index2.utiller.syncDelay(random);
1728
1726
 
1729
- case 19:
1727
+ case 18:
1730
1728
  if (!isRequiredTerminate) {
1731
- _context28.next = 42;
1729
+ _context28.next = 41;
1732
1730
  break;
1733
1731
  }
1734
1732
 
1735
1733
  _index2.utiller.appendInfo("\u4E3B\u7DDA\u7A0B\u6536\u5230\u95DC\u9589\u6307\u4EE4...");
1736
1734
 
1737
1735
  _iterator6 = _createForOfIteratorHelper(poollers);
1738
- _context28.prev = 22;
1736
+ _context28.prev = 21;
1739
1737
 
1740
1738
  _iterator6.s();
1741
1739
 
1742
- case 24:
1740
+ case 23:
1743
1741
  if ((_step6 = _iterator6.n()).done) {
1744
- _context28.next = 33;
1742
+ _context28.next = 32;
1745
1743
  break;
1746
1744
  }
1747
1745
 
@@ -1749,48 +1747,48 @@ var InfinitePool = /*#__PURE__*/function () {
1749
1747
 
1750
1748
  _index2.utiller.appendInfo("POOLER ".concat(pooller.getPoolId(), " \u6B63\u5728\u95DC\u9589\u4E2D"));
1751
1749
 
1752
- _context28.next = 29;
1750
+ _context28.next = 28;
1753
1751
  return pooller.stopInBackground();
1754
1752
 
1755
- case 29:
1753
+ case 28:
1756
1754
  pooller.showState();
1757
1755
 
1758
1756
  _index2.utiller.appendInfo("POOLER ".concat(pooller.getPoolId(), " \u95DC\u9589\u6210\u529F!"));
1759
1757
 
1760
- case 31:
1761
- _context28.next = 24;
1758
+ case 30:
1759
+ _context28.next = 23;
1762
1760
  break;
1763
1761
 
1764
- case 33:
1765
- _context28.next = 38;
1762
+ case 32:
1763
+ _context28.next = 37;
1766
1764
  break;
1767
1765
 
1768
- case 35:
1769
- _context28.prev = 35;
1770
- _context28.t0 = _context28["catch"](22);
1766
+ case 34:
1767
+ _context28.prev = 34;
1768
+ _context28.t0 = _context28["catch"](21);
1771
1769
 
1772
1770
  _iterator6.e(_context28.t0);
1773
1771
 
1774
- case 38:
1775
- _context28.prev = 38;
1772
+ case 37:
1773
+ _context28.prev = 37;
1776
1774
 
1777
1775
  _iterator6.f();
1778
1776
 
1779
- return _context28.finish(38);
1777
+ return _context28.finish(37);
1780
1778
 
1781
- case 41:
1782
- return _context28.abrupt("break", 44);
1779
+ case 40:
1780
+ return _context28.abrupt("break", 43);
1783
1781
 
1784
- case 42:
1782
+ case 41:
1785
1783
  _context28.next = 11;
1786
1784
  break;
1787
1785
 
1788
- case 44:
1786
+ case 43:
1789
1787
  case "end":
1790
1788
  return _context28.stop();
1791
1789
  }
1792
1790
  }
1793
- }, _callee28, null, [[22, 35, 38, 41]]);
1791
+ }, _callee28, null, [[21, 34, 37, 40]]);
1794
1792
  }));
1795
1793
 
1796
1794
  function exampleOfInfiniteUnStopLoopingIssue() {
@@ -251,7 +251,9 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
251
251
 
252
252
  }, {
253
253
  key: "isPathExist",
254
- value: function isPathExist(path) {
254
+ value:
255
+ /** 是一個存在的檔案 */
256
+ function isPathExist(path) {
255
257
  return _fs["default"].existsSync(path);
256
258
  }
257
259
  /** path = a/b/c/file.js , newName = 'two'
@@ -748,7 +750,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
748
750
  key: "copySingleFile",
749
751
  value: function copySingleFile(from, dest, fileName) {
750
752
  var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
751
- var destination = _lodash["default"].isEmpty(fileName) ? dest : _path5["default"].join(dest, fileName);
753
+ var destination = _lodash["default"].isString(fileName) && !_lodash["default"].isEmpty(fileName) ? _path5["default"].join(dest, fileName) : dest;
752
754
  if (_fs["default"].existsSync(destination) && !force) throw new _index2["default"](8006, destination);
753
755
 
754
756
  _fs["default"].copyFileSync(from, destination);
@@ -783,8 +785,6 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
783
785
  key: "cleanChildFiles",
784
786
  value: function () {
785
787
  var _cleanChildFiles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(path) {
786
- var _this5 = this;
787
-
788
788
  var predicate,
789
789
  _len5,
790
790
  exclude,
@@ -804,7 +804,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
804
804
  };
805
805
 
806
806
  if (!_fs["default"].existsSync(path)) {
807
- _context7.next = 26;
807
+ _context7.next = 25;
808
808
  break;
809
809
  }
810
810
 
@@ -820,7 +820,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
820
820
 
821
821
  case 7:
822
822
  if ((_step5 = _iterator5.n()).done) {
823
- _context7.next = 15;
823
+ _context7.next = 14;
824
824
  break;
825
825
  }
826
826
 
@@ -831,52 +831,48 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
831
831
  break;
832
832
  }
833
833
 
834
- return _context7.abrupt("continue", 13);
834
+ return _context7.abrupt("continue", 12);
835
835
 
836
836
  case 11:
837
- _fs["default"].truncate(file.absolute, 0, function (result) {
838
- if (!_lodash["default"].isUndefined(result) && !_lodash["default"].isNull(result)) _this5.appendInfo(result);
839
- });
840
-
841
- this.appendInfo("".concat(file.absolute, " \u88AB\u6E05\u7684\u4E7E\u4E7E\u6DE8\u6DE8\uFF01"));
837
+ this.cleanFileContent(file.absolute);
842
838
 
843
- case 13:
839
+ case 12:
844
840
  _context7.next = 7;
845
841
  break;
846
842
 
847
- case 15:
848
- _context7.next = 20;
843
+ case 14:
844
+ _context7.next = 19;
849
845
  break;
850
846
 
851
- case 17:
852
- _context7.prev = 17;
847
+ case 16:
848
+ _context7.prev = 16;
853
849
  _context7.t0 = _context7["catch"](5);
854
850
 
855
851
  _iterator5.e(_context7.t0);
856
852
 
857
- case 20:
858
- _context7.prev = 20;
853
+ case 19:
854
+ _context7.prev = 19;
859
855
 
860
856
  _iterator5.f();
861
857
 
862
- return _context7.finish(20);
858
+ return _context7.finish(19);
863
859
 
864
- case 23:
865
- _context7.next = 25;
866
- return this.syncDelay(500);
860
+ case 22:
861
+ _context7.next = 24;
862
+ return this.syncDelay(50);
867
863
 
868
- case 25:
864
+ case 24:
869
865
  return _context7.abrupt("return", files);
870
866
 
871
- case 26:
867
+ case 25:
872
868
  return _context7.abrupt("return", false);
873
869
 
874
- case 27:
870
+ case 26:
875
871
  case "end":
876
872
  return _context7.stop();
877
873
  }
878
874
  }
879
- }, _callee7, this, [[5, 17, 20, 23]]);
875
+ }, _callee7, this, [[5, 16, 19, 22]]);
880
876
  }));
881
877
 
882
878
  function cleanChildFiles(_x7) {
@@ -885,6 +881,15 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
885
881
 
886
882
  return cleanChildFiles;
887
883
  }()
884
+ /** 將檔案清除乾淨, 但不刪掉檔案, 這樣hot reload的監聽才不會遺失*/
885
+
886
+ }, {
887
+ key: "cleanFileContent",
888
+ value: function cleanFileContent(path) {
889
+ _fs["default"].truncateSync(path, 0);
890
+
891
+ this.appendInfo("".concat(path, " \u5167\u5BB9\u88AB\u6E05\u9664\uFF01"));
892
+ }
888
893
  }, {
889
894
  key: "syncWithExistPackage",
890
895
  value: function () {
@@ -942,7 +947,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
942
947
  key: "packageTemplatify",
943
948
  value: function () {
944
949
  var _packageTemplatify = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(path, packageName) {
945
- var _this6 = this;
950
+ var _this5 = this;
946
951
 
947
952
  var existFolders, dirPath, packagejson, classBase, ideaWorkspacePath, workspace, splited, indexOfRunManager, indexOfList;
948
953
  return _regenerator["default"].wrap(function _callee9$(_context9) {
@@ -993,7 +998,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
993
998
  workspace = this.getFileContextInRaw(ideaWorkspacePath);
994
999
  splited = workspace.split("\n");
995
1000
  indexOfRunManager = _lodash["default"].findIndex(splited, function (line) {
996
- return _this6.has(line, 'name="RunManager');
1001
+ return _this5.has(line, 'name="RunManager');
997
1002
  });
998
1003
  this.insertToArray(splited, indexOfRunManager, "<configuration name=\"".concat(packageName, "\"\ntype=\"NodeJSConfigurationType\"\npath-to-node=\"$USER_HOME$/.nvm/versions/node/v14.4.0/bin/node\"\nnode-parameters=\"--require @babel/register\"\npath-to-js-file=\"").concat(_path5["default"].resolve(dirPath), "/src/index.js\"\nworking-dir=\"").concat(_path5["default"].resolve(dirPath), "\" >"), " <envs>", " <env name=\"self_debug\" value=\"true\" />", " <env name=\"is_node\" value=\"true\" />", " </envs>", " <method v=\"2\" />", "</configuration>");
999
1004
  indexOfList = _lodash["default"].findIndex(splited, function (line) {
@@ -1061,10 +1066,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1061
1066
  }, {
1062
1067
  key: "getLogString",
1063
1068
  value: function getLogString(datas) {
1064
- var _this7 = this;
1069
+ var _this6 = this;
1065
1070
 
1066
1071
  return datas.map(function (data) {
1067
- return _this7.isJson(data) || _lodash["default"].isObject(data) || _lodash["default"].isArray(data) ? _this7.deepFlat(data) : data;
1072
+ return _this6.isJson(data) || _lodash["default"].isObject(data) || _lodash["default"].isArray(data) ? _this6.deepFlat(data) : data;
1068
1073
  }).join(" ,");
1069
1074
  }
1070
1075
  /** 如果file不存在,就會產生file,force_delete 可以強制刪除cache file*/
@@ -1072,20 +1077,22 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1072
1077
  }, {
1073
1078
  key: "appendFile",
1074
1079
  value: function appendFile(path, data) {
1075
- var newLine = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1076
- var force_delete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1080
+ var newlineOnceFileNotEmpty = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
1081
+ var forceDelete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1077
1082
 
1078
1083
  var options = function options(err) {
1079
1084
  throw new _index2["default"](8001, err);
1080
1085
  };
1081
1086
 
1082
- if (force_delete) this.syncDeleteFile(path);
1083
-
1084
- if (!_fs["default"].existsSync(path)) {
1085
- _fs["default"].writeFileSync(path, data, options);
1086
- } else {
1087
- _fs["default"].appendFileSync(path, "".concat(newLine ? "\n" : "").concat(data), options);
1087
+ if (!this.isValidFilePath(path)) {
1088
+ throw new _index2["default"](9999, "\u4E0D\u662F\u500B\u5408\u6CD5\u7684file\u8DEF\u5F91 ==> '' ".concat(path, " ''"));
1088
1089
  }
1090
+
1091
+ this.persistByPath(path);
1092
+ if (forceDelete) this.cleanFileContent(path);
1093
+ if (this.isEmptyFile(path)) newlineOnceFileNotEmpty = false;
1094
+
1095
+ _fs["default"].appendFileSync(path, "".concat(newlineOnceFileNotEmpty ? "\n" : "").concat(data), options);
1089
1096
  }
1090
1097
  /** 快速把資料結構印出來看 */
1091
1098
 
@@ -1128,21 +1135,21 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1128
1135
 
1129
1136
  }, {
1130
1137
  key: "copySingleFileConservative",
1131
- value: function copySingleFileConservative(pathOfDestination, latestFile) {
1138
+ value: function copySingleFileConservative(pathOfDestinationFolder, latestFile) {
1132
1139
  if (this.isEmptyFile(latestFile.absolute)) {
1133
1140
  this.appendInfo("".concat(latestFile.absolute, " is empty file, ignore copy behavior"));
1134
1141
  return;
1135
1142
  }
1136
1143
 
1137
- if (!_fs["default"].existsSync(pathOfDestination)) {
1138
- this.appendInfo("".concat(pathOfDestination, " is not exist, easy to override"));
1139
- } else if (_fs["default"].existsSync(pathOfDestination) && this.getFileLastModifiedTime(pathOfDestination) < latestFile.lastModifiedTime + 3600) {
1140
- this.appendInfo("".concat(pathOfDestination, " is the latest, ignore this run"));
1144
+ if (!_fs["default"].existsSync(pathOfDestinationFolder)) {
1145
+ this.appendInfo("".concat(pathOfDestinationFolder, " is not exist, easy to override"));
1146
+ } else if (_fs["default"].existsSync(pathOfDestinationFolder) && this.getFileLastModifiedTime(pathOfDestinationFolder) > latestFile.lastModifiedTime) {
1147
+ this.appendInfo("".concat(pathOfDestinationFolder, " is the latest, ignore this run"));
1141
1148
  return;
1142
1149
  }
1143
1150
 
1144
- this.persistByPath(this.getFolderPathOfSpecificPath(pathOfDestination));
1145
- this.copySingleFile(latestFile.absolute, pathOfDestination, undefined, true);
1151
+ this.persistByPath(this.getFolderPathOfSpecificPath(pathOfDestinationFolder));
1152
+ this.copySingleFile(latestFile.absolute, pathOfDestinationFolder, undefined, true);
1146
1153
  }
1147
1154
  }, {
1148
1155
  key: "syncDeleteFile",
@@ -1194,7 +1201,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1194
1201
  key: "generatePackage",
1195
1202
  value: function () {
1196
1203
  var _generatePackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
1197
- var _this8 = this;
1204
+ var _this7 = this;
1198
1205
 
1199
1206
  var path,
1200
1207
  deployToNPMServer,
@@ -1218,7 +1225,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1218
1225
  return _lodash["default"].isEqual(each.fileName, "package");
1219
1226
  });
1220
1227
  packagejsons = packagejsons.map(function (each) {
1221
- return _this8.getFolderPathOfSpecificPath(each.absolute);
1228
+ return _this7.getFolderPathOfSpecificPath(each.absolute);
1222
1229
  });
1223
1230
 
1224
1231
  for (_len8 = _args11.length, exclude = new Array(_len8 > 2 ? _len8 - 2 : 0), _key8 = 2; _key8 < _len8; _key8++) {
@@ -1228,7 +1235,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1228
1235
  _iterator8 = _createForOfIteratorHelper(packagejsons);
1229
1236
  _context11.prev = 7;
1230
1237
  _loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
1231
- var path, tempFolderPath, release, pathOfPackageJson, indexFileName, templatePath, _yield$_this8$upgrade, moduleName, version;
1238
+ var path, tempFolderPath, release, pathOfPackageJson, indexFileName, templatePath, _yield$_this7$upgrade, moduleName, version;
1232
1239
 
1233
1240
  return _regenerator["default"].wrap(function _loop$(_context10) {
1234
1241
  while (1) {
@@ -1236,9 +1243,9 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1236
1243
  case 0:
1237
1244
  path = _step8.value;
1238
1245
 
1239
- if (!_this8.isAndEquals.apply(_this8, (0, _toConsumableArray2["default"])(exclude.map(function (projectName) {
1246
+ if (!_this7.isAndEquals.apply(_this7, (0, _toConsumableArray2["default"])(exclude.map(function (projectName) {
1240
1247
  return function () {
1241
- return !_this8.has(path, projectName);
1248
+ return !_this7.has(path, projectName);
1242
1249
  };
1243
1250
  })))) {
1244
1251
  _context10.next = 40;
@@ -1246,17 +1253,17 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1246
1253
  }
1247
1254
 
1248
1255
  _context10.next = 4;
1249
- return _this8.generateTempFolderWithCleanSrc(path);
1256
+ return _this7.generateTempFolderWithCleanSrc(path);
1250
1257
 
1251
1258
  case 4:
1252
1259
  tempFolderPath = _context10.sent;
1253
1260
 
1254
1261
  /** 產生release資料夾 */
1255
- release = _this8.persistByPath(_path5["default"].join(path, "release"));
1262
+ release = _this7.persistByPath(_path5["default"].join(path, "release"));
1256
1263
  /** 利用babel 產生出 es5相容性高的src file */
1257
1264
 
1258
1265
  _context10.next = 8;
1259
- return _this8.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
1266
+ return _this7.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
1260
1267
 
1261
1268
  case 8:
1262
1269
  pathOfPackageJson = _path5["default"].join(path, "package.json");
@@ -1264,14 +1271,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1264
1271
  indexFileName = "sample.npm.module.index.js";
1265
1272
  /** 複製公版的index.js */
1266
1273
 
1267
- _this8.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
1274
+ _this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
1268
1275
  /** template就是樣板的概念 */
1269
1276
 
1270
1277
 
1271
1278
  templatePath = _path5["default"].join(path, "template");
1272
1279
 
1273
- if (_this8.isPathExist(templatePath)) {
1274
- _this8.copyFromFolderToDestFolder(templatePath, _this8.persistByPath(_path5["default"].join(release, "template")));
1280
+ if (_this7.isPathExist(templatePath)) {
1281
+ _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path5["default"].join(release, "template")));
1275
1282
  }
1276
1283
 
1277
1284
  if (!deployToNPMServer) {
@@ -1280,26 +1287,26 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1280
1287
  }
1281
1288
 
1282
1289
  _context10.next = 17;
1283
- return _this8.upgradePackageJsonVersion(pathOfPackageJson);
1290
+ return _this7.upgradePackageJsonVersion(pathOfPackageJson);
1284
1291
 
1285
1292
  case 17:
1286
- _yield$_this8$upgrade = _context10.sent;
1287
- moduleName = _yield$_this8$upgrade.moduleName;
1288
- version = _yield$_this8$upgrade.version;
1293
+ _yield$_this7$upgrade = _context10.sent;
1294
+ moduleName = _yield$_this7$upgrade.moduleName;
1295
+ version = _yield$_this7$upgrade.version;
1289
1296
  _context10.next = 22;
1290
- return _this8.updateVersionOfTemplate(moduleName, version);
1297
+ return _this7.updateVersionOfTemplate(moduleName, version);
1291
1298
 
1292
1299
  case 22:
1293
1300
  /** 把package.json release放進去 */
1294
- _this8.copySingleFile(pathOfPackageJson, _path5["default"].join(release, "package.json"), undefined, true);
1301
+ _this7.copySingleFile(pathOfPackageJson, _path5["default"].join(release, "package.json"), undefined, true);
1295
1302
  /** 安裝一個沒有devDependency 的node_module */
1296
1303
 
1297
1304
 
1298
1305
  _context10.next = 25;
1299
- return _this8.executeCommandLine("\ncd ".concat(release, " && yarn install --production"));
1306
+ return _this7.executeCommandLine("\ncd ".concat(release, " && yarn install --production"));
1300
1307
 
1301
1308
  case 25:
1302
- _this8.appendInfo("build ".concat(path, " succeed"));
1309
+ _this7.appendInfo("build ".concat(path, " succeed"));
1303
1310
  /** 部署到 local server*/
1304
1311
 
1305
1312
 
@@ -1309,7 +1316,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1309
1316
  }
1310
1317
 
1311
1318
  _context10.next = 29;
1312
- return _this8.executeCommandLine("cd ".concat(release, " && npm publish"));
1319
+ return _this7.executeCommandLine("cd ".concat(release, " && npm publish"));
1313
1320
 
1314
1321
  case 29:
1315
1322
  _context10.next = 36;
@@ -1319,7 +1326,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1319
1326
  _context10.prev = 31;
1320
1327
  _context10.t0 = _context10["catch"](9);
1321
1328
  _context10.next = 35;
1322
- return _this8.deleteSelfByPath(release, true);
1329
+ return _this7.deleteSelfByPath(release, true);
1323
1330
 
1324
1331
  case 35:
1325
1332
  throw new _index2["default"](9999, "generatePackage \u5831\u932F, ".concat(_context10.t0.message));
@@ -1327,7 +1334,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1327
1334
  case 36:
1328
1335
  _context10.prev = 36;
1329
1336
  _context10.next = 39;
1330
- return _this8.deleteSelfByPath(tempFolderPath, true);
1337
+ return _this7.deleteSelfByPath(tempFolderPath, true);
1331
1338
 
1332
1339
  case 39:
1333
1340
  return _context10.finish(36);
@@ -1574,7 +1581,16 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1574
1581
  key: "getExtensionFromPath",
1575
1582
  value: function getExtensionFromPath(path) {
1576
1583
  var name = path.split("/").pop();
1577
- return name.split(".").pop();
1584
+ var segments = name.split(".");
1585
+ return _lodash["default"].size(segments) > 1 ? segments.pop() : "";
1586
+ }
1587
+ /** 是一個/a/b/c.js 的檔案路徑 */
1588
+
1589
+ }, {
1590
+ key: "isValidFilePath",
1591
+ value: function isValidFilePath(path) {
1592
+ var extension = this.getExtensionFromPath(path);
1593
+ return _lodash["default"].size(extension) > 0;
1578
1594
  }
1579
1595
  }, {
1580
1596
  key: "isEmptyFile",
@@ -1812,6 +1828,15 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1812
1828
 
1813
1829
  return generateTempFolderWithCleanSrc;
1814
1830
  }()
1831
+ /** 讓file content清除後,在寫入資料, 避免destined file address改變*/
1832
+
1833
+ }, {
1834
+ key: "rewriteFile2File",
1835
+ value: function rewriteFile2File(from, destination) {
1836
+ var content = this.getFileContextInRaw(from);
1837
+ if (_lodash["default"].isEmpty(content)) throw new _index2["default"](9999, "rewrite 功能會避免空值覆蓋, 這是一個設計");
1838
+ this.appendFile(destination, content, true, true);
1839
+ }
1815
1840
  }]);
1816
1841
  return NodeUtiller;
1817
1842
  }(_index["default"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.84",
3
+ "version": "1.0.87",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "configerer": "^1.0.11",
14
- "utiller": "^1.0.83",
14
+ "utiller": "^1.0.86",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.9",
17
17
  "lodash": "^4.17.20",