utiller 1.0.86 → 1.0.89

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.
@@ -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"].isString(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(10);
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
 
@@ -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,19 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1812
1828
 
1813
1829
  return generateTempFolderWithCleanSrc;
1814
1830
  }()
1831
+ /**
1832
+ * from, destination
1833
+ *
1834
+ * 讓file content清除後,在寫入資料, 避免destined file address改變*/
1835
+
1836
+ }, {
1837
+ key: "rewriteFile2File",
1838
+ value: function rewriteFile2File(from, destination) {
1839
+ var content = this.getFileContextInRaw(from);
1840
+ if (_lodash["default"].isEmpty(content)) throw new _index2["default"](9999, "rewrite 功能會避免空值覆蓋, 這是一個設計");
1841
+ this.appendFile(destination, content, true, true);
1842
+ this.appendInfo("rewrite from:".concat(from, " => dest:").concat(destination, " succeed"));
1843
+ }
1815
1844
  }]);
1816
1845
  return NodeUtiller;
1817
1846
  }(_index["default"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.86",
3
+ "version": "1.0.89",
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.85",
14
+ "utiller": "^1.0.88",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.9",
17
17
  "lodash": "^4.17.20",