utiller 1.0.297 → 1.0.298

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.
@@ -16,7 +16,7 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
16
16
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
17
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
18
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
- var _path4 = _interopRequireDefault(require("path"));
19
+ var _path5 = _interopRequireDefault(require("path"));
20
20
  var _fs = _interopRequireDefault(require("fs"));
21
21
  var _promises = _interopRequireDefault(require("fs/promises"));
22
22
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -96,7 +96,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
96
96
  */
97
97
  (0, _defineProperty2["default"])(_this, "getPathAfterSpecificFolder", function (fullPath) {
98
98
  var folder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "src";
99
- var parts = fullPath.split(_path4["default"].sep);
99
+ var parts = fullPath.split(_path5["default"].sep);
100
100
  for (var i = parts.length - 1; i >= 0; i--) {
101
101
  if (parts[i] === folder) {
102
102
  return "/" + parts.slice(i + 1).join("/");
@@ -118,10 +118,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
118
118
  return (0, _createClass2["default"])(NodeUtiller, [{
119
119
  key: "findSpecificFolderByPath",
120
120
  value: function findSpecificFolderByPath(path, folderName) {
121
- var absolute = _path4["default"].resolve(path);
122
- var parts = absolute.split(_path4["default"].sep);
121
+ var absolute = _path5["default"].resolve(path);
122
+ var parts = absolute.split(_path5["default"].sep);
123
123
  while (parts.length) {
124
- var joined = _path4["default"].join.apply(_path4["default"], (0, _toConsumableArray2["default"])(parts).concat([folderName]));
124
+ var joined = _path5["default"].join.apply(_path5["default"], (0, _toConsumableArray2["default"])(parts).concat([folderName]));
125
125
  if (_fs["default"].existsSync(joined)) return joined;
126
126
  parts.pop();
127
127
  }
@@ -192,7 +192,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
192
192
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
193
193
  var entry = _step.value;
194
194
  if (excludes.includes(entry.name)) continue;
195
- var fullPath = _path4["default"].join(path, entry.name);
195
+ var fullPath = _path5["default"].join(path, entry.name);
196
196
  if (entry.isDirectory()) {
197
197
  result.push.apply(result, (0, _toConsumableArray2["default"])(this.findFilePathBy.apply(this, [fullPath, predicate].concat(excludes))));
198
198
  } else if (entry.isFile()) {
@@ -226,9 +226,9 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
226
226
  this.appendError("renameFile \u932F\u8AA4, path: ".concat(path, ", newName: ").concat(newName));
227
227
  return;
228
228
  }
229
- var dir = _path4["default"].dirname(path);
230
- var ext = _path4["default"].extname(path);
231
- var newPath = _path4["default"].join(dir, "".concat(newName).concat(ext));
229
+ var dir = _path5["default"].dirname(path);
230
+ var ext = _path5["default"].extname(path);
231
+ var newPath = _path5["default"].join(dir, "".concat(newName).concat(ext));
232
232
  _fs["default"].renameSync(path, newPath);
233
233
  }
234
234
 
@@ -236,7 +236,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
236
236
  }, {
237
237
  key: "getPathInfo",
238
238
  value: function getPathInfo(path) {
239
- var absolute = _path4["default"].resolve(path);
239
+ var absolute = _path5["default"].resolve(path);
240
240
  var obj = {
241
241
  path: path,
242
242
  absolute: absolute,
@@ -312,7 +312,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
312
312
  } finally {
313
313
  _iterator2.f();
314
314
  }
315
- return _path4["default"].resolve(path);
315
+ return _path5["default"].resolve(path);
316
316
  }
317
317
 
318
318
  /**
@@ -609,7 +609,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
609
609
  try {
610
610
  var files = _fs["default"].readdirSync(_path);
611
611
  return files.map(function (file) {
612
- return _this3.getPathInfo(_path4["default"].join(_path, file));
612
+ return _this3.getPathInfo(_path5["default"].join(_path, file));
613
613
  });
614
614
  } catch (error) {
615
615
  throw new _index2["default"](8002, error);
@@ -625,7 +625,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
625
625
  key: "copySingleFile",
626
626
  value: function copySingleFile(from, dest, fileName) {
627
627
  var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
628
- var destination = fileName && fileName.trim() ? _path4["default"].join(dest, fileName) : dest;
628
+ var destination = fileName && fileName.trim() ? _path5["default"].join(dest, fileName) : dest;
629
629
  if (_fs["default"].existsSync(destination) && !force) {
630
630
  throw new _index2["default"](8006, destination);
631
631
  }
@@ -634,7 +634,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
634
634
  }, {
635
635
  key: "ensureFolderExists",
636
636
  value: function ensureFolderExists(folderPath) {
637
- var resolved = _path4["default"].resolve(folderPath);
637
+ var resolved = _path5["default"].resolve(folderPath);
638
638
  if (_fs["default"].existsSync(resolved)) return;
639
639
  _fs["default"].mkdirSync(resolved, {
640
640
  recursive: true
@@ -807,14 +807,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
807
807
  /** 6.要產生webstorm run case? */
808
808
  ideaWorkspacePath = "".concat(this.findSpecificFolderByPath(dirPath, ".idea"), "/workspace.xml");
809
809
  /** 7.要產生cd script 腳本 **/
810
- this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path4["default"].resolve(dirPath)));
810
+ this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path5["default"].resolve(dirPath)));
811
811
  if (_fs["default"].existsSync(ideaWorkspacePath)) {
812
812
  workspace = this.getFileContextInRaw(ideaWorkspacePath);
813
813
  splited = workspace.split("\n");
814
814
  indexOfRunManager = _lodash["default"].findIndex(splited, function (line) {
815
815
  return _this5.has(line, 'name="RunManager');
816
816
  });
817
- this.insertToArray(splited, indexOfRunManager, "<configuration name=\"".concat(packageName, "\"\ntype=\"NodeJSConfigurationType\"\npath-to-node=\"$USER_HOME$/.nvm/versions/node/v18.19.1/bin/node\"\nnode-parameters=\"--require @babel/register\"\npath-to-js-file=\"").concat(_path4["default"].resolve(dirPath), "/src/index.js\"\nworking-dir=\"").concat(_path4["default"].resolve(dirPath), "\" >"), " <envs>", " <env name=\"self_debug\" value=\"true\" />", " <env name=\"is_node\" value=\"true\" />", " </envs>", " <method v=\"2\" />", "</configuration>");
817
+ this.insertToArray(splited, indexOfRunManager, "<configuration name=\"".concat(packageName, "\"\ntype=\"NodeJSConfigurationType\"\npath-to-node=\"$USER_HOME$/.nvm/versions/node/v18.19.1/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>");
818
818
  indexOfList = _lodash["default"].findIndex(splited, function (line) {
819
819
  return _lodash["default"].isEqual(_lodash["default"].trim(line), "<list>");
820
820
  }, indexOfRunManager);
@@ -824,7 +824,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
824
824
  this.appendError("".concat(ideaWorkspacePath, " not exist"));
825
825
  }
826
826
  _context10.next = 17;
827
- return this.executeCommandLine("cd ".concat(_path4["default"].resolve(dirPath), " && npm install"));
827
+ return this.executeCommandLine("cd ".concat(_path5["default"].resolve(dirPath), " && npm install"));
828
828
  case 17:
829
829
  this.appendInfo("build ".concat(packageName, " succeed!"));
830
830
  case 18:
@@ -876,14 +876,15 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
876
876
  /** 如果file不存在,就會產生file,force_delete 可以強制刪除cache file*/
877
877
  }, {
878
878
  key: "appendFile",
879
- value: function appendFile(path, data) {
879
+ value: function appendFile(filePath, data) {
880
880
  var newline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
881
881
  var forceDelete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
882
882
  try {
883
- if (forceDelete && _fs["default"].existsSync(path)) _fs["default"].unlinkSync(path);
884
- if (!_fs["default"].existsSync(path)) this.persistByPath(path);
883
+ var resolvedPath = path.resolve(filePath); // <<--- 正規化路徑
884
+ if (forceDelete && _fs["default"].existsSync(resolvedPath)) _fs["default"].unlinkSync(resolvedPath);
885
+ if (!_fs["default"].existsSync(resolvedPath)) this.persistByPath(resolvedPath);
885
886
  var content = "".concat(newline ? "\n" : "").concat(data);
886
- _fs["default"].appendFileSync(path, content);
887
+ _fs["default"].appendFileSync(resolvedPath, content);
887
888
  } catch (err) {
888
889
  throw new _index2["default"](8001, err);
889
890
  }
@@ -913,7 +914,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
913
914
  while (1) switch (_context11.prev = _context11.next) {
914
915
  case 0:
915
916
  ignoreP = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : false;
916
- path = _path4["default"].resolve(path);
917
+ path = _path5["default"].resolve(path);
917
918
  this.appendFile(path, JSON.stringify(object), true, true);
918
919
  if (ignoreP) {
919
920
  _context11.next = 6;
@@ -1029,7 +1030,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1029
1030
  }
1030
1031
 
1031
1032
  // 確保目的路徑存在(遞迴建立)
1032
- this.ensureFolderExists(_path4["default"].dirname(destPath));
1033
+ this.ensureFolderExists(_path5["default"].dirname(destPath));
1033
1034
 
1034
1035
  // 強制複製
1035
1036
  this.copySingleFile(absolute, destPath, undefined, true);
@@ -1122,25 +1123,25 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1122
1123
  case 4:
1123
1124
  tempFolderPath = _context13.sent;
1124
1125
  /** 產生release資料夾 */
1125
- release = _this7.persistByPath(_path4["default"].join(path, "release"));
1126
+ release = _this7.persistByPath(_path5["default"].join(path, "release"));
1126
1127
  /** 利用babel 產生出 es5相容性高的src file */
1127
1128
  _context13.next = 8;
1128
1129
  return _this7.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
1129
1130
  case 8:
1130
- pathOfPackageJson = _path4["default"].join(path, "package.json");
1131
+ pathOfPackageJson = _path5["default"].join(path, "package.json");
1131
1132
  _context13.prev = 9;
1132
1133
  indexFileName = "sample.npm.module.index.js";
1133
1134
  /** 複製公版的index.js */
1134
1135
  _this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
1135
1136
 
1136
1137
  /** template就是樣板的概念 */
1137
- templatePath = _path4["default"].join(path, "template");
1138
+ templatePath = _path5["default"].join(path, "template");
1138
1139
  if (!_this7.isPathExist(templatePath)) {
1139
1140
  _context13.next = 16;
1140
1141
  break;
1141
1142
  }
1142
1143
  _context13.next = 16;
1143
- return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path4["default"].join(release, "template")));
1144
+ return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path5["default"].join(release, "template")));
1144
1145
  case 16:
1145
1146
  if (!deployToNPMServer) {
1146
1147
  _context13.next = 24;
@@ -1156,10 +1157,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1156
1157
  return _this7.updateVersionOfTemplate(moduleName, version);
1157
1158
  case 24:
1158
1159
  /** 把package.json release放進去 */
1159
- _this7.copySingleFile(pathOfPackageJson, _path4["default"].join(release, "package.json"), undefined, true);
1160
+ _this7.copySingleFile(pathOfPackageJson, _path5["default"].join(release, "package.json"), undefined, true);
1160
1161
 
1161
1162
  /** 安裝一個沒有devDependency 的node_module */
1162
- if (!(forceInstallNodeModule || !_this7.isPathExist(_path4["default"].join(release, "node_module")))) {
1163
+ if (!(forceInstallNodeModule || !_this7.isPathExist(_path5["default"].join(release, "node_module")))) {
1163
1164
  _context13.next = 30;
1164
1165
  break;
1165
1166
  }
@@ -1238,7 +1239,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1238
1239
  key: "updateVersionOfTemplate",
1239
1240
  value: (function () {
1240
1241
  var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(dependency, newVersion) {
1241
- var paths, _i, _paths, path, succeedOfPersistFile, json;
1242
+ var paths, _i, _paths, _path4, succeedOfPersistFile, json;
1242
1243
  return _regenerator["default"].wrap(function _callee14$(_context15) {
1243
1244
  while (1) switch (_context15.prev = _context15.next) {
1244
1245
  case 0:
@@ -1249,13 +1250,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1249
1250
  _context15.next = 24;
1250
1251
  break;
1251
1252
  }
1252
- path = _paths[_i];
1253
- if (!this.isPathExist(path)) {
1253
+ _path4 = _paths[_i];
1254
+ if (!this.isPathExist(_path4)) {
1254
1255
  _context15.next = 21;
1255
1256
  break;
1256
1257
  }
1257
1258
  succeedOfPersistFile = false;
1258
- json = this.getJsonObjByFilePath(path);
1259
+ json = this.getJsonObjByFilePath(_path4);
1259
1260
  if (!(json && json.dependencies && json.dependencies[dependency])) {
1260
1261
  _context15.next = 18;
1261
1262
  break;
@@ -1263,7 +1264,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1263
1264
  json.dependencies[dependency] = "^".concat(newVersion);
1264
1265
  _context15.prev = 9;
1265
1266
  _context15.next = 12;
1266
- return this.writeJsonThanPrettier(path, json);
1267
+ return this.writeJsonThanPrettier(_path4, json);
1267
1268
  case 12:
1268
1269
  succeedOfPersistFile = true;
1269
1270
  _context15.next = 18;
@@ -1278,7 +1279,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1278
1279
  break;
1279
1280
  }
1280
1281
  _context15.next = 21;
1281
- return this.updateFileOfSpecificLine(path, function (line) {
1282
+ return this.updateFileOfSpecificLine(_path4, function (line) {
1282
1283
  return " \"".concat(dependency, "\":\"^").concat(newVersion, "\"").concat(_lodash["default"].endsWith(_lodash["default"].trim(line), "," ? "," : ""));
1283
1284
  }, function (each) {
1284
1285
  return _lodash["default"].startsWith(_lodash["default"].trim(each), "\"".concat(dependency, "\""));
@@ -1473,7 +1474,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1473
1474
  case 0:
1474
1475
  width = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : 200;
1475
1476
  _context19.next = 3;
1476
- return this.executeCommandLine("cd ".concat(_path4["default"].resolve("."), " && npx prettier --write ").concat(_path4["default"].resolve(path), " --print-width ").concat(width));
1477
+ return this.executeCommandLine("cd ".concat(_path5["default"].resolve("."), " && npx prettier --write ").concat(_path5["default"].resolve(path), " --print-width ").concat(width));
1477
1478
  case 3:
1478
1479
  case "end":
1479
1480
  return _context19.stop();
@@ -1643,7 +1644,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1643
1644
  var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
1644
1645
  if (_lodash["default"].isEqual(this.getExtensionFromPath(path), "js")) {
1645
1646
  var _source$key;
1646
- var source = require(_path4["default"].resolve(path))["default"];
1647
+ var source = require(_path5["default"].resolve(path))["default"];
1647
1648
  return (_source$key = source[key]) !== null && _source$key !== void 0 ? _source$key : defaultValue;
1648
1649
  } else {
1649
1650
  throw new _index2["default"](8020, "path is not js file, which is ".concat(path));
@@ -1816,8 +1817,8 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1816
1817
  while (1) switch (_context26.prev = _context26.next) {
1817
1818
  case 0:
1818
1819
  this.appendInfo("generateTempFolderWithCleanSrc", basePath);
1819
- sourceFile = _path4["default"].join(basePath, "src");
1820
- tempFolderPath = _path4["default"].join(basePath, "temp");
1820
+ sourceFile = _path5["default"].join(basePath, "src");
1821
+ tempFolderPath = _path5["default"].join(basePath, "temp");
1821
1822
  if (_fs["default"].existsSync(sourceFile)) {
1822
1823
  _context26.next = 5;
1823
1824
  break;
@@ -1858,7 +1859,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1858
1859
 
1859
1860
  // 美化代碼
1860
1861
  _context26.next = 25;
1861
- return this.executeCommandLine("cd ".concat(_path4["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
1862
+ return this.executeCommandLine("cd ".concat(_path5["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
1862
1863
  case 25:
1863
1864
  _context26.next = 13;
1864
1865
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.297",
3
+ "version": "1.0.298",
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.296",
14
+ "utiller": "^1.0.297",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.12",
17
17
  "lodash": "^4.17.20",