utiller 1.0.285 → 1.0.287
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.
- package/lib/utiller/nodeutiller.js +667 -662
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -16,21 +15,18 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
|
|
|
16
15
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
16
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
18
17
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
-
var
|
|
18
|
+
var _path4 = _interopRequireDefault(require("path"));
|
|
20
19
|
var _fs = _interopRequireDefault(require("fs"));
|
|
21
20
|
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
21
|
+
var _child_process = require("child_process");
|
|
22
22
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
23
|
-
var _child_process = _interopRequireDefault(require("child_process"));
|
|
24
|
-
var _configerer = require("configerer");
|
|
25
|
-
var _index = _interopRequireDefault(require("./index"));
|
|
26
|
-
var _index2 = _interopRequireDefault(require("../exceptioner/index"));
|
|
27
|
-
var _pdfParse = _interopRequireDefault(require("pdf-parse"));
|
|
28
|
-
var _del = _interopRequireWildcard(require("del"));
|
|
29
23
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
24
|
+
var _del = _interopRequireDefault(require("del"));
|
|
25
|
+
var _pdfParse = _interopRequireDefault(require("pdf-parse"));
|
|
30
26
|
var _prompt = _interopRequireDefault(require("prompt"));
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
var _configerer = require("configerer");
|
|
28
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
29
|
+
var _index2 = _interopRequireDefault(require("../exceptioner/index.js"));
|
|
34
30
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
35
31
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
36
32
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -47,98 +43,18 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
47
43
|
/**================================= only in node.js ================================= */
|
|
48
44
|
/** 是否把log message 存到 info.txt*/
|
|
49
45
|
(0, _defineProperty2["default"])(_this, "isPersistIntoLogFile", true);
|
|
50
|
-
/**
|
|
51
|
-
* 遞回的去找出folder每一個child file, 預設是全部檔案, 可以透過predicate做filter, 可以exclude 指定的 'folder name'
|
|
52
|
-
*
|
|
53
|
-
* predicate: predicate(pathInfo); predicate帶的參數是 pathInfo object
|
|
54
|
-
*
|
|
55
|
-
* excludes 忽略掉的資料夾名稱
|
|
56
|
-
*
|
|
57
|
-
* return [...{
|
|
58
|
-
path: 'database/index.js',
|
|
59
|
-
fileName: 'index',
|
|
60
|
-
extension: 'js',
|
|
61
|
-
dirName: database
|
|
62
|
-
absolute: '/Users/davidtu/cross-achieve/mimi19up/mimi19up-scrapy/database/index.js'}
|
|
63
|
-
] */
|
|
64
|
-
(0, _defineProperty2["default"])(_this, "findFilePathBy", function (path) {
|
|
65
|
-
var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (each) {
|
|
66
|
-
return true;
|
|
67
|
-
};
|
|
68
|
-
if (!_fs["default"].existsSync(path)) return [];
|
|
69
|
-
var list = _fs["default"].readdirSync(path);
|
|
70
|
-
var files = [];
|
|
71
|
-
for (var _len2 = arguments.length, excludes = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
72
|
-
excludes[_key2 - 2] = arguments[_key2];
|
|
73
|
-
}
|
|
74
|
-
var _iterator = _createForOfIteratorHelper(list),
|
|
75
|
-
_step;
|
|
76
|
-
try {
|
|
77
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
78
|
-
var item = _step.value;
|
|
79
|
-
if (_lodash["default"].includes(excludes, item)) continue;
|
|
80
|
-
var currentpath = _path5["default"].join(path, item);
|
|
81
|
-
if (_fs["default"].lstatSync(currentpath).isDirectory()) {
|
|
82
|
-
var _this2;
|
|
83
|
-
files.push.apply(files, (0, _toConsumableArray2["default"])((_this2 = _this).findFilePathBy.apply(_this2, [currentpath, predicate].concat(excludes))));
|
|
84
|
-
} else if (_fs["default"].lstatSync(currentpath).isFile()) {
|
|
85
|
-
var pathInfo = _this.getPathInfo(currentpath);
|
|
86
|
-
if (predicate(pathInfo)) {
|
|
87
|
-
files.push(pathInfo);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
throw new _index2["default"](8003, item, currentpath);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
_iterator.e(err);
|
|
95
|
-
} finally {
|
|
96
|
-
_iterator.f();
|
|
97
|
-
}
|
|
98
|
-
return files;
|
|
99
|
-
});
|
|
100
46
|
/** return [...{path: ,fileName: ,extension: ,absolute: ,dirName:}]*/
|
|
101
47
|
(0, _defineProperty2["default"])(_this, "findFilePathByExtension", function (rootpath) {
|
|
102
|
-
var
|
|
48
|
+
var _this2;
|
|
103
49
|
var _extension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
104
50
|
var reg = new RegExp("^[^.].+.(".concat(_lodash["default"].join(_extension, "|"), ")$"));
|
|
105
|
-
for (var
|
|
106
|
-
exclude[
|
|
51
|
+
for (var _len2 = arguments.length, exclude = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
52
|
+
exclude[_key2 - 2] = arguments[_key2];
|
|
107
53
|
}
|
|
108
|
-
return (
|
|
54
|
+
return (_this2 = _this).findFilePathBy.apply(_this2, [rootpath, function (item) {
|
|
109
55
|
return reg.test(item.fileNameExtension);
|
|
110
56
|
}].concat(exclude));
|
|
111
57
|
});
|
|
112
|
-
(0, _defineProperty2["default"])(_this, "executeCommandLine", /*#__PURE__*/function () {
|
|
113
|
-
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(command) {
|
|
114
|
-
var self;
|
|
115
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
116
|
-
while (1) switch (_context.prev = _context.next) {
|
|
117
|
-
case 0:
|
|
118
|
-
self = _this;
|
|
119
|
-
_this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
|
|
120
|
-
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
121
|
-
_child_process["default"].exec(command, function (error, stdout, stderr) {
|
|
122
|
-
self.appendInfo("".concat(stdout));
|
|
123
|
-
self.appendInfo("".concat(stderr));
|
|
124
|
-
if (error) {
|
|
125
|
-
self.appendError("\u57F7\u884C\u932F\u8AA4: ".concat(error));
|
|
126
|
-
reject(error);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
resolve(stdout.trim());
|
|
130
|
-
});
|
|
131
|
-
}));
|
|
132
|
-
case 3:
|
|
133
|
-
case "end":
|
|
134
|
-
return _context.stop();
|
|
135
|
-
}
|
|
136
|
-
}, _callee);
|
|
137
|
-
}));
|
|
138
|
-
return function (_x) {
|
|
139
|
-
return _ref.apply(this, arguments);
|
|
140
|
-
};
|
|
141
|
-
}());
|
|
142
58
|
/**
|
|
143
59
|
* 從絕對路徑中取出 "src/" 之後的部分(包含前置 /)
|
|
144
60
|
* @param {string} fullPath - 完整的絕對檔案路徑
|
|
@@ -147,7 +63,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
147
63
|
*/
|
|
148
64
|
(0, _defineProperty2["default"])(_this, "getPathAfterSpecificFolder", function (fullPath) {
|
|
149
65
|
var folder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "src";
|
|
150
|
-
var parts = _lodash["default"].split(fullPath,
|
|
66
|
+
var parts = _lodash["default"].split(fullPath, _path4["default"].sep);
|
|
151
67
|
var indexOfSrc = _lodash["default"].findLastIndex(parts, function (part) {
|
|
152
68
|
return part === folder;
|
|
153
69
|
});
|
|
@@ -170,34 +86,37 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
170
86
|
return (0, _createClass2["default"])(NodeUtiller, [{
|
|
171
87
|
key: "findSpecificFolderByPath",
|
|
172
88
|
value: function findSpecificFolderByPath(path, folderName) {
|
|
173
|
-
var absolute =
|
|
174
|
-
var
|
|
175
|
-
while (
|
|
176
|
-
|
|
89
|
+
var absolute = _path4["default"].resolve(path);
|
|
90
|
+
var parts = absolute.split(_path4["default"].sep);
|
|
91
|
+
while (parts.length) {
|
|
92
|
+
var joined = _path4["default"].join.apply(_path4["default"], (0, _toConsumableArray2["default"])(parts).concat([folderName]));
|
|
93
|
+
if (_fs["default"].existsSync(joined)) return joined;
|
|
94
|
+
parts.pop();
|
|
177
95
|
}
|
|
178
|
-
return
|
|
96
|
+
return null;
|
|
179
97
|
}
|
|
180
98
|
|
|
181
99
|
/** {numpages, numrender, info, text, version} */
|
|
182
100
|
}, {
|
|
183
101
|
key: "getPDFText",
|
|
184
102
|
value: (function () {
|
|
185
|
-
var _getPDFText = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
186
|
-
var
|
|
187
|
-
return _regenerator["default"].wrap(function
|
|
188
|
-
while (1) switch (
|
|
103
|
+
var _getPDFText = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(path) {
|
|
104
|
+
var buffer;
|
|
105
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
106
|
+
while (1) switch (_context.prev = _context.next) {
|
|
189
107
|
case 0:
|
|
190
|
-
|
|
191
|
-
return
|
|
192
|
-
return data;
|
|
193
|
-
}));
|
|
108
|
+
_context.next = 2;
|
|
109
|
+
return _promises["default"].readFile(path);
|
|
194
110
|
case 2:
|
|
111
|
+
buffer = _context.sent;
|
|
112
|
+
return _context.abrupt("return", (0, _pdfParse["default"])(buffer));
|
|
113
|
+
case 4:
|
|
195
114
|
case "end":
|
|
196
|
-
return
|
|
115
|
+
return _context.stop();
|
|
197
116
|
}
|
|
198
|
-
},
|
|
117
|
+
}, _callee);
|
|
199
118
|
}));
|
|
200
|
-
function getPDFText(
|
|
119
|
+
function getPDFText(_x) {
|
|
201
120
|
return _getPDFText.apply(this, arguments);
|
|
202
121
|
}
|
|
203
122
|
return getPDFText;
|
|
@@ -207,10 +126,61 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
207
126
|
value: function printf() {
|
|
208
127
|
this.appendInfo("i can use in node.js only yo yo");
|
|
209
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 遞回的去找出folder每一個child file, 預設是全部檔案, 可以透過predicate做filter, 可以exclude 指定的 'folder name'
|
|
132
|
+
*
|
|
133
|
+
* predicate: predicate(pathInfo); predicate帶的參數是 pathInfo object
|
|
134
|
+
*
|
|
135
|
+
* excludes 忽略掉的資料夾名稱
|
|
136
|
+
*
|
|
137
|
+
* return [...{
|
|
138
|
+
path: 'database/index.js',
|
|
139
|
+
fileName: 'index',
|
|
140
|
+
extension: 'js',
|
|
141
|
+
dirName: database
|
|
142
|
+
absolute: '/Users/davidtu/cross-achieve/mimi19up/mimi19up-scrapy/database/index.js'}
|
|
143
|
+
] */
|
|
144
|
+
}, {
|
|
145
|
+
key: "findFilePathBy",
|
|
146
|
+
value: function findFilePathBy(path) {
|
|
147
|
+
var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
if (!_fs["default"].existsSync(path)) return [];
|
|
151
|
+
var result = [];
|
|
152
|
+
var entries = _fs["default"].readdirSync(path, {
|
|
153
|
+
withFileTypes: true
|
|
154
|
+
});
|
|
155
|
+
for (var _len3 = arguments.length, excludes = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
156
|
+
excludes[_key3 - 2] = arguments[_key3];
|
|
157
|
+
}
|
|
158
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
159
|
+
_step;
|
|
160
|
+
try {
|
|
161
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
162
|
+
var entry = _step.value;
|
|
163
|
+
if (excludes.includes(entry.name)) continue;
|
|
164
|
+
var fullPath = _path4["default"].join(path, entry.name);
|
|
165
|
+
if (entry.isDirectory()) {
|
|
166
|
+
result.push.apply(result, (0, _toConsumableArray2["default"])(this.findFilePathBy.apply(this, [fullPath, predicate].concat(excludes))));
|
|
167
|
+
} else if (entry.isFile()) {
|
|
168
|
+
var info = this.getPathInfo(fullPath);
|
|
169
|
+
if (predicate(info)) result.push(info);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
_iterator.e(err);
|
|
174
|
+
} finally {
|
|
175
|
+
_iterator.f();
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** 是一個存在的檔案 */
|
|
210
181
|
}, {
|
|
211
182
|
key: "isPathExist",
|
|
212
|
-
value:
|
|
213
|
-
function isPathExist(path) {
|
|
183
|
+
value: function isPathExist(path) {
|
|
214
184
|
return _fs["default"].existsSync(path);
|
|
215
185
|
}
|
|
216
186
|
|
|
@@ -221,65 +191,43 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
221
191
|
key: "renameFile",
|
|
222
192
|
value: function renameFile(path) {
|
|
223
193
|
var newName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fileName";
|
|
224
|
-
if (!this.
|
|
225
|
-
this.appendError("
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (_lodash["default"].isEmpty(newName)) {
|
|
229
|
-
this.appendError("984522,new name is empty");
|
|
194
|
+
if (!this.isFile(path) || !newName) {
|
|
195
|
+
this.appendError("renameFile \u932F\u8AA4, path: ".concat(path, ", newName: ").concat(newName));
|
|
230
196
|
return;
|
|
231
197
|
}
|
|
232
|
-
var
|
|
233
|
-
|
|
198
|
+
var dir = _path4["default"].dirname(path);
|
|
199
|
+
var ext = _path4["default"].extname(path);
|
|
200
|
+
var newPath = _path4["default"].join(dir, "".concat(newName).concat(ext));
|
|
201
|
+
_fs["default"].renameSync(path, newPath);
|
|
234
202
|
}
|
|
235
|
-
|
|
236
|
-
//todo 應該要改成class
|
|
237
203
|
}, {
|
|
238
204
|
key: "getPathInfo",
|
|
239
205
|
value: function getPathInfo(path) {
|
|
240
|
-
var absolute =
|
|
241
|
-
var
|
|
206
|
+
var absolute = _path4["default"].resolve(path);
|
|
207
|
+
var stat = _fs["default"].statSync(absolute);
|
|
208
|
+
var parsed = _path4["default"].parse(absolute);
|
|
209
|
+
return {
|
|
242
210
|
path: path,
|
|
243
211
|
absolute: absolute,
|
|
244
|
-
isFile:
|
|
245
|
-
isDirectory:
|
|
246
|
-
dirName:
|
|
247
|
-
folderName:
|
|
248
|
-
dirPath:
|
|
249
|
-
folderPath:
|
|
250
|
-
extension:
|
|
251
|
-
fileName:
|
|
252
|
-
fileNameExtension:
|
|
253
|
-
lastModifiedTime:
|
|
254
|
-
name:
|
|
212
|
+
isFile: stat.isFile(),
|
|
213
|
+
isDirectory: stat.isDirectory(),
|
|
214
|
+
dirName: parsed.dir.split(_path4["default"].sep).pop(),
|
|
215
|
+
folderName: parsed.dir.split(_path4["default"].sep).pop(),
|
|
216
|
+
dirPath: parsed.dir,
|
|
217
|
+
folderPath: parsed.dir,
|
|
218
|
+
extension: parsed.ext.slice(1),
|
|
219
|
+
fileName: parsed.name,
|
|
220
|
+
fileNameExtension: parsed.base,
|
|
221
|
+
lastModifiedTime: stat.mtimeMs,
|
|
222
|
+
name: parsed.name
|
|
255
223
|
};
|
|
256
|
-
if (this.isFile(absolute)) {
|
|
257
|
-
obj["extension"] = absolute.split(".").pop();
|
|
258
|
-
var fileNameStrings = absolute.split("/").pop().split(".");
|
|
259
|
-
fileNameStrings.pop();
|
|
260
|
-
/** todo 要是遇到 asd.sdsd.js 就麻煩了 */
|
|
261
|
-
obj["fileName"] = fileNameStrings.join(".");
|
|
262
|
-
obj["name"] = fileNameStrings.join(".");
|
|
263
|
-
obj["dirName"] = _lodash["default"].nth(absolute.split("/"), -2);
|
|
264
|
-
obj["folderName"] = _lodash["default"].nth(absolute.split("/"), -2);
|
|
265
|
-
obj["isFile"] = true;
|
|
266
|
-
obj["dirPath"] = this.getFolderPathOfSpecificPath(absolute);
|
|
267
|
-
obj["folderPath"] = this.getFolderPathOfSpecificPath(absolute);
|
|
268
|
-
obj["isDirectory"] = false;
|
|
269
|
-
obj["fileNameExtension"] = "".concat(obj.fileName, ".").concat(obj.extension);
|
|
270
|
-
obj["lastModifiedTime"] = this.getFileLastModifiedTime(absolute);
|
|
271
|
-
}
|
|
272
|
-
if (this.isDirectory(absolute)) {
|
|
273
|
-
obj["dirName"] = absolute.split("/").pop();
|
|
274
|
-
}
|
|
275
|
-
return obj;
|
|
276
224
|
}
|
|
277
225
|
}, {
|
|
278
226
|
key: "syncExecuteCommandLine",
|
|
279
227
|
value: function syncExecuteCommandLine(command) {
|
|
280
228
|
var self = this;
|
|
281
229
|
this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
|
|
282
|
-
_child_process
|
|
230
|
+
(0, _child_process.exec)("".concat(command), function (error, stdout, stderr) {
|
|
283
231
|
self.appendInfo("".concat(stdout));
|
|
284
232
|
self.appendInfo("".concat(stderr));
|
|
285
233
|
if (error !== null) {
|
|
@@ -287,30 +235,61 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
287
235
|
}
|
|
288
236
|
});
|
|
289
237
|
}
|
|
238
|
+
}, {
|
|
239
|
+
key: "executeCommandLine",
|
|
240
|
+
value: function () {
|
|
241
|
+
var _executeCommandLine = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(command) {
|
|
242
|
+
var _this3 = this;
|
|
243
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
244
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
245
|
+
case 0:
|
|
246
|
+
this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
|
|
247
|
+
return _context2.abrupt("return", new Promise(function (resolve, reject) {
|
|
248
|
+
(0, _child_process.exec)(command, function (error, stdout, stderr) {
|
|
249
|
+
_this3.appendInfo(stdout);
|
|
250
|
+
_this3.appendInfo(stderr);
|
|
251
|
+
if (error) {
|
|
252
|
+
_this3.appendError("\u932F\u8AA4\uFF1A".concat(error));
|
|
253
|
+
reject(error);
|
|
254
|
+
} else {
|
|
255
|
+
resolve(stdout.trim());
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}));
|
|
259
|
+
case 2:
|
|
260
|
+
case "end":
|
|
261
|
+
return _context2.stop();
|
|
262
|
+
}
|
|
263
|
+
}, _callee2, this);
|
|
264
|
+
}));
|
|
265
|
+
function executeCommandLine(_x2) {
|
|
266
|
+
return _executeCommandLine.apply(this, arguments);
|
|
267
|
+
}
|
|
268
|
+
return executeCommandLine;
|
|
269
|
+
}() /** '/a/b/c.js' 把它變成真的 */
|
|
290
270
|
}, {
|
|
291
271
|
key: "persistByPath",
|
|
292
|
-
value:
|
|
293
|
-
|
|
294
|
-
var
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (!_fs["default"].existsSync(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
} else {
|
|
306
|
-
_fs["default"].mkdirSync(currentPath);
|
|
307
|
-
}
|
|
272
|
+
value: function persistByPath(path) {
|
|
273
|
+
var parts = path.split("/");
|
|
274
|
+
var current = "";
|
|
275
|
+
var _iterator2 = _createForOfIteratorHelper(parts),
|
|
276
|
+
_step2;
|
|
277
|
+
try {
|
|
278
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
279
|
+
var part = _step2.value;
|
|
280
|
+
if (!part) continue;
|
|
281
|
+
current += "/".concat(part);
|
|
282
|
+
if (!_fs["default"].existsSync(current)) {
|
|
283
|
+
var hasExt = part.includes(".");
|
|
284
|
+
hasExt ? _fs["default"].writeFileSync(current, "") : _fs["default"].mkdirSync(current);
|
|
308
285
|
}
|
|
309
|
-
} catch (error) {
|
|
310
|
-
throw new _index2["default"](8008, "currentPath => ".concat(currentPath), error);
|
|
311
286
|
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
_iterator2.e(err);
|
|
289
|
+
} finally {
|
|
290
|
+
_iterator2.f();
|
|
312
291
|
}
|
|
313
|
-
return
|
|
292
|
+
return _path4["default"].resolve(path);
|
|
314
293
|
}
|
|
315
294
|
|
|
316
295
|
/**
|
|
@@ -320,30 +299,51 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
320
299
|
* */
|
|
321
300
|
}, {
|
|
322
301
|
key: "copyFromFolderToDestFolder",
|
|
323
|
-
value: function
|
|
324
|
-
var
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
302
|
+
value: (function () {
|
|
303
|
+
var _copyFromFolderToDestFolder = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(from, dest) {
|
|
304
|
+
var override,
|
|
305
|
+
preserveTimestamps,
|
|
306
|
+
filter,
|
|
307
|
+
_args3 = arguments;
|
|
308
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
309
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
310
|
+
case 0:
|
|
311
|
+
override = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : true;
|
|
312
|
+
preserveTimestamps = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : false;
|
|
313
|
+
filter = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : function () {
|
|
314
|
+
return true;
|
|
315
|
+
};
|
|
316
|
+
if (!(!_fs["default"].existsSync(from) || !_fs["default"].existsSync(dest))) {
|
|
317
|
+
_context3.next = 5;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
throw new _index2["default"](8009, "".concat(from, " or ").concat(dest, " is not exist!"));
|
|
321
|
+
case 5:
|
|
322
|
+
this.appendInfo("\u8907\u88FD\u4E2D ".concat(from, "/* => ").concat(dest, "/*"));
|
|
323
|
+
_fsExtra["default"].copySync(from, dest, {
|
|
324
|
+
preserveTimestamps: preserveTimestamps,
|
|
325
|
+
overwrite: override,
|
|
326
|
+
filter: filter
|
|
327
|
+
});
|
|
328
|
+
this.appendInfo("\u8907\u88FD\u5B8C\u6210 ".concat(from, "/* => ").concat(dest, "/*"));
|
|
329
|
+
case 8:
|
|
330
|
+
case "end":
|
|
331
|
+
return _context3.stop();
|
|
332
|
+
}
|
|
333
|
+
}, _callee3, this);
|
|
334
|
+
}));
|
|
335
|
+
function copyFromFolderToDestFolder(_x3, _x4) {
|
|
336
|
+
return _copyFromFolderToDestFolder.apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
return copyFromFolderToDestFolder;
|
|
339
|
+
}() /** remove all under dir */)
|
|
340
340
|
}, {
|
|
341
341
|
key: "cleanAllFiles",
|
|
342
342
|
value: function cleanAllFiles(dir) {
|
|
343
343
|
if (this.isDirectory(dir)) {
|
|
344
|
-
this.appendInfo("\
|
|
344
|
+
this.appendInfo("\u6E05\u9664\u6240\u6709\u6A94\u6848\u65BC ".concat(dir));
|
|
345
345
|
_fsExtra["default"].emptyDirSync(dir);
|
|
346
|
-
this.appendInfo("\
|
|
346
|
+
this.appendInfo("\u6E05\u9664\u6210\u529F\uFF1A".concat(dir));
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
|
|
@@ -351,16 +351,16 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
351
351
|
}, {
|
|
352
352
|
key: "deleteSelfByPath",
|
|
353
353
|
value: (function () {
|
|
354
|
-
var _deleteSelfByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
355
|
-
return _regenerator["default"].wrap(function
|
|
356
|
-
while (1) switch (
|
|
354
|
+
var _deleteSelfByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(path, force) {
|
|
355
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
356
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
357
357
|
case 0:
|
|
358
358
|
if (!_fs["default"].existsSync(path)) {
|
|
359
|
-
|
|
359
|
+
_context4.next = 5;
|
|
360
360
|
break;
|
|
361
361
|
}
|
|
362
362
|
this.appendInfo("\u6E96\u5099\u522A\u6389 ".concat(path, ",{force:").concat(force, "}"));
|
|
363
|
-
|
|
363
|
+
_context4.next = 4;
|
|
364
364
|
return (0, _del["default"])(path, {
|
|
365
365
|
force: force
|
|
366
366
|
});
|
|
@@ -368,11 +368,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
368
368
|
this.appendInfo("\u6210\u529F\u522A\u6389\u4E86 ".concat(path));
|
|
369
369
|
case 5:
|
|
370
370
|
case "end":
|
|
371
|
-
return
|
|
371
|
+
return _context4.stop();
|
|
372
372
|
}
|
|
373
|
-
},
|
|
373
|
+
}, _callee4, this);
|
|
374
374
|
}));
|
|
375
|
-
function deleteSelfByPath(
|
|
375
|
+
function deleteSelfByPath(_x5, _x6) {
|
|
376
376
|
return _deleteSelfByPath.apply(this, arguments);
|
|
377
377
|
}
|
|
378
378
|
return deleteSelfByPath;
|
|
@@ -380,20 +380,20 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
380
380
|
}, {
|
|
381
381
|
key: "deleteFileOrFolder",
|
|
382
382
|
value: function () {
|
|
383
|
-
var _deleteFileOrFolder = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
384
|
-
return _regenerator["default"].wrap(function
|
|
385
|
-
while (1) switch (
|
|
383
|
+
var _deleteFileOrFolder = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(path) {
|
|
384
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
385
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
386
386
|
case 0:
|
|
387
387
|
this.appendInfo("\u522A\u6389\u4E86 ".concat(path));
|
|
388
|
-
|
|
388
|
+
_context5.next = 3;
|
|
389
389
|
return (0, _del["default"])(path);
|
|
390
390
|
case 3:
|
|
391
391
|
case "end":
|
|
392
|
-
return
|
|
392
|
+
return _context5.stop();
|
|
393
393
|
}
|
|
394
|
-
},
|
|
394
|
+
}, _callee5, this);
|
|
395
395
|
}));
|
|
396
|
-
function deleteFileOrFolder(
|
|
396
|
+
function deleteFileOrFolder(_x7) {
|
|
397
397
|
return _deleteFileOrFolder.apply(this, arguments);
|
|
398
398
|
}
|
|
399
399
|
return deleteFileOrFolder;
|
|
@@ -401,50 +401,50 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
401
401
|
}, {
|
|
402
402
|
key: "deleteChildByPath",
|
|
403
403
|
value: (function () {
|
|
404
|
-
var _deleteChildByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
404
|
+
var _deleteChildByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(path) {
|
|
405
405
|
var force,
|
|
406
406
|
pathes,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return _regenerator["default"].wrap(function
|
|
412
|
-
while (1) switch (
|
|
407
|
+
_iterator3,
|
|
408
|
+
_step3,
|
|
409
|
+
_path,
|
|
410
|
+
_args6 = arguments;
|
|
411
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
412
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
413
413
|
case 0:
|
|
414
|
-
force =
|
|
414
|
+
force = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : false;
|
|
415
415
|
pathes = this.getChildPathByPath(path);
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
_iterator3 = _createForOfIteratorHelper(pathes);
|
|
417
|
+
_context6.prev = 3;
|
|
418
|
+
_iterator3.s();
|
|
419
419
|
case 5:
|
|
420
|
-
if ((
|
|
421
|
-
|
|
420
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
421
|
+
_context6.next = 11;
|
|
422
422
|
break;
|
|
423
423
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return this.deleteSelfByPath(
|
|
424
|
+
_path = _step3.value;
|
|
425
|
+
_context6.next = 9;
|
|
426
|
+
return this.deleteSelfByPath(_path.absolute, force);
|
|
427
427
|
case 9:
|
|
428
|
-
|
|
428
|
+
_context6.next = 5;
|
|
429
429
|
break;
|
|
430
430
|
case 11:
|
|
431
|
-
|
|
431
|
+
_context6.next = 16;
|
|
432
432
|
break;
|
|
433
433
|
case 13:
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
_context6.prev = 13;
|
|
435
|
+
_context6.t0 = _context6["catch"](3);
|
|
436
|
+
_iterator3.e(_context6.t0);
|
|
437
437
|
case 16:
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return
|
|
438
|
+
_context6.prev = 16;
|
|
439
|
+
_iterator3.f();
|
|
440
|
+
return _context6.finish(16);
|
|
441
441
|
case 19:
|
|
442
442
|
case "end":
|
|
443
|
-
return
|
|
443
|
+
return _context6.stop();
|
|
444
444
|
}
|
|
445
|
-
},
|
|
445
|
+
}, _callee6, this, [[3, 13, 16, 19]]);
|
|
446
446
|
}));
|
|
447
|
-
function deleteChildByPath(
|
|
447
|
+
function deleteChildByPath(_x8) {
|
|
448
448
|
return _deleteChildByPath.apply(this, arguments);
|
|
449
449
|
}
|
|
450
450
|
return deleteChildByPath;
|
|
@@ -452,116 +452,117 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
452
452
|
}, {
|
|
453
453
|
key: "getFileCountsOfFolder",
|
|
454
454
|
value: function getFileCountsOfFolder(path) {
|
|
455
|
-
|
|
455
|
+
try {
|
|
456
456
|
return _fs["default"].readdirSync(path).length;
|
|
457
|
+
} catch (_unused) {
|
|
458
|
+
return -1;
|
|
457
459
|
}
|
|
458
|
-
return -1;
|
|
459
460
|
}
|
|
460
461
|
}, {
|
|
461
462
|
key: "reinstallNodeModules",
|
|
462
463
|
value: function () {
|
|
463
|
-
var _reinstallNodeModules = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
464
|
+
var _reinstallNodeModules = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
464
465
|
var path,
|
|
465
466
|
_len4,
|
|
466
467
|
exclude,
|
|
467
468
|
_key4,
|
|
468
469
|
ex,
|
|
469
470
|
paths,
|
|
470
|
-
|
|
471
|
-
|
|
471
|
+
_iterator4,
|
|
472
|
+
_step4,
|
|
472
473
|
_json,
|
|
473
474
|
path_module_root,
|
|
474
475
|
path_gen_node_module,
|
|
475
476
|
path_lock_json,
|
|
476
|
-
|
|
477
|
-
|
|
477
|
+
_iterator5,
|
|
478
|
+
_step5,
|
|
478
479
|
_json2,
|
|
479
480
|
_path_module_root,
|
|
480
481
|
_path_gen_node_module,
|
|
481
|
-
|
|
482
|
-
return _regenerator["default"].wrap(function
|
|
483
|
-
while (1) switch (
|
|
482
|
+
_args7 = arguments;
|
|
483
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
484
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
484
485
|
case 0:
|
|
485
|
-
path =
|
|
486
|
-
for (_len4 =
|
|
487
|
-
exclude[_key4 - 1] =
|
|
486
|
+
path = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : "../";
|
|
487
|
+
for (_len4 = _args7.length, exclude = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
488
|
+
exclude[_key4 - 1] = _args7[_key4];
|
|
488
489
|
}
|
|
489
490
|
ex = [].concat(exclude, ["node_modules", "utiller", "configerer"]);
|
|
490
491
|
/** utiller 不能刪掉,不然就爆了, configer是他的依賴也不能刪 */
|
|
491
492
|
paths = this.findFilePathBy.apply(this, [path, function (each) {
|
|
492
493
|
return _lodash["default"].isEqual(each.fileNameExtension, "package.json");
|
|
493
494
|
}].concat((0, _toConsumableArray2["default"])(ex)));
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
495
|
+
_iterator4 = _createForOfIteratorHelper(paths);
|
|
496
|
+
_context7.prev = 5;
|
|
497
|
+
_iterator4.s();
|
|
497
498
|
case 7:
|
|
498
|
-
if ((
|
|
499
|
-
|
|
499
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
500
|
+
_context7.next = 20;
|
|
500
501
|
break;
|
|
501
502
|
}
|
|
502
|
-
_json =
|
|
503
|
+
_json = _step4.value;
|
|
503
504
|
path_module_root = this.getFileDirPath(_json.absolute);
|
|
504
505
|
path_gen_node_module = "".concat(path_module_root, "node_modules");
|
|
505
506
|
path_lock_json = "".concat(path_module_root, "package-lock.json");
|
|
506
|
-
|
|
507
|
+
_context7.next = 14;
|
|
507
508
|
return (0, _del["default"])(path_lock_json);
|
|
508
509
|
case 14:
|
|
509
510
|
this.appendInfo("\u522A\u6389\u4E86 ".concat(path_lock_json));
|
|
510
|
-
|
|
511
|
+
_context7.next = 17;
|
|
511
512
|
return (0, _del["default"])(path_gen_node_module);
|
|
512
513
|
case 17:
|
|
513
514
|
this.appendInfo("\u522A\u6389\u4E86 ".concat(path_gen_node_module));
|
|
514
515
|
case 18:
|
|
515
|
-
|
|
516
|
+
_context7.next = 7;
|
|
516
517
|
break;
|
|
517
518
|
case 20:
|
|
518
|
-
|
|
519
|
+
_context7.next = 25;
|
|
519
520
|
break;
|
|
520
521
|
case 22:
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
_context7.prev = 22;
|
|
523
|
+
_context7.t0 = _context7["catch"](5);
|
|
524
|
+
_iterator4.e(_context7.t0);
|
|
524
525
|
case 25:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
return
|
|
526
|
+
_context7.prev = 25;
|
|
527
|
+
_iterator4.f();
|
|
528
|
+
return _context7.finish(25);
|
|
528
529
|
case 28:
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
530
|
+
_iterator5 = _createForOfIteratorHelper(paths);
|
|
531
|
+
_context7.prev = 29;
|
|
532
|
+
_iterator5.s();
|
|
532
533
|
case 31:
|
|
533
|
-
if ((
|
|
534
|
-
|
|
534
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
535
|
+
_context7.next = 40;
|
|
535
536
|
break;
|
|
536
537
|
}
|
|
537
|
-
_json2 =
|
|
538
|
+
_json2 = _step5.value;
|
|
538
539
|
_path_module_root = this.getFileDirPath(_json2.absolute);
|
|
539
540
|
_path_gen_node_module = "".concat(_path_module_root, "node_modules");
|
|
540
541
|
if (_fs["default"].existsSync(_path_gen_node_module)) {
|
|
541
|
-
|
|
542
|
+
_context7.next = 38;
|
|
542
543
|
break;
|
|
543
544
|
}
|
|
544
|
-
|
|
545
|
+
_context7.next = 38;
|
|
545
546
|
return this.executeCommandLine("cd ".concat(_path_module_root, " && npm install"));
|
|
546
547
|
case 38:
|
|
547
|
-
|
|
548
|
+
_context7.next = 31;
|
|
548
549
|
break;
|
|
549
550
|
case 40:
|
|
550
|
-
|
|
551
|
+
_context7.next = 45;
|
|
551
552
|
break;
|
|
552
553
|
case 42:
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
554
|
+
_context7.prev = 42;
|
|
555
|
+
_context7.t1 = _context7["catch"](29);
|
|
556
|
+
_iterator5.e(_context7.t1);
|
|
556
557
|
case 45:
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return
|
|
558
|
+
_context7.prev = 45;
|
|
559
|
+
_iterator5.f();
|
|
560
|
+
return _context7.finish(45);
|
|
560
561
|
case 48:
|
|
561
562
|
case "end":
|
|
562
|
-
return
|
|
563
|
+
return _context7.stop();
|
|
563
564
|
}
|
|
564
|
-
},
|
|
565
|
+
}, _callee7, this, [[5, 22, 25, 28], [29, 42, 45, 48]]);
|
|
565
566
|
}));
|
|
566
567
|
function reinstallNodeModules() {
|
|
567
568
|
return _reinstallNodeModules.apply(this, arguments);
|
|
@@ -571,25 +572,25 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
571
572
|
}, {
|
|
572
573
|
key: "getNamesOfFolderChild",
|
|
573
574
|
value: function getNamesOfFolderChild(path) {
|
|
574
|
-
return
|
|
575
|
-
return
|
|
576
|
-
}).map(function (
|
|
577
|
-
return
|
|
575
|
+
return this.getChildPathByPath(path).filter(function (p) {
|
|
576
|
+
return p.isDirectory;
|
|
577
|
+
}).map(function (p) {
|
|
578
|
+
return p.dirName;
|
|
578
579
|
});
|
|
579
580
|
}
|
|
580
581
|
|
|
581
582
|
/** 從給的path 找到 one level 的 file/dir Path */
|
|
582
583
|
}, {
|
|
583
584
|
key: "getChildPathByPath",
|
|
584
|
-
value: function getChildPathByPath(
|
|
585
|
+
value: function getChildPathByPath(path) {
|
|
585
586
|
var _this4 = this;
|
|
586
587
|
try {
|
|
587
|
-
var files = _fs["default"].readdirSync(
|
|
588
|
-
return files.map(function (
|
|
589
|
-
return _this4.getPathInfo(
|
|
588
|
+
var files = _fs["default"].readdirSync(path);
|
|
589
|
+
return files.map(function (name) {
|
|
590
|
+
return _this4.getPathInfo(_path4["default"].join(path, name));
|
|
590
591
|
});
|
|
591
|
-
} catch (
|
|
592
|
-
throw new _index2["default"](8002,
|
|
592
|
+
} catch (e) {
|
|
593
|
+
throw new _index2["default"](8002, e);
|
|
593
594
|
}
|
|
594
595
|
}
|
|
595
596
|
|
|
@@ -602,108 +603,114 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
602
603
|
key: "copySingleFile",
|
|
603
604
|
value: function copySingleFile(from, dest, fileName) {
|
|
604
605
|
var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
605
|
-
var destination = _lodash["default"].isString(fileName) && !_lodash["default"].isEmpty(fileName) ?
|
|
606
|
+
var destination = _lodash["default"].isString(fileName) && !_lodash["default"].isEmpty(fileName) ? _path4["default"].join(dest, fileName) : dest;
|
|
606
607
|
if (_fs["default"].existsSync(destination) && !force) throw new _index2["default"](8006, destination);
|
|
607
608
|
_fs["default"].copyFileSync(from, destination);
|
|
608
609
|
}
|
|
609
610
|
}, {
|
|
610
611
|
key: "getNodeEnvVariable",
|
|
611
612
|
value: function getNodeEnvVariable(key) {
|
|
613
|
+
var _process$env$key;
|
|
612
614
|
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
613
|
-
|
|
614
|
-
return value === undefined ? defaultValue : value;
|
|
615
|
+
return (_process$env$key = process.env[key]) !== null && _process$env$key !== void 0 ? _process$env$key : defaultValue;
|
|
615
616
|
}
|
|
616
617
|
}, {
|
|
617
618
|
key: "isDirectory",
|
|
618
619
|
value: function isDirectory(path) {
|
|
619
|
-
|
|
620
|
-
|
|
620
|
+
try {
|
|
621
|
+
return _fs["default"].statSync(path).isDirectory();
|
|
622
|
+
} catch (_unused2) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
621
625
|
}
|
|
622
626
|
}, {
|
|
623
627
|
key: "isFile",
|
|
624
628
|
value: function isFile(path) {
|
|
625
|
-
|
|
626
|
-
|
|
629
|
+
try {
|
|
630
|
+
return _fs["default"].statSync(path).isFile();
|
|
631
|
+
} catch (_unused3) {
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
627
634
|
}
|
|
628
635
|
}, {
|
|
629
636
|
key: "isImageFile",
|
|
630
637
|
value: function isImageFile(file) {
|
|
631
|
-
return
|
|
638
|
+
return ["svg", "png", "jpg", "jpeg"].includes(file.extension);
|
|
632
639
|
}
|
|
633
640
|
|
|
634
641
|
/** 把內容都抹掉each 是 fileName, ex:index.js*/
|
|
635
642
|
}, {
|
|
636
643
|
key: "cleanChildFiles",
|
|
637
644
|
value: (function () {
|
|
638
|
-
var _cleanChildFiles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
645
|
+
var _cleanChildFiles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(path) {
|
|
639
646
|
var predicate,
|
|
640
647
|
_len5,
|
|
641
648
|
exclude,
|
|
642
649
|
_key5,
|
|
643
650
|
files,
|
|
644
|
-
|
|
645
|
-
|
|
651
|
+
_iterator6,
|
|
652
|
+
_step6,
|
|
646
653
|
file,
|
|
647
|
-
|
|
648
|
-
return _regenerator["default"].wrap(function
|
|
649
|
-
while (1) switch (
|
|
654
|
+
_args8 = arguments;
|
|
655
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
656
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
650
657
|
case 0:
|
|
651
|
-
predicate =
|
|
658
|
+
predicate = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : function (each) {
|
|
652
659
|
return true;
|
|
653
660
|
};
|
|
654
661
|
if (!_fs["default"].existsSync(path)) {
|
|
655
|
-
|
|
662
|
+
_context8.next = 26;
|
|
656
663
|
break;
|
|
657
664
|
}
|
|
658
|
-
for (_len5 =
|
|
659
|
-
exclude[_key5 - 2] =
|
|
665
|
+
for (_len5 = _args8.length, exclude = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
|
|
666
|
+
exclude[_key5 - 2] = _args8[_key5];
|
|
660
667
|
}
|
|
661
668
|
files = this.findFilePathBy.apply(this, [path, predicate].concat(exclude));
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
669
|
+
_iterator6 = _createForOfIteratorHelper(files);
|
|
670
|
+
_context8.prev = 5;
|
|
671
|
+
_iterator6.s();
|
|
665
672
|
case 7:
|
|
666
|
-
if ((
|
|
667
|
-
|
|
673
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
674
|
+
_context8.next = 15;
|
|
668
675
|
break;
|
|
669
676
|
}
|
|
670
|
-
file =
|
|
677
|
+
file = _step6.value;
|
|
671
678
|
if (!this.isImageFile(file)) {
|
|
672
|
-
|
|
679
|
+
_context8.next = 11;
|
|
673
680
|
break;
|
|
674
681
|
}
|
|
675
|
-
return
|
|
682
|
+
return _context8.abrupt("continue", 13);
|
|
676
683
|
case 11:
|
|
677
684
|
this.cleanFileContent(file.absolute);
|
|
678
685
|
this.appendInfo("\u6210\u529F cleanChildFiles() -> '".concat(file.path, "'"));
|
|
679
686
|
case 13:
|
|
680
|
-
|
|
687
|
+
_context8.next = 7;
|
|
681
688
|
break;
|
|
682
689
|
case 15:
|
|
683
|
-
|
|
690
|
+
_context8.next = 20;
|
|
684
691
|
break;
|
|
685
692
|
case 17:
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
693
|
+
_context8.prev = 17;
|
|
694
|
+
_context8.t0 = _context8["catch"](5);
|
|
695
|
+
_iterator6.e(_context8.t0);
|
|
689
696
|
case 20:
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
return
|
|
697
|
+
_context8.prev = 20;
|
|
698
|
+
_iterator6.f();
|
|
699
|
+
return _context8.finish(20);
|
|
693
700
|
case 23:
|
|
694
|
-
|
|
701
|
+
_context8.next = 25;
|
|
695
702
|
return this.syncDelay(1);
|
|
696
703
|
case 25:
|
|
697
|
-
return
|
|
704
|
+
return _context8.abrupt("return", files);
|
|
698
705
|
case 26:
|
|
699
|
-
return
|
|
706
|
+
return _context8.abrupt("return", false);
|
|
700
707
|
case 27:
|
|
701
708
|
case "end":
|
|
702
|
-
return
|
|
709
|
+
return _context8.stop();
|
|
703
710
|
}
|
|
704
|
-
},
|
|
711
|
+
}, _callee8, this, [[5, 17, 20, 23]]);
|
|
705
712
|
}));
|
|
706
|
-
function cleanChildFiles(
|
|
713
|
+
function cleanChildFiles(_x9) {
|
|
707
714
|
return _cleanChildFiles.apply(this, arguments);
|
|
708
715
|
}
|
|
709
716
|
return cleanChildFiles;
|
|
@@ -720,41 +727,41 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
720
727
|
}, {
|
|
721
728
|
key: "syncWithExistPackage",
|
|
722
729
|
value: function () {
|
|
723
|
-
var _syncWithExistPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
730
|
+
var _syncWithExistPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
|
|
724
731
|
var path,
|
|
725
732
|
paths,
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
return _regenerator["default"].wrap(function
|
|
731
|
-
while (1) switch (
|
|
733
|
+
_iterator7,
|
|
734
|
+
_step7,
|
|
735
|
+
_path2,
|
|
736
|
+
_args9 = arguments;
|
|
737
|
+
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
738
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
732
739
|
case 0:
|
|
733
|
-
path =
|
|
740
|
+
path = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : "../";
|
|
734
741
|
/** 產生shell_script_腳本 */
|
|
735
742
|
paths = this.findFilePathBy(path, function (each) {
|
|
736
743
|
return _lodash["default"].isEqual(each.fileNameExtension, "package.json");
|
|
737
744
|
}, "node_modules");
|
|
738
|
-
|
|
745
|
+
_iterator7 = _createForOfIteratorHelper(paths);
|
|
739
746
|
try {
|
|
740
|
-
for (
|
|
741
|
-
|
|
747
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
748
|
+
_path2 = _step7.value;
|
|
742
749
|
try {
|
|
743
|
-
if (!_lodash["default"].isEqual(
|
|
750
|
+
if (!_lodash["default"].isEqual(_path2.dirName, "..")) this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(_path2.dirName), "cd ".concat(this.getFolderPathOfSpecificPath(_path2.absolute)));
|
|
744
751
|
} catch (error) {
|
|
745
752
|
this.appendInfo(error.message);
|
|
746
753
|
}
|
|
747
754
|
}
|
|
748
755
|
} catch (err) {
|
|
749
|
-
|
|
756
|
+
_iterator7.e(err);
|
|
750
757
|
} finally {
|
|
751
|
-
|
|
758
|
+
_iterator7.f();
|
|
752
759
|
}
|
|
753
760
|
case 4:
|
|
754
761
|
case "end":
|
|
755
|
-
return
|
|
762
|
+
return _context9.stop();
|
|
756
763
|
}
|
|
757
|
-
},
|
|
764
|
+
}, _callee9, this);
|
|
758
765
|
}));
|
|
759
766
|
function syncWithExistPackage() {
|
|
760
767
|
return _syncWithExistPackage.apply(this, arguments);
|
|
@@ -764,17 +771,17 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
764
771
|
}, {
|
|
765
772
|
key: "packageTemplatify",
|
|
766
773
|
value: function () {
|
|
767
|
-
var _packageTemplatify = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
774
|
+
var _packageTemplatify = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(path, packageName) {
|
|
768
775
|
var _this5 = this;
|
|
769
776
|
var existFolders, dirPath, packagejson, classBase, ideaWorkspacePath, workspace, splited, indexOfRunManager, indexOfList;
|
|
770
|
-
return _regenerator["default"].wrap(function
|
|
771
|
-
while (1) switch (
|
|
777
|
+
return _regenerator["default"].wrap(function _callee10$(_context10) {
|
|
778
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
772
779
|
case 0:
|
|
773
780
|
existFolders = this.getChildPathByPath(path).map(function (each) {
|
|
774
781
|
return each.absolute.split("/").pop();
|
|
775
782
|
});
|
|
776
783
|
if (!this.has(existFolders, packageName)) {
|
|
777
|
-
|
|
784
|
+
_context10.next = 3;
|
|
778
785
|
break;
|
|
779
786
|
}
|
|
780
787
|
throw new _index2["default"](8004, " packageName ===> '".concat(packageName, "'"));
|
|
@@ -799,14 +806,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
799
806
|
/** 6.要產生webstorm run case? */
|
|
800
807
|
ideaWorkspacePath = "".concat(this.findSpecificFolderByPath(dirPath, ".idea"), "/workspace.xml");
|
|
801
808
|
/** 7.要產生cd script 腳本 **/
|
|
802
|
-
this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(
|
|
809
|
+
this.insertShellCommand(_configerer.configerer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path4["default"].resolve(dirPath)));
|
|
803
810
|
if (_fs["default"].existsSync(ideaWorkspacePath)) {
|
|
804
811
|
workspace = this.getFileContextInRaw(ideaWorkspacePath);
|
|
805
812
|
splited = workspace.split("\n");
|
|
806
813
|
indexOfRunManager = _lodash["default"].findIndex(splited, function (line) {
|
|
807
814
|
return _this5.has(line, 'name="RunManager');
|
|
808
815
|
});
|
|
809
|
-
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(
|
|
816
|
+
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>");
|
|
810
817
|
indexOfList = _lodash["default"].findIndex(splited, function (line) {
|
|
811
818
|
return _lodash["default"].isEqual(_lodash["default"].trim(line), "<list>");
|
|
812
819
|
}, indexOfRunManager);
|
|
@@ -815,17 +822,17 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
815
822
|
} else {
|
|
816
823
|
this.appendError("".concat(ideaWorkspacePath, " not exist"));
|
|
817
824
|
}
|
|
818
|
-
|
|
819
|
-
return this.executeCommandLine("cd ".concat(
|
|
825
|
+
_context10.next = 17;
|
|
826
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].resolve(dirPath), " && npm install"));
|
|
820
827
|
case 17:
|
|
821
828
|
this.appendInfo("build ".concat(packageName, " succeed!"));
|
|
822
829
|
case 18:
|
|
823
830
|
case "end":
|
|
824
|
-
return
|
|
831
|
+
return _context10.stop();
|
|
825
832
|
}
|
|
826
|
-
},
|
|
833
|
+
}, _callee10, this);
|
|
827
834
|
}));
|
|
828
|
-
function packageTemplatify(
|
|
835
|
+
function packageTemplatify(_x10, _x11) {
|
|
829
836
|
return _packageTemplatify.apply(this, arguments);
|
|
830
837
|
}
|
|
831
838
|
return packageTemplatify;
|
|
@@ -854,72 +861,70 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
854
861
|
}, {
|
|
855
862
|
key: "appendLog",
|
|
856
863
|
value: function appendLog(path, messages) {
|
|
857
|
-
var
|
|
864
|
+
var isError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
865
|
+
var msg = "".concat(this.getCurrentTimeFormat(), " ").concat(isError ? "ERROR" : "LOG", " : ").concat(messages.map(this.stringifyLog).join(" ,"));
|
|
858
866
|
if (!this.isProductionEnvironment()) {
|
|
859
867
|
var _console, _console2;
|
|
860
|
-
|
|
868
|
+
isError ? (_console = console).error.apply(_console, (0, _toConsumableArray2["default"])(messages)) : (_console2 = console).log.apply(_console2, (0, _toConsumableArray2["default"])(messages));
|
|
861
869
|
}
|
|
862
870
|
if (this.isPersistIntoLogFile) {
|
|
863
|
-
|
|
864
|
-
this.appendFile(path, messageOfSpecificLog);
|
|
871
|
+
this.appendFile(path, msg);
|
|
865
872
|
}
|
|
866
873
|
}
|
|
867
|
-
}, {
|
|
868
|
-
key: "getLogString",
|
|
869
|
-
value: function getLogString(datas) {
|
|
870
|
-
var _this6 = this;
|
|
871
|
-
return datas.map(function (data) {
|
|
872
|
-
return _this6.isJson(data) || _lodash["default"].isObject(data) || _lodash["default"].isArray(data) ? _this6.deepFlat(data) : data;
|
|
873
|
-
}).join(" ,");
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/** 如果file不存在,就會產生file,force_delete 可以強制刪除cache file*/
|
|
877
874
|
}, {
|
|
878
875
|
key: "appendFile",
|
|
879
|
-
value:
|
|
880
|
-
|
|
876
|
+
value: /** 如果file不存在,就會產生file,force_delete 可以強制刪除cache file*/
|
|
877
|
+
function appendFile(path, data) {
|
|
878
|
+
var newline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
881
879
|
var forceDelete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
882
|
-
|
|
880
|
+
try {
|
|
881
|
+
if (forceDelete && _fs["default"].existsSync(path)) _fs["default"].unlinkSync(path);
|
|
882
|
+
if (!_fs["default"].existsSync(path)) this.persistByPath(path);
|
|
883
|
+
var content = "".concat(newline ? "\n" : "").concat(data);
|
|
884
|
+
_fs["default"].appendFileSync(path, content);
|
|
885
|
+
} catch (err) {
|
|
883
886
|
throw new _index2["default"](8001, err);
|
|
884
|
-
};
|
|
885
|
-
if (!this.isValidFilePath(path)) {
|
|
886
|
-
throw new _index2["default"](9999, "\u4E0D\u662F\u500B\u5408\u6CD5\u7684file\u8DEF\u5F91 ==> '' ".concat(path, " ''"));
|
|
887
|
-
}
|
|
888
|
-
if (forceDelete) {
|
|
889
|
-
this.cleanFileContent(path);
|
|
890
|
-
newlineOnceFileNotEmpty = false;
|
|
891
|
-
this.persistByPath(path);
|
|
892
|
-
} else if (this.isEmptyFile(path)) {
|
|
893
|
-
newlineOnceFileNotEmpty = false;
|
|
894
887
|
}
|
|
895
|
-
_fs["default"].appendFileSync(path, "".concat(newlineOnceFileNotEmpty ? "\n" : "").concat(data), options);
|
|
896
888
|
}
|
|
897
889
|
|
|
898
890
|
/** 常常要把JSON的內容印出來,所以這個很方便 */
|
|
891
|
+
}, {
|
|
892
|
+
key: "stringifyLog",
|
|
893
|
+
value: function stringifyLog(data) {
|
|
894
|
+
return (0, _typeof2["default"])(data) === "object" ? JSON.stringify(data) : String(data);
|
|
895
|
+
}
|
|
896
|
+
}, {
|
|
897
|
+
key: "getLogString",
|
|
898
|
+
value: function getLogString(datas) {
|
|
899
|
+
var _this6 = this;
|
|
900
|
+
return datas.map(function (data) {
|
|
901
|
+
return _this6.isJson(data) || _lodash["default"].isObject(data) || _lodash["default"].isArray(data) ? _this6.deepFlat(data) : data;
|
|
902
|
+
}).join(" ,");
|
|
903
|
+
}
|
|
899
904
|
}, {
|
|
900
905
|
key: "persistJsonFilePrettier",
|
|
901
906
|
value: (function () {
|
|
902
|
-
var _persistJsonFilePrettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
903
|
-
var
|
|
904
|
-
|
|
905
|
-
return _regenerator["default"].wrap(function
|
|
906
|
-
while (1) switch (
|
|
907
|
+
var _persistJsonFilePrettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(path, object) {
|
|
908
|
+
var ignorePrettier,
|
|
909
|
+
_args11 = arguments;
|
|
910
|
+
return _regenerator["default"].wrap(function _callee11$(_context11) {
|
|
911
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
907
912
|
case 0:
|
|
908
|
-
|
|
909
|
-
this.appendFile(path, JSON.stringify(object), true, true);
|
|
910
|
-
if (
|
|
911
|
-
|
|
913
|
+
ignorePrettier = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : false;
|
|
914
|
+
this.appendFile(path, JSON.stringify(object, null, 2), true, true);
|
|
915
|
+
if (ignorePrettier) {
|
|
916
|
+
_context11.next = 5;
|
|
912
917
|
break;
|
|
913
918
|
}
|
|
914
|
-
|
|
919
|
+
_context11.next = 5;
|
|
915
920
|
return this.prettier(path, 120);
|
|
916
921
|
case 5:
|
|
917
922
|
case "end":
|
|
918
|
-
return
|
|
923
|
+
return _context11.stop();
|
|
919
924
|
}
|
|
920
|
-
},
|
|
925
|
+
}, _callee11, this);
|
|
921
926
|
}));
|
|
922
|
-
function persistJsonFilePrettier(
|
|
927
|
+
function persistJsonFilePrettier(_x12, _x13) {
|
|
923
928
|
return _persistJsonFilePrettier.apply(this, arguments);
|
|
924
929
|
}
|
|
925
930
|
return persistJsonFilePrettier;
|
|
@@ -937,32 +942,32 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
937
942
|
}, {
|
|
938
943
|
key: "readFileContentByPath",
|
|
939
944
|
value: (function () {
|
|
940
|
-
var _readFileContentByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
945
|
+
var _readFileContentByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(path, cache) {
|
|
941
946
|
var _cache$path;
|
|
942
|
-
return _regenerator["default"].wrap(function
|
|
943
|
-
while (1) switch (
|
|
947
|
+
return _regenerator["default"].wrap(function _callee12$(_context12) {
|
|
948
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
944
949
|
case 0:
|
|
945
950
|
if (!((_cache$path = cache[path]) !== null && _cache$path !== void 0)) {
|
|
946
|
-
|
|
951
|
+
_context12.next = 4;
|
|
947
952
|
break;
|
|
948
953
|
}
|
|
949
|
-
|
|
950
|
-
|
|
954
|
+
_context12.t0 = _cache$path;
|
|
955
|
+
_context12.next = 7;
|
|
951
956
|
break;
|
|
952
957
|
case 4:
|
|
953
|
-
|
|
958
|
+
_context12.next = 6;
|
|
954
959
|
return _promises["default"].readFile(path, "utf-8");
|
|
955
960
|
case 6:
|
|
956
|
-
|
|
961
|
+
_context12.t0 = cache[path] = _context12.sent;
|
|
957
962
|
case 7:
|
|
958
|
-
return
|
|
963
|
+
return _context12.abrupt("return", _context12.t0);
|
|
959
964
|
case 8:
|
|
960
965
|
case "end":
|
|
961
|
-
return
|
|
966
|
+
return _context12.stop();
|
|
962
967
|
}
|
|
963
|
-
},
|
|
968
|
+
}, _callee12);
|
|
964
969
|
}));
|
|
965
|
-
function readFileContentByPath(
|
|
970
|
+
function readFileContentByPath(_x14, _x15) {
|
|
966
971
|
return _readFileContentByPath.apply(this, arguments);
|
|
967
972
|
}
|
|
968
973
|
return readFileContentByPath;
|
|
@@ -972,11 +977,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
972
977
|
value: function singleFileTemplatify() {
|
|
973
978
|
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "./";
|
|
974
979
|
var all = this.findFilePathByExtension(path, ["js"], "node_modules");
|
|
975
|
-
var
|
|
976
|
-
|
|
980
|
+
var _iterator8 = _createForOfIteratorHelper(all),
|
|
981
|
+
_step8;
|
|
977
982
|
try {
|
|
978
|
-
for (
|
|
979
|
-
var file =
|
|
983
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
984
|
+
var file = _step8.value;
|
|
980
985
|
var content = this.getFileContextInRaw(file.absolute).trim();
|
|
981
986
|
if (_lodash["default"].isEmpty(content)) {
|
|
982
987
|
this.appendInfo(file.fileName, file.absolute);
|
|
@@ -985,9 +990,9 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
985
990
|
}
|
|
986
991
|
}
|
|
987
992
|
} catch (err) {
|
|
988
|
-
|
|
993
|
+
_iterator8.e(err);
|
|
989
994
|
} finally {
|
|
990
|
-
|
|
995
|
+
_iterator8.f();
|
|
991
996
|
}
|
|
992
997
|
}
|
|
993
998
|
|
|
@@ -1046,7 +1051,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1046
1051
|
}, {
|
|
1047
1052
|
key: "generatePackage",
|
|
1048
1053
|
value: (function () {
|
|
1049
|
-
var _generatePackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1054
|
+
var _generatePackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
|
|
1050
1055
|
var _this7 = this;
|
|
1051
1056
|
var path,
|
|
1052
1057
|
deployToNPMServer,
|
|
@@ -1055,16 +1060,16 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1055
1060
|
_len8,
|
|
1056
1061
|
exclude,
|
|
1057
1062
|
_key8,
|
|
1058
|
-
|
|
1059
|
-
|
|
1063
|
+
_iterator9,
|
|
1064
|
+
_step9,
|
|
1060
1065
|
_loop,
|
|
1061
|
-
|
|
1062
|
-
return _regenerator["default"].wrap(function
|
|
1063
|
-
while (1) switch (
|
|
1066
|
+
_args14 = arguments;
|
|
1067
|
+
return _regenerator["default"].wrap(function _callee13$(_context14) {
|
|
1068
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1064
1069
|
case 0:
|
|
1065
|
-
path =
|
|
1066
|
-
deployToNPMServer =
|
|
1067
|
-
forceInstallNodeModule =
|
|
1070
|
+
path = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : "./";
|
|
1071
|
+
deployToNPMServer = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : false;
|
|
1072
|
+
forceInstallNodeModule = _args14.length > 2 && _args14[2] !== undefined ? _args14[2] : true;
|
|
1068
1073
|
packagejsons = this.findFilePathByExtension(path, ["json"], "node_modules", "release");
|
|
1069
1074
|
packagejsons = _lodash["default"].filter(packagejsons, function (each) {
|
|
1070
1075
|
return _lodash["default"].isEqual(each.fileName, "package");
|
|
@@ -1072,132 +1077,136 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1072
1077
|
packagejsons = packagejsons.map(function (each) {
|
|
1073
1078
|
return _this7.getFolderPathOfSpecificPath(each.absolute);
|
|
1074
1079
|
});
|
|
1075
|
-
for (_len8 =
|
|
1076
|
-
exclude[_key8 - 3] =
|
|
1080
|
+
for (_len8 = _args14.length, exclude = new Array(_len8 > 3 ? _len8 - 3 : 0), _key8 = 3; _key8 < _len8; _key8++) {
|
|
1081
|
+
exclude[_key8 - 3] = _args14[_key8];
|
|
1077
1082
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1083
|
+
_iterator9 = _createForOfIteratorHelper(packagejsons);
|
|
1084
|
+
_context14.prev = 8;
|
|
1080
1085
|
_loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
|
|
1081
1086
|
var path, tempFolderPath, release, pathOfPackageJson, indexFileName, templatePath, _yield$_this7$upgrade, moduleName, version;
|
|
1082
|
-
return _regenerator["default"].wrap(function _loop$(
|
|
1083
|
-
while (1) switch (
|
|
1087
|
+
return _regenerator["default"].wrap(function _loop$(_context13) {
|
|
1088
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1084
1089
|
case 0:
|
|
1085
|
-
path =
|
|
1090
|
+
path = _step9.value;
|
|
1086
1091
|
if (!_this7.isAndEquals.apply(_this7, (0, _toConsumableArray2["default"])(exclude.map(function (projectName) {
|
|
1087
1092
|
return function () {
|
|
1088
1093
|
return !_this7.has(path, projectName);
|
|
1089
1094
|
};
|
|
1090
1095
|
})))) {
|
|
1091
|
-
|
|
1096
|
+
_context13.next = 46;
|
|
1092
1097
|
break;
|
|
1093
1098
|
}
|
|
1094
|
-
|
|
1099
|
+
_context13.next = 4;
|
|
1095
1100
|
return _this7.generateTempFolderWithCleanSrc(path);
|
|
1096
1101
|
case 4:
|
|
1097
|
-
tempFolderPath =
|
|
1102
|
+
tempFolderPath = _context13.sent;
|
|
1098
1103
|
/** 產生release資料夾 */
|
|
1099
|
-
release = _this7.persistByPath(
|
|
1104
|
+
release = _this7.persistByPath(_path4["default"].join(path, "release"));
|
|
1100
1105
|
/** 利用babel 產生出 es5相容性高的src file */
|
|
1101
|
-
|
|
1106
|
+
_context13.next = 8;
|
|
1102
1107
|
return _this7.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
|
|
1103
1108
|
case 8:
|
|
1104
|
-
pathOfPackageJson =
|
|
1105
|
-
|
|
1109
|
+
pathOfPackageJson = _path4["default"].join(path, "package.json");
|
|
1110
|
+
_context13.prev = 9;
|
|
1106
1111
|
indexFileName = "sample.npm.module.index.js";
|
|
1107
1112
|
/** 複製公版的index.js */
|
|
1108
1113
|
_this7.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/".concat(indexFileName), release, "index.js", true);
|
|
1109
1114
|
|
|
1110
1115
|
/** template就是樣板的概念 */
|
|
1111
|
-
templatePath =
|
|
1112
|
-
if (_this7.isPathExist(templatePath)) {
|
|
1113
|
-
|
|
1116
|
+
templatePath = _path4["default"].join(path, "template");
|
|
1117
|
+
if (!_this7.isPathExist(templatePath)) {
|
|
1118
|
+
_context13.next = 16;
|
|
1119
|
+
break;
|
|
1114
1120
|
}
|
|
1121
|
+
_context13.next = 16;
|
|
1122
|
+
return _this7.copyFromFolderToDestFolder(templatePath, _this7.persistByPath(_path4["default"].join(release, "template")));
|
|
1123
|
+
case 16:
|
|
1115
1124
|
if (!deployToNPMServer) {
|
|
1116
|
-
|
|
1125
|
+
_context13.next = 24;
|
|
1117
1126
|
break;
|
|
1118
1127
|
}
|
|
1119
|
-
|
|
1128
|
+
_context13.next = 19;
|
|
1120
1129
|
return _this7.upgradePackageJsonVersion(pathOfPackageJson);
|
|
1121
|
-
case
|
|
1122
|
-
_yield$_this7$upgrade =
|
|
1130
|
+
case 19:
|
|
1131
|
+
_yield$_this7$upgrade = _context13.sent;
|
|
1123
1132
|
moduleName = _yield$_this7$upgrade.moduleName;
|
|
1124
1133
|
version = _yield$_this7$upgrade.version;
|
|
1125
|
-
|
|
1134
|
+
_context13.next = 24;
|
|
1126
1135
|
return _this7.updateVersionOfTemplate(moduleName, version);
|
|
1127
|
-
case
|
|
1136
|
+
case 24:
|
|
1128
1137
|
/** 把package.json release放進去 */
|
|
1129
|
-
_this7.copySingleFile(pathOfPackageJson,
|
|
1138
|
+
_this7.copySingleFile(pathOfPackageJson, _path4["default"].join(release, "package.json"), undefined, true);
|
|
1130
1139
|
|
|
1131
1140
|
/** 安裝一個沒有devDependency 的node_module */
|
|
1132
|
-
if (!(forceInstallNodeModule || !_this7.isPathExist(
|
|
1133
|
-
|
|
1141
|
+
if (!(forceInstallNodeModule || !_this7.isPathExist(_path4["default"].join(release, "node_module")))) {
|
|
1142
|
+
_context13.next = 30;
|
|
1134
1143
|
break;
|
|
1135
1144
|
}
|
|
1136
|
-
|
|
1145
|
+
_context13.next = 28;
|
|
1137
1146
|
return _this7.executeCommandLine("cd ".concat(release, " && yarn install --production"));
|
|
1138
|
-
case 26:
|
|
1139
|
-
_context12.next = 29;
|
|
1140
|
-
break;
|
|
1141
1147
|
case 28:
|
|
1148
|
+
_context13.next = 31;
|
|
1149
|
+
break;
|
|
1150
|
+
case 30:
|
|
1142
1151
|
_this7.appendInfo("ignore node-module install behavior");
|
|
1143
|
-
case
|
|
1152
|
+
case 31:
|
|
1144
1153
|
_this7.appendInfo("build ".concat(path, " succeed"));
|
|
1145
1154
|
|
|
1146
1155
|
/** 部署到 local server*/
|
|
1147
1156
|
if (!deployToNPMServer) {
|
|
1148
|
-
|
|
1157
|
+
_context13.next = 35;
|
|
1149
1158
|
break;
|
|
1150
1159
|
}
|
|
1151
|
-
|
|
1160
|
+
_context13.next = 35;
|
|
1152
1161
|
return _this7.executeCommandLine("cd ".concat(release, " && npm publish"));
|
|
1153
|
-
case 33:
|
|
1154
|
-
_context12.next = 40;
|
|
1155
|
-
break;
|
|
1156
1162
|
case 35:
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1163
|
+
_context13.next = 42;
|
|
1164
|
+
break;
|
|
1165
|
+
case 37:
|
|
1166
|
+
_context13.prev = 37;
|
|
1167
|
+
_context13.t0 = _context13["catch"](9);
|
|
1168
|
+
_context13.next = 41;
|
|
1160
1169
|
return _this7.deleteSelfByPath(release, true);
|
|
1161
|
-
case
|
|
1162
|
-
throw new _index2["default"](9999, "generatePackage \u5831\u932F, ".concat(
|
|
1163
|
-
case
|
|
1164
|
-
|
|
1165
|
-
|
|
1170
|
+
case 41:
|
|
1171
|
+
throw new _index2["default"](9999, "generatePackage \u5831\u932F, ".concat(_context13.t0.message));
|
|
1172
|
+
case 42:
|
|
1173
|
+
_context13.prev = 42;
|
|
1174
|
+
_context13.next = 45;
|
|
1166
1175
|
return _this7.deleteSelfByPath(tempFolderPath, true);
|
|
1167
|
-
case
|
|
1168
|
-
return
|
|
1169
|
-
case
|
|
1176
|
+
case 45:
|
|
1177
|
+
return _context13.finish(42);
|
|
1178
|
+
case 46:
|
|
1170
1179
|
case "end":
|
|
1171
|
-
return
|
|
1180
|
+
return _context13.stop();
|
|
1172
1181
|
}
|
|
1173
|
-
}, _loop, null, [[9,
|
|
1182
|
+
}, _loop, null, [[9, 37, 42, 46]]);
|
|
1174
1183
|
});
|
|
1175
|
-
|
|
1184
|
+
_iterator9.s();
|
|
1176
1185
|
case 11:
|
|
1177
|
-
if ((
|
|
1178
|
-
|
|
1186
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1187
|
+
_context14.next = 15;
|
|
1179
1188
|
break;
|
|
1180
1189
|
}
|
|
1181
|
-
return
|
|
1190
|
+
return _context14.delegateYield(_loop(), "t0", 13);
|
|
1182
1191
|
case 13:
|
|
1183
|
-
|
|
1192
|
+
_context14.next = 11;
|
|
1184
1193
|
break;
|
|
1185
1194
|
case 15:
|
|
1186
|
-
|
|
1195
|
+
_context14.next = 20;
|
|
1187
1196
|
break;
|
|
1188
1197
|
case 17:
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1198
|
+
_context14.prev = 17;
|
|
1199
|
+
_context14.t1 = _context14["catch"](8);
|
|
1200
|
+
_iterator9.e(_context14.t1);
|
|
1192
1201
|
case 20:
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
return
|
|
1202
|
+
_context14.prev = 20;
|
|
1203
|
+
_iterator9.f();
|
|
1204
|
+
return _context14.finish(20);
|
|
1196
1205
|
case 23:
|
|
1197
1206
|
case "end":
|
|
1198
|
-
return
|
|
1207
|
+
return _context14.stop();
|
|
1199
1208
|
}
|
|
1200
|
-
},
|
|
1209
|
+
}, _callee13, this, [[8, 17, 20, 23]]);
|
|
1201
1210
|
}));
|
|
1202
1211
|
function generatePackage() {
|
|
1203
1212
|
return _generatePackage.apply(this, arguments);
|
|
@@ -1207,47 +1216,47 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1207
1216
|
}, {
|
|
1208
1217
|
key: "updateVersionOfTemplate",
|
|
1209
1218
|
value: (function () {
|
|
1210
|
-
var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1219
|
+
var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(dependency, newVersion) {
|
|
1211
1220
|
var paths, _i, _paths, path, succeedOfPersistFile, json;
|
|
1212
|
-
return _regenerator["default"].wrap(function
|
|
1213
|
-
while (1) switch (
|
|
1221
|
+
return _regenerator["default"].wrap(function _callee14$(_context15) {
|
|
1222
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1214
1223
|
case 0:
|
|
1215
1224
|
paths = ["/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/admin.package.json.mustache", "/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/web.package.json.mustache", "/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/functions.package.json.mustache", "/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/sample.package.json", "/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/package.json"];
|
|
1216
1225
|
_i = 0, _paths = paths;
|
|
1217
1226
|
case 2:
|
|
1218
1227
|
if (!(_i < _paths.length)) {
|
|
1219
|
-
|
|
1228
|
+
_context15.next = 24;
|
|
1220
1229
|
break;
|
|
1221
1230
|
}
|
|
1222
1231
|
path = _paths[_i];
|
|
1223
1232
|
if (!this.isPathExist(path)) {
|
|
1224
|
-
|
|
1233
|
+
_context15.next = 21;
|
|
1225
1234
|
break;
|
|
1226
1235
|
}
|
|
1227
1236
|
succeedOfPersistFile = false;
|
|
1228
1237
|
json = this.getJsonObjByFilePath(path);
|
|
1229
1238
|
if (!(json && json.dependencies && json.dependencies[dependency])) {
|
|
1230
|
-
|
|
1239
|
+
_context15.next = 18;
|
|
1231
1240
|
break;
|
|
1232
1241
|
}
|
|
1233
1242
|
json.dependencies[dependency] = "^".concat(newVersion);
|
|
1234
|
-
|
|
1235
|
-
|
|
1243
|
+
_context15.prev = 9;
|
|
1244
|
+
_context15.next = 12;
|
|
1236
1245
|
return this.writeJsonThanPrettier(path, json);
|
|
1237
1246
|
case 12:
|
|
1238
1247
|
succeedOfPersistFile = true;
|
|
1239
|
-
|
|
1248
|
+
_context15.next = 18;
|
|
1240
1249
|
break;
|
|
1241
1250
|
case 15:
|
|
1242
|
-
|
|
1243
|
-
|
|
1251
|
+
_context15.prev = 15;
|
|
1252
|
+
_context15.t0 = _context15["catch"](9);
|
|
1244
1253
|
succeedOfPersistFile = true;
|
|
1245
1254
|
case 18:
|
|
1246
1255
|
if (succeedOfPersistFile) {
|
|
1247
|
-
|
|
1256
|
+
_context15.next = 21;
|
|
1248
1257
|
break;
|
|
1249
1258
|
}
|
|
1250
|
-
|
|
1259
|
+
_context15.next = 21;
|
|
1251
1260
|
return this.updateFileOfSpecificLine(path, function (line) {
|
|
1252
1261
|
return " \"".concat(dependency, "\":\"^").concat(newVersion, "\"").concat(_lodash["default"].endsWith(_lodash["default"].trim(line), "," ? "," : ""));
|
|
1253
1262
|
}, function (each) {
|
|
@@ -1255,17 +1264,18 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1255
1264
|
});
|
|
1256
1265
|
case 21:
|
|
1257
1266
|
_i++;
|
|
1258
|
-
|
|
1267
|
+
_context15.next = 2;
|
|
1259
1268
|
break;
|
|
1260
1269
|
case 24:
|
|
1261
|
-
|
|
1262
|
-
|
|
1270
|
+
_context15.next = 26;
|
|
1271
|
+
return this.copyFromFolderToDestFolder("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/", "/Users/davidtu/cross-achieve/high/idea-inventer/newp/template/", true, true);
|
|
1272
|
+
case 26:
|
|
1263
1273
|
case "end":
|
|
1264
|
-
return
|
|
1274
|
+
return _context15.stop();
|
|
1265
1275
|
}
|
|
1266
|
-
},
|
|
1276
|
+
}, _callee14, this, [[9, 15]]);
|
|
1267
1277
|
}));
|
|
1268
|
-
function updateVersionOfTemplate(
|
|
1278
|
+
function updateVersionOfTemplate(_x16, _x17) {
|
|
1269
1279
|
return _updateVersionOfTemplate.apply(this, arguments);
|
|
1270
1280
|
}
|
|
1271
1281
|
return updateVersionOfTemplate;
|
|
@@ -1280,20 +1290,20 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1280
1290
|
}, {
|
|
1281
1291
|
key: "updateFileOfSpecificLine",
|
|
1282
1292
|
value: (function () {
|
|
1283
|
-
var _updateFileOfSpecificLine = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1293
|
+
var _updateFileOfSpecificLine = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(pathOfFile) {
|
|
1284
1294
|
var contentOfUpdated,
|
|
1285
1295
|
predicate,
|
|
1286
1296
|
context,
|
|
1287
1297
|
split,
|
|
1288
1298
|
line,
|
|
1289
|
-
|
|
1290
|
-
return _regenerator["default"].wrap(function
|
|
1291
|
-
while (1) switch (
|
|
1299
|
+
_args16 = arguments;
|
|
1300
|
+
return _regenerator["default"].wrap(function _callee15$(_context16) {
|
|
1301
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1292
1302
|
case 0:
|
|
1293
|
-
contentOfUpdated =
|
|
1303
|
+
contentOfUpdated = _args16.length > 1 && _args16[1] !== undefined ? _args16[1] : function (line) {
|
|
1294
1304
|
return "updated";
|
|
1295
1305
|
};
|
|
1296
|
-
predicate =
|
|
1306
|
+
predicate = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : function (line) {
|
|
1297
1307
|
return true;
|
|
1298
1308
|
};
|
|
1299
1309
|
context = this.getFileContextInRaw(pathOfFile);
|
|
@@ -1305,11 +1315,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1305
1315
|
this.appendFile(pathOfFile, split.join("\n"), true, true);
|
|
1306
1316
|
case 7:
|
|
1307
1317
|
case "end":
|
|
1308
|
-
return
|
|
1318
|
+
return _context16.stop();
|
|
1309
1319
|
}
|
|
1310
|
-
},
|
|
1320
|
+
}, _callee15, this);
|
|
1311
1321
|
}));
|
|
1312
|
-
function updateFileOfSpecificLine(
|
|
1322
|
+
function updateFileOfSpecificLine(_x18) {
|
|
1313
1323
|
return _updateFileOfSpecificLine.apply(this, arguments);
|
|
1314
1324
|
}
|
|
1315
1325
|
return updateFileOfSpecificLine;
|
|
@@ -1317,20 +1327,20 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1317
1327
|
}, {
|
|
1318
1328
|
key: "writeJsonThanPrettier",
|
|
1319
1329
|
value: function () {
|
|
1320
|
-
var _writeJsonThanPrettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1321
|
-
return _regenerator["default"].wrap(function
|
|
1322
|
-
while (1) switch (
|
|
1330
|
+
var _writeJsonThanPrettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(path, json) {
|
|
1331
|
+
return _regenerator["default"].wrap(function _callee16$(_context17) {
|
|
1332
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1323
1333
|
case 0:
|
|
1324
1334
|
this.writeFileInJSON(path, json);
|
|
1325
|
-
|
|
1335
|
+
_context17.next = 3;
|
|
1326
1336
|
return this.prettier(path);
|
|
1327
1337
|
case 3:
|
|
1328
1338
|
case "end":
|
|
1329
|
-
return
|
|
1339
|
+
return _context17.stop();
|
|
1330
1340
|
}
|
|
1331
|
-
},
|
|
1341
|
+
}, _callee16, this);
|
|
1332
1342
|
}));
|
|
1333
|
-
function writeJsonThanPrettier(
|
|
1343
|
+
function writeJsonThanPrettier(_x19, _x20) {
|
|
1334
1344
|
return _writeJsonThanPrettier.apply(this, arguments);
|
|
1335
1345
|
}
|
|
1336
1346
|
return writeJsonThanPrettier;
|
|
@@ -1338,50 +1348,50 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1338
1348
|
}, {
|
|
1339
1349
|
key: "enrichEachPackageJson",
|
|
1340
1350
|
value: (function () {
|
|
1341
|
-
var _enrichEachPackageJson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1342
|
-
var jsons, packages,
|
|
1343
|
-
return _regenerator["default"].wrap(function
|
|
1344
|
-
while (1) switch (
|
|
1351
|
+
var _enrichEachPackageJson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(path) {
|
|
1352
|
+
var jsons, packages, _iterator10, _step10, _path3, json, script;
|
|
1353
|
+
return _regenerator["default"].wrap(function _callee17$(_context18) {
|
|
1354
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1345
1355
|
case 0:
|
|
1346
1356
|
jsons = this.findFilePathByExtension(path, ["json"], "gen", "node_modules", "release");
|
|
1347
1357
|
packages = _lodash["default"].filter(jsons, function (each) {
|
|
1348
1358
|
return _lodash["default"].isEqual(each.fileName, "package") || _lodash["default"].isEqual(each.fileName, "admin.package") || _lodash["default"].isEqual(each.fileName, "web.package") || _lodash["default"].isEqual(each.fileName, "functions.package");
|
|
1349
1359
|
});
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1360
|
+
_iterator10 = _createForOfIteratorHelper(packages);
|
|
1361
|
+
_context18.prev = 3;
|
|
1362
|
+
_iterator10.s();
|
|
1353
1363
|
case 5:
|
|
1354
|
-
if ((
|
|
1355
|
-
|
|
1364
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1365
|
+
_context18.next = 14;
|
|
1356
1366
|
break;
|
|
1357
1367
|
}
|
|
1358
|
-
|
|
1359
|
-
json = this.getJsonObjByFilePath(
|
|
1368
|
+
_path3 = _step10.value;
|
|
1369
|
+
json = this.getJsonObjByFilePath(_path3.absolute);
|
|
1360
1370
|
script = json.scripts ? json.scripts : {};
|
|
1361
1371
|
script["updateConfigerer"] = "npm update configerer --save";
|
|
1362
|
-
|
|
1363
|
-
return this.writeJsonThanPrettier(
|
|
1372
|
+
_context18.next = 12;
|
|
1373
|
+
return this.writeJsonThanPrettier(_path3.absolute, json);
|
|
1364
1374
|
case 12:
|
|
1365
|
-
|
|
1375
|
+
_context18.next = 5;
|
|
1366
1376
|
break;
|
|
1367
1377
|
case 14:
|
|
1368
|
-
|
|
1378
|
+
_context18.next = 19;
|
|
1369
1379
|
break;
|
|
1370
1380
|
case 16:
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1381
|
+
_context18.prev = 16;
|
|
1382
|
+
_context18.t0 = _context18["catch"](3);
|
|
1383
|
+
_iterator10.e(_context18.t0);
|
|
1374
1384
|
case 19:
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
return
|
|
1385
|
+
_context18.prev = 19;
|
|
1386
|
+
_iterator10.f();
|
|
1387
|
+
return _context18.finish(19);
|
|
1378
1388
|
case 22:
|
|
1379
1389
|
case "end":
|
|
1380
|
-
return
|
|
1390
|
+
return _context18.stop();
|
|
1381
1391
|
}
|
|
1382
|
-
},
|
|
1392
|
+
}, _callee17, this, [[3, 16, 19, 22]]);
|
|
1383
1393
|
}));
|
|
1384
|
-
function enrichEachPackageJson(
|
|
1394
|
+
function enrichEachPackageJson(_x21) {
|
|
1385
1395
|
return _enrichEachPackageJson.apply(this, arguments);
|
|
1386
1396
|
}
|
|
1387
1397
|
return enrichEachPackageJson;
|
|
@@ -1422,22 +1432,22 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1422
1432
|
}, {
|
|
1423
1433
|
key: "prettier",
|
|
1424
1434
|
value: (function () {
|
|
1425
|
-
var _prettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1435
|
+
var _prettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(path) {
|
|
1426
1436
|
var width,
|
|
1427
|
-
|
|
1428
|
-
return _regenerator["default"].wrap(function
|
|
1429
|
-
while (1) switch (
|
|
1437
|
+
_args19 = arguments;
|
|
1438
|
+
return _regenerator["default"].wrap(function _callee18$(_context19) {
|
|
1439
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1430
1440
|
case 0:
|
|
1431
|
-
width =
|
|
1432
|
-
|
|
1433
|
-
return this.executeCommandLine("cd ".concat(
|
|
1441
|
+
width = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : 200;
|
|
1442
|
+
_context19.next = 3;
|
|
1443
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].resolve("."), " && npx prettier --write ").concat(_path4["default"].resolve(path), " --print-width ").concat(width));
|
|
1434
1444
|
case 3:
|
|
1435
1445
|
case "end":
|
|
1436
|
-
return
|
|
1446
|
+
return _context19.stop();
|
|
1437
1447
|
}
|
|
1438
|
-
},
|
|
1448
|
+
}, _callee18, this);
|
|
1439
1449
|
}));
|
|
1440
|
-
function prettier(
|
|
1450
|
+
function prettier(_x22) {
|
|
1441
1451
|
return _prettier.apply(this, arguments);
|
|
1442
1452
|
}
|
|
1443
1453
|
return prettier;
|
|
@@ -1452,12 +1462,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1452
1462
|
}, {
|
|
1453
1463
|
key: "getFileLastModifiedTime",
|
|
1454
1464
|
value: function getFileLastModifiedTime(path) {
|
|
1455
|
-
|
|
1456
|
-
* console.log(`File Data Last Modified: ${stats.mtime}`);
|
|
1457
|
-
* console.log(`File Status Last Modified: ${stats.ctime}`);
|
|
1458
|
-
*/
|
|
1459
|
-
var stats = _fs["default"].statSync(path);
|
|
1460
|
-
return stats.mtimeMs;
|
|
1465
|
+
return _fs["default"].statSync(path).mtimeMs;
|
|
1461
1466
|
}
|
|
1462
1467
|
}, {
|
|
1463
1468
|
key: "getJsonObjByFilePath",
|
|
@@ -1470,21 +1475,21 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1470
1475
|
}, {
|
|
1471
1476
|
key: "upgradePackageJsonVersion",
|
|
1472
1477
|
value: (function () {
|
|
1473
|
-
var _upgradePackageJsonVersion = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1478
|
+
var _upgradePackageJsonVersion = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(path) {
|
|
1474
1479
|
var json;
|
|
1475
|
-
return _regenerator["default"].wrap(function
|
|
1476
|
-
while (1) switch (
|
|
1480
|
+
return _regenerator["default"].wrap(function _callee19$(_context20) {
|
|
1481
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1477
1482
|
case 0:
|
|
1478
1483
|
if (!_lodash["default"].isEqual("json", this.getPathInfo(path).extension)) {
|
|
1479
|
-
|
|
1484
|
+
_context20.next = 8;
|
|
1480
1485
|
break;
|
|
1481
1486
|
}
|
|
1482
1487
|
json = this.getJsonObjByFilePath(path);
|
|
1483
1488
|
json.version = this.getStringOfVersionIncrement(json.version);
|
|
1484
|
-
|
|
1489
|
+
_context20.next = 5;
|
|
1485
1490
|
return this.writeJsonThanPrettier(path, json);
|
|
1486
1491
|
case 5:
|
|
1487
|
-
return
|
|
1492
|
+
return _context20.abrupt("return", {
|
|
1488
1493
|
version: json.version,
|
|
1489
1494
|
moduleName: json.name
|
|
1490
1495
|
});
|
|
@@ -1492,11 +1497,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1492
1497
|
throw new _index2["default"](8020, "path is not package.json, which is ".concat(path));
|
|
1493
1498
|
case 9:
|
|
1494
1499
|
case "end":
|
|
1495
|
-
return
|
|
1500
|
+
return _context20.stop();
|
|
1496
1501
|
}
|
|
1497
|
-
},
|
|
1502
|
+
}, _callee19, this);
|
|
1498
1503
|
}));
|
|
1499
|
-
function upgradePackageJsonVersion(
|
|
1504
|
+
function upgradePackageJsonVersion(_x23) {
|
|
1500
1505
|
return _upgradePackageJsonVersion.apply(this, arguments);
|
|
1501
1506
|
}
|
|
1502
1507
|
return upgradePackageJsonVersion;
|
|
@@ -1509,7 +1514,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1509
1514
|
}, {
|
|
1510
1515
|
key: "reWriteJsonAttribute",
|
|
1511
1516
|
value: (function () {
|
|
1512
|
-
var _reWriteJsonAttribute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1517
|
+
var _reWriteJsonAttribute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(path) {
|
|
1513
1518
|
var json,
|
|
1514
1519
|
_len9,
|
|
1515
1520
|
attrs,
|
|
@@ -1517,27 +1522,27 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1517
1522
|
_i2,
|
|
1518
1523
|
_attrs,
|
|
1519
1524
|
attr,
|
|
1520
|
-
|
|
1521
|
-
return _regenerator["default"].wrap(function
|
|
1522
|
-
while (1) switch (
|
|
1525
|
+
_args21 = arguments;
|
|
1526
|
+
return _regenerator["default"].wrap(function _callee20$(_context21) {
|
|
1527
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1523
1528
|
case 0:
|
|
1524
1529
|
if (!_lodash["default"].isEqual("json", this.getPathInfo(path).extension)) {
|
|
1525
|
-
|
|
1530
|
+
_context21.next = 17;
|
|
1526
1531
|
break;
|
|
1527
1532
|
}
|
|
1528
1533
|
json = this.getJsonObjByFilePath(path);
|
|
1529
|
-
for (_len9 =
|
|
1530
|
-
attrs[_key9 - 1] =
|
|
1534
|
+
for (_len9 = _args21.length, attrs = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
|
|
1535
|
+
attrs[_key9 - 1] = _args21[_key9];
|
|
1531
1536
|
}
|
|
1532
1537
|
_i2 = 0, _attrs = attrs;
|
|
1533
1538
|
case 4:
|
|
1534
1539
|
if (!(_i2 < _attrs.length)) {
|
|
1535
|
-
|
|
1540
|
+
_context21.next = 12;
|
|
1536
1541
|
break;
|
|
1537
1542
|
}
|
|
1538
1543
|
attr = _attrs[_i2];
|
|
1539
1544
|
if (_lodash["default"].isObject(attr)) {
|
|
1540
|
-
|
|
1545
|
+
_context21.next = 8;
|
|
1541
1546
|
break;
|
|
1542
1547
|
}
|
|
1543
1548
|
throw new _index2["default"](9999, "84451515 attr is not object, which is 'type=".concat((0, _typeof2["default"])(attr), " => ").concat(attr, "'"));
|
|
@@ -1545,13 +1550,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1545
1550
|
json[this.getObjectKey(attr)] = this.getObjectValue(attr);
|
|
1546
1551
|
case 9:
|
|
1547
1552
|
_i2++;
|
|
1548
|
-
|
|
1553
|
+
_context21.next = 4;
|
|
1549
1554
|
break;
|
|
1550
1555
|
case 12:
|
|
1551
|
-
|
|
1556
|
+
_context21.next = 14;
|
|
1552
1557
|
return this.writeJsonThanPrettier(path, json);
|
|
1553
1558
|
case 14:
|
|
1554
|
-
return
|
|
1559
|
+
return _context21.abrupt("return", {
|
|
1555
1560
|
version: json.version,
|
|
1556
1561
|
moduleName: json.name
|
|
1557
1562
|
});
|
|
@@ -1559,11 +1564,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1559
1564
|
throw new _index2["default"](9999, "reWriteJsonAttribute() => path is not package.json, which is ".concat(path));
|
|
1560
1565
|
case 18:
|
|
1561
1566
|
case "end":
|
|
1562
|
-
return
|
|
1567
|
+
return _context21.stop();
|
|
1563
1568
|
}
|
|
1564
|
-
},
|
|
1569
|
+
}, _callee20, this);
|
|
1565
1570
|
}));
|
|
1566
|
-
function reWriteJsonAttribute(
|
|
1571
|
+
function reWriteJsonAttribute(_x24) {
|
|
1567
1572
|
return _reWriteJsonAttribute.apply(this, arguments);
|
|
1568
1573
|
}
|
|
1569
1574
|
return reWriteJsonAttribute;
|
|
@@ -1602,7 +1607,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1602
1607
|
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
1603
1608
|
if (_lodash["default"].isEqual(this.getExtensionFromPath(path), "js")) {
|
|
1604
1609
|
var _source$key;
|
|
1605
|
-
var source = require(
|
|
1610
|
+
var source = require(_path4["default"].resolve(path))["default"];
|
|
1606
1611
|
return (_source$key = source[key]) !== null && _source$key !== void 0 ? _source$key : defaultValue;
|
|
1607
1612
|
} else {
|
|
1608
1613
|
throw new _index2["default"](8020, "path is not js file, which is ".concat(path));
|
|
@@ -1616,7 +1621,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1616
1621
|
}, {
|
|
1617
1622
|
key: "rewriteAttributeOfSourceJs",
|
|
1618
1623
|
value: (function () {
|
|
1619
|
-
var _rewriteAttributeOfSourceJs = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1624
|
+
var _rewriteAttributeOfSourceJs = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21(path) {
|
|
1620
1625
|
var _this8 = this;
|
|
1621
1626
|
var _len10,
|
|
1622
1627
|
attrs,
|
|
@@ -1624,27 +1629,27 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1624
1629
|
_loop2,
|
|
1625
1630
|
_i3,
|
|
1626
1631
|
_attrs2,
|
|
1627
|
-
|
|
1628
|
-
return _regenerator["default"].wrap(function
|
|
1629
|
-
while (1) switch (
|
|
1632
|
+
_args23 = arguments;
|
|
1633
|
+
return _regenerator["default"].wrap(function _callee21$(_context23) {
|
|
1634
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1630
1635
|
case 0:
|
|
1631
1636
|
if (this.isPathExist(path)) {
|
|
1632
|
-
|
|
1637
|
+
_context23.next = 2;
|
|
1633
1638
|
break;
|
|
1634
1639
|
}
|
|
1635
1640
|
throw new _index2["default"](9999, "4849813 ".concat(path, " is not exist"));
|
|
1636
1641
|
case 2:
|
|
1637
|
-
for (_len10 =
|
|
1638
|
-
attrs[_key10 - 1] =
|
|
1642
|
+
for (_len10 = _args23.length, attrs = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
|
|
1643
|
+
attrs[_key10 - 1] = _args23[_key10];
|
|
1639
1644
|
}
|
|
1640
1645
|
_loop2 = /*#__PURE__*/_regenerator["default"].mark(function _loop2() {
|
|
1641
1646
|
var attr, key, value, contents, index;
|
|
1642
|
-
return _regenerator["default"].wrap(function _loop2$(
|
|
1643
|
-
while (1) switch (
|
|
1647
|
+
return _regenerator["default"].wrap(function _loop2$(_context22) {
|
|
1648
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1644
1649
|
case 0:
|
|
1645
1650
|
attr = _attrs2[_i3];
|
|
1646
1651
|
if (_lodash["default"].isObject(attr)) {
|
|
1647
|
-
|
|
1652
|
+
_context22.next = 3;
|
|
1648
1653
|
break;
|
|
1649
1654
|
}
|
|
1650
1655
|
throw new _index2["default"](9999, "4984651 attr is not object, which is 'type=".concat((0, _typeof2["default"])(attr), " => ").concat(attr, "'"));
|
|
@@ -1660,30 +1665,30 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1660
1665
|
_this8.appendFile(path, contents.join("\n"), true, true);
|
|
1661
1666
|
case 9:
|
|
1662
1667
|
case "end":
|
|
1663
|
-
return
|
|
1668
|
+
return _context22.stop();
|
|
1664
1669
|
}
|
|
1665
1670
|
}, _loop2);
|
|
1666
1671
|
});
|
|
1667
1672
|
_i3 = 0, _attrs2 = attrs;
|
|
1668
1673
|
case 5:
|
|
1669
1674
|
if (!(_i3 < _attrs2.length)) {
|
|
1670
|
-
|
|
1675
|
+
_context23.next = 10;
|
|
1671
1676
|
break;
|
|
1672
1677
|
}
|
|
1673
|
-
return
|
|
1678
|
+
return _context23.delegateYield(_loop2(), "t0", 7);
|
|
1674
1679
|
case 7:
|
|
1675
1680
|
_i3++;
|
|
1676
|
-
|
|
1681
|
+
_context23.next = 5;
|
|
1677
1682
|
break;
|
|
1678
1683
|
case 10:
|
|
1679
|
-
return
|
|
1684
|
+
return _context23.abrupt("return", attrs);
|
|
1680
1685
|
case 11:
|
|
1681
1686
|
case "end":
|
|
1682
|
-
return
|
|
1687
|
+
return _context23.stop();
|
|
1683
1688
|
}
|
|
1684
|
-
},
|
|
1689
|
+
}, _callee21, this);
|
|
1685
1690
|
}));
|
|
1686
|
-
function rewriteAttributeOfSourceJs(
|
|
1691
|
+
function rewriteAttributeOfSourceJs(_x25) {
|
|
1687
1692
|
return _rewriteAttributeOfSourceJs.apply(this, arguments);
|
|
1688
1693
|
}
|
|
1689
1694
|
return rewriteAttributeOfSourceJs;
|
|
@@ -1691,27 +1696,27 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1691
1696
|
}, {
|
|
1692
1697
|
key: "getAnswerFromPromptQ",
|
|
1693
1698
|
value: function () {
|
|
1694
|
-
var _getAnswerFromPromptQ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1699
|
+
var _getAnswerFromPromptQ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee22() {
|
|
1695
1700
|
var configs,
|
|
1696
|
-
|
|
1697
|
-
return _regenerator["default"].wrap(function
|
|
1698
|
-
while (1) switch (
|
|
1701
|
+
_args24 = arguments;
|
|
1702
|
+
return _regenerator["default"].wrap(function _callee22$(_context24) {
|
|
1703
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1699
1704
|
case 0:
|
|
1700
|
-
configs =
|
|
1705
|
+
configs = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : [{
|
|
1701
1706
|
name: "name",
|
|
1702
1707
|
require: true,
|
|
1703
1708
|
description: "type the name"
|
|
1704
1709
|
}];
|
|
1705
1710
|
_prompt["default"].start();
|
|
1706
|
-
|
|
1711
|
+
_context24.next = 4;
|
|
1707
1712
|
return _prompt["default"].get(configs);
|
|
1708
1713
|
case 4:
|
|
1709
|
-
return
|
|
1714
|
+
return _context24.abrupt("return", _context24.sent);
|
|
1710
1715
|
case 5:
|
|
1711
1716
|
case "end":
|
|
1712
|
-
return
|
|
1717
|
+
return _context24.stop();
|
|
1713
1718
|
}
|
|
1714
|
-
},
|
|
1719
|
+
}, _callee22);
|
|
1715
1720
|
}));
|
|
1716
1721
|
function getAnswerFromPromptQ() {
|
|
1717
1722
|
return _getAnswerFromPromptQ.apply(this, arguments);
|
|
@@ -1734,27 +1739,27 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1734
1739
|
}, {
|
|
1735
1740
|
key: "getObjectFromPromptQ",
|
|
1736
1741
|
value: (function () {
|
|
1737
|
-
var _getObjectFromPromptQ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1742
|
+
var _getObjectFromPromptQ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee23() {
|
|
1738
1743
|
var _len11,
|
|
1739
1744
|
configs,
|
|
1740
1745
|
_key11,
|
|
1741
|
-
|
|
1742
|
-
return _regenerator["default"].wrap(function
|
|
1743
|
-
while (1) switch (
|
|
1746
|
+
_args25 = arguments;
|
|
1747
|
+
return _regenerator["default"].wrap(function _callee23$(_context25) {
|
|
1748
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1744
1749
|
case 0:
|
|
1745
1750
|
_prompt["default"].start();
|
|
1746
|
-
for (_len11 =
|
|
1747
|
-
configs[_key11] =
|
|
1751
|
+
for (_len11 = _args25.length, configs = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
|
|
1752
|
+
configs[_key11] = _args25[_key11];
|
|
1748
1753
|
}
|
|
1749
|
-
|
|
1754
|
+
_context25.next = 4;
|
|
1750
1755
|
return _prompt["default"].get(configs);
|
|
1751
1756
|
case 4:
|
|
1752
|
-
return
|
|
1757
|
+
return _context25.abrupt("return", _context25.sent);
|
|
1753
1758
|
case 5:
|
|
1754
1759
|
case "end":
|
|
1755
|
-
return
|
|
1760
|
+
return _context25.stop();
|
|
1756
1761
|
}
|
|
1757
|
-
},
|
|
1762
|
+
}, _callee23);
|
|
1758
1763
|
}));
|
|
1759
1764
|
function getObjectFromPromptQ() {
|
|
1760
1765
|
return _getObjectFromPromptQ.apply(this, arguments);
|
|
@@ -1764,30 +1769,30 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1764
1769
|
}, {
|
|
1765
1770
|
key: "generateTempFolderWithCleanSrc",
|
|
1766
1771
|
value: (function () {
|
|
1767
|
-
var _generateTempFolderWithCleanSrc = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
1768
|
-
var sourceFile, tempFolderPath,
|
|
1769
|
-
return _regenerator["default"].wrap(function
|
|
1770
|
-
while (1) switch (
|
|
1772
|
+
var _generateTempFolderWithCleanSrc = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(path) {
|
|
1773
|
+
var sourceFile, tempFolderPath, _iterator11, _step11, file, tempFilePath, stmts, indexOfStart, indexOfEnd;
|
|
1774
|
+
return _regenerator["default"].wrap(function _callee24$(_context26) {
|
|
1775
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1771
1776
|
case 0:
|
|
1772
1777
|
this.appendInfo("generateTempFolderWithCleanSrc", path);
|
|
1773
|
-
sourceFile =
|
|
1774
|
-
tempFolderPath =
|
|
1778
|
+
sourceFile = _path4["default"].join(path, "src");
|
|
1779
|
+
tempFolderPath = _path4["default"].join(path, "temp");
|
|
1775
1780
|
if (!_fs["default"].existsSync(sourceFile)) {
|
|
1776
|
-
|
|
1781
|
+
_context26.next = 31;
|
|
1777
1782
|
break;
|
|
1778
1783
|
}
|
|
1779
1784
|
this.appendInfo("generateTempFolderWithCleanSrc", "source", sourceFile);
|
|
1780
1785
|
this.persistByPath(tempFolderPath);
|
|
1781
1786
|
this.copyFromFolderToDestFolder(sourceFile, tempFolderPath);
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1787
|
+
_iterator11 = _createForOfIteratorHelper(this.findFilePathBy(tempFolderPath));
|
|
1788
|
+
_context26.prev = 8;
|
|
1789
|
+
_iterator11.s();
|
|
1785
1790
|
case 10:
|
|
1786
|
-
if ((
|
|
1787
|
-
|
|
1791
|
+
if ((_step11 = _iterator11.n()).done) {
|
|
1792
|
+
_context26.next = 23;
|
|
1788
1793
|
break;
|
|
1789
1794
|
}
|
|
1790
|
-
file =
|
|
1795
|
+
file = _step11.value;
|
|
1791
1796
|
tempFilePath = file.absolute;
|
|
1792
1797
|
stmts = this.getFileContextInRaw(tempFilePath).split("\n").map(function (line) {
|
|
1793
1798
|
return _lodash["default"].trim(line);
|
|
@@ -1801,37 +1806,37 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1801
1806
|
return _lodash["default"].isEqual(stmt, "}");
|
|
1802
1807
|
});
|
|
1803
1808
|
if (!(indexOfEnd > 0 && indexOfStart > 0 && indexOfEnd > indexOfStart)) {
|
|
1804
|
-
|
|
1809
|
+
_context26.next = 21;
|
|
1805
1810
|
break;
|
|
1806
1811
|
}
|
|
1807
1812
|
/** 刪除掉 if(configerer.DEBUG) {...........} */
|
|
1808
1813
|
this.dropItemsByIndex(stmts, indexOfStart, indexOfEnd);
|
|
1809
1814
|
this.appendFile(tempFilePath, _lodash["default"].join(stmts, "\n"), true, true);
|
|
1810
|
-
|
|
1811
|
-
return this.executeCommandLine("cd ".concat(
|
|
1815
|
+
_context26.next = 21;
|
|
1816
|
+
return this.executeCommandLine("cd ".concat(_path4["default"].resolve("".concat(this.getFileDirPath(tempFilePath))), " &&\nnpx prettier --write ").concat(tempFilePath));
|
|
1812
1817
|
case 21:
|
|
1813
|
-
|
|
1818
|
+
_context26.next = 10;
|
|
1814
1819
|
break;
|
|
1815
1820
|
case 23:
|
|
1816
|
-
|
|
1821
|
+
_context26.next = 28;
|
|
1817
1822
|
break;
|
|
1818
1823
|
case 25:
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1824
|
+
_context26.prev = 25;
|
|
1825
|
+
_context26.t0 = _context26["catch"](8);
|
|
1826
|
+
_iterator11.e(_context26.t0);
|
|
1822
1827
|
case 28:
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
return
|
|
1828
|
+
_context26.prev = 28;
|
|
1829
|
+
_iterator11.f();
|
|
1830
|
+
return _context26.finish(28);
|
|
1826
1831
|
case 31:
|
|
1827
|
-
return
|
|
1832
|
+
return _context26.abrupt("return", tempFolderPath);
|
|
1828
1833
|
case 32:
|
|
1829
1834
|
case "end":
|
|
1830
|
-
return
|
|
1835
|
+
return _context26.stop();
|
|
1831
1836
|
}
|
|
1832
|
-
},
|
|
1837
|
+
}, _callee24, this, [[8, 25, 28, 31]]);
|
|
1833
1838
|
}));
|
|
1834
|
-
function generateTempFolderWithCleanSrc(
|
|
1839
|
+
function generateTempFolderWithCleanSrc(_x26) {
|
|
1835
1840
|
return _generateTempFolderWithCleanSrc.apply(this, arguments);
|
|
1836
1841
|
}
|
|
1837
1842
|
return generateTempFolderWithCleanSrc;
|
|
@@ -1843,11 +1848,11 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1843
1848
|
)
|
|
1844
1849
|
}, {
|
|
1845
1850
|
key: "rewriteFile2File",
|
|
1846
|
-
value: function rewriteFile2File(from,
|
|
1851
|
+
value: function rewriteFile2File(from, to) {
|
|
1847
1852
|
var content = this.getFileContextInRaw(from);
|
|
1848
|
-
if (
|
|
1849
|
-
this.appendFile(
|
|
1850
|
-
this.appendInfo("rewrite from:".concat(from, " =>
|
|
1853
|
+
if (!content.trim()) throw new _index2["default"](9999, "".concat(from, " \u70BA\u7A7A\uFF0C\u907F\u514D\u8986\u84CB"));
|
|
1854
|
+
this.appendFile(to, content, true, true);
|
|
1855
|
+
this.appendInfo("rewrite from:".concat(from, " => to:").concat(to, " \u6210\u529F"));
|
|
1851
1856
|
}
|
|
1852
1857
|
|
|
1853
1858
|
/** 取得file第一行statement */
|