utiller 1.0.298 → 1.0.299
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
|
|
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(
|
|
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 =
|
|
122
|
-
var parts = absolute.split(
|
|
121
|
+
var absolute = _path4["default"].resolve(path);
|
|
122
|
+
var parts = absolute.split(_path4["default"].sep);
|
|
123
123
|
while (parts.length) {
|
|
124
|
-
var joined =
|
|
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 =
|
|
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 =
|
|
230
|
-
var ext =
|
|
231
|
-
var newPath =
|
|
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 =
|
|
239
|
+
var absolute = _path4["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
|
|
315
|
+
return _path4["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(
|
|
612
|
+
return _this3.getPathInfo(_path4["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() ?
|
|
628
|
+
var destination = fileName && fileName.trim() ? _path4["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 =
|
|
637
|
+
var resolved = _path4["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(
|
|
810
|
+
this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path4["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(
|
|
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>");
|
|
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(
|
|
827
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].resolve(dirPath), " && npm install"));
|
|
828
828
|
case 17:
|
|
829
829
|
this.appendInfo("build ".concat(packageName, " succeed!"));
|
|
830
830
|
case 18:
|
|
@@ -880,7 +880,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
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
|
-
var resolvedPath =
|
|
883
|
+
var resolvedPath = _path4["default"].resolve(filePath); // <<--- 正規化路徑
|
|
884
884
|
if (forceDelete && _fs["default"].existsSync(resolvedPath)) _fs["default"].unlinkSync(resolvedPath);
|
|
885
885
|
if (!_fs["default"].existsSync(resolvedPath)) this.persistByPath(resolvedPath);
|
|
886
886
|
var content = "".concat(newline ? "\n" : "").concat(data);
|
|
@@ -914,7 +914,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
914
914
|
while (1) switch (_context11.prev = _context11.next) {
|
|
915
915
|
case 0:
|
|
916
916
|
ignoreP = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : false;
|
|
917
|
-
path =
|
|
917
|
+
path = _path4["default"].resolve(path);
|
|
918
918
|
this.appendFile(path, JSON.stringify(object), true, true);
|
|
919
919
|
if (ignoreP) {
|
|
920
920
|
_context11.next = 6;
|
|
@@ -1030,7 +1030,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
1032
|
// 確保目的路徑存在(遞迴建立)
|
|
1033
|
-
this.ensureFolderExists(
|
|
1033
|
+
this.ensureFolderExists(_path4["default"].dirname(destPath));
|
|
1034
1034
|
|
|
1035
1035
|
// 強制複製
|
|
1036
1036
|
this.copySingleFile(absolute, destPath, undefined, true);
|
|
@@ -1123,25 +1123,25 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1123
1123
|
case 4:
|
|
1124
1124
|
tempFolderPath = _context13.sent;
|
|
1125
1125
|
/** 產生release資料夾 */
|
|
1126
|
-
release = _this7.persistByPath(
|
|
1126
|
+
release = _this7.persistByPath(_path4["default"].join(path, "release"));
|
|
1127
1127
|
/** 利用babel 產生出 es5相容性高的src file */
|
|
1128
1128
|
_context13.next = 8;
|
|
1129
1129
|
return _this7.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
|
|
1130
1130
|
case 8:
|
|
1131
|
-
pathOfPackageJson =
|
|
1131
|
+
pathOfPackageJson = _path4["default"].join(path, "package.json");
|
|
1132
1132
|
_context13.prev = 9;
|
|
1133
1133
|
indexFileName = "sample.npm.module.index.js";
|
|
1134
1134
|
/** 複製公版的index.js */
|
|
1135
1135
|
_this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
|
|
1136
1136
|
|
|
1137
1137
|
/** template就是樣板的概念 */
|
|
1138
|
-
templatePath =
|
|
1138
|
+
templatePath = _path4["default"].join(path, "template");
|
|
1139
1139
|
if (!_this7.isPathExist(templatePath)) {
|
|
1140
1140
|
_context13.next = 16;
|
|
1141
1141
|
break;
|
|
1142
1142
|
}
|
|
1143
1143
|
_context13.next = 16;
|
|
1144
|
-
return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(
|
|
1144
|
+
return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path4["default"].join(release, "template")));
|
|
1145
1145
|
case 16:
|
|
1146
1146
|
if (!deployToNPMServer) {
|
|
1147
1147
|
_context13.next = 24;
|
|
@@ -1157,10 +1157,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1157
1157
|
return _this7.updateVersionOfTemplate(moduleName, version);
|
|
1158
1158
|
case 24:
|
|
1159
1159
|
/** 把package.json release放進去 */
|
|
1160
|
-
_this7.copySingleFile(pathOfPackageJson,
|
|
1160
|
+
_this7.copySingleFile(pathOfPackageJson, _path4["default"].join(release, "package.json"), undefined, true);
|
|
1161
1161
|
|
|
1162
1162
|
/** 安裝一個沒有devDependency 的node_module */
|
|
1163
|
-
if (!(forceInstallNodeModule || !_this7.isPathExist(
|
|
1163
|
+
if (!(forceInstallNodeModule || !_this7.isPathExist(_path4["default"].join(release, "node_module")))) {
|
|
1164
1164
|
_context13.next = 30;
|
|
1165
1165
|
break;
|
|
1166
1166
|
}
|
|
@@ -1239,7 +1239,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1239
1239
|
key: "updateVersionOfTemplate",
|
|
1240
1240
|
value: (function () {
|
|
1241
1241
|
var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(dependency, newVersion) {
|
|
1242
|
-
var paths, _i, _paths,
|
|
1242
|
+
var paths, _i, _paths, path, succeedOfPersistFile, json;
|
|
1243
1243
|
return _regenerator["default"].wrap(function _callee14$(_context15) {
|
|
1244
1244
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1245
1245
|
case 0:
|
|
@@ -1250,13 +1250,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1250
1250
|
_context15.next = 24;
|
|
1251
1251
|
break;
|
|
1252
1252
|
}
|
|
1253
|
-
|
|
1254
|
-
if (!this.isPathExist(
|
|
1253
|
+
path = _paths[_i];
|
|
1254
|
+
if (!this.isPathExist(path)) {
|
|
1255
1255
|
_context15.next = 21;
|
|
1256
1256
|
break;
|
|
1257
1257
|
}
|
|
1258
1258
|
succeedOfPersistFile = false;
|
|
1259
|
-
json = this.getJsonObjByFilePath(
|
|
1259
|
+
json = this.getJsonObjByFilePath(path);
|
|
1260
1260
|
if (!(json && json.dependencies && json.dependencies[dependency])) {
|
|
1261
1261
|
_context15.next = 18;
|
|
1262
1262
|
break;
|
|
@@ -1264,7 +1264,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1264
1264
|
json.dependencies[dependency] = "^".concat(newVersion);
|
|
1265
1265
|
_context15.prev = 9;
|
|
1266
1266
|
_context15.next = 12;
|
|
1267
|
-
return this.writeJsonThanPrettier(
|
|
1267
|
+
return this.writeJsonThanPrettier(path, json);
|
|
1268
1268
|
case 12:
|
|
1269
1269
|
succeedOfPersistFile = true;
|
|
1270
1270
|
_context15.next = 18;
|
|
@@ -1279,7 +1279,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1279
1279
|
break;
|
|
1280
1280
|
}
|
|
1281
1281
|
_context15.next = 21;
|
|
1282
|
-
return this.updateFileOfSpecificLine(
|
|
1282
|
+
return this.updateFileOfSpecificLine(path, function (line) {
|
|
1283
1283
|
return " \"".concat(dependency, "\":\"^").concat(newVersion, "\"").concat(_lodash["default"].endsWith(_lodash["default"].trim(line), "," ? "," : ""));
|
|
1284
1284
|
}, function (each) {
|
|
1285
1285
|
return _lodash["default"].startsWith(_lodash["default"].trim(each), "\"".concat(dependency, "\""));
|
|
@@ -1474,7 +1474,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1474
1474
|
case 0:
|
|
1475
1475
|
width = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : 200;
|
|
1476
1476
|
_context19.next = 3;
|
|
1477
|
-
return this.executeCommandLine("cd ".concat(
|
|
1477
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].resolve("."), " && npx prettier --write ").concat(_path4["default"].resolve(path), " --print-width ").concat(width));
|
|
1478
1478
|
case 3:
|
|
1479
1479
|
case "end":
|
|
1480
1480
|
return _context19.stop();
|
|
@@ -1644,7 +1644,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1644
1644
|
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
1645
1645
|
if (_lodash["default"].isEqual(this.getExtensionFromPath(path), "js")) {
|
|
1646
1646
|
var _source$key;
|
|
1647
|
-
var source = require(
|
|
1647
|
+
var source = require(_path4["default"].resolve(path))["default"];
|
|
1648
1648
|
return (_source$key = source[key]) !== null && _source$key !== void 0 ? _source$key : defaultValue;
|
|
1649
1649
|
} else {
|
|
1650
1650
|
throw new _index2["default"](8020, "path is not js file, which is ".concat(path));
|
|
@@ -1817,8 +1817,8 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1817
1817
|
while (1) switch (_context26.prev = _context26.next) {
|
|
1818
1818
|
case 0:
|
|
1819
1819
|
this.appendInfo("generateTempFolderWithCleanSrc", basePath);
|
|
1820
|
-
sourceFile =
|
|
1821
|
-
tempFolderPath =
|
|
1820
|
+
sourceFile = _path4["default"].join(basePath, "src");
|
|
1821
|
+
tempFolderPath = _path4["default"].join(basePath, "temp");
|
|
1822
1822
|
if (_fs["default"].existsSync(sourceFile)) {
|
|
1823
1823
|
_context26.next = 5;
|
|
1824
1824
|
break;
|
|
@@ -1859,7 +1859,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1859
1859
|
|
|
1860
1860
|
// 美化代碼
|
|
1861
1861
|
_context26.next = 25;
|
|
1862
|
-
return this.executeCommandLine("cd ".concat(
|
|
1862
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
|
|
1863
1863
|
case 25:
|
|
1864
1864
|
_context26.next = 13;
|
|
1865
1865
|
break;
|
package/package.json
CHANGED