utiller 1.0.291 → 1.0.293
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 +208 -163
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
|
@@ -91,19 +91,18 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
91
91
|
/**
|
|
92
92
|
* 從絕對路徑中取出 "src/" 之後的部分(包含前置 /)
|
|
93
93
|
* @param {string} fullPath - 完整的絕對檔案路徑
|
|
94
|
-
* @param {string} folder - 針對/folder/之後作為split
|
|
94
|
+
* @param {string} folder - 針對/folder/之後作為split起點(預設為 src)
|
|
95
95
|
* @returns {string} - 以 / 開頭、從 src/ 之後開始的相對路徑
|
|
96
96
|
*/
|
|
97
97
|
(0, _defineProperty2["default"])(_this, "getPathAfterSpecificFolder", function (fullPath) {
|
|
98
98
|
var folder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "src";
|
|
99
|
-
var parts =
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return _lodash["default"].join(relativeParts, "/");
|
|
99
|
+
var parts = fullPath.split(path.sep);
|
|
100
|
+
for (var i = parts.length - 1; i >= 0; i--) {
|
|
101
|
+
if (parts[i] === folder) {
|
|
102
|
+
return "/" + parts.slice(i + 1).join("/");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return "";
|
|
107
106
|
});
|
|
108
107
|
/**
|
|
109
108
|
* 從絕對路徑中取出 "src/" 之後的部分(包含前置 /)
|
|
@@ -120,11 +119,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
120
119
|
key: "findSpecificFolderByPath",
|
|
121
120
|
value: function findSpecificFolderByPath(path, folderName) {
|
|
122
121
|
var absolute = _path5["default"].resolve(path);
|
|
123
|
-
var
|
|
124
|
-
while (
|
|
125
|
-
|
|
122
|
+
var parts = absolute.split(_path5["default"].sep);
|
|
123
|
+
while (parts.length) {
|
|
124
|
+
var joined = _path5["default"].join.apply(_path5["default"], (0, _toConsumableArray2["default"])(parts).concat([folderName]));
|
|
125
|
+
if (_fs["default"].existsSync(joined)) return joined;
|
|
126
|
+
parts.pop();
|
|
126
127
|
}
|
|
127
|
-
return
|
|
128
|
+
return null;
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
/** {numpages, numrender, info, text, version} */
|
|
@@ -593,10 +594,10 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
593
594
|
}, {
|
|
594
595
|
key: "getNamesOfFolderChild",
|
|
595
596
|
value: function getNamesOfFolderChild(path) {
|
|
596
|
-
return
|
|
597
|
-
return
|
|
598
|
-
}).map(function (
|
|
599
|
-
return
|
|
597
|
+
return this.getChildPathByPath(path).filter(function (p) {
|
|
598
|
+
return p.isDirectory;
|
|
599
|
+
}).map(function (p) {
|
|
600
|
+
return p.dirName;
|
|
600
601
|
});
|
|
601
602
|
}
|
|
602
603
|
|
|
@@ -624,10 +625,21 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
624
625
|
key: "copySingleFile",
|
|
625
626
|
value: function copySingleFile(from, dest, fileName) {
|
|
626
627
|
var force = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
627
|
-
var destination =
|
|
628
|
-
if (_fs["default"].existsSync(destination) && !force)
|
|
628
|
+
var destination = fileName && fileName.trim() ? _path5["default"].join(dest, fileName) : dest;
|
|
629
|
+
if (_fs["default"].existsSync(destination) && !force) {
|
|
630
|
+
throw new _index2["default"](8006, destination);
|
|
631
|
+
}
|
|
629
632
|
_fs["default"].copyFileSync(from, destination);
|
|
630
633
|
}
|
|
634
|
+
}, {
|
|
635
|
+
key: "ensureFolderExists",
|
|
636
|
+
value: function ensureFolderExists(folderPath) {
|
|
637
|
+
var resolved = _path5["default"].resolve(folderPath);
|
|
638
|
+
if (_fs["default"].existsSync(resolved)) return;
|
|
639
|
+
_fs["default"].mkdirSync(resolved, {
|
|
640
|
+
recursive: true
|
|
641
|
+
});
|
|
642
|
+
}
|
|
631
643
|
}, {
|
|
632
644
|
key: "getNodeEnvVariable",
|
|
633
645
|
value: function getNodeEnvVariable(key) {
|
|
@@ -650,7 +662,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
650
662
|
}, {
|
|
651
663
|
key: "isImageFile",
|
|
652
664
|
value: function isImageFile(file) {
|
|
653
|
-
return
|
|
665
|
+
return ["svg", "png", "jpg", "jpeg"].includes(file.extension);
|
|
654
666
|
}
|
|
655
667
|
|
|
656
668
|
/** 把內容都抹掉each 是 fileName, ex:index.js*/
|
|
@@ -985,23 +997,41 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
985
997
|
_iterator7.f();
|
|
986
998
|
}
|
|
987
999
|
}
|
|
1000
|
+
}, {
|
|
1001
|
+
key: "isFileEmpty",
|
|
1002
|
+
value: function isFileEmpty(path) {
|
|
1003
|
+
var content = this.getFileContextInRaw(path);
|
|
1004
|
+
return !content || !content.trim();
|
|
1005
|
+
}
|
|
988
1006
|
|
|
989
1007
|
/** 保守的複製檔案, 如果檔案比較舊, 或是檔案是空的, 就放棄copy行為 */
|
|
990
1008
|
}, {
|
|
991
1009
|
key: "copySingleFileConservative",
|
|
992
|
-
value: function copySingleFileConservative(
|
|
993
|
-
|
|
994
|
-
|
|
1010
|
+
value: function copySingleFileConservative(destPath, latestFile) {
|
|
1011
|
+
var absolute = latestFile.absolute,
|
|
1012
|
+
lastModifiedTime = latestFile.lastModifiedTime;
|
|
1013
|
+
|
|
1014
|
+
// 先確認檔案是否為空
|
|
1015
|
+
if (!this.isPathExist(absolute) || this.isFileEmpty(absolute)) {
|
|
1016
|
+
this.appendInfo("".concat(absolute, " is empty file, ignore copy behavior"));
|
|
995
1017
|
return;
|
|
996
1018
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1019
|
+
var destExists = _fs["default"].existsSync(destPath);
|
|
1020
|
+
|
|
1021
|
+
// 如果目的檔案存在且比來源更新,則跳過
|
|
1022
|
+
if (destExists && this.getFileLastModifiedTime(destPath) > lastModifiedTime) {
|
|
1023
|
+
this.appendInfo("".concat(destPath, " is the latest, ignore this run"));
|
|
1001
1024
|
return;
|
|
1002
1025
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1026
|
+
if (!destExists) {
|
|
1027
|
+
this.appendInfo("".concat(destPath, " does not exist, safe to copy."));
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// 確保目的路徑存在(遞迴建立)
|
|
1031
|
+
this.ensureFolderExists(_path5["default"].dirname(destPath));
|
|
1032
|
+
|
|
1033
|
+
// 強制複製
|
|
1034
|
+
this.copySingleFile(absolute, destPath, undefined, true);
|
|
1005
1035
|
}
|
|
1006
1036
|
}, {
|
|
1007
1037
|
key: "syncDeleteFile",
|
|
@@ -1207,7 +1237,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1207
1237
|
key: "updateVersionOfTemplate",
|
|
1208
1238
|
value: (function () {
|
|
1209
1239
|
var _updateVersionOfTemplate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(dependency, newVersion) {
|
|
1210
|
-
var paths, _i, _paths,
|
|
1240
|
+
var paths, _i, _paths, _path4, succeedOfPersistFile, json;
|
|
1211
1241
|
return _regenerator["default"].wrap(function _callee14$(_context15) {
|
|
1212
1242
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1213
1243
|
case 0:
|
|
@@ -1218,13 +1248,13 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1218
1248
|
_context15.next = 24;
|
|
1219
1249
|
break;
|
|
1220
1250
|
}
|
|
1221
|
-
|
|
1222
|
-
if (!this.isPathExist(
|
|
1251
|
+
_path4 = _paths[_i];
|
|
1252
|
+
if (!this.isPathExist(_path4)) {
|
|
1223
1253
|
_context15.next = 21;
|
|
1224
1254
|
break;
|
|
1225
1255
|
}
|
|
1226
1256
|
succeedOfPersistFile = false;
|
|
1227
|
-
json = this.getJsonObjByFilePath(
|
|
1257
|
+
json = this.getJsonObjByFilePath(_path4);
|
|
1228
1258
|
if (!(json && json.dependencies && json.dependencies[dependency])) {
|
|
1229
1259
|
_context15.next = 18;
|
|
1230
1260
|
break;
|
|
@@ -1232,7 +1262,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1232
1262
|
json.dependencies[dependency] = "^".concat(newVersion);
|
|
1233
1263
|
_context15.prev = 9;
|
|
1234
1264
|
_context15.next = 12;
|
|
1235
|
-
return this.writeJsonThanPrettier(
|
|
1265
|
+
return this.writeJsonThanPrettier(_path4, json);
|
|
1236
1266
|
case 12:
|
|
1237
1267
|
succeedOfPersistFile = true;
|
|
1238
1268
|
_context15.next = 18;
|
|
@@ -1247,7 +1277,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1247
1277
|
break;
|
|
1248
1278
|
}
|
|
1249
1279
|
_context15.next = 21;
|
|
1250
|
-
return this.updateFileOfSpecificLine(
|
|
1280
|
+
return this.updateFileOfSpecificLine(_path4, function (line) {
|
|
1251
1281
|
return " \"".concat(dependency, "\":\"^").concat(newVersion, "\"").concat(_lodash["default"].endsWith(_lodash["default"].trim(line), "," ? "," : ""));
|
|
1252
1282
|
}, function (each) {
|
|
1253
1283
|
return _lodash["default"].startsWith(_lodash["default"].trim(each), "\"".concat(dependency, "\""));
|
|
@@ -1284,8 +1314,8 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1284
1314
|
var contentOfUpdated,
|
|
1285
1315
|
predicate,
|
|
1286
1316
|
context,
|
|
1287
|
-
|
|
1288
|
-
|
|
1317
|
+
lines,
|
|
1318
|
+
index,
|
|
1289
1319
|
_args16 = arguments;
|
|
1290
1320
|
return _regenerator["default"].wrap(function _callee15$(_context16) {
|
|
1291
1321
|
while (1) switch (_context16.prev = _context16.next) {
|
|
@@ -1297,13 +1327,18 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1297
1327
|
return true;
|
|
1298
1328
|
};
|
|
1299
1329
|
context = this.getFileContextInRaw(pathOfFile);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1330
|
+
lines = context.split("\n");
|
|
1331
|
+
index = lines.findIndex(predicate);
|
|
1332
|
+
if (!(index === -1)) {
|
|
1333
|
+
_context16.next = 7;
|
|
1334
|
+
break;
|
|
1335
|
+
}
|
|
1336
|
+
return _context16.abrupt("return");
|
|
1306
1337
|
case 7:
|
|
1338
|
+
// 無匹配行則略過
|
|
1339
|
+
lines[index] = contentOfUpdated(lines[index]);
|
|
1340
|
+
this.appendFile(pathOfFile, lines.join("\n"), true, true);
|
|
1341
|
+
case 9:
|
|
1307
1342
|
case "end":
|
|
1308
1343
|
return _context16.stop();
|
|
1309
1344
|
}
|
|
@@ -1338,48 +1373,55 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1338
1373
|
}, {
|
|
1339
1374
|
key: "enrichEachPackageJson",
|
|
1340
1375
|
value: (function () {
|
|
1341
|
-
var _enrichEachPackageJson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(
|
|
1342
|
-
var
|
|
1376
|
+
var _enrichEachPackageJson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(rootPath) {
|
|
1377
|
+
var validNames, jsonFiles, packageFiles, _iterator9, _step9, absolute, json;
|
|
1343
1378
|
return _regenerator["default"].wrap(function _callee17$(_context18) {
|
|
1344
1379
|
while (1) switch (_context18.prev = _context18.next) {
|
|
1345
1380
|
case 0:
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1381
|
+
validNames = new Set(["package", "admin.package", "web.package", "functions.package"]);
|
|
1382
|
+
jsonFiles = this.findFilePathByExtension(rootPath, ["json"], "gen", "node_modules", "release");
|
|
1383
|
+
packageFiles = jsonFiles.filter(function (file) {
|
|
1384
|
+
return validNames.has(file.fileName);
|
|
1349
1385
|
});
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1386
|
+
if (!(packageFiles.length === 0)) {
|
|
1387
|
+
_context18.next = 5;
|
|
1388
|
+
break;
|
|
1389
|
+
}
|
|
1390
|
+
return _context18.abrupt("return");
|
|
1353
1391
|
case 5:
|
|
1392
|
+
_iterator9 = _createForOfIteratorHelper(packageFiles);
|
|
1393
|
+
_context18.prev = 6;
|
|
1394
|
+
_iterator9.s();
|
|
1395
|
+
case 8:
|
|
1354
1396
|
if ((_step9 = _iterator9.n()).done) {
|
|
1355
|
-
_context18.next =
|
|
1397
|
+
_context18.next = 17;
|
|
1356
1398
|
break;
|
|
1357
1399
|
}
|
|
1358
|
-
|
|
1359
|
-
json = this.getJsonObjByFilePath(
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
_context18.next =
|
|
1363
|
-
return this.writeJsonThanPrettier(
|
|
1364
|
-
case
|
|
1365
|
-
_context18.next =
|
|
1400
|
+
absolute = _step9.value.absolute;
|
|
1401
|
+
json = this.getJsonObjByFilePath(absolute);
|
|
1402
|
+
json.scripts || (json.scripts = {});
|
|
1403
|
+
json.scripts.updateConfigerer = "npm update configerer --save";
|
|
1404
|
+
_context18.next = 15;
|
|
1405
|
+
return this.writeJsonThanPrettier(absolute, json);
|
|
1406
|
+
case 15:
|
|
1407
|
+
_context18.next = 8;
|
|
1366
1408
|
break;
|
|
1367
|
-
case
|
|
1368
|
-
_context18.next =
|
|
1409
|
+
case 17:
|
|
1410
|
+
_context18.next = 22;
|
|
1369
1411
|
break;
|
|
1370
|
-
case 16:
|
|
1371
|
-
_context18.prev = 16;
|
|
1372
|
-
_context18.t0 = _context18["catch"](3);
|
|
1373
|
-
_iterator9.e(_context18.t0);
|
|
1374
1412
|
case 19:
|
|
1375
1413
|
_context18.prev = 19;
|
|
1376
|
-
|
|
1377
|
-
|
|
1414
|
+
_context18.t0 = _context18["catch"](6);
|
|
1415
|
+
_iterator9.e(_context18.t0);
|
|
1378
1416
|
case 22:
|
|
1417
|
+
_context18.prev = 22;
|
|
1418
|
+
_iterator9.f();
|
|
1419
|
+
return _context18.finish(22);
|
|
1420
|
+
case 25:
|
|
1379
1421
|
case "end":
|
|
1380
1422
|
return _context18.stop();
|
|
1381
1423
|
}
|
|
1382
|
-
}, _callee17, this, [[
|
|
1424
|
+
}, _callee17, this, [[6, 19, 22, 25]]);
|
|
1383
1425
|
}));
|
|
1384
1426
|
function enrichEachPackageJson(_x21) {
|
|
1385
1427
|
return _enrichEachPackageJson.apply(this, arguments);
|
|
@@ -1456,8 +1498,7 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1456
1498
|
* console.log(`File Data Last Modified: ${stats.mtime}`);
|
|
1457
1499
|
* console.log(`File Status Last Modified: ${stats.ctime}`);
|
|
1458
1500
|
*/
|
|
1459
|
-
|
|
1460
|
-
return stats.mtimeMs;
|
|
1501
|
+
return _fs["default"].statSync(path).mtimeMs;
|
|
1461
1502
|
}
|
|
1462
1503
|
}, {
|
|
1463
1504
|
key: "getJsonObjByFilePath",
|
|
@@ -1509,11 +1550,14 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1509
1550
|
}, {
|
|
1510
1551
|
key: "reWriteJsonAttribute",
|
|
1511
1552
|
value: (function () {
|
|
1512
|
-
var _reWriteJsonAttribute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(
|
|
1513
|
-
var
|
|
1553
|
+
var _reWriteJsonAttribute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(filePath) {
|
|
1554
|
+
var _this$getPathInfo,
|
|
1555
|
+
extension,
|
|
1514
1556
|
_len9,
|
|
1515
1557
|
attrs,
|
|
1516
1558
|
_key9,
|
|
1559
|
+
invalidAttr,
|
|
1560
|
+
json,
|
|
1517
1561
|
_i2,
|
|
1518
1562
|
_attrs,
|
|
1519
1563
|
attr,
|
|
@@ -1521,43 +1565,39 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1521
1565
|
return _regenerator["default"].wrap(function _callee20$(_context21) {
|
|
1522
1566
|
while (1) switch (_context21.prev = _context21.next) {
|
|
1523
1567
|
case 0:
|
|
1524
|
-
|
|
1525
|
-
|
|
1568
|
+
_this$getPathInfo = this.getPathInfo(filePath), extension = _this$getPathInfo.extension;
|
|
1569
|
+
if (!(extension !== "json")) {
|
|
1570
|
+
_context21.next = 3;
|
|
1526
1571
|
break;
|
|
1527
1572
|
}
|
|
1528
|
-
json
|
|
1573
|
+
throw new _index2["default"](9999, "reWriteJsonAttribute() => path is not package.json, which is ".concat(filePath));
|
|
1574
|
+
case 3:
|
|
1529
1575
|
for (_len9 = _args21.length, attrs = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
|
|
1530
1576
|
attrs[_key9 - 1] = _args21[_key9];
|
|
1531
1577
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1578
|
+
// 驗證所有 attr 必須是 object
|
|
1579
|
+
invalidAttr = attrs.find(function (attr) {
|
|
1580
|
+
return (0, _typeof2["default"])(attr) !== "object" || attr === null;
|
|
1581
|
+
});
|
|
1582
|
+
if (!invalidAttr) {
|
|
1583
|
+
_context21.next = 7;
|
|
1536
1584
|
break;
|
|
1537
1585
|
}
|
|
1538
|
-
attr =
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1586
|
+
throw new _index2["default"](9999, "84451515 attr is not object, which is 'type=".concat((0, _typeof2["default"])(invalidAttr), " => ").concat(invalidAttr, "'"));
|
|
1587
|
+
case 7:
|
|
1588
|
+
json = this.getJsonObjByFilePath(filePath);
|
|
1589
|
+
for (_i2 = 0, _attrs = attrs; _i2 < _attrs.length; _i2++) {
|
|
1590
|
+
attr = _attrs[_i2];
|
|
1591
|
+
json[this.getObjectKey(attr)] = this.getObjectValue(attr);
|
|
1542
1592
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
case 9:
|
|
1547
|
-
_i2++;
|
|
1548
|
-
_context21.next = 4;
|
|
1549
|
-
break;
|
|
1550
|
-
case 12:
|
|
1551
|
-
_context21.next = 14;
|
|
1552
|
-
return this.writeJsonThanPrettier(path, json);
|
|
1553
|
-
case 14:
|
|
1593
|
+
_context21.next = 11;
|
|
1594
|
+
return this.writeJsonThanPrettier(filePath, json);
|
|
1595
|
+
case 11:
|
|
1554
1596
|
return _context21.abrupt("return", {
|
|
1555
1597
|
version: json.version,
|
|
1556
1598
|
moduleName: json.name
|
|
1557
1599
|
});
|
|
1558
|
-
case
|
|
1559
|
-
throw new _index2["default"](9999, "reWriteJsonAttribute() => path is not package.json, which is ".concat(path));
|
|
1560
|
-
case 18:
|
|
1600
|
+
case 12:
|
|
1561
1601
|
case "end":
|
|
1562
1602
|
return _context21.stop();
|
|
1563
1603
|
}
|
|
@@ -1760,78 +1800,85 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1760
1800
|
return _getObjectFromPromptQ.apply(this, arguments);
|
|
1761
1801
|
}
|
|
1762
1802
|
return getObjectFromPromptQ;
|
|
1763
|
-
}()
|
|
1803
|
+
}()
|
|
1804
|
+
/** 產出一個/temp,然後把/src 複製過去, 再把裡面每一個file的 if(DEBUG)給去除掉,再加上prettier */
|
|
1805
|
+
/** 找出if (configerer) 當作start */
|
|
1806
|
+
/** 找出 } 當作 end */
|
|
1807
|
+
/** 刪除掉 if(configerer.DEBUG) {...........} */
|
|
1808
|
+
)
|
|
1764
1809
|
}, {
|
|
1765
1810
|
key: "generateTempFolderWithCleanSrc",
|
|
1766
1811
|
value: (function () {
|
|
1767
|
-
var _generateTempFolderWithCleanSrc = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(
|
|
1768
|
-
var sourceFile, tempFolderPath, _iterator10, _step10,
|
|
1812
|
+
var _generateTempFolderWithCleanSrc = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee24(basePath) {
|
|
1813
|
+
var sourceFile, tempFolderPath, filePaths, _iterator10, _step10, tempFilePath, rawLines, trimmedLines, start, end, updatedContent;
|
|
1769
1814
|
return _regenerator["default"].wrap(function _callee24$(_context26) {
|
|
1770
1815
|
while (1) switch (_context26.prev = _context26.next) {
|
|
1771
1816
|
case 0:
|
|
1772
|
-
this.appendInfo("generateTempFolderWithCleanSrc",
|
|
1773
|
-
sourceFile = _path5["default"].join(
|
|
1774
|
-
tempFolderPath = _path5["default"].join(
|
|
1775
|
-
if (
|
|
1776
|
-
_context26.next =
|
|
1817
|
+
this.appendInfo("generateTempFolderWithCleanSrc", basePath);
|
|
1818
|
+
sourceFile = _path5["default"].join(basePath, "src");
|
|
1819
|
+
tempFolderPath = _path5["default"].join(basePath, "temp");
|
|
1820
|
+
if (_fs["default"].existsSync(sourceFile)) {
|
|
1821
|
+
_context26.next = 5;
|
|
1777
1822
|
break;
|
|
1778
1823
|
}
|
|
1824
|
+
return _context26.abrupt("return", tempFolderPath);
|
|
1825
|
+
case 5:
|
|
1779
1826
|
this.appendInfo("generateTempFolderWithCleanSrc", "source", sourceFile);
|
|
1780
1827
|
this.persistByPath(tempFolderPath);
|
|
1781
|
-
_context26.next =
|
|
1828
|
+
_context26.next = 9;
|
|
1782
1829
|
return this.copyFromFolderToDestFolder(sourceFile, tempFolderPath);
|
|
1783
|
-
case
|
|
1784
|
-
|
|
1785
|
-
|
|
1830
|
+
case 9:
|
|
1831
|
+
filePaths = this.findFilePathBy(tempFolderPath);
|
|
1832
|
+
_iterator10 = _createForOfIteratorHelper(filePaths);
|
|
1833
|
+
_context26.prev = 11;
|
|
1786
1834
|
_iterator10.s();
|
|
1787
|
-
case
|
|
1835
|
+
case 13:
|
|
1788
1836
|
if ((_step10 = _iterator10.n()).done) {
|
|
1789
|
-
_context26.next =
|
|
1837
|
+
_context26.next = 27;
|
|
1790
1838
|
break;
|
|
1791
1839
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
return
|
|
1796
|
-
});
|
|
1797
|
-
/** 找出if (configerer) 當作start */
|
|
1798
|
-
indexOfStart = _lodash["default"].findIndex(stmts, function (stmt) {
|
|
1799
|
-
return _lodash["default"].startsWith(stmt, "if (configerer.DEBUG_MODE)");
|
|
1840
|
+
tempFilePath = _step10.value.absolute;
|
|
1841
|
+
rawLines = this.getFileContextInRaw(tempFilePath).split("\n");
|
|
1842
|
+
trimmedLines = rawLines.map(function (line) {
|
|
1843
|
+
return line.trim();
|
|
1800
1844
|
});
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
return _lodash["default"].isEqual(stmt, "}");
|
|
1845
|
+
start = trimmedLines.findIndex(function (line) {
|
|
1846
|
+
return line.startsWith("if (configerer.DEBUG_MODE)");
|
|
1804
1847
|
});
|
|
1805
|
-
|
|
1806
|
-
|
|
1848
|
+
end = trimmedLines.lastIndexOf("}");
|
|
1849
|
+
if (!(start >= 0 && end > start)) {
|
|
1850
|
+
_context26.next = 25;
|
|
1807
1851
|
break;
|
|
1808
1852
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
_context26.next =
|
|
1853
|
+
// 移除 DEBUG 區塊
|
|
1854
|
+
rawLines.splice(start, end - start + 1);
|
|
1855
|
+
updatedContent = rawLines.join("\n");
|
|
1856
|
+
this.appendFile(tempFilePath, updatedContent, true, true);
|
|
1857
|
+
|
|
1858
|
+
// 美化代碼
|
|
1859
|
+
_context26.next = 25;
|
|
1860
|
+
return this.executeCommandLine("cd ".concat(_path5["default"].dirname(tempFilePath), " && npx prettier --write \"").concat(tempFilePath, "\""));
|
|
1861
|
+
case 25:
|
|
1862
|
+
_context26.next = 13;
|
|
1816
1863
|
break;
|
|
1817
|
-
case
|
|
1818
|
-
_context26.next =
|
|
1864
|
+
case 27:
|
|
1865
|
+
_context26.next = 32;
|
|
1819
1866
|
break;
|
|
1820
|
-
case 26:
|
|
1821
|
-
_context26.prev = 26;
|
|
1822
|
-
_context26.t0 = _context26["catch"](9);
|
|
1823
|
-
_iterator10.e(_context26.t0);
|
|
1824
1867
|
case 29:
|
|
1825
1868
|
_context26.prev = 29;
|
|
1826
|
-
|
|
1827
|
-
|
|
1869
|
+
_context26.t0 = _context26["catch"](11);
|
|
1870
|
+
_iterator10.e(_context26.t0);
|
|
1828
1871
|
case 32:
|
|
1872
|
+
_context26.prev = 32;
|
|
1873
|
+
_iterator10.f();
|
|
1874
|
+
return _context26.finish(32);
|
|
1875
|
+
case 35:
|
|
1829
1876
|
return _context26.abrupt("return", tempFolderPath);
|
|
1830
|
-
case
|
|
1877
|
+
case 36:
|
|
1831
1878
|
case "end":
|
|
1832
1879
|
return _context26.stop();
|
|
1833
1880
|
}
|
|
1834
|
-
}, _callee24, this, [[
|
|
1881
|
+
}, _callee24, this, [[11, 29, 32, 35]]);
|
|
1835
1882
|
}));
|
|
1836
1883
|
function generateTempFolderWithCleanSrc(_x26) {
|
|
1837
1884
|
return _generateTempFolderWithCleanSrc.apply(this, arguments);
|
|
@@ -1841,15 +1888,15 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1841
1888
|
/**
|
|
1842
1889
|
* from, destination
|
|
1843
1890
|
*
|
|
1844
|
-
* 讓file content清除後,在寫入資料, 避免
|
|
1891
|
+
* 讓file content清除後,在寫入資料, 避免to(destination) file address改變*/
|
|
1845
1892
|
)
|
|
1846
1893
|
}, {
|
|
1847
1894
|
key: "rewriteFile2File",
|
|
1848
|
-
value: function rewriteFile2File(from,
|
|
1895
|
+
value: function rewriteFile2File(from, to) {
|
|
1849
1896
|
var content = this.getFileContextInRaw(from);
|
|
1850
|
-
if (
|
|
1851
|
-
this.appendFile(
|
|
1852
|
-
this.appendInfo("rewrite from:".concat(from, " =>
|
|
1897
|
+
if (!content.trim()) throw new _index2["default"](9999, "".concat(from, " \u70BA\u7A7A\uFF0C\u907F\u514D\u8986\u84CB"));
|
|
1898
|
+
this.appendFile(to, content, true, true);
|
|
1899
|
+
this.appendInfo("rewrite from:".concat(from, " => to:").concat(to, " \u6210\u529F"));
|
|
1853
1900
|
}
|
|
1854
1901
|
|
|
1855
1902
|
/** 取得file第一行statement */
|
|
@@ -1866,26 +1913,24 @@ var NodeUtiller = /*#__PURE__*/function (_Utiller) {
|
|
|
1866
1913
|
/** 因為code gen有很多要js file要執行 persistent, 沒有修改過{const edit = true}的index persist就不要理它 */
|
|
1867
1914
|
}, {
|
|
1868
1915
|
key: "isFileEditSucceed",
|
|
1869
|
-
value: function isFileEditSucceed(
|
|
1870
|
-
if (!this.isPathExist(
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
var context = this.getFileContextInRaw(path);
|
|
1875
|
-
if (_lodash["default"].isEmpty(_lodash["default"].trim(context))) {
|
|
1916
|
+
value: function isFileEditSucceed(filePath) {
|
|
1917
|
+
if (!this.isPathExist(filePath)) return false;
|
|
1918
|
+
var file = this.getPathInfo(filePath);
|
|
1919
|
+
var context = this.getFileContextInRaw(filePath).trim();
|
|
1920
|
+
if (context === "") {
|
|
1876
1921
|
this.appendInfo("74985465 path ".concat(file.path, " is empty file, file would not persist"));
|
|
1877
1922
|
return false;
|
|
1878
1923
|
}
|
|
1879
1924
|
try {
|
|
1880
|
-
var
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
var
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1925
|
+
var firstLine = context.split("\n")[0];
|
|
1926
|
+
|
|
1927
|
+
// 偵測形如:const edit = true;
|
|
1928
|
+
var match = firstLine.match(/const\s+edit\s*=\s*(true|false)\s*;?/);
|
|
1929
|
+
if (!match) return false;
|
|
1930
|
+
var editValue = match[1] === "true";
|
|
1931
|
+
if (editValue === true) {
|
|
1932
|
+
return true;
|
|
1933
|
+
}
|
|
1889
1934
|
} catch (error) {
|
|
1890
1935
|
this.appendError("66445411 ".concat(error.message));
|
|
1891
1936
|
return false;
|
package/package.json
CHANGED