utiller 1.0.385 → 1.0.387

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.
@@ -58,27 +58,43 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
58
58
  return reg.test(item.fileNameExtension);
59
59
  }].concat(exclude));
60
60
  });
61
+ // 💡 調整函式簽名以接收可選的執行路徑 (path/cwd)
61
62
  (0, _defineProperty2["default"])(_this, "executeCommandLine", /*#__PURE__*/function () {
62
63
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(command) {
63
- var self;
64
+ var executionPath,
65
+ self,
66
+ _args = arguments;
64
67
  return _regenerator["default"].wrap(function _callee$(_context) {
65
68
  while (1) switch (_context.prev = _context.next) {
66
69
  case 0:
67
- self = _this;
68
- _this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
70
+ executionPath = _args.length > 1 && _args[1] !== undefined ? _args[1] : process.cwd();
71
+ self = _this; // 輸出時顯示執行的目錄,增加可讀性
72
+ _this.appendInfo("\u57F7\u884C\u8173\u672C: ".concat(command));
73
+ _this.appendInfo("\u57F7\u884C\u8DEF\u5F91: ".concat(executionPath));
69
74
  return _context.abrupt("return", new Promise(function (resolve, reject) {
70
- _child_process["default"].exec(command, function (error, stdout, stderr) {
75
+ // 核心改動:將執行路徑作為 options 物件的 cwd 屬性傳遞
76
+ _child_process["default"].exec(command, {
77
+ cwd: executionPath
78
+ },
79
+ // ⬅️ 新增的 options 物件,指定 cwd
80
+ function (error, stdout, stderr) {
71
81
  self.appendInfo("".concat(stdout));
72
82
  self.appendInfo("".concat(stderr));
73
83
  if (error) {
74
84
  self.appendError("\u57F7\u884C\u932F\u8AA4: ".concat(error));
75
- reject(error);
85
+
86
+ // 🚨 重要的錯誤處理:將 stderr 包含在拒絕訊息中,便於除錯
87
+ var fullError = new Error("Command failed: ".concat(error.message));
88
+ fullError.code = error.code;
89
+ fullError.stdout = stdout;
90
+ fullError.stderr = stderr;
91
+ reject(fullError);
76
92
  return;
77
93
  }
78
94
  resolve(stdout.trim());
79
95
  });
80
96
  }));
81
- case 3:
97
+ case 5:
82
98
  case "end":
83
99
  return _context.stop();
84
100
  }
@@ -1108,7 +1124,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1108
1124
  _iterator7 = _createForOfIteratorHelper(packagejsons);
1109
1125
  _context14.prev = 8;
1110
1126
  _loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
1111
- var path, tempFolderPath, release, localBabelPath, pathOfPackageJson, indexFileName, templatePath, _yield$_this7$upgrade, moduleName, version;
1127
+ var path, tempFolderPath, release, pathOfPackageJson, indexFileName, templatePath, _yield$_this7$upgrade, moduleName, version;
1112
1128
  return _regenerator["default"].wrap(function _loop$(_context13) {
1113
1129
  while (1) switch (_context13.prev = _context13.next) {
1114
1130
  case 0:
@@ -1118,7 +1134,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1118
1134
  return !_this7.has(path, projectName);
1119
1135
  };
1120
1136
  })))) {
1121
- _context13.next = 47;
1137
+ _context13.next = 46;
1122
1138
  break;
1123
1139
  }
1124
1140
  _context13.next = 4;
@@ -1128,12 +1144,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1128
1144
  /** 產生release資料夾 */
1129
1145
  release = _this7.persistByPath(_path4["default"].join(path, "release"));
1130
1146
  /** 利用babel 產生出 es5相容性高的src file */
1131
- localBabelPath = "".concat(path, "/node_modules/.bin/babel");
1132
- _context13.next = 9;
1133
- return _this7.executeCommandLine("cd ".concat(path, " && ").concat(localBabelPath, " ./temp --out-dir ./release/lib"));
1134
- case 9:
1147
+ _context13.next = 8;
1148
+ return _this7.executeCommandLine("npx babel ./temp --out-dir ./release/lib", path);
1149
+ case 8:
1135
1150
  pathOfPackageJson = _path4["default"].join(path, "package.json");
1136
- _context13.prev = 10;
1151
+ _context13.prev = 9;
1137
1152
  indexFileName = "sample.npm.module.index.js";
1138
1153
  /** 複製公版的index.js */
1139
1154
  _this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
@@ -1141,71 +1156,71 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
1141
1156
  /** template就是樣板的概念 */
1142
1157
  templatePath = _path4["default"].join(path, "template");
1143
1158
  if (!_this7.isPathExist(templatePath)) {
1144
- _context13.next = 17;
1159
+ _context13.next = 16;
1145
1160
  break;
1146
1161
  }
1147
- _context13.next = 17;
1162
+ _context13.next = 16;
1148
1163
  return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path4["default"].join(release, "template")));
1149
- case 17:
1164
+ case 16:
1150
1165
  if (!deployToNPMServer) {
1151
- _context13.next = 25;
1166
+ _context13.next = 24;
1152
1167
  break;
1153
1168
  }
1154
- _context13.next = 20;
1169
+ _context13.next = 19;
1155
1170
  return _this7.upgradePackageJsonVersion(pathOfPackageJson);
1156
- case 20:
1171
+ case 19:
1157
1172
  _yield$_this7$upgrade = _context13.sent;
1158
1173
  moduleName = _yield$_this7$upgrade.moduleName;
1159
1174
  version = _yield$_this7$upgrade.version;
1160
- _context13.next = 25;
1175
+ _context13.next = 24;
1161
1176
  return _this7.updateVersionOfTemplate(moduleName, version);
1162
- case 25:
1177
+ case 24:
1163
1178
  /** 把package.json release放進去 */
1164
1179
  _this7.copySingleFile(pathOfPackageJson, _path4["default"].join(release, "package.json"), undefined, true);
1165
1180
 
1166
1181
  /** 安裝一個沒有devDependency 的node_module */
1167
1182
  if (!(forceInstallNodeModule || !_this7.isPathExist(_path4["default"].join(release, "node_module")))) {
1168
- _context13.next = 31;
1183
+ _context13.next = 30;
1169
1184
  break;
1170
1185
  }
1171
- _context13.next = 29;
1186
+ _context13.next = 28;
1172
1187
  return _this7.executeCommandLine("cd ".concat(release, " && yarn install --production"));
1173
- case 29:
1174
- _context13.next = 32;
1188
+ case 28:
1189
+ _context13.next = 31;
1175
1190
  break;
1176
- case 31:
1191
+ case 30:
1177
1192
  _this7.appendInfo("ignore node-module install behavior");
1178
- case 32:
1193
+ case 31:
1179
1194
  _this7.appendInfo("build ".concat(path, " succeed"));
1180
1195
 
1181
1196
  /** 部署到 local server*/
1182
1197
  if (!deployToNPMServer) {
1183
- _context13.next = 36;
1198
+ _context13.next = 35;
1184
1199
  break;
1185
1200
  }
1186
- _context13.next = 36;
1201
+ _context13.next = 35;
1187
1202
  return _this7.executeCommandLine("cd ".concat(release, " && npm publish"));
1188
- case 36:
1189
- _context13.next = 43;
1190
- break;
1191
- case 38:
1192
- _context13.prev = 38;
1193
- _context13.t0 = _context13["catch"](10);
1203
+ case 35:
1194
1204
  _context13.next = 42;
1205
+ break;
1206
+ case 37:
1207
+ _context13.prev = 37;
1208
+ _context13.t0 = _context13["catch"](9);
1209
+ _context13.next = 41;
1195
1210
  return _this7.deleteSelfByPath(release, true);
1196
- case 42:
1211
+ case 41:
1197
1212
  throw new _index2["default"](9999, "generatePackage \u5831\u932F, ".concat(_context13.t0.message));
1198
- case 43:
1199
- _context13.prev = 43;
1200
- _context13.next = 46;
1213
+ case 42:
1214
+ _context13.prev = 42;
1215
+ _context13.next = 45;
1201
1216
  return _this7.deleteSelfByPath(tempFolderPath, true);
1217
+ case 45:
1218
+ return _context13.finish(42);
1202
1219
  case 46:
1203
- return _context13.finish(43);
1204
- case 47:
1205
1220
  case "end":
1206
1221
  return _context13.stop();
1207
1222
  }
1208
- }, _loop, null, [[10, 38, 43, 47]]);
1223
+ }, _loop, null, [[9, 37, 42, 46]]);
1209
1224
  });
1210
1225
  _iterator7.s();
1211
1226
  case 11:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.385",
3
+ "version": "1.0.387",
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.23",
14
- "utiller": "^1.0.384",
14
+ "utiller": "^1.0.386",
15
15
  "linepayer": "^1.0.15",
16
16
  "databazer": "^1.0.17",
17
17
  "lodash": "^4.17.20",