utiller 1.0.305 → 1.0.307

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 _path5 = _interopRequireDefault(require("path"));
19
+ var _path4 = _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(_path5["default"].sep);
99
+ var parts = fullPath.split(_path4["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 = _path5["default"].resolve(path);
122
- var parts = absolute.split(_path5["default"].sep);
121
+ var absolute = _path4["default"].resolve(path);
122
+ var parts = absolute.split(_path4["default"].sep);
123
123
  while (parts.length) {
124
- var joined = _path5["default"].join.apply(_path5["default"], (0, _toConsumableArray2["default"])(parts).concat([folderName]));
124
+ var joined = _path4["default"].join.apply(_path4["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 = _path5["default"].join(path, entry.name);
195
+ var fullPath = _path4["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 = _path5["default"].dirname(path);
230
- var ext = _path5["default"].extname(path);
231
- var newPath = _path5["default"].join(dir, "".concat(newName).concat(ext));
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));
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 = _path5["default"].resolve(path);
239
+ var absolute = _path4["default"].resolve(path);
240
240
  var obj = {
241
241
  path: path,
242
242
  absolute: absolute,
@@ -290,14 +290,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
290
290
  key: "persistByPath",
291
291
  value: /** '/a/b/c.js' 把它變成真的 */
292
292
  function persistByPath(targetPath) {
293
- var isAbsolute = _path5["default"].isAbsolute(targetPath);
293
+ var isAbsolute = _path4["default"].isAbsolute(targetPath);
294
294
  var parts = targetPath.split("/").filter(Boolean);
295
295
  var lastPart = parts[parts.length - 1];
296
- var isFile = _path5["default"].extname(lastPart) !== ""; // ← 正規判斷副檔名
296
+ var isFile = _path4["default"].extname(lastPart) !== ""; // ← 正規判斷副檔名
297
297
 
298
- var current = isAbsolute ? path.sep : "";
298
+ var current = isAbsolute ? _path4["default"].sep : "";
299
299
  for (var i = 0; i < parts.length; i++) {
300
- current = _path5["default"].join(current, parts[i]);
300
+ current = _path4["default"].join(current, parts[i]);
301
301
  if (!_fs["default"].existsSync(current)) {
302
302
  if (i === parts.length - 1 && isFile) {
303
303
  // 最後一個而且是檔案 → 建檔案
@@ -310,7 +310,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
310
310
  }
311
311
  }
312
312
  }
313
- return _path5["default"].resolve(targetPath);
313
+ return _path4["default"].resolve(targetPath);
314
314
  }
315
315
 
316
316
  /**
@@ -607,7 +607,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
607
607
  try {
608
608
  var files = _fs["default"].readdirSync(_path);
609
609
  return files.map(function (file) {
610
- return _this3.getPathInfo(_path5["default"].join(_path, file));
610
+ return _this3.getPathInfo(_path4["default"].join(_path, file));
611
611
  });
612
612
  } catch (error) {
613
613
  throw new _index2["default"](8002, error);
@@ -623,7 +623,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
623
623
  key: "copySingleFile",
624
624
  value: function copySingleFile(from, dest, fileName) {
625
625
  var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
626
- var destination = fileName && fileName.trim() ? _path5["default"].join(dest, fileName) : dest;
626
+ var destination = fileName && fileName.trim() ? _path4["default"].join(dest, fileName) : dest;
627
627
  if (_fs["default"].existsSync(destination) && !force) {
628
628
  throw new _index2["default"](8006, destination);
629
629
  }
@@ -632,7 +632,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
632
632
  }, {
633
633
  key: "ensureFolderExists",
634
634
  value: function ensureFolderExists(folderPath) {
635
- var resolved = _path5["default"].resolve(folderPath);
635
+ var resolved = _path4["default"].resolve(folderPath);
636
636
  if (_fs["default"].existsSync(resolved)) return;
637
637
  _fs["default"].mkdirSync(resolved, {
638
638
  recursive: true
@@ -805,14 +805,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
805
805
  /** 6.要產生webstorm run case? */
806
806
  ideaWorkspacePath = "".concat(this.findSpecificFolderByPath(dirPath, ".idea"), "/workspace.xml");
807
807
  /** 7.要產生cd script 腳本 **/
808
- this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path5["default"].resolve(dirPath)));
808
+ this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path4["default"].resolve(dirPath)));
809
809
  if (_fs["default"].existsSync(ideaWorkspacePath)) {
810
810
  workspace = this.getFileContextInRaw(ideaWorkspacePath);
811
811
  splited = workspace.split("\n");
812
812
  indexOfRunManager = _lodash["default"].findIndex(splited, function (line) {
813
813
  return _this5.has(line, 'name="RunManager');
814
814
  });
815
- 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>");
815
+ 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>");
816
816
  indexOfList = _lodash["default"].findIndex(splited, function (line) {
817
817
  return _lodash["default"].isEqual(_lodash["default"].trim(line), "<list>");
818
818
  }, indexOfRunManager);
@@ -822,7 +822,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
822
822
  this.appendError("".concat(ideaWorkspacePath, " not exist"));
823
823
  }
824
824
  _context10.next = 17;
825
- return this.executeCommandLine("cd ".concat(_path5["default"].resolve(dirPath), " && npm install"));
825
+ return this.executeCommandLine("cd ".concat(_path4["default"].resolve(dirPath), " && npm install"));
826
826
  case 17:
827
827
  this.appendInfo("build ".concat(packageName, " succeed!"));
828
828
  case 18:
@@ -878,7 +878,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
878
878
  var newline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
879
879
  var forceDelete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
880
880
  try {
881
- var resolvedPath = _path5["default"].resolve(filePath); // <<--- 正規化路徑
881
+ var resolvedPath = _path4["default"].resolve(filePath); // <<--- 正規化路徑
882
882
  if (forceDelete && _fs["default"].existsSync(resolvedPath)) _fs["default"].unlinkSync(resolvedPath);
883
883
  if (!_fs["default"].existsSync(resolvedPath)) this.persistByPath(resolvedPath);
884
884
  var content = "".concat(newline ? "\n" : "").concat(data);
@@ -912,7 +912,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
912
912
  while (1) switch (_context11.prev = _context11.next) {
913
913
  case 0:
914
914
  ignoreP = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : false;
915
- path = _path5["default"].resolve(path);
915
+ path = _path4["default"].resolve(path);
916
916
  this.appendFile(path, JSON.stringify(object), true, true);
917
917
  if (ignoreP) {
918
918
  _context11.next = 6;
@@ -1028,7 +1028,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1028
1028
  }
1029
1029
 
1030
1030
  // 確保目的路徑存在(遞迴建立)
1031
- this.ensureFolderExists(_path5["default"].dirname(destPath));
1031
+ this.ensureFolderExists(_path4["default"].dirname(destPath));
1032
1032
 
1033
1033
  // 強制複製
1034
1034
  this.copySingleFile(absolute, destPath, undefined, true);
@@ -1121,25 +1121,25 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1121
1121
  case 4:
1122
1122
  tempFolderPath = _context13.sent;
1123
1123
  /** 產生release資料夾 */
1124
- release = _this7.persistByPath(_path5["default"].join(path, "release"));
1124
+ release = _this7.persistByPath(_path4["default"].join(path, "release"));
1125
1125
  /** 利用babel 產生出 es5相容性高的src file */
1126
1126
  _context13.next = 8;
1127
1127
  return _this7.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
1128
1128
  case 8:
1129
- pathOfPackageJson = _path5["default"].join(path, "package.json");
1129
+ pathOfPackageJson = _path4["default"].join(path, "package.json");
1130
1130
  _context13.prev = 9;
1131
1131
  indexFileName = "sample.npm.module.index.js";
1132
1132
  /** 複製公版的index.js */
1133
1133
  _this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
1134
1134
 
1135
1135
  /** template就是樣板的概念 */
1136
- templatePath = _path5["default"].join(path, "template");
1136
+ templatePath = _path4["default"].join(path, "template");
1137
1137
  if (!_this7.isPathExist(templatePath)) {
1138
1138
  _context13.next = 16;
1139
1139
  break;
1140
1140
  }
1141
1141
  _context13.next = 16;
1142
- return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path5["default"].join(release, "template")));
1142
+ return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path4["default"].join(release, "template")));
1143
1143
  case 16:
1144
1144
  if (!deployToNPMServer) {
1145
1145
  _context13.next = 24;
@@ -1155,10 +1155,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1155
1155
  return _this7.updateVersionOfTemplate(moduleName, version);
1156
1156
  case 24:
1157
1157
  /** 把package.json release放進去 */
1158
- _this7.copySingleFile(pathOfPackageJson, _path5["default"].join(release, "package.json"), undefined, true);
1158
+ _this7.copySingleFile(pathOfPackageJson, _path4["default"].join(release, "package.json"), undefined, true);
1159
1159
 
1160
1160
  /** 安裝一個沒有devDependency 的node_module */
1161
- if (!(forceInstallNodeModule || !_this7.isPathExist(_path5["default"].join(release, "node_module")))) {
1161
+ if (!(forceInstallNodeModule || !_this7.isPathExist(_path4["default"].join(release, "node_module")))) {
1162
1162
  _context13.next = 30;
1163
1163
  break;
1164
1164
  }
@@ -1237,7 +1237,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1237
1237
  key: "updateVersionOfTemplate",
1238
1238
  value: (function () {
1239
1239
  var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(dependency, newVersion) {
1240
- var paths, _i, _paths, _path4, succeedOfPersistFile, json;
1240
+ var paths, _i, _paths, path, succeedOfPersistFile, json;
1241
1241
  return _regenerator["default"].wrap(function _callee14$(_context15) {
1242
1242
  while (1) switch (_context15.prev = _context15.next) {
1243
1243
  case 0:
@@ -1248,13 +1248,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1248
1248
  _context15.next = 24;
1249
1249
  break;
1250
1250
  }
1251
- _path4 = _paths[_i];
1252
- if (!this.isPathExist(_path4)) {
1251
+ path = _paths[_i];
1252
+ if (!this.isPathExist(path)) {
1253
1253
  _context15.next = 21;
1254
1254
  break;
1255
1255
  }
1256
1256
  succeedOfPersistFile = false;
1257
- json = this.getJsonObjByFilePath(_path4);
1257
+ json = this.getJsonObjByFilePath(path);
1258
1258
  if (!(json && json.dependencies && json.dependencies[dependency])) {
1259
1259
  _context15.next = 18;
1260
1260
  break;
@@ -1262,7 +1262,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1262
1262
  json.dependencies[dependency] = "^".concat(newVersion);
1263
1263
  _context15.prev = 9;
1264
1264
  _context15.next = 12;
1265
- return this.writeJsonThanPrettier(_path4, json);
1265
+ return this.writeJsonThanPrettier(path, json);
1266
1266
  case 12:
1267
1267
  succeedOfPersistFile = true;
1268
1268
  _context15.next = 18;
@@ -1277,7 +1277,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1277
1277
  break;
1278
1278
  }
1279
1279
  _context15.next = 21;
1280
- return this.updateFileOfSpecificLine(_path4, function (line) {
1280
+ return this.updateFileOfSpecificLine(path, function (line) {
1281
1281
  return " \"".concat(dependency, "\":\"^").concat(newVersion, "\"").concat(_lodash["default"].endsWith(_lodash["default"].trim(line), "," ? "," : ""));
1282
1282
  }, function (each) {
1283
1283
  return _lodash["default"].startsWith(_lodash["default"].trim(each), "\"".concat(dependency, "\""));
@@ -1472,7 +1472,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1472
1472
  case 0:
1473
1473
  width = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : 200;
1474
1474
  _context19.next = 3;
1475
- return this.executeCommandLine("cd ".concat(_path5["default"].resolve("."), " && npx prettier --write ").concat(_path5["default"].resolve(path), " --print-width ").concat(width));
1475
+ return this.executeCommandLine("cd ".concat(_path4["default"].resolve("."), " && npx prettier --write ").concat(_path4["default"].resolve(path), " --print-width ").concat(width));
1476
1476
  case 3:
1477
1477
  case "end":
1478
1478
  return _context19.stop();
@@ -1642,7 +1642,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1642
1642
  var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
1643
1643
  if (_lodash["default"].isEqual(this.getExtensionFromPath(path), "js")) {
1644
1644
  var _source$key;
1645
- var source = require(_path5["default"].resolve(path))["default"];
1645
+ var source = require(_path4["default"].resolve(path))["default"];
1646
1646
  return (_source$key = source[key]) !== null && _source$key !== void 0 ? _source$key : defaultValue;
1647
1647
  } else {
1648
1648
  throw new _index2["default"](8020, "path is not js file, which is ".concat(path));
@@ -1815,8 +1815,8 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1815
1815
  while (1) switch (_context26.prev = _context26.next) {
1816
1816
  case 0:
1817
1817
  this.appendInfo("generateTempFolderWithCleanSrc", basePath);
1818
- sourceFile = _path5["default"].join(basePath, "src");
1819
- tempFolderPath = _path5["default"].join(basePath, "temp");
1818
+ sourceFile = _path4["default"].join(basePath, "src");
1819
+ tempFolderPath = _path4["default"].join(basePath, "temp");
1820
1820
  if (_fs["default"].existsSync(sourceFile)) {
1821
1821
  _context26.next = 5;
1822
1822
  break;
@@ -1857,7 +1857,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1857
1857
 
1858
1858
  // 美化代碼
1859
1859
  _context26.next = 25;
1860
- return this.executeCommandLine("cd ".concat(_path5["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
1860
+ return this.executeCommandLine("cd ".concat(_path4["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
1861
1861
  case 25:
1862
1862
  _context26.next = 13;
1863
1863
  break;
@@ -1924,8 +1924,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1924
1924
  try {
1925
1925
  var firstLine = context.split("\n")[0];
1926
1926
 
1927
- // 偵測形如:const edit = true;
1928
- var match = firstLine.match(/const\s+edit\s*=\s*(true|false)\s*;?/);
1927
+ /**
1928
+ * const\s+:匹配 const 與其後至少一個空白。
1929
+ * ([a-zA-Z_]\w*):匹配合法變數名稱(第一個字為英文字母或底線,其後可為英文字母、數字、底線)。
1930
+ * \s*=\s*:匹配等號兩邊的空白。
1931
+ * (true|false):匹配布林值。
1932
+ * \s*;?:匹配可有可無的分號及其前空白。
1933
+ */
1934
+ var match = firstLine.match(/const\s+([a-zA-Z_]\w*)\s*=\s*(true|false)\s*;?/);
1929
1935
  if (!match) return false;
1930
1936
  var editValue = match[1] === "true";
1931
1937
  if (editValue === true) {
@@ -1959,8 +1965,8 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1959
1965
  }
1960
1966
  var shouldHaveDotSlash = (_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.startsWith("./");
1961
1967
  var cleanArgs = (_args$2 = args[0]) !== null && _args$2 !== void 0 && _args$2.startsWith("./") ? [args[0].slice(2)].concat((0, _toConsumableArray2["default"])(args.slice(1))) : args;
1962
- var joined = _path5["default"].join.apply(_path5["default"], (0, _toConsumableArray2["default"])(cleanArgs));
1963
- return shouldHaveDotSlash && !_path5["default"].isAbsolute(joined) ? "./".concat(joined) : joined;
1968
+ var joined = _path4["default"].join.apply(_path4["default"], (0, _toConsumableArray2["default"])(cleanArgs));
1969
+ return shouldHaveDotSlash && !_path4["default"].isAbsolute(joined) ? "./".concat(joined) : joined;
1964
1970
  }
1965
1971
  }]);
1966
1972
  }(_index["default"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.305",
3
+ "version": "1.0.307",
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.304",
14
+ "utiller": "^1.0.306",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.12",
17
17
  "lodash": "^4.17.20",