utiller 1.0.23
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/index.js +21 -0
- package/lib/exceptioner/ERRORs.js +191 -0
- package/lib/exceptioner/index.js +89 -0
- package/lib/index.js +39 -0
- package/lib/pooller/index.js +1249 -0
- package/lib/utiller/index.js +1439 -0
- package/lib/utiller/nodeutiller.js +1745 -0
- package/package.json +33 -0
- package/template/sample.babel.config.js +18 -0
- package/template/sample.index.js +21 -0
- package/template/sample.package.json +29 -0
- package/template/sample.src.index.js +23 -0
- package/template/sample.warning.index.js +1 -0
|
@@ -0,0 +1,1745 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
20
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
21
|
+
|
|
22
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
|
+
|
|
24
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
25
|
+
|
|
26
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
27
|
+
|
|
28
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
29
|
+
|
|
30
|
+
var _path5 = _interopRequireDefault(require("path"));
|
|
31
|
+
|
|
32
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
33
|
+
|
|
34
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
35
|
+
|
|
36
|
+
var _child_process = _interopRequireDefault(require("child_process"));
|
|
37
|
+
|
|
38
|
+
var _configer = require("configer");
|
|
39
|
+
|
|
40
|
+
var _index = _interopRequireDefault(require("./index"));
|
|
41
|
+
|
|
42
|
+
var _index2 = _interopRequireDefault(require("../exceptioner/index"));
|
|
43
|
+
|
|
44
|
+
var _pdfParse = _interopRequireDefault(require("pdf-parse"));
|
|
45
|
+
|
|
46
|
+
var _del = _interopRequireDefault(require("del"));
|
|
47
|
+
|
|
48
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
49
|
+
|
|
50
|
+
var _prompt = _interopRequireDefault(require("prompt"));
|
|
51
|
+
|
|
52
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
53
|
+
|
|
54
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
55
|
+
|
|
56
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
57
|
+
|
|
58
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
59
|
+
|
|
60
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
61
|
+
|
|
62
|
+
var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
63
|
+
(0, _inherits2["default"])(NodeUtiller, _Utiller);
|
|
64
|
+
|
|
65
|
+
var _super = _createSuper(NodeUtiller);
|
|
66
|
+
|
|
67
|
+
function NodeUtiller() {
|
|
68
|
+
var _this;
|
|
69
|
+
|
|
70
|
+
(0, _classCallCheck2["default"])(this, NodeUtiller);
|
|
71
|
+
|
|
72
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
73
|
+
args[_key] = arguments[_key];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
77
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "findFilePathBy", function (path) {
|
|
78
|
+
var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (each) {
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
if (!_fs["default"].existsSync(path)) return [];
|
|
82
|
+
|
|
83
|
+
var list = _fs["default"].readdirSync(path);
|
|
84
|
+
|
|
85
|
+
var files = [];
|
|
86
|
+
|
|
87
|
+
for (var _len2 = arguments.length, excludes = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
88
|
+
excludes[_key2 - 2] = arguments[_key2];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var _iterator = _createForOfIteratorHelper(list),
|
|
92
|
+
_step;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
96
|
+
var item = _step.value;
|
|
97
|
+
if (_lodash["default"].includes(excludes, item)) continue;
|
|
98
|
+
|
|
99
|
+
var currentpath = _path5["default"].join(path, item);
|
|
100
|
+
|
|
101
|
+
if (_fs["default"].lstatSync(currentpath).isDirectory()) {
|
|
102
|
+
var _this2;
|
|
103
|
+
|
|
104
|
+
files.push.apply(files, (0, _toConsumableArray2["default"])((_this2 = _this).findFilePathBy.apply(_this2, [currentpath, predicate].concat(excludes))));
|
|
105
|
+
} else if (_fs["default"].lstatSync(currentpath).isFile()) {
|
|
106
|
+
var pathInfo = _this.getPathInfo(currentpath);
|
|
107
|
+
|
|
108
|
+
if (predicate(pathInfo)) {
|
|
109
|
+
files.push(pathInfo);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
throw new _index2["default"](8003, item, currentpath);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
_iterator.e(err);
|
|
117
|
+
} finally {
|
|
118
|
+
_iterator.f();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return files;
|
|
122
|
+
});
|
|
123
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "findFilePathByExtension", function (rootpath) {
|
|
124
|
+
var _this3;
|
|
125
|
+
|
|
126
|
+
var _extension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
127
|
+
|
|
128
|
+
var reg = new RegExp("^[^.].+.(".concat(_lodash["default"].join(_extension, "|"), ")$"));
|
|
129
|
+
|
|
130
|
+
for (var _len3 = arguments.length, exclude = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
131
|
+
exclude[_key3 - 2] = arguments[_key3];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (_this3 = _this).findFilePathBy.apply(_this3, [rootpath, function (item) {
|
|
135
|
+
return reg.test(item.fileNameExtension);
|
|
136
|
+
}].concat(exclude));
|
|
137
|
+
});
|
|
138
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "executeCommandLine", /*#__PURE__*/function () {
|
|
139
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(command) {
|
|
140
|
+
var self;
|
|
141
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
142
|
+
while (1) {
|
|
143
|
+
switch (_context.prev = _context.next) {
|
|
144
|
+
case 0:
|
|
145
|
+
self = (0, _assertThisInitialized2["default"])(_this);
|
|
146
|
+
|
|
147
|
+
_this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
|
|
148
|
+
|
|
149
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
150
|
+
_child_process["default"].exec(command, function (error, stdout, stderr) {
|
|
151
|
+
self.appendInfo("".concat(stdout));
|
|
152
|
+
self.appendInfo("".concat(stderr));
|
|
153
|
+
|
|
154
|
+
if (error) {
|
|
155
|
+
self.appendError("\u57F7\u884C\u932F\u8AA4: ".concat(error));
|
|
156
|
+
reject(error);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
resolve(stdout.trim());
|
|
161
|
+
});
|
|
162
|
+
}));
|
|
163
|
+
|
|
164
|
+
case 3:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context.stop();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, _callee);
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
return function (_x) {
|
|
173
|
+
return _ref.apply(this, arguments);
|
|
174
|
+
};
|
|
175
|
+
}());
|
|
176
|
+
return _this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
(0, _createClass2["default"])(NodeUtiller, [{
|
|
180
|
+
key: "findSpecificFolderByPath",
|
|
181
|
+
value:
|
|
182
|
+
/**================================= only in node.js ================================= */
|
|
183
|
+
function findSpecificFolderByPath(path, folderName) {
|
|
184
|
+
var absolute = _path5["default"].resolve(path);
|
|
185
|
+
|
|
186
|
+
var splited = absolute.split("/");
|
|
187
|
+
|
|
188
|
+
while (!_fs["default"].existsSync("".concat(splited.join("/"), "/").concat(folderName)) && splited.length > 0) {
|
|
189
|
+
splited.pop();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return "".concat(splited.join("/"), "/.idea");
|
|
193
|
+
}
|
|
194
|
+
/** path ==> /asd/cc/dfj/jei3.mp3 => */
|
|
195
|
+
|
|
196
|
+
}, {
|
|
197
|
+
key: "isPathEqualsFileType",
|
|
198
|
+
value: function isPathEqualsFileType(path, type) {
|
|
199
|
+
var extension = path.split(".").pop();
|
|
200
|
+
return _lodash["default"].isEqual(extension, type);
|
|
201
|
+
}
|
|
202
|
+
/** {numpages, numrender, info, text, version} */
|
|
203
|
+
|
|
204
|
+
}, {
|
|
205
|
+
key: "getPDFText",
|
|
206
|
+
value: function () {
|
|
207
|
+
var _getPDFText = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(path) {
|
|
208
|
+
var dataBuffer;
|
|
209
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
210
|
+
while (1) {
|
|
211
|
+
switch (_context2.prev = _context2.next) {
|
|
212
|
+
case 0:
|
|
213
|
+
dataBuffer = _fs["default"].readFileSync(path);
|
|
214
|
+
return _context2.abrupt("return", (0, _pdfParse["default"])(dataBuffer).then(function (data) {
|
|
215
|
+
return data;
|
|
216
|
+
}));
|
|
217
|
+
|
|
218
|
+
case 2:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context2.stop();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}, _callee2);
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
function getPDFText(_x2) {
|
|
227
|
+
return _getPDFText.apply(this, arguments);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return getPDFText;
|
|
231
|
+
}()
|
|
232
|
+
}, {
|
|
233
|
+
key: "printf",
|
|
234
|
+
value: function printf() {
|
|
235
|
+
this.appendInfo("i can use in node.js only yo yo");
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 遞回的去找出folder每一個child file, 預設是全部檔案, 可以透過predicate做filter, 可以exclude 指定的 'folder name'
|
|
239
|
+
*
|
|
240
|
+
* predicate: predicate(pathInfo); predicate帶的參數是 pathInfo object
|
|
241
|
+
*
|
|
242
|
+
* excludes 忽略掉的資料夾名稱
|
|
243
|
+
*
|
|
244
|
+
* return [...{
|
|
245
|
+
path: 'database/index.js',
|
|
246
|
+
fileName: 'index',
|
|
247
|
+
extension: 'js',
|
|
248
|
+
dirName: database
|
|
249
|
+
absolute: '/Users/davidtu/cross-achieve/mimi19up/mimi19up-scrapy/database/index.js'}
|
|
250
|
+
] */
|
|
251
|
+
|
|
252
|
+
}, {
|
|
253
|
+
key: "isPathExist",
|
|
254
|
+
value: function isPathExist(path) {
|
|
255
|
+
return _fs["default"].existsSync(path);
|
|
256
|
+
}
|
|
257
|
+
/** path = a/b/c/file.js , newName = 'two'
|
|
258
|
+
* output => a/b/c/two.js
|
|
259
|
+
* */
|
|
260
|
+
|
|
261
|
+
}, {
|
|
262
|
+
key: "renameFile",
|
|
263
|
+
value: function renameFile(path) {
|
|
264
|
+
var newName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "fileName";
|
|
265
|
+
|
|
266
|
+
if (!this.isPathExist(path) || !this.isFile(path)) {
|
|
267
|
+
this.appendError("984521 path not exist or not a file path");
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (_lodash["default"].isEmpty(newName)) {
|
|
272
|
+
this.appendError("984522,new name is empty");
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var next = _path5["default"].join(this.getFileDirPath(path), "".concat(newName, ".").concat(this.getExtensionFromPath(path)));
|
|
277
|
+
|
|
278
|
+
_fs["default"].renameSync(path, next);
|
|
279
|
+
} //todo 應該要改成class
|
|
280
|
+
|
|
281
|
+
}, {
|
|
282
|
+
key: "getPathInfo",
|
|
283
|
+
value: function getPathInfo(path) {
|
|
284
|
+
var absolute = _path5["default"].resolve(path);
|
|
285
|
+
|
|
286
|
+
var obj = {
|
|
287
|
+
path: path,
|
|
288
|
+
absolute: absolute,
|
|
289
|
+
isFile: false,
|
|
290
|
+
isDirectory: true,
|
|
291
|
+
dirName: undefined,
|
|
292
|
+
extension: undefined,
|
|
293
|
+
fileName: undefined,
|
|
294
|
+
fileNameExtension: undefined,
|
|
295
|
+
lastModifiedTime: undefined
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
if (this.isFile(absolute)) {
|
|
299
|
+
obj["extension"] = absolute.split(".").pop();
|
|
300
|
+
var fileNameStrings = absolute.split("/").pop().split(".");
|
|
301
|
+
fileNameStrings.pop();
|
|
302
|
+
/** 要是遇到 asd.sdsd.js 就麻煩了 */
|
|
303
|
+
|
|
304
|
+
obj["fileName"] = fileNameStrings.join(".");
|
|
305
|
+
obj["dirName"] = _lodash["default"].nth(absolute.split("/"), -2);
|
|
306
|
+
obj["isFile"] = true;
|
|
307
|
+
obj["isDirectory"] = false;
|
|
308
|
+
obj["fileNameExtension"] = "".concat(obj.fileName, ".").concat(obj.extension);
|
|
309
|
+
obj["lastModifiedTime"] = this.getFileLastModifiedTime(absolute);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (this.isDirectory(absolute)) {
|
|
313
|
+
obj["dirName"] = absolute.split("/").pop();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return obj;
|
|
317
|
+
}
|
|
318
|
+
/** return [...{path: ,fileName: ,extension: ,absolute: ,dirName:}]*/
|
|
319
|
+
|
|
320
|
+
}, {
|
|
321
|
+
key: "syncExecuteCommandLine",
|
|
322
|
+
value: function syncExecuteCommandLine(command) {
|
|
323
|
+
var self = this;
|
|
324
|
+
this.appendInfo("\u57F7\u884C\u8173\u672C ".concat(command));
|
|
325
|
+
|
|
326
|
+
_child_process["default"].exec("".concat(command), function (error, stdout, stderr) {
|
|
327
|
+
self.appendInfo("".concat(stdout));
|
|
328
|
+
self.appendInfo("".concat(stderr));
|
|
329
|
+
|
|
330
|
+
if (error !== null) {
|
|
331
|
+
self.appendError("exec error: ".concat(error));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}, {
|
|
336
|
+
key: "persistByPath",
|
|
337
|
+
value:
|
|
338
|
+
/** '/a/b/c.js' 把它變成真的 */
|
|
339
|
+
function persistByPath(path) {
|
|
340
|
+
var dirs = _lodash["default"].split(path, "/");
|
|
341
|
+
|
|
342
|
+
for (var index = 0; index < dirs.length; index++) {
|
|
343
|
+
var currentPath = _lodash["default"].join(_lodash["default"].take(dirs, index + 1), "/");
|
|
344
|
+
/** 避免 /Users/davidtu/cross-achieve/ 這種狀況, 字串首是slash */
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
if (currentPath === "") continue;
|
|
348
|
+
|
|
349
|
+
var currentDir = _lodash["default"].nth(dirs, index);
|
|
350
|
+
|
|
351
|
+
var hasExtension = this.has(currentDir, ".") && !_lodash["default"].isEmpty(currentDir.split(".").pop());
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
if (!_fs["default"].existsSync(currentPath)) {
|
|
355
|
+
if (hasExtension) {
|
|
356
|
+
_fs["default"].openSync(currentPath, "wx");
|
|
357
|
+
} else {
|
|
358
|
+
_fs["default"].mkdirSync(currentPath);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw new _index2["default"](8008, "currentPath => ".concat(currentPath), error);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return _path5["default"].resolve(path);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* filter:function, 就filter,(path) => {要就true}
|
|
370
|
+
* override: boolean, 要不要override檔案:default true;
|
|
371
|
+
* preserveTimestamps : boolean, 要不要保留原始檔案的時間, 不然就是cp的時間,default true;
|
|
372
|
+
* */
|
|
373
|
+
|
|
374
|
+
}, {
|
|
375
|
+
key: "copyFromFolderToDestFolder",
|
|
376
|
+
value: function copyFromFolderToDestFolder(from, dest) {
|
|
377
|
+
var override = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
378
|
+
var preserveTimestamps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
379
|
+
var filter = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function () {
|
|
380
|
+
return true;
|
|
381
|
+
};
|
|
382
|
+
if (!_fs["default"].existsSync(from) || !_fs["default"].existsSync(from)) throw new _index2["default"](8009, "".concat(from, " or ").concat(dest, " is not exist!"));
|
|
383
|
+
this.appendInfo("\u6B63\u5728\u8907\u88FDing ".concat(from, "/* => ").concat(dest, "/* succeed"));
|
|
384
|
+
|
|
385
|
+
_fsExtra["default"].copySync(from, dest, {
|
|
386
|
+
preserveTimestamps: preserveTimestamps,
|
|
387
|
+
override: override,
|
|
388
|
+
filter: filter
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
this.appendInfo("\u8907\u88FD\u6210\u529F ".concat(from, "/* => ").concat(dest, "/* succeed"));
|
|
392
|
+
}
|
|
393
|
+
/** 取得檔案的目錄, path => c://folderName/fileName.js to c://folderName */
|
|
394
|
+
|
|
395
|
+
}, {
|
|
396
|
+
key: "getFileDirPath",
|
|
397
|
+
value: function getFileDirPath(path) {
|
|
398
|
+
var slash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
399
|
+
return _lodash["default"].join(_lodash["default"].initial(_lodash["default"].split(path, "/")), "/") + (slash ? "/" : "");
|
|
400
|
+
}
|
|
401
|
+
/** 刪掉自己, force能夠強制刪除 自己root_dir 以外的path */
|
|
402
|
+
|
|
403
|
+
}, {
|
|
404
|
+
key: "deleteSelfByPath",
|
|
405
|
+
value: function () {
|
|
406
|
+
var _deleteSelfByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(path, force) {
|
|
407
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
408
|
+
while (1) {
|
|
409
|
+
switch (_context3.prev = _context3.next) {
|
|
410
|
+
case 0:
|
|
411
|
+
if (!_fs["default"].existsSync(path)) {
|
|
412
|
+
_context3.next = 5;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
this.appendInfo("\u6E96\u5099\u522A\u6389 ".concat(path, ",{force:").concat(force, "}"));
|
|
417
|
+
_context3.next = 4;
|
|
418
|
+
return (0, _del["default"])(path, {
|
|
419
|
+
force: force
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
case 4:
|
|
423
|
+
this.appendInfo("\u6210\u529F\u522A\u6389\u4E86 ".concat(path));
|
|
424
|
+
|
|
425
|
+
case 5:
|
|
426
|
+
case "end":
|
|
427
|
+
return _context3.stop();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}, _callee3, this);
|
|
431
|
+
}));
|
|
432
|
+
|
|
433
|
+
function deleteSelfByPath(_x3, _x4) {
|
|
434
|
+
return _deleteSelfByPath.apply(this, arguments);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return deleteSelfByPath;
|
|
438
|
+
}()
|
|
439
|
+
/** absolute=> /acc/bbv/{target}/index.js 檢查有沒有在他下面 */
|
|
440
|
+
|
|
441
|
+
}, {
|
|
442
|
+
key: "isUnderTargetPath",
|
|
443
|
+
value: function isUnderTargetPath(absolute, target) {
|
|
444
|
+
var segments = absolute.split("/");
|
|
445
|
+
return this.has(segments, target);
|
|
446
|
+
}
|
|
447
|
+
/** 取得folder底下的file counts*/
|
|
448
|
+
|
|
449
|
+
}, {
|
|
450
|
+
key: "getFileCountsOfFolder",
|
|
451
|
+
value: function getFileCountsOfFolder(path) {
|
|
452
|
+
if (this.isDirectory(path)) {
|
|
453
|
+
return _fs["default"].readdirSync(path).length;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return -1;
|
|
457
|
+
}
|
|
458
|
+
/** 刪掉自己目錄內的孩子, force能夠強制刪除 自己root_dir 以外的path */
|
|
459
|
+
|
|
460
|
+
}, {
|
|
461
|
+
key: "deleteChildByPath",
|
|
462
|
+
value: function () {
|
|
463
|
+
var _deleteChildByPath = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(path) {
|
|
464
|
+
var force,
|
|
465
|
+
pathes,
|
|
466
|
+
_iterator2,
|
|
467
|
+
_step2,
|
|
468
|
+
_path2,
|
|
469
|
+
_args4 = arguments;
|
|
470
|
+
|
|
471
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
472
|
+
while (1) {
|
|
473
|
+
switch (_context4.prev = _context4.next) {
|
|
474
|
+
case 0:
|
|
475
|
+
force = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : false;
|
|
476
|
+
pathes = this.getChildPathByPath(path);
|
|
477
|
+
_iterator2 = _createForOfIteratorHelper(pathes);
|
|
478
|
+
_context4.prev = 3;
|
|
479
|
+
|
|
480
|
+
_iterator2.s();
|
|
481
|
+
|
|
482
|
+
case 5:
|
|
483
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
484
|
+
_context4.next = 11;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
_path2 = _step2.value;
|
|
489
|
+
_context4.next = 9;
|
|
490
|
+
return this.deleteSelfByPath(_path2.absolute, force);
|
|
491
|
+
|
|
492
|
+
case 9:
|
|
493
|
+
_context4.next = 5;
|
|
494
|
+
break;
|
|
495
|
+
|
|
496
|
+
case 11:
|
|
497
|
+
_context4.next = 16;
|
|
498
|
+
break;
|
|
499
|
+
|
|
500
|
+
case 13:
|
|
501
|
+
_context4.prev = 13;
|
|
502
|
+
_context4.t0 = _context4["catch"](3);
|
|
503
|
+
|
|
504
|
+
_iterator2.e(_context4.t0);
|
|
505
|
+
|
|
506
|
+
case 16:
|
|
507
|
+
_context4.prev = 16;
|
|
508
|
+
|
|
509
|
+
_iterator2.f();
|
|
510
|
+
|
|
511
|
+
return _context4.finish(16);
|
|
512
|
+
|
|
513
|
+
case 19:
|
|
514
|
+
case "end":
|
|
515
|
+
return _context4.stop();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}, _callee4, this, [[3, 13, 16, 19]]);
|
|
519
|
+
}));
|
|
520
|
+
|
|
521
|
+
function deleteChildByPath(_x5) {
|
|
522
|
+
return _deleteChildByPath.apply(this, arguments);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return deleteChildByPath;
|
|
526
|
+
}()
|
|
527
|
+
}, {
|
|
528
|
+
key: "reinstallNodeModules",
|
|
529
|
+
value: function () {
|
|
530
|
+
var _reinstallNodeModules = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
531
|
+
var path,
|
|
532
|
+
_len4,
|
|
533
|
+
exclude,
|
|
534
|
+
_key4,
|
|
535
|
+
ex,
|
|
536
|
+
paths,
|
|
537
|
+
_iterator3,
|
|
538
|
+
_step3,
|
|
539
|
+
_json,
|
|
540
|
+
path_module_root,
|
|
541
|
+
path_gen_node_module,
|
|
542
|
+
path_lock_json,
|
|
543
|
+
_iterator4,
|
|
544
|
+
_step4,
|
|
545
|
+
_json2,
|
|
546
|
+
_path_module_root,
|
|
547
|
+
_path_gen_node_module,
|
|
548
|
+
_args5 = arguments;
|
|
549
|
+
|
|
550
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
551
|
+
while (1) {
|
|
552
|
+
switch (_context5.prev = _context5.next) {
|
|
553
|
+
case 0:
|
|
554
|
+
path = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : "../";
|
|
555
|
+
|
|
556
|
+
for (_len4 = _args5.length, exclude = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
557
|
+
exclude[_key4 - 1] = _args5[_key4];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
ex = [].concat(exclude, ["node_modules", "utiller", "configer"]);
|
|
561
|
+
/** utiller 不能刪掉,不然就爆了, configer是他的依賴也不能刪 */
|
|
562
|
+
|
|
563
|
+
paths = this.findFilePathBy.apply(this, [path, function (each) {
|
|
564
|
+
return _lodash["default"].isEqual(each.fileNameExtension, "package.json");
|
|
565
|
+
}].concat((0, _toConsumableArray2["default"])(ex)));
|
|
566
|
+
_iterator3 = _createForOfIteratorHelper(paths);
|
|
567
|
+
_context5.prev = 5;
|
|
568
|
+
|
|
569
|
+
_iterator3.s();
|
|
570
|
+
|
|
571
|
+
case 7:
|
|
572
|
+
if ((_step3 = _iterator3.n()).done) {
|
|
573
|
+
_context5.next = 20;
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
_json = _step3.value;
|
|
578
|
+
path_module_root = this.getFileDirPath(_json.absolute);
|
|
579
|
+
path_gen_node_module = "".concat(path_module_root, "node_modules");
|
|
580
|
+
path_lock_json = "".concat(path_module_root, "package-lock.json");
|
|
581
|
+
_context5.next = 14;
|
|
582
|
+
return (0, _del["default"])(path_lock_json);
|
|
583
|
+
|
|
584
|
+
case 14:
|
|
585
|
+
this.appendInfo("\u522A\u6389\u4E86 ".concat(path_lock_json));
|
|
586
|
+
_context5.next = 17;
|
|
587
|
+
return (0, _del["default"])(path_gen_node_module);
|
|
588
|
+
|
|
589
|
+
case 17:
|
|
590
|
+
this.appendInfo("\u522A\u6389\u4E86 ".concat(path_gen_node_module));
|
|
591
|
+
|
|
592
|
+
case 18:
|
|
593
|
+
_context5.next = 7;
|
|
594
|
+
break;
|
|
595
|
+
|
|
596
|
+
case 20:
|
|
597
|
+
_context5.next = 25;
|
|
598
|
+
break;
|
|
599
|
+
|
|
600
|
+
case 22:
|
|
601
|
+
_context5.prev = 22;
|
|
602
|
+
_context5.t0 = _context5["catch"](5);
|
|
603
|
+
|
|
604
|
+
_iterator3.e(_context5.t0);
|
|
605
|
+
|
|
606
|
+
case 25:
|
|
607
|
+
_context5.prev = 25;
|
|
608
|
+
|
|
609
|
+
_iterator3.f();
|
|
610
|
+
|
|
611
|
+
return _context5.finish(25);
|
|
612
|
+
|
|
613
|
+
case 28:
|
|
614
|
+
_iterator4 = _createForOfIteratorHelper(paths);
|
|
615
|
+
_context5.prev = 29;
|
|
616
|
+
|
|
617
|
+
_iterator4.s();
|
|
618
|
+
|
|
619
|
+
case 31:
|
|
620
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
621
|
+
_context5.next = 40;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
_json2 = _step4.value;
|
|
626
|
+
_path_module_root = this.getFileDirPath(_json2.absolute);
|
|
627
|
+
_path_gen_node_module = "".concat(_path_module_root, "node_modules");
|
|
628
|
+
|
|
629
|
+
if (_fs["default"].existsSync(_path_gen_node_module)) {
|
|
630
|
+
_context5.next = 38;
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
_context5.next = 38;
|
|
635
|
+
return this.executeCommandLine("cd ".concat(_path_module_root, " && npm install"));
|
|
636
|
+
|
|
637
|
+
case 38:
|
|
638
|
+
_context5.next = 31;
|
|
639
|
+
break;
|
|
640
|
+
|
|
641
|
+
case 40:
|
|
642
|
+
_context5.next = 45;
|
|
643
|
+
break;
|
|
644
|
+
|
|
645
|
+
case 42:
|
|
646
|
+
_context5.prev = 42;
|
|
647
|
+
_context5.t1 = _context5["catch"](29);
|
|
648
|
+
|
|
649
|
+
_iterator4.e(_context5.t1);
|
|
650
|
+
|
|
651
|
+
case 45:
|
|
652
|
+
_context5.prev = 45;
|
|
653
|
+
|
|
654
|
+
_iterator4.f();
|
|
655
|
+
|
|
656
|
+
return _context5.finish(45);
|
|
657
|
+
|
|
658
|
+
case 48:
|
|
659
|
+
case "end":
|
|
660
|
+
return _context5.stop();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}, _callee5, this, [[5, 22, 25, 28], [29, 42, 45, 48]]);
|
|
664
|
+
}));
|
|
665
|
+
|
|
666
|
+
function reinstallNodeModules() {
|
|
667
|
+
return _reinstallNodeModules.apply(this, arguments);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return reinstallNodeModules;
|
|
671
|
+
}()
|
|
672
|
+
}, {
|
|
673
|
+
key: "deleteFileOrFolder",
|
|
674
|
+
value: function () {
|
|
675
|
+
var _deleteFileOrFolder = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(path) {
|
|
676
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
677
|
+
while (1) {
|
|
678
|
+
switch (_context6.prev = _context6.next) {
|
|
679
|
+
case 0:
|
|
680
|
+
this.appendInfo("\u522A\u6389\u4E86 ".concat(path));
|
|
681
|
+
_context6.next = 3;
|
|
682
|
+
return (0, _del["default"])(path);
|
|
683
|
+
|
|
684
|
+
case 3:
|
|
685
|
+
case "end":
|
|
686
|
+
return _context6.stop();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}, _callee6, this);
|
|
690
|
+
}));
|
|
691
|
+
|
|
692
|
+
function deleteFileOrFolder(_x6) {
|
|
693
|
+
return _deleteFileOrFolder.apply(this, arguments);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return deleteFileOrFolder;
|
|
697
|
+
}()
|
|
698
|
+
/** 拿到目錄下的資料夾列表 */
|
|
699
|
+
|
|
700
|
+
}, {
|
|
701
|
+
key: "getNamesOfFolderChild",
|
|
702
|
+
value: function getNamesOfFolderChild(path) {
|
|
703
|
+
return _lodash["default"].filter(this.getChildPathByPath(path), function (each) {
|
|
704
|
+
return each.isDirectory;
|
|
705
|
+
}).map(function (path) {
|
|
706
|
+
return path.dirName;
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
/** 從給的path 找到 one level 的 file/dir Path */
|
|
710
|
+
|
|
711
|
+
}, {
|
|
712
|
+
key: "getChildPathByPath",
|
|
713
|
+
value: function getChildPathByPath(_path) {
|
|
714
|
+
var _this4 = this;
|
|
715
|
+
|
|
716
|
+
try {
|
|
717
|
+
var files = _fs["default"].readdirSync(_path);
|
|
718
|
+
|
|
719
|
+
return files.map(function (file) {
|
|
720
|
+
return _this4.getPathInfo(_path5["default"].join(_path, file));
|
|
721
|
+
});
|
|
722
|
+
} catch (error) {
|
|
723
|
+
throw new _index2["default"](8002, error);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/** from :'./template/sample.babel.config.js
|
|
727
|
+
* destDir : '/template'
|
|
728
|
+
* fileName: 'fileName.extension' => 如果fileName 是 empty ,dest就是必須包含新檔名
|
|
729
|
+
* force 就是強制覆蓋他啦
|
|
730
|
+
* */
|
|
731
|
+
|
|
732
|
+
}, {
|
|
733
|
+
key: "copySingleFile",
|
|
734
|
+
value: function copySingleFile(from, dest, fileName) {
|
|
735
|
+
var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
736
|
+
var destination = _lodash["default"].isEmpty(fileName) ? dest : _path5["default"].join(dest, fileName);
|
|
737
|
+
if (_fs["default"].existsSync(destination) && !force) throw new _index2["default"](8006, destination);
|
|
738
|
+
|
|
739
|
+
_fs["default"].copyFileSync(from, destination);
|
|
740
|
+
}
|
|
741
|
+
}, {
|
|
742
|
+
key: "getNodeEnvVariable",
|
|
743
|
+
value: function getNodeEnvVariable(key) {
|
|
744
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
745
|
+
var value = process.env[key];
|
|
746
|
+
return value === undefined ? defaultValue : value;
|
|
747
|
+
}
|
|
748
|
+
}, {
|
|
749
|
+
key: "isDirectory",
|
|
750
|
+
value: function isDirectory(path) {
|
|
751
|
+
return _fs["default"].lstatSync(path).isDirectory();
|
|
752
|
+
}
|
|
753
|
+
}, {
|
|
754
|
+
key: "isFile",
|
|
755
|
+
value: function isFile(path) {
|
|
756
|
+
return _fs["default"].lstatSync(path).isFile();
|
|
757
|
+
}
|
|
758
|
+
}, {
|
|
759
|
+
key: "isImageFile",
|
|
760
|
+
value: function isImageFile(file) {
|
|
761
|
+
return this.isOrEquals(file.extension, "svg", "png", "jpg", "jpeg");
|
|
762
|
+
}
|
|
763
|
+
/** 把內容都抹掉each 是 fileName, ex:index.js*/
|
|
764
|
+
|
|
765
|
+
}, {
|
|
766
|
+
key: "cleanChildFiles",
|
|
767
|
+
value: function () {
|
|
768
|
+
var _cleanChildFiles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(path) {
|
|
769
|
+
var _this5 = this;
|
|
770
|
+
|
|
771
|
+
var predicate,
|
|
772
|
+
_len5,
|
|
773
|
+
exclude,
|
|
774
|
+
_key5,
|
|
775
|
+
files,
|
|
776
|
+
_iterator5,
|
|
777
|
+
_step5,
|
|
778
|
+
file,
|
|
779
|
+
_args7 = arguments;
|
|
780
|
+
|
|
781
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
782
|
+
while (1) {
|
|
783
|
+
switch (_context7.prev = _context7.next) {
|
|
784
|
+
case 0:
|
|
785
|
+
predicate = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : function (each) {
|
|
786
|
+
return true;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
if (!_fs["default"].existsSync(path)) {
|
|
790
|
+
_context7.next = 26;
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
for (_len5 = _args7.length, exclude = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
|
|
795
|
+
exclude[_key5 - 2] = _args7[_key5];
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
files = this.findFilePathBy.apply(this, [path, predicate].concat(exclude));
|
|
799
|
+
_iterator5 = _createForOfIteratorHelper(files);
|
|
800
|
+
_context7.prev = 5;
|
|
801
|
+
|
|
802
|
+
_iterator5.s();
|
|
803
|
+
|
|
804
|
+
case 7:
|
|
805
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
806
|
+
_context7.next = 15;
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
file = _step5.value;
|
|
811
|
+
|
|
812
|
+
if (!this.isImageFile(file)) {
|
|
813
|
+
_context7.next = 11;
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
return _context7.abrupt("continue", 13);
|
|
818
|
+
|
|
819
|
+
case 11:
|
|
820
|
+
_fs["default"].truncate(file.absolute, 0, function (result) {
|
|
821
|
+
if (!_lodash["default"].isUndefined(result) && !_lodash["default"].isNull(result)) _this5.appendInfo(result);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
this.appendInfo("".concat(file.absolute, " \u88AB\u6E05\u7684\u4E7E\u4E7E\u6DE8\u6DE8\uFF01"));
|
|
825
|
+
|
|
826
|
+
case 13:
|
|
827
|
+
_context7.next = 7;
|
|
828
|
+
break;
|
|
829
|
+
|
|
830
|
+
case 15:
|
|
831
|
+
_context7.next = 20;
|
|
832
|
+
break;
|
|
833
|
+
|
|
834
|
+
case 17:
|
|
835
|
+
_context7.prev = 17;
|
|
836
|
+
_context7.t0 = _context7["catch"](5);
|
|
837
|
+
|
|
838
|
+
_iterator5.e(_context7.t0);
|
|
839
|
+
|
|
840
|
+
case 20:
|
|
841
|
+
_context7.prev = 20;
|
|
842
|
+
|
|
843
|
+
_iterator5.f();
|
|
844
|
+
|
|
845
|
+
return _context7.finish(20);
|
|
846
|
+
|
|
847
|
+
case 23:
|
|
848
|
+
_context7.next = 25;
|
|
849
|
+
return this.syncDelay(500);
|
|
850
|
+
|
|
851
|
+
case 25:
|
|
852
|
+
return _context7.abrupt("return", files);
|
|
853
|
+
|
|
854
|
+
case 26:
|
|
855
|
+
return _context7.abrupt("return", false);
|
|
856
|
+
|
|
857
|
+
case 27:
|
|
858
|
+
case "end":
|
|
859
|
+
return _context7.stop();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}, _callee7, this, [[5, 17, 20, 23]]);
|
|
863
|
+
}));
|
|
864
|
+
|
|
865
|
+
function cleanChildFiles(_x7) {
|
|
866
|
+
return _cleanChildFiles.apply(this, arguments);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
return cleanChildFiles;
|
|
870
|
+
}()
|
|
871
|
+
}, {
|
|
872
|
+
key: "syncWithExistPackage",
|
|
873
|
+
value: function () {
|
|
874
|
+
var _syncWithExistPackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
|
|
875
|
+
var path,
|
|
876
|
+
paths,
|
|
877
|
+
_iterator6,
|
|
878
|
+
_step6,
|
|
879
|
+
_path3,
|
|
880
|
+
_args8 = arguments;
|
|
881
|
+
|
|
882
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
883
|
+
while (1) {
|
|
884
|
+
switch (_context8.prev = _context8.next) {
|
|
885
|
+
case 0:
|
|
886
|
+
path = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : "../";
|
|
887
|
+
|
|
888
|
+
/** 產生shell_script_腳本 */
|
|
889
|
+
paths = this.findFilePathBy(path, function (each) {
|
|
890
|
+
return _lodash["default"].isEqual(each.fileNameExtension, "package.json");
|
|
891
|
+
}, "node_modules");
|
|
892
|
+
_iterator6 = _createForOfIteratorHelper(paths);
|
|
893
|
+
|
|
894
|
+
try {
|
|
895
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
896
|
+
_path3 = _step6.value;
|
|
897
|
+
|
|
898
|
+
try {
|
|
899
|
+
if (!_lodash["default"].isEqual(_path3.dirName, "..")) this.insertShellCommand(_configer.configer.BASE_SHELL_SCRIPT, "cd_".concat(_path3.dirName), "cd ".concat(this.getFolderPathOfSpecificPath(_path3.absolute)));
|
|
900
|
+
} catch (error) {
|
|
901
|
+
this.appendInfo(error.message);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
} catch (err) {
|
|
905
|
+
_iterator6.e(err);
|
|
906
|
+
} finally {
|
|
907
|
+
_iterator6.f();
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
case 4:
|
|
911
|
+
case "end":
|
|
912
|
+
return _context8.stop();
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}, _callee8, this);
|
|
916
|
+
}));
|
|
917
|
+
|
|
918
|
+
function syncWithExistPackage() {
|
|
919
|
+
return _syncWithExistPackage.apply(this, arguments);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
return syncWithExistPackage;
|
|
923
|
+
}()
|
|
924
|
+
}, {
|
|
925
|
+
key: "packageTemplatify",
|
|
926
|
+
value: function () {
|
|
927
|
+
var _packageTemplatify = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(path, packageName) {
|
|
928
|
+
var _this6 = this;
|
|
929
|
+
|
|
930
|
+
var existFolders, dirPath, packagejson, classBase, ideaWorkspacePath, workspace, splited, indexOfRunManager, indexOfList;
|
|
931
|
+
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
932
|
+
while (1) {
|
|
933
|
+
switch (_context9.prev = _context9.next) {
|
|
934
|
+
case 0:
|
|
935
|
+
existFolders = this.getChildPathByPath(path).map(function (each) {
|
|
936
|
+
return each.absolute.split("/").pop();
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
if (!this.has(existFolders, packageName)) {
|
|
940
|
+
_context9.next = 3;
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
throw new _index2["default"](8004, " packageName ===> '".concat(packageName, "'"));
|
|
945
|
+
|
|
946
|
+
case 3:
|
|
947
|
+
dirPath = "".concat(path, "/").concat(packageName);
|
|
948
|
+
/** 1.產生package folder */
|
|
949
|
+
|
|
950
|
+
_fs["default"].mkdirSync(dirPath);
|
|
951
|
+
/** 2.要有babel.config.js? */
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
_fs["default"].copyFileSync("./template/sample.babel.config.js", "".concat(dirPath, "/babel.config.js"));
|
|
955
|
+
/** 3.要有package,json */
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
packagejson = this.getJsonObjByFilePath("./template/sample.package.json");
|
|
959
|
+
packagejson["name"] = packageName;
|
|
960
|
+
this.writeFileInJSON("".concat(dirPath, "/package.json"), packagejson);
|
|
961
|
+
/** 4.要在 src/${index.js}, dir/index.js */
|
|
962
|
+
|
|
963
|
+
this.persistByPath("".concat(dirPath, "/src"));
|
|
964
|
+
classBase = String.format(this.getFileContextInRaw("./template/sample.src.index.js"), packageName, "明悅", new Date());
|
|
965
|
+
|
|
966
|
+
_fs["default"].writeFileSync("".concat(dirPath, "/src/index.js"), classBase);
|
|
967
|
+
/** 6.要產生webstorm run case? */
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
ideaWorkspacePath = "".concat(this.findSpecificFolderByPath(dirPath, ".idea"), "/workspace.xml");
|
|
971
|
+
/** 7.要產生cd script 腳本 **/
|
|
972
|
+
|
|
973
|
+
this.insertShellCommand(_configer.configer.BASE_SHELL_SCRIPT, "cd_".concat(packageName), "cd ".concat(_path5["default"].resolve(dirPath)));
|
|
974
|
+
|
|
975
|
+
if (_fs["default"].existsSync(ideaWorkspacePath)) {
|
|
976
|
+
workspace = this.getFileContextInRaw(ideaWorkspacePath);
|
|
977
|
+
splited = workspace.split("\n");
|
|
978
|
+
indexOfRunManager = _lodash["default"].findIndex(splited, function (line) {
|
|
979
|
+
return _this6.has(line, 'name="RunManager');
|
|
980
|
+
});
|
|
981
|
+
this.insertToArray(splited, indexOfRunManager, "<configuration name=\"".concat(packageName, "\"\ntype=\"NodeJSConfigurationType\"\npath-to-node=\"$USER_HOME$/.nvm/versions/node/v14.4.0/bin/node\"\nnode-parameters=\"--require @babel/register\"\npath-to-js-file=\"").concat(_path5["default"].resolve(dirPath), "/src/index.js\"\nworking-dir=\"").concat(_path5["default"].resolve(dirPath), "\" >"), " <envs>", " <env name=\"self_debug\" value=\"true\" />", " <env name=\"is_node\" value=\"true\" />", " </envs>", " <method v=\"2\" />", "</configuration>");
|
|
982
|
+
indexOfList = _lodash["default"].findIndex(splited, function (line) {
|
|
983
|
+
return _lodash["default"].isEqual(_lodash["default"].trim(line), "<list>");
|
|
984
|
+
}, indexOfRunManager);
|
|
985
|
+
this.insertToArray(splited, indexOfList, " <item itemvalue=\"Node.js.".concat(packageName, "\" />"));
|
|
986
|
+
|
|
987
|
+
_fs["default"].writeFileSync(ideaWorkspacePath, splited.join("\n"));
|
|
988
|
+
} else {
|
|
989
|
+
this.appendError("".concat(ideaWorkspacePath, " not exist"));
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
_context9.next = 17;
|
|
993
|
+
return this.executeCommandLine("cd ".concat(_path5["default"].resolve(dirPath), " && npm install"));
|
|
994
|
+
|
|
995
|
+
case 17:
|
|
996
|
+
this.appendInfo("build ".concat(packageName, " succeed!"));
|
|
997
|
+
|
|
998
|
+
case 18:
|
|
999
|
+
case "end":
|
|
1000
|
+
return _context9.stop();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
}, _callee9, this);
|
|
1004
|
+
}));
|
|
1005
|
+
|
|
1006
|
+
function packageTemplatify(_x8, _x9) {
|
|
1007
|
+
return _packageTemplatify.apply(this, arguments);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
return packageTemplatify;
|
|
1011
|
+
}()
|
|
1012
|
+
}, {
|
|
1013
|
+
key: "appendInfo",
|
|
1014
|
+
value: function appendInfo() {
|
|
1015
|
+
for (var _len6 = arguments.length, data = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1016
|
+
data[_key6] = arguments[_key6];
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
return this.appendLog(_configer.configer.PATH_INFO_LOG, data, false);
|
|
1020
|
+
}
|
|
1021
|
+
}, {
|
|
1022
|
+
key: "appendError",
|
|
1023
|
+
value: function appendError() {
|
|
1024
|
+
for (var _len7 = arguments.length, data = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1025
|
+
data[_key7] = arguments[_key7];
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
return this.appendLog(_configer.configer.PATH_ERROR_LOG, data, true);
|
|
1029
|
+
}
|
|
1030
|
+
}, {
|
|
1031
|
+
key: "appendLog",
|
|
1032
|
+
value: function appendLog(path, datas) {
|
|
1033
|
+
var _console, _console2;
|
|
1034
|
+
|
|
1035
|
+
var isError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
1036
|
+
isError ? (_console = console).error.apply(_console, (0, _toConsumableArray2["default"])(datas)) : (_console2 = console).log.apply(_console2, (0, _toConsumableArray2["default"])(datas));
|
|
1037
|
+
var log = "".concat(isError ? "ERROR" : "LOG", " : ").concat(this.getLogString(datas));
|
|
1038
|
+
var persistlog = "".concat(new Date(), " ").concat(log);
|
|
1039
|
+
this.appendFile(path, persistlog);
|
|
1040
|
+
}
|
|
1041
|
+
}, {
|
|
1042
|
+
key: "getLogString",
|
|
1043
|
+
value: function getLogString(datas) {
|
|
1044
|
+
var _this7 = this;
|
|
1045
|
+
|
|
1046
|
+
return datas.map(function (data) {
|
|
1047
|
+
return _this7.isJson(data) || _lodash["default"].isObject(data) || _lodash["default"].isArray(data) ? _this7.deepFlat(data) : data;
|
|
1048
|
+
}).join(" ,");
|
|
1049
|
+
}
|
|
1050
|
+
/** 如果file不存在,就會產生file,force_delete 可以強制刪除cache file*/
|
|
1051
|
+
|
|
1052
|
+
}, {
|
|
1053
|
+
key: "appendFile",
|
|
1054
|
+
value: function appendFile(path, data) {
|
|
1055
|
+
var newLine = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
1056
|
+
var force_delete = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1057
|
+
|
|
1058
|
+
var options = function options(err) {
|
|
1059
|
+
throw new _index2["default"](8001, err);
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
if (force_delete) this.syncDeleteFile(path);
|
|
1063
|
+
|
|
1064
|
+
if (!_fs["default"].existsSync(path)) {
|
|
1065
|
+
_fs["default"].writeFileSync(path, data, options);
|
|
1066
|
+
} else {
|
|
1067
|
+
_fs["default"].appendFileSync(path, "".concat(newLine ? "\n" : "").concat(data), options);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
}, {
|
|
1071
|
+
key: "singleFileTemplatify",
|
|
1072
|
+
value: function singleFileTemplatify() {
|
|
1073
|
+
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "./";
|
|
1074
|
+
var all = this.findFilePathByExtension(path, ["js"], "node_modules");
|
|
1075
|
+
|
|
1076
|
+
var _iterator7 = _createForOfIteratorHelper(all),
|
|
1077
|
+
_step7;
|
|
1078
|
+
|
|
1079
|
+
try {
|
|
1080
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1081
|
+
var file = _step7.value;
|
|
1082
|
+
var content = this.getFileContextInRaw(file.absolute).trim();
|
|
1083
|
+
|
|
1084
|
+
if (_lodash["default"].isEmpty(content)) {
|
|
1085
|
+
this.appendInfo(file.fileName, file.absolute);
|
|
1086
|
+
var className = _lodash["default"].isEqual(file.fileName, "index") ? file.dirName : file.fileName;
|
|
1087
|
+
|
|
1088
|
+
_fs["default"].writeFileSync(file.absolute, String.format(this.getFileContextInRaw(".\n/template/s\nample.src.index.js"), className, "明悅", new Date()));
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
} catch (err) {
|
|
1092
|
+
_iterator7.e(err);
|
|
1093
|
+
} finally {
|
|
1094
|
+
_iterator7.f();
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}, {
|
|
1098
|
+
key: "syncDeleteFile",
|
|
1099
|
+
value: function syncDeleteFile(path) {
|
|
1100
|
+
if (_fs["default"].existsSync(path)) _fs["default"].unlinkSync(path);
|
|
1101
|
+
}
|
|
1102
|
+
}, {
|
|
1103
|
+
key: "getFileContextInJSON",
|
|
1104
|
+
value: function getFileContextInJSON(path) {
|
|
1105
|
+
try {
|
|
1106
|
+
if (_fs["default"].existsSync(path)) {
|
|
1107
|
+
return JSON.parse(_fs["default"].readFileSync(path, "utf-8"));
|
|
1108
|
+
}
|
|
1109
|
+
} catch (error) {
|
|
1110
|
+
throw new _index2["default"](9999, error.message);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
return {};
|
|
1114
|
+
}
|
|
1115
|
+
/** 讀取path,然後用utf-8的方式 */
|
|
1116
|
+
|
|
1117
|
+
}, {
|
|
1118
|
+
key: "getFileContextInRaw",
|
|
1119
|
+
value: function getFileContextInRaw(path) {
|
|
1120
|
+
if (!_fs["default"].existsSync(path)) return "";
|
|
1121
|
+
return _fs["default"].readFileSync(path, "utf-8");
|
|
1122
|
+
}
|
|
1123
|
+
}, {
|
|
1124
|
+
key: "writeFileInJSON",
|
|
1125
|
+
value: function writeFileInJSON(path, param) {
|
|
1126
|
+
var data = JSON.stringify(param, null, 2);
|
|
1127
|
+
|
|
1128
|
+
_fs["default"].writeFileSync(path, data);
|
|
1129
|
+
}
|
|
1130
|
+
/** ../folderName/fileName.xxx => ./folderName */
|
|
1131
|
+
|
|
1132
|
+
}, {
|
|
1133
|
+
key: "getFolderPathOfSpecificPath",
|
|
1134
|
+
value: function getFolderPathOfSpecificPath(path) {
|
|
1135
|
+
var splited = path.split("/");
|
|
1136
|
+
splited.pop();
|
|
1137
|
+
return splited.join("/");
|
|
1138
|
+
}
|
|
1139
|
+
/** 用來pack lib_project, 不然其他import lib_project的專案會無法讀懂es6
|
|
1140
|
+
* release folder 會被自動ignore到
|
|
1141
|
+
* exclude 裡面可以放專案名稱, 例如 free_marker,question_update */
|
|
1142
|
+
|
|
1143
|
+
}, {
|
|
1144
|
+
key: "generatePackage",
|
|
1145
|
+
value: function () {
|
|
1146
|
+
var _generatePackage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
|
|
1147
|
+
var _this8 = this;
|
|
1148
|
+
|
|
1149
|
+
var path,
|
|
1150
|
+
deployToNPMServer,
|
|
1151
|
+
packagejsons,
|
|
1152
|
+
_len8,
|
|
1153
|
+
exclude,
|
|
1154
|
+
_key8,
|
|
1155
|
+
_iterator8,
|
|
1156
|
+
_step8,
|
|
1157
|
+
_loop,
|
|
1158
|
+
_args11 = arguments;
|
|
1159
|
+
|
|
1160
|
+
return _regenerator["default"].wrap(function _callee10$(_context11) {
|
|
1161
|
+
while (1) {
|
|
1162
|
+
switch (_context11.prev = _context11.next) {
|
|
1163
|
+
case 0:
|
|
1164
|
+
path = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : "./";
|
|
1165
|
+
deployToNPMServer = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : true;
|
|
1166
|
+
packagejsons = this.findFilePathByExtension(path, ["json"], "node_modules", "release");
|
|
1167
|
+
packagejsons = _lodash["default"].filter(packagejsons, function (each) {
|
|
1168
|
+
return _lodash["default"].isEqual(each.fileName, "package");
|
|
1169
|
+
});
|
|
1170
|
+
packagejsons = packagejsons.map(function (each) {
|
|
1171
|
+
return _this8.getFolderPathOfSpecificPath(each.absolute);
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
for (_len8 = _args11.length, exclude = new Array(_len8 > 2 ? _len8 - 2 : 0), _key8 = 2; _key8 < _len8; _key8++) {
|
|
1175
|
+
exclude[_key8 - 2] = _args11[_key8];
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
_iterator8 = _createForOfIteratorHelper(packagejsons);
|
|
1179
|
+
_context11.prev = 7;
|
|
1180
|
+
_loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
|
|
1181
|
+
var path, tempFolderPath, release, templatePath, pathOfPackageJson, _yield$_this8$upgrade, name, version;
|
|
1182
|
+
|
|
1183
|
+
return _regenerator["default"].wrap(function _loop$(_context10) {
|
|
1184
|
+
while (1) {
|
|
1185
|
+
switch (_context10.prev = _context10.next) {
|
|
1186
|
+
case 0:
|
|
1187
|
+
path = _step8.value;
|
|
1188
|
+
|
|
1189
|
+
if (!_this8.isAndEquals.apply(_this8, (0, _toConsumableArray2["default"])(exclude.map(function (projectName) {
|
|
1190
|
+
return function () {
|
|
1191
|
+
return !_this8.has(path, projectName);
|
|
1192
|
+
};
|
|
1193
|
+
})))) {
|
|
1194
|
+
_context10.next = 28;
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
_context10.next = 4;
|
|
1199
|
+
return _this8.generateTempFolderWithCleanSrc(path);
|
|
1200
|
+
|
|
1201
|
+
case 4:
|
|
1202
|
+
tempFolderPath = _context10.sent;
|
|
1203
|
+
|
|
1204
|
+
/** 產生release資料夾 */
|
|
1205
|
+
release = _this8.persistByPath(_path5["default"].join(path, "release"));
|
|
1206
|
+
/** 利用babel 產生出 es5相容性高的src file */
|
|
1207
|
+
|
|
1208
|
+
_context10.next = 8;
|
|
1209
|
+
return _this8.executeCommandLine("cd ".concat(path, " && npx babel ./temp --out-dir ./release/lib"));
|
|
1210
|
+
|
|
1211
|
+
case 8:
|
|
1212
|
+
/** 複製公版的index.js */
|
|
1213
|
+
_this8.copySingleFile("/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/sample.index.js", release, "index.js", true);
|
|
1214
|
+
/** template就是樣板的概念 */
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
templatePath = _path5["default"].join(path, "template");
|
|
1218
|
+
|
|
1219
|
+
if (_this8.isPathExist(templatePath)) {
|
|
1220
|
+
_this8.copyFromFolderToDestFolder(templatePath, _this8.persistByPath(_path5["default"].join(release, "template")));
|
|
1221
|
+
}
|
|
1222
|
+
/** 升級package.json的版號 */
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
pathOfPackageJson = _path5["default"].join(path, "package.json");
|
|
1226
|
+
_context10.next = 14;
|
|
1227
|
+
return _this8.upgradePackageJsonVersion(pathOfPackageJson);
|
|
1228
|
+
|
|
1229
|
+
case 14:
|
|
1230
|
+
_yield$_this8$upgrade = _context10.sent;
|
|
1231
|
+
name = _yield$_this8$upgrade.name;
|
|
1232
|
+
version = _yield$_this8$upgrade.version;
|
|
1233
|
+
|
|
1234
|
+
/** 把package.json 放進去 */
|
|
1235
|
+
_this8.copySingleFile(pathOfPackageJson, _path5["default"].join(release, "package.json"), undefined, true);
|
|
1236
|
+
/** 安裝一個沒有devDependency 的node_module */
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
_context10.next = 20;
|
|
1240
|
+
return _this8.executeCommandLine("\ncd ".concat(release, " && yarn install --production"));
|
|
1241
|
+
|
|
1242
|
+
case 20:
|
|
1243
|
+
_this8.appendInfo("build ".concat(path, " succeed"));
|
|
1244
|
+
/** 部署到 local server*/
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
if (!deployToNPMServer) {
|
|
1248
|
+
_context10.next = 28;
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
_context10.next = 24;
|
|
1253
|
+
return _this8.executeCommandLine("cd ".concat(release, " && npm publish"));
|
|
1254
|
+
|
|
1255
|
+
case 24:
|
|
1256
|
+
_context10.next = 26;
|
|
1257
|
+
return _this8.deleteSelfByPath(tempFolderPath, true);
|
|
1258
|
+
|
|
1259
|
+
case 26:
|
|
1260
|
+
_context10.next = 28;
|
|
1261
|
+
return _this8.updateVersionOfTemplate(name, version);
|
|
1262
|
+
|
|
1263
|
+
case 28:
|
|
1264
|
+
case "end":
|
|
1265
|
+
return _context10.stop();
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}, _loop);
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
_iterator8.s();
|
|
1272
|
+
|
|
1273
|
+
case 10:
|
|
1274
|
+
if ((_step8 = _iterator8.n()).done) {
|
|
1275
|
+
_context11.next = 14;
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
return _context11.delegateYield(_loop(), "t0", 12);
|
|
1280
|
+
|
|
1281
|
+
case 12:
|
|
1282
|
+
_context11.next = 10;
|
|
1283
|
+
break;
|
|
1284
|
+
|
|
1285
|
+
case 14:
|
|
1286
|
+
_context11.next = 19;
|
|
1287
|
+
break;
|
|
1288
|
+
|
|
1289
|
+
case 16:
|
|
1290
|
+
_context11.prev = 16;
|
|
1291
|
+
_context11.t1 = _context11["catch"](7);
|
|
1292
|
+
|
|
1293
|
+
_iterator8.e(_context11.t1);
|
|
1294
|
+
|
|
1295
|
+
case 19:
|
|
1296
|
+
_context11.prev = 19;
|
|
1297
|
+
|
|
1298
|
+
_iterator8.f();
|
|
1299
|
+
|
|
1300
|
+
return _context11.finish(19);
|
|
1301
|
+
|
|
1302
|
+
case 22:
|
|
1303
|
+
case "end":
|
|
1304
|
+
return _context11.stop();
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}, _callee10, this, [[7, 16, 19, 22]]);
|
|
1308
|
+
}));
|
|
1309
|
+
|
|
1310
|
+
function generatePackage() {
|
|
1311
|
+
return _generatePackage.apply(this, arguments);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
return generatePackage;
|
|
1315
|
+
}()
|
|
1316
|
+
/** 用來更新樣板裡面的模組版本 */
|
|
1317
|
+
|
|
1318
|
+
}, {
|
|
1319
|
+
key: "updateVersionOfTemplate",
|
|
1320
|
+
value: function () {
|
|
1321
|
+
var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(dependency, newVersion) {
|
|
1322
|
+
var paths, _i, _paths, path, json;
|
|
1323
|
+
|
|
1324
|
+
return _regenerator["default"].wrap(function _callee11$(_context12) {
|
|
1325
|
+
while (1) {
|
|
1326
|
+
switch (_context12.prev = _context12.next) {
|
|
1327
|
+
case 0:
|
|
1328
|
+
paths = ["/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/admin.package.json", "/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/web.package.json", "/Users/davidtu/cross-achieve/high/idea-inventer/free_marker/template/functions.package.json", "/Users/davidtu/cross-achieve/high/idea-inventer/utiller/template/sample.package.json"];
|
|
1329
|
+
_i = 0, _paths = paths;
|
|
1330
|
+
|
|
1331
|
+
case 2:
|
|
1332
|
+
if (!(_i < _paths.length)) {
|
|
1333
|
+
_context12.next = 13;
|
|
1334
|
+
break;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
path = _paths[_i];
|
|
1338
|
+
|
|
1339
|
+
if (!this.isPathExist(path)) {
|
|
1340
|
+
_context12.next = 10;
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
json = this.getJsonObjByFilePath(path);
|
|
1345
|
+
|
|
1346
|
+
if (!(json && json.dependencies && json.dependencies[dependency])) {
|
|
1347
|
+
_context12.next = 10;
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
json.dependencies[dependency] = "^".concat(newVersion);
|
|
1352
|
+
_context12.next = 10;
|
|
1353
|
+
return this.writeJsonThanPrettier(path, json);
|
|
1354
|
+
|
|
1355
|
+
case 10:
|
|
1356
|
+
_i++;
|
|
1357
|
+
_context12.next = 2;
|
|
1358
|
+
break;
|
|
1359
|
+
|
|
1360
|
+
case 13:
|
|
1361
|
+
case "end":
|
|
1362
|
+
return _context12.stop();
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}, _callee11, this);
|
|
1366
|
+
}));
|
|
1367
|
+
|
|
1368
|
+
function updateVersionOfTemplate(_x10, _x11) {
|
|
1369
|
+
return _updateVersionOfTemplate.apply(this, arguments);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
return updateVersionOfTemplate;
|
|
1373
|
+
}()
|
|
1374
|
+
}, {
|
|
1375
|
+
key: "writeJsonThanPrettier",
|
|
1376
|
+
value: function () {
|
|
1377
|
+
var _writeJsonThanPrettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(path, json) {
|
|
1378
|
+
return _regenerator["default"].wrap(function _callee12$(_context13) {
|
|
1379
|
+
while (1) {
|
|
1380
|
+
switch (_context13.prev = _context13.next) {
|
|
1381
|
+
case 0:
|
|
1382
|
+
this.writeFileInJSON(path, json);
|
|
1383
|
+
_context13.next = 3;
|
|
1384
|
+
return this.prettier(path);
|
|
1385
|
+
|
|
1386
|
+
case 3:
|
|
1387
|
+
case "end":
|
|
1388
|
+
return _context13.stop();
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}, _callee12, this);
|
|
1392
|
+
}));
|
|
1393
|
+
|
|
1394
|
+
function writeJsonThanPrettier(_x12, _x13) {
|
|
1395
|
+
return _writeJsonThanPrettier.apply(this, arguments);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
return writeJsonThanPrettier;
|
|
1399
|
+
}()
|
|
1400
|
+
/** 用來豐富package.json的功能 */
|
|
1401
|
+
|
|
1402
|
+
}, {
|
|
1403
|
+
key: "enrichEachPackageJson",
|
|
1404
|
+
value: function () {
|
|
1405
|
+
var _enrichEachPackageJson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(path) {
|
|
1406
|
+
var jsons, packages, _iterator9, _step9, _path4, json;
|
|
1407
|
+
|
|
1408
|
+
return _regenerator["default"].wrap(function _callee13$(_context14) {
|
|
1409
|
+
while (1) {
|
|
1410
|
+
switch (_context14.prev = _context14.next) {
|
|
1411
|
+
case 0:
|
|
1412
|
+
jsons = this.findFilePathByExtension(path, ["json"], "gen", "node_modules", "release");
|
|
1413
|
+
packages = _lodash["default"].filter(jsons, function (each) {
|
|
1414
|
+
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");
|
|
1415
|
+
});
|
|
1416
|
+
_iterator9 = _createForOfIteratorHelper(packages);
|
|
1417
|
+
_context14.prev = 3;
|
|
1418
|
+
|
|
1419
|
+
_iterator9.s();
|
|
1420
|
+
|
|
1421
|
+
case 5:
|
|
1422
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1423
|
+
_context14.next = 13;
|
|
1424
|
+
break;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
_path4 = _step9.value;
|
|
1428
|
+
json = this.getJsonObjByFilePath(_path4.absolute); // const script = json.author ? json.scripts : {};
|
|
1429
|
+
|
|
1430
|
+
json["author"] = "davidtu<freshingmoon0725@gmail.com>";
|
|
1431
|
+
_context14.next = 11;
|
|
1432
|
+
return this.writeJsonThanPrettier(_path4.absolute, json);
|
|
1433
|
+
|
|
1434
|
+
case 11:
|
|
1435
|
+
_context14.next = 5;
|
|
1436
|
+
break;
|
|
1437
|
+
|
|
1438
|
+
case 13:
|
|
1439
|
+
_context14.next = 18;
|
|
1440
|
+
break;
|
|
1441
|
+
|
|
1442
|
+
case 15:
|
|
1443
|
+
_context14.prev = 15;
|
|
1444
|
+
_context14.t0 = _context14["catch"](3);
|
|
1445
|
+
|
|
1446
|
+
_iterator9.e(_context14.t0);
|
|
1447
|
+
|
|
1448
|
+
case 18:
|
|
1449
|
+
_context14.prev = 18;
|
|
1450
|
+
|
|
1451
|
+
_iterator9.f();
|
|
1452
|
+
|
|
1453
|
+
return _context14.finish(18);
|
|
1454
|
+
|
|
1455
|
+
case 21:
|
|
1456
|
+
case "end":
|
|
1457
|
+
return _context14.stop();
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}, _callee13, this, [[3, 15, 18, 21]]);
|
|
1461
|
+
}));
|
|
1462
|
+
|
|
1463
|
+
function enrichEachPackageJson(_x14) {
|
|
1464
|
+
return _enrichEachPackageJson.apply(this, arguments);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
return enrichEachPackageJson;
|
|
1468
|
+
}()
|
|
1469
|
+
}, {
|
|
1470
|
+
key: "insertShellCommand",
|
|
1471
|
+
value: function insertShellCommand() {
|
|
1472
|
+
var shellPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _configer.configer.BASE_SHELL_SCRIPT;
|
|
1473
|
+
var alias = arguments.length > 1 ? arguments[1] : undefined;
|
|
1474
|
+
var command = arguments.length > 2 ? arguments[2] : undefined;
|
|
1475
|
+
|
|
1476
|
+
if (this.isStringContainInLines(this.getFileContextInRaw(shellPath), alias)) {
|
|
1477
|
+
throw new _index2["default"](8007, "alias ".concat(alias, " is exist"));
|
|
1478
|
+
} else {
|
|
1479
|
+
var line = "alias ".concat(alias, "='").concat(command, "'");
|
|
1480
|
+
this.appendFile(shellPath, line);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
}, {
|
|
1484
|
+
key: "getAdminCredential",
|
|
1485
|
+
value: function getAdminCredential() {
|
|
1486
|
+
return this.getJsonObjByFilePath("/Users/davidtu/cross-achieve/mimi/idea-inventer/firebaser/key/mimi19up-firebase-adminsdk.json");
|
|
1487
|
+
}
|
|
1488
|
+
/** http://wnj.cdji/david.mp3 => david.mp3 */
|
|
1489
|
+
|
|
1490
|
+
}, {
|
|
1491
|
+
key: "getFileNameExtensionFromPath",
|
|
1492
|
+
value: function getFileNameExtensionFromPath(path) {
|
|
1493
|
+
var name = path.split("/").pop();
|
|
1494
|
+
return name;
|
|
1495
|
+
}
|
|
1496
|
+
/** http://wnj.cdji/david.mp3 => mp3 */
|
|
1497
|
+
|
|
1498
|
+
}, {
|
|
1499
|
+
key: "getExtensionFromPath",
|
|
1500
|
+
value: function getExtensionFromPath(path) {
|
|
1501
|
+
var name = path.split("/").pop();
|
|
1502
|
+
return name.split(".").pop();
|
|
1503
|
+
}
|
|
1504
|
+
}, {
|
|
1505
|
+
key: "isEmptyFile",
|
|
1506
|
+
value: function isEmptyFile(path) {
|
|
1507
|
+
return _lodash["default"].isEqual("", this.getFileContextInRaw(path).trim());
|
|
1508
|
+
}
|
|
1509
|
+
/** 把檔案弄得好看一點 */
|
|
1510
|
+
|
|
1511
|
+
}, {
|
|
1512
|
+
key: "prettier",
|
|
1513
|
+
value: function () {
|
|
1514
|
+
var _prettier = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(path) {
|
|
1515
|
+
return _regenerator["default"].wrap(function _callee14$(_context15) {
|
|
1516
|
+
while (1) {
|
|
1517
|
+
switch (_context15.prev = _context15.next) {
|
|
1518
|
+
case 0:
|
|
1519
|
+
_context15.next = 2;
|
|
1520
|
+
return this.executeCommandLine("cd ".concat(_path5["default"].resolve("."), " && npx prettier --write ").concat(_path5["default"].resolve(path)));
|
|
1521
|
+
|
|
1522
|
+
case 2:
|
|
1523
|
+
case "end":
|
|
1524
|
+
return _context15.stop();
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}, _callee14, this);
|
|
1528
|
+
}));
|
|
1529
|
+
|
|
1530
|
+
function prettier(_x15) {
|
|
1531
|
+
return _prettier.apply(this, arguments);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
return prettier;
|
|
1535
|
+
}()
|
|
1536
|
+
}, {
|
|
1537
|
+
key: "getFileLastModifiedTime",
|
|
1538
|
+
value: function getFileLastModifiedTime(path) {
|
|
1539
|
+
/**
|
|
1540
|
+
* onsole.log(`File Data Last Modified: ${stats.mtime}`);
|
|
1541
|
+
console.log(`File Status Last Modified: ${stats.ctime}`);
|
|
1542
|
+
*/
|
|
1543
|
+
var stats = _fs["default"].statSync(path);
|
|
1544
|
+
|
|
1545
|
+
return stats.mtimeMs;
|
|
1546
|
+
}
|
|
1547
|
+
}, {
|
|
1548
|
+
key: "getJsonObjByFilePath",
|
|
1549
|
+
value: function getJsonObjByFilePath(path) {
|
|
1550
|
+
this.appendInfo("ready to json path:".concat(path));
|
|
1551
|
+
return JSON.parse(this.getFileContextInRaw(path));
|
|
1552
|
+
}
|
|
1553
|
+
/** increment version number, 回傳latest version, name */
|
|
1554
|
+
|
|
1555
|
+
}, {
|
|
1556
|
+
key: "upgradePackageJsonVersion",
|
|
1557
|
+
value: function () {
|
|
1558
|
+
var _upgradePackageJsonVersion = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(path) {
|
|
1559
|
+
var json, numbers, last;
|
|
1560
|
+
return _regenerator["default"].wrap(function _callee15$(_context16) {
|
|
1561
|
+
while (1) {
|
|
1562
|
+
switch (_context16.prev = _context16.next) {
|
|
1563
|
+
case 0:
|
|
1564
|
+
if (!_lodash["default"].isEqual("package.json", this.getPathInfo(path).fileNameExtension)) {
|
|
1565
|
+
_context16.next = 11;
|
|
1566
|
+
break;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
json = this.getJsonObjByFilePath(path);
|
|
1570
|
+
numbers = json.version.split(".").map(function (each) {
|
|
1571
|
+
return _lodash["default"].toNumber(each);
|
|
1572
|
+
});
|
|
1573
|
+
last = numbers.length - 1;
|
|
1574
|
+
numbers[last] = numbers[last] + 1;
|
|
1575
|
+
json.version = numbers.join(".");
|
|
1576
|
+
_context16.next = 8;
|
|
1577
|
+
return this.writeJsonThanPrettier(path, json);
|
|
1578
|
+
|
|
1579
|
+
case 8:
|
|
1580
|
+
return _context16.abrupt("return", {
|
|
1581
|
+
version: json.version,
|
|
1582
|
+
name: json.name
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
case 11:
|
|
1586
|
+
throw new _index2["default"](8020, "path is not package.json, which is ".concat(path));
|
|
1587
|
+
|
|
1588
|
+
case 12:
|
|
1589
|
+
case "end":
|
|
1590
|
+
return _context16.stop();
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}, _callee15, this);
|
|
1594
|
+
}));
|
|
1595
|
+
|
|
1596
|
+
function upgradePackageJsonVersion(_x16) {
|
|
1597
|
+
return _upgradePackageJsonVersion.apply(this, arguments);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
return upgradePackageJsonVersion;
|
|
1601
|
+
}()
|
|
1602
|
+
}, {
|
|
1603
|
+
key: "getAnswerFromPromptQ",
|
|
1604
|
+
value: function () {
|
|
1605
|
+
var _getAnswerFromPromptQ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16() {
|
|
1606
|
+
var configs,
|
|
1607
|
+
_args17 = arguments;
|
|
1608
|
+
return _regenerator["default"].wrap(function _callee16$(_context17) {
|
|
1609
|
+
while (1) {
|
|
1610
|
+
switch (_context17.prev = _context17.next) {
|
|
1611
|
+
case 0:
|
|
1612
|
+
configs = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : [{
|
|
1613
|
+
name: "name",
|
|
1614
|
+
require: true,
|
|
1615
|
+
description: "type the name"
|
|
1616
|
+
}];
|
|
1617
|
+
|
|
1618
|
+
_prompt["default"].start();
|
|
1619
|
+
|
|
1620
|
+
_context17.next = 4;
|
|
1621
|
+
return _prompt["default"].get(configs);
|
|
1622
|
+
|
|
1623
|
+
case 4:
|
|
1624
|
+
return _context17.abrupt("return", _context17.sent);
|
|
1625
|
+
|
|
1626
|
+
case 5:
|
|
1627
|
+
case "end":
|
|
1628
|
+
return _context17.stop();
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}, _callee16);
|
|
1632
|
+
}));
|
|
1633
|
+
|
|
1634
|
+
function getAnswerFromPromptQ() {
|
|
1635
|
+
return _getAnswerFromPromptQ.apply(this, arguments);
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
return getAnswerFromPromptQ;
|
|
1639
|
+
}()
|
|
1640
|
+
/** 產出一個/temp,然後把/src 複製過去, 再把裡面每一個file的 if(DEBUG)給去除掉,再加上prettier */
|
|
1641
|
+
|
|
1642
|
+
}, {
|
|
1643
|
+
key: "generateTempFolderWithCleanSrc",
|
|
1644
|
+
value: function () {
|
|
1645
|
+
var _generateTempFolderWithCleanSrc = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(path) {
|
|
1646
|
+
var sourceFile, tempFolderPath, _iterator10, _step10, file, tempFilePath, stmts, indexOfStart, indexOfEnd;
|
|
1647
|
+
|
|
1648
|
+
return _regenerator["default"].wrap(function _callee17$(_context18) {
|
|
1649
|
+
while (1) {
|
|
1650
|
+
switch (_context18.prev = _context18.next) {
|
|
1651
|
+
case 0:
|
|
1652
|
+
this.appendInfo("generateTempFolderWithCleanSrc", path);
|
|
1653
|
+
sourceFile = _path5["default"].join(path, "src");
|
|
1654
|
+
tempFolderPath = _path5["default"].join(path, "temp");
|
|
1655
|
+
|
|
1656
|
+
if (!_fs["default"].existsSync(sourceFile)) {
|
|
1657
|
+
_context18.next = 31;
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
this.appendInfo("generateTempFolderWithCleanSrc", "source", sourceFile);
|
|
1662
|
+
this.persistByPath(tempFolderPath);
|
|
1663
|
+
this.copyFromFolderToDestFolder(sourceFile, tempFolderPath);
|
|
1664
|
+
_iterator10 = _createForOfIteratorHelper(this.findFilePathBy(tempFolderPath));
|
|
1665
|
+
_context18.prev = 8;
|
|
1666
|
+
|
|
1667
|
+
_iterator10.s();
|
|
1668
|
+
|
|
1669
|
+
case 10:
|
|
1670
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1671
|
+
_context18.next = 23;
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
file = _step10.value;
|
|
1676
|
+
tempFilePath = file.absolute;
|
|
1677
|
+
stmts = this.getFileContextInRaw(tempFilePath).split("\n").map(function (line) {
|
|
1678
|
+
return _lodash["default"].trim(line);
|
|
1679
|
+
});
|
|
1680
|
+
/** 找出if (configer) 當作start */
|
|
1681
|
+
|
|
1682
|
+
indexOfStart = _lodash["default"].findIndex(stmts, function (stmt) {
|
|
1683
|
+
return _lodash["default"].startsWith(stmt, "if (configer.DEBUG_MODE)");
|
|
1684
|
+
});
|
|
1685
|
+
/** 找出 } 當作 end */
|
|
1686
|
+
|
|
1687
|
+
indexOfEnd = _lodash["default"].findLastIndex(stmts, function (stmt) {
|
|
1688
|
+
return _lodash["default"].isEqual(stmt, "}");
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
if (!(indexOfEnd > 0 && indexOfStart > 0 && indexOfEnd > indexOfStart)) {
|
|
1692
|
+
_context18.next = 21;
|
|
1693
|
+
break;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/** 刪除掉 if(configer.DEBUG) {...........} */
|
|
1697
|
+
this.dropItemsByIndex(stmts, indexOfStart, indexOfEnd);
|
|
1698
|
+
this.appendFile(tempFilePath, _lodash["default"].join(stmts, "\n"), true, true);
|
|
1699
|
+
_context18.next = 21;
|
|
1700
|
+
return this.executeCommandLine("cd ".concat(_path5["default"].resolve("".concat(this.getFileDirPath(tempFilePath))), " &&\nnpx prettier --write ").concat(tempFilePath));
|
|
1701
|
+
|
|
1702
|
+
case 21:
|
|
1703
|
+
_context18.next = 10;
|
|
1704
|
+
break;
|
|
1705
|
+
|
|
1706
|
+
case 23:
|
|
1707
|
+
_context18.next = 28;
|
|
1708
|
+
break;
|
|
1709
|
+
|
|
1710
|
+
case 25:
|
|
1711
|
+
_context18.prev = 25;
|
|
1712
|
+
_context18.t0 = _context18["catch"](8);
|
|
1713
|
+
|
|
1714
|
+
_iterator10.e(_context18.t0);
|
|
1715
|
+
|
|
1716
|
+
case 28:
|
|
1717
|
+
_context18.prev = 28;
|
|
1718
|
+
|
|
1719
|
+
_iterator10.f();
|
|
1720
|
+
|
|
1721
|
+
return _context18.finish(28);
|
|
1722
|
+
|
|
1723
|
+
case 31:
|
|
1724
|
+
return _context18.abrupt("return", tempFolderPath);
|
|
1725
|
+
|
|
1726
|
+
case 32:
|
|
1727
|
+
case "end":
|
|
1728
|
+
return _context18.stop();
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}, _callee17, this, [[8, 25, 28, 31]]);
|
|
1732
|
+
}));
|
|
1733
|
+
|
|
1734
|
+
function generateTempFolderWithCleanSrc(_x17) {
|
|
1735
|
+
return _generateTempFolderWithCleanSrc.apply(this, arguments);
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
return generateTempFolderWithCleanSrc;
|
|
1739
|
+
}()
|
|
1740
|
+
}]);
|
|
1741
|
+
return NodeUtiller;
|
|
1742
|
+
}(_index["default"]);
|
|
1743
|
+
|
|
1744
|
+
var _default = NodeUtiller;
|
|
1745
|
+
exports["default"] = _default;
|