@cocojs/cli 0.0.1-alpha.18 → 0.0.1-alpha.19
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/dist/build-dot-coco-process/index.js +304 -356
- package/dist/index.js +63 -36
- package/package.json +1 -1
|
@@ -26,16 +26,7 @@ function _interopNamespaceDefault(e) {
|
|
|
26
26
|
|
|
27
27
|
var process__namespace = /*#__PURE__*/_interopNamespaceDefault(process$1);
|
|
28
28
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
29
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
30
29
|
|
|
31
|
-
function _arrayLikeToArray(r, a) {
|
|
32
|
-
(null == a || a > r.length) && (a = r.length);
|
|
33
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
34
|
-
return n;
|
|
35
|
-
}
|
|
36
|
-
function _arrayWithoutHoles(r) {
|
|
37
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
38
|
-
}
|
|
39
30
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
40
31
|
try {
|
|
41
32
|
var i = n[a](c),
|
|
@@ -75,54 +66,6 @@ function _createClass(e, r, t) {
|
|
|
75
66
|
writable: false
|
|
76
67
|
}), e;
|
|
77
68
|
}
|
|
78
|
-
function _createForOfIteratorHelper(r, e) {
|
|
79
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
80
|
-
if (!t) {
|
|
81
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
82
|
-
t && (r = t);
|
|
83
|
-
var n = 0,
|
|
84
|
-
F = function () {};
|
|
85
|
-
return {
|
|
86
|
-
s: F,
|
|
87
|
-
n: function () {
|
|
88
|
-
return n >= r.length ? {
|
|
89
|
-
done: true
|
|
90
|
-
} : {
|
|
91
|
-
done: false,
|
|
92
|
-
value: r[n++]
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
e: function (r) {
|
|
96
|
-
throw r;
|
|
97
|
-
},
|
|
98
|
-
f: F
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
102
|
-
}
|
|
103
|
-
var o,
|
|
104
|
-
a = true,
|
|
105
|
-
u = false;
|
|
106
|
-
return {
|
|
107
|
-
s: function () {
|
|
108
|
-
t = t.call(r);
|
|
109
|
-
},
|
|
110
|
-
n: function () {
|
|
111
|
-
var r = t.next();
|
|
112
|
-
return a = r.done, r;
|
|
113
|
-
},
|
|
114
|
-
e: function (r) {
|
|
115
|
-
u = true, o = r;
|
|
116
|
-
},
|
|
117
|
-
f: function () {
|
|
118
|
-
try {
|
|
119
|
-
a || null == t.return || t.return();
|
|
120
|
-
} finally {
|
|
121
|
-
if (u) throw o;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
69
|
function _defineProperty(e, r, t) {
|
|
127
70
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
128
71
|
value: t,
|
|
@@ -131,12 +74,6 @@ function _defineProperty(e, r, t) {
|
|
|
131
74
|
writable: true
|
|
132
75
|
}) : e[r] = t, e;
|
|
133
76
|
}
|
|
134
|
-
function _iterableToArray(r) {
|
|
135
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
136
|
-
}
|
|
137
|
-
function _nonIterableSpread() {
|
|
138
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
139
|
-
}
|
|
140
77
|
function ownKeys(e, r) {
|
|
141
78
|
var t = Object.keys(e);
|
|
142
79
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -266,9 +203,6 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
266
203
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
267
204
|
}, _regeneratorDefine(e, r, n, t);
|
|
268
205
|
}
|
|
269
|
-
function _toConsumableArray(r) {
|
|
270
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
271
|
-
}
|
|
272
206
|
function _toPrimitive(t, r) {
|
|
273
207
|
if ("object" != typeof t || !t) return t;
|
|
274
208
|
var e = t[Symbol.toPrimitive];
|
|
@@ -292,13 +226,6 @@ function _typeof(o) {
|
|
|
292
226
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
293
227
|
}, _typeof(o);
|
|
294
228
|
}
|
|
295
|
-
function _unsupportedIterableToArray(r, a) {
|
|
296
|
-
if (r) {
|
|
297
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
298
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
299
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
229
|
|
|
303
230
|
var Project = /*#__PURE__*/function () {
|
|
304
231
|
function Project(projectPath) {
|
|
@@ -442,13 +369,18 @@ function doMerge(config1, config2) {
|
|
|
442
369
|
return merged;
|
|
443
370
|
}
|
|
444
371
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
372
|
+
var number = 0;
|
|
373
|
+
var RE_DEFAULT_EXPORT = /export\s+default\s+(\w+);?\s?/;
|
|
374
|
+
/**
|
|
375
|
+
* console.log(numberToLetter(0)); // A
|
|
376
|
+
* console.log(numberToLetter(1)); // B
|
|
377
|
+
* console.log(numberToLetter(25)); // Z
|
|
378
|
+
* console.log(numberToLetter(26)); // AA
|
|
379
|
+
* console.log(numberToLetter(27)); // AB
|
|
380
|
+
* console.log(numberToLetter(51)); // AZ
|
|
381
|
+
* console.log(numberToLetter(52)); // BA
|
|
382
|
+
* @param n
|
|
383
|
+
*/
|
|
452
384
|
function numberToLetter(n) {
|
|
453
385
|
var result = '';
|
|
454
386
|
while (n >= 0) {
|
|
@@ -458,17 +390,9 @@ function numberToLetter(n) {
|
|
|
458
390
|
}
|
|
459
391
|
return result;
|
|
460
392
|
}
|
|
461
|
-
|
|
462
|
-
var PATH_TYPE;
|
|
463
|
-
(function (PATH_TYPE) {
|
|
464
|
-
PATH_TYPE[PATH_TYPE["FOLDER"] = 0] = "FOLDER";
|
|
465
|
-
PATH_TYPE[PATH_TYPE["FILE"] = 1] = "FILE";
|
|
466
|
-
})(PATH_TYPE || (PATH_TYPE = {}));
|
|
467
|
-
var number = 0;
|
|
468
|
-
var RE_DEFAULT_EXPORT = /export\s+default\s+(\w+);?\s?/;
|
|
469
|
-
function scanOneFile(filePath, decorator) {
|
|
393
|
+
function scanOneFile(filePath) {
|
|
470
394
|
var content = fs__namespace.readFileSync(filePath, 'utf-8');
|
|
471
|
-
if (
|
|
395
|
+
if (RE_DEFAULT_EXPORT.test(content)) {
|
|
472
396
|
// todo 需要校验export出来的class名称和注解的是否一致
|
|
473
397
|
// const className = RE_DEFAULT_EXPORT.exec(content)[1];
|
|
474
398
|
return {
|
|
@@ -478,298 +402,324 @@ function scanOneFile(filePath, decorator) {
|
|
|
478
402
|
}
|
|
479
403
|
return null;
|
|
480
404
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
var
|
|
488
|
-
|
|
489
|
-
_step;
|
|
490
|
-
try {
|
|
491
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
492
|
-
var file = _step.value;
|
|
493
|
-
var filePath = path__namespace.join(_path, file);
|
|
494
|
-
var stat = fs__namespace.statSync(filePath);
|
|
495
|
-
if (stat.isDirectory()) {
|
|
496
|
-
var find = doScan(PATH_TYPE.FOLDER, filePath, fileExt, decorator);
|
|
497
|
-
if (find.length) {
|
|
498
|
-
result.push.apply(result, _toConsumableArray(find));
|
|
499
|
-
}
|
|
500
|
-
} else if (stat.isFile() && path__namespace.extname(filePath) === fileExt) {
|
|
501
|
-
var r = scanOneFile(filePath, decorator);
|
|
502
|
-
if (r) {
|
|
503
|
-
result.push(r);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
} catch (err) {
|
|
508
|
-
_iterator.e(err);
|
|
509
|
-
} finally {
|
|
510
|
-
_iterator.f();
|
|
511
|
-
}
|
|
512
|
-
} else if (type === PATH_TYPE.FILE) {
|
|
513
|
-
var _r = scanOneFile(_path, decorator);
|
|
514
|
-
if (_r) {
|
|
515
|
-
result.push(_r);
|
|
405
|
+
|
|
406
|
+
function debounce(fn) {
|
|
407
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
|
|
408
|
+
var timer = null;
|
|
409
|
+
return function () {
|
|
410
|
+
var _this = this;
|
|
411
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
412
|
+
args[_key] = arguments[_key];
|
|
516
413
|
}
|
|
517
|
-
|
|
518
|
-
|
|
414
|
+
// 每次触发,先清空之前的定时器(重置延迟)
|
|
415
|
+
if (timer) clearTimeout(timer);
|
|
416
|
+
// 重新设置定时器,延迟执行
|
|
417
|
+
timer = setTimeout(function () {
|
|
418
|
+
fn.apply(_this, args);
|
|
419
|
+
timer = null;
|
|
420
|
+
}, delay);
|
|
421
|
+
};
|
|
519
422
|
}
|
|
520
|
-
var scanPathConfig = [{
|
|
521
|
-
// 配置项
|
|
522
|
-
type: PATH_TYPE.FOLDER,
|
|
523
|
-
path: Project.CONFIG_DIR,
|
|
524
|
-
fileExt: '.ts',
|
|
525
|
-
decorator: '@configuration'
|
|
526
|
-
}, {
|
|
527
|
-
// 布局
|
|
528
|
-
type: PATH_TYPE.FOLDER,
|
|
529
|
-
path: Project.LAYOUT_DIR,
|
|
530
|
-
fileExt: '.tsx',
|
|
531
|
-
decorator: '@layout'
|
|
532
|
-
}, {
|
|
533
|
-
// 页面
|
|
534
|
-
type: PATH_TYPE.FOLDER,
|
|
535
|
-
path: Project.PAGE_DIR,
|
|
536
|
-
fileExt: '.tsx',
|
|
537
|
-
decorator: '@page'
|
|
538
|
-
}, {
|
|
539
|
-
// 控制器
|
|
540
|
-
type: PATH_TYPE.FOLDER,
|
|
541
|
-
path: Project.Flow_DIR,
|
|
542
|
-
fileExt: '.ts',
|
|
543
|
-
decorator: '@flow'
|
|
544
|
-
}, {
|
|
545
|
-
// 通用组件
|
|
546
|
-
type: PATH_TYPE.FOLDER,
|
|
547
|
-
path: Project.COMPONENTS_DIR,
|
|
548
|
-
fileExt: '.ts',
|
|
549
|
-
decorator: '@component'
|
|
550
|
-
}, {
|
|
551
|
-
// 接口
|
|
552
|
-
type: PATH_TYPE.FOLDER,
|
|
553
|
-
path: Project.API_DIR,
|
|
554
|
-
fileExt: '.ts',
|
|
555
|
-
decorator: '@api'
|
|
556
|
-
}, {
|
|
557
|
-
// 视图
|
|
558
|
-
type: PATH_TYPE.FOLDER,
|
|
559
|
-
path: Project.VIEW_DIR,
|
|
560
|
-
fileExt: '.tsx',
|
|
561
|
-
decorator: '@view'
|
|
562
|
-
}, {
|
|
563
|
-
// 全局数据
|
|
564
|
-
type: PATH_TYPE.FOLDER,
|
|
565
|
-
path: Project.GLOBAL_DATA_DIR,
|
|
566
|
-
fileExt: '.ts',
|
|
567
|
-
decorator: '@globalData'
|
|
568
|
-
}, {
|
|
569
|
-
// 全局状态
|
|
570
|
-
type: PATH_TYPE.FOLDER,
|
|
571
|
-
path: Project.STORE_DIR,
|
|
572
|
-
fileExt: '.ts',
|
|
573
|
-
decorator: '@store'
|
|
574
|
-
}, {
|
|
575
|
-
// 入口文件
|
|
576
|
-
type: PATH_TYPE.FILE,
|
|
577
|
-
path: Project.APPLICATION,
|
|
578
|
-
fileExt: '.ts',
|
|
579
|
-
decorator: '@webApplication'
|
|
580
|
-
}];
|
|
581
|
-
var scan = function scan(project) {
|
|
582
|
-
return scanPathConfig.reduce(function (prev, curr) {
|
|
583
|
-
prev.push.apply(prev, _toConsumableArray(doScan(curr.type, project.genFullPath(curr.path), curr.fileExt, curr.decorator)));
|
|
584
|
-
return prev;
|
|
585
|
-
}, []);
|
|
586
|
-
};
|
|
587
423
|
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
var monorepoPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.';
|
|
596
|
-
_classCallCheck(this, DotCocoBuilder);
|
|
597
|
-
_defineProperty(this, "project", void 0);
|
|
598
|
-
_defineProperty(this, "iocComponents", void 0);
|
|
599
|
-
_defineProperty(this, "cmd", void 0);
|
|
600
|
-
_defineProperty(this, "srcWatcher", void 0);
|
|
601
|
-
_defineProperty(this, "propertiesWatcher", void 0);
|
|
602
|
-
_defineProperty(this, "ensureEmptyDotCocoFolder", function (project) {
|
|
603
|
-
if (fs.existsSync(project.dotCocoAbsPath)) {
|
|
604
|
-
fs.rmSync(project.dotCocoAbsPath, {
|
|
605
|
-
recursive: true
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
fs.mkdirSync(project.dotCocoAbsPath);
|
|
609
|
-
});
|
|
424
|
+
var Event;
|
|
425
|
+
(function (Event) {
|
|
426
|
+
Event[Event["InitBuildFinished"] = 0] = "InitBuildFinished";
|
|
427
|
+
})(Event || (Event = {}));
|
|
428
|
+
var debouncedGenIndexTsx = debounce(genIndexTsx);
|
|
429
|
+
var debouncedMergeProperties = debounce(merge);
|
|
430
|
+
var DotCocoBuilder = /*#__PURE__*/function () {
|
|
610
431
|
/**
|
|
611
|
-
*
|
|
432
|
+
* 目前仅支持单体应用,为了单元测试,可以传入子应用相对项目根的路径
|
|
433
|
+
* @param monorepoPath
|
|
612
434
|
*/
|
|
613
|
-
|
|
614
|
-
_this
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
435
|
+
function DotCocoBuilder() {
|
|
436
|
+
var _this = this;
|
|
437
|
+
var monorepoPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.';
|
|
438
|
+
_classCallCheck(this, DotCocoBuilder);
|
|
439
|
+
_defineProperty(this, "status", null);
|
|
440
|
+
_defineProperty(this, "isWatch", null);
|
|
441
|
+
_defineProperty(this, "project", void 0);
|
|
442
|
+
_defineProperty(this, "iocComponents", void 0);
|
|
443
|
+
_defineProperty(this, "cmd", null);
|
|
444
|
+
_defineProperty(this, "srcWatcher", void 0);
|
|
445
|
+
_defineProperty(this, "srcWatcherReadyTriggered", void 0);
|
|
446
|
+
_defineProperty(this, "propertiesWatcher", void 0);
|
|
447
|
+
_defineProperty(this, "propertiesWatcherReadyTriggered", void 0);
|
|
448
|
+
_defineProperty(this, "stopPromise", void 0);
|
|
449
|
+
_defineProperty(this, "stopPromiseResolved", void 0);
|
|
450
|
+
_defineProperty(this, "stopPromiseRejected", void 0);
|
|
451
|
+
_defineProperty(this, "trigger", void 0);
|
|
452
|
+
_defineProperty(this, "ensureEmptyDotCocoFolder", function (project) {
|
|
453
|
+
if (fs.existsSync(project.dotCocoAbsPath)) {
|
|
454
|
+
fs.rmSync(project.dotCocoAbsPath, {
|
|
455
|
+
recursive: true
|
|
456
|
+
});
|
|
631
457
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
458
|
+
fs.mkdirSync(project.dotCocoAbsPath);
|
|
459
|
+
});
|
|
460
|
+
_defineProperty(this, "isTsTsxFile", function (path) {
|
|
461
|
+
return path.endsWith('.ts') || path.endsWith('.tsx');
|
|
462
|
+
});
|
|
463
|
+
_defineProperty(this, "handleAddFile", function (filePath) {
|
|
464
|
+
if (_this.isTsTsxFile(filePath)) {
|
|
465
|
+
var scanRlt = scanOneFile(_this.project.genFullPath(filePath));
|
|
466
|
+
if (scanRlt !== null) {
|
|
467
|
+
if (!_this.iocComponents.find(function (i) {
|
|
468
|
+
return i.filePath === scanRlt.filePath;
|
|
469
|
+
})) {
|
|
470
|
+
// 新增一个组件
|
|
471
|
+
_this.iocComponents.push(scanRlt);
|
|
472
|
+
debouncedGenIndexTsx(_this.project, _this.iocComponents);
|
|
473
|
+
}
|
|
640
474
|
}
|
|
641
475
|
}
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
_defineProperty(this, "handleDeleteFile", function (filePath) {
|
|
645
|
-
if (_this.isTsTsxFile(filePath)) {
|
|
646
|
-
var fullPath = _this.project.genFullPath(filePath);
|
|
647
|
-
var index = _this.iocComponents.findIndex(function (i) {
|
|
648
|
-
return i.filePath === fullPath;
|
|
649
|
-
});
|
|
650
|
-
if (index > 0) {
|
|
651
|
-
_this.iocComponents.splice(index, 1);
|
|
652
|
-
genIndexTsx(_this.project, _this.iocComponents);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
_defineProperty(this, "watchSrc", function () {
|
|
657
|
-
_this.srcWatcher = chokidar.watch(_this.project.srcAbsPath, {
|
|
658
|
-
ignored: function ignored(absPath, stats) {
|
|
659
|
-
// 忽略.coco文件夹
|
|
660
|
-
var srcPath = path.relative(_this.project.srcAbsPath, absPath);
|
|
661
|
-
return srcPath.startsWith('.coco');
|
|
662
|
-
},
|
|
663
|
-
ignoreInitial: true,
|
|
664
|
-
cwd: _this.project.srcAbsPath
|
|
665
476
|
});
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
return false;
|
|
477
|
+
_defineProperty(this, "handleDeleteFile", function (filePath) {
|
|
478
|
+
if (_this.isTsTsxFile(filePath)) {
|
|
479
|
+
var fullPath = _this.project.genFullPath(filePath);
|
|
480
|
+
var index = _this.iocComponents.findIndex(function (i) {
|
|
481
|
+
return i.filePath === fullPath;
|
|
482
|
+
});
|
|
483
|
+
if (index > 0) {
|
|
484
|
+
_this.iocComponents.splice(index, 1);
|
|
485
|
+
debouncedGenIndexTsx(_this.project, _this.iocComponents);
|
|
676
486
|
}
|
|
677
|
-
|
|
678
|
-
},
|
|
679
|
-
ignoreInitial: true,
|
|
680
|
-
cwd: _this.project.srcAbsPath
|
|
487
|
+
}
|
|
681
488
|
});
|
|
682
|
-
|
|
683
|
-
|
|
489
|
+
_defineProperty(this, "tryEmitInitialBuildFinished", function () {
|
|
490
|
+
if (_this.srcWatcherReadyTriggered && _this.propertiesWatcherReadyTriggered) {
|
|
491
|
+
// 因为生成文件都是在debounce函数中执行的,所以等待genIndexTsx执行后再通知初次构建成功。
|
|
492
|
+
// 这里使用使用简单的做法,真正严谨就是同步的,不过暂时不需要。
|
|
493
|
+
setTimeout(function () {
|
|
494
|
+
var _this$trigger;
|
|
495
|
+
return (_this$trigger = _this.trigger) === null || _this$trigger === void 0 ? void 0 : _this$trigger.call(_this, Event.InitBuildFinished);
|
|
496
|
+
}, 1000);
|
|
497
|
+
if (!_this.isWatch) {
|
|
498
|
+
setTimeout(_this.stopWatch, 1000);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
684
501
|
});
|
|
685
|
-
|
|
686
|
-
|
|
502
|
+
/**
|
|
503
|
+
* 所描 src 下所有的 ts tsx 文件
|
|
504
|
+
* 排除.coco文件夹
|
|
505
|
+
* 目前不会校验page组件是否在/src/page文件夹下的,后续有必要的话添加。
|
|
506
|
+
*/
|
|
507
|
+
_defineProperty(this, "watchSrc", function () {
|
|
508
|
+
_this.srcWatcher = chokidar.watch(_this.project.srcAbsPath, {
|
|
509
|
+
ignored: function ignored(absPath, stats) {
|
|
510
|
+
if (absPath === _this.project.dotCocoAbsPath) {
|
|
511
|
+
// 忽略.coco文件夹
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
if (DotCocoBuilder.ignoredSrcFileExt.find(function (ext) {
|
|
515
|
+
return absPath.endsWith(ext);
|
|
516
|
+
})) {
|
|
517
|
+
// 忽略非 ts tsx 文件
|
|
518
|
+
return true;
|
|
519
|
+
}
|
|
520
|
+
return false;
|
|
521
|
+
},
|
|
522
|
+
ignoreInitial: false,
|
|
523
|
+
cwd: _this.project.srcAbsPath
|
|
524
|
+
});
|
|
525
|
+
_this.srcWatcher.on('add', _this.handleAddFile);
|
|
526
|
+
_this.srcWatcher.on('change', _this.handleAddFile);
|
|
527
|
+
_this.srcWatcher.on('unlink', _this.handleDeleteFile);
|
|
528
|
+
_this.srcWatcher.on('ready', function () {
|
|
529
|
+
_this.srcWatcherReadyTriggered = true;
|
|
530
|
+
_this.tryEmitInitialBuildFinished();
|
|
531
|
+
});
|
|
532
|
+
_this.srcWatcher.on('error', function (error) {
|
|
533
|
+
process.send("src error ".concat(error));
|
|
534
|
+
});
|
|
687
535
|
});
|
|
688
|
-
|
|
689
|
-
|
|
536
|
+
_defineProperty(this, "watchProperties", function () {
|
|
537
|
+
_this.propertiesWatcher = chokidar.watch(_this.project.propertiesAbsPath, {
|
|
538
|
+
ignored: function ignored(absPath, stats) {
|
|
539
|
+
var filename = path.relative(_this.project.propertiesAbsPath, absPath);
|
|
540
|
+
return absPath !== _this.project.propertiesAbsPath && filename !== defaultPropertiesName && filename !== propertiesFileName(_this.cmd);
|
|
541
|
+
},
|
|
542
|
+
ignoreInitial: false,
|
|
543
|
+
cwd: _this.project.propertiesAbsPath
|
|
544
|
+
});
|
|
545
|
+
_this.propertiesWatcher.on('add', function () {
|
|
546
|
+
return debouncedMergeProperties(_this.project, _this.cmd);
|
|
547
|
+
});
|
|
548
|
+
_this.propertiesWatcher.on('change', function () {
|
|
549
|
+
return debouncedMergeProperties(_this.project, _this.cmd);
|
|
550
|
+
});
|
|
551
|
+
_this.propertiesWatcher.on('unlink', function () {
|
|
552
|
+
return debouncedMergeProperties(_this.project, _this.cmd);
|
|
553
|
+
});
|
|
554
|
+
_this.propertiesWatcher.on('ready', function () {
|
|
555
|
+
_this.propertiesWatcherReadyTriggered = true;
|
|
556
|
+
_this.tryEmitInitialBuildFinished();
|
|
557
|
+
});
|
|
558
|
+
_this.propertiesWatcher.on('error', function (error) {
|
|
559
|
+
process.send("properties error ".concat(error));
|
|
560
|
+
});
|
|
690
561
|
});
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
562
|
+
/**
|
|
563
|
+
* 开始构建
|
|
564
|
+
* @param watch 是否启用 watch。否在ready事件之后终止;是:需要手动调用stopWatch停止
|
|
565
|
+
*/
|
|
566
|
+
_defineProperty(this, "start", /*#__PURE__*/function () {
|
|
567
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(watch) {
|
|
568
|
+
return _regenerator().w(function (_context) {
|
|
569
|
+
while (1) switch (_context.n) {
|
|
570
|
+
case 0:
|
|
571
|
+
if (!(_this.status !== 'constructed')) {
|
|
572
|
+
_context.n = 1;
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
return _context.a(2, _this.stopPromise);
|
|
576
|
+
case 1:
|
|
577
|
+
_this.status = 'running';
|
|
578
|
+
_this.isWatch = !!watch;
|
|
579
|
+
_this.stopPromise = new Promise(function (resolve, reject) {
|
|
580
|
+
_this.stopPromiseResolved = resolve;
|
|
581
|
+
_this.stopPromiseRejected = reject;
|
|
582
|
+
});
|
|
583
|
+
_this.watchSrc();
|
|
584
|
+
_this.watchProperties();
|
|
585
|
+
return _context.a(2, _this.stopPromise);
|
|
712
586
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
587
|
+
}, _callee);
|
|
588
|
+
}));
|
|
589
|
+
return function (_x) {
|
|
590
|
+
return _ref.apply(this, arguments);
|
|
591
|
+
};
|
|
592
|
+
}());
|
|
593
|
+
_defineProperty(this, "stopWatch", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
594
|
+
return _regenerator().w(function (_context2) {
|
|
595
|
+
while (1) switch (_context2.n) {
|
|
596
|
+
case 0:
|
|
597
|
+
if (!(_this.status !== 'running')) {
|
|
598
|
+
_context2.n = 1;
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
return _context2.a(2);
|
|
602
|
+
case 1:
|
|
603
|
+
if (!_this.srcWatcher) {
|
|
604
|
+
_context2.n = 3;
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
_context2.n = 2;
|
|
608
|
+
return _this.srcWatcher.close();
|
|
609
|
+
case 2:
|
|
610
|
+
_this.srcWatcher = null;
|
|
611
|
+
case 3:
|
|
612
|
+
if (!_this.propertiesWatcher) {
|
|
613
|
+
_context2.n = 5;
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
_context2.n = 4;
|
|
617
|
+
return _this.propertiesWatcher.close();
|
|
618
|
+
case 4:
|
|
619
|
+
_this.propertiesWatcher = null;
|
|
620
|
+
case 5:
|
|
621
|
+
_this.stopPromiseResolved();
|
|
622
|
+
_this.reset();
|
|
623
|
+
case 6:
|
|
624
|
+
return _context2.a(2);
|
|
625
|
+
}
|
|
626
|
+
}, _callee2);
|
|
627
|
+
})));
|
|
628
|
+
_defineProperty(this, "buildOnce", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
629
|
+
return _regenerator().w(function (_context3) {
|
|
630
|
+
while (1) switch (_context3.n) {
|
|
631
|
+
case 0:
|
|
632
|
+
return _context3.a(2, _this.start(false));
|
|
633
|
+
}
|
|
634
|
+
}, _callee3);
|
|
635
|
+
})));
|
|
636
|
+
_defineProperty(this, "buildAndWatch", function () {
|
|
637
|
+
return _this.start(true);
|
|
638
|
+
});
|
|
639
|
+
this.reset();
|
|
640
|
+
this.project = new Project(monorepoPath);
|
|
641
|
+
this.ensureEmptyDotCocoFolder(this.project);
|
|
642
|
+
}
|
|
643
|
+
return _createClass(DotCocoBuilder, [{
|
|
644
|
+
key: "reset",
|
|
645
|
+
value: function reset() {
|
|
646
|
+
this.status = 'constructed';
|
|
647
|
+
this.isWatch = null;
|
|
648
|
+
this.iocComponents = [];
|
|
649
|
+
this.cmd = null;
|
|
650
|
+
this.srcWatcher = null;
|
|
651
|
+
this.srcWatcherReadyTriggered = false;
|
|
652
|
+
this.propertiesWatcher = null;
|
|
653
|
+
this.propertiesWatcherReadyTriggered = false;
|
|
654
|
+
this.stopPromise = null;
|
|
655
|
+
this.stopPromiseResolved = null;
|
|
656
|
+
this.stopPromiseRejected = null;
|
|
657
|
+
this.trigger = null;
|
|
658
|
+
}
|
|
659
|
+
}, {
|
|
660
|
+
key: "addEventListener",
|
|
661
|
+
value: function addEventListener(listener) {
|
|
662
|
+
if (this.trigger) {
|
|
663
|
+
throw new Error('目前只需要支持一个listener');
|
|
719
664
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
665
|
+
this.trigger = listener;
|
|
666
|
+
}
|
|
667
|
+
}]);
|
|
668
|
+
}();
|
|
669
|
+
_defineProperty(DotCocoBuilder, "ignoredSrcFileExt", ['.js', '.jsx', '.css', '.less', '.sass', '.scss', '.json', '.node']);
|
|
725
670
|
|
|
726
671
|
function startListening(builder) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
{
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
672
|
+
process$1.on('message', /*#__PURE__*/function () {
|
|
673
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(msg) {
|
|
674
|
+
var _t;
|
|
675
|
+
return _regenerator().w(function (_context) {
|
|
676
|
+
while (1) switch (_context.n) {
|
|
677
|
+
case 0:
|
|
678
|
+
_t = msg;
|
|
679
|
+
_context.n = _t === 'build-once' ? 1 : _t === 'build-and-watch' ? 3 : 4;
|
|
680
|
+
break;
|
|
681
|
+
case 1:
|
|
682
|
+
_context.n = 2;
|
|
683
|
+
return builder.buildOnce();
|
|
684
|
+
case 2:
|
|
685
|
+
process$1.send('build-success');
|
|
686
|
+
return _context.a(3, 5);
|
|
687
|
+
case 3:
|
|
688
|
+
builder.addEventListener(function (e) {
|
|
689
|
+
if (e === Event.InitBuildFinished) {
|
|
690
|
+
process$1.send('init-build-success');
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
builder.buildAndWatch();
|
|
694
|
+
return _context.a(3, 5);
|
|
695
|
+
case 4:
|
|
696
|
+
process$1.send("dot coco process rcv msg:[".concat(msg, "]"));
|
|
697
|
+
return _context.a(3, 5);
|
|
698
|
+
case 5:
|
|
699
|
+
return _context.a(2);
|
|
748
700
|
}
|
|
749
|
-
|
|
750
|
-
|
|
701
|
+
}, _callee);
|
|
702
|
+
}));
|
|
703
|
+
return function (_x) {
|
|
704
|
+
return _ref.apply(this, arguments);
|
|
705
|
+
};
|
|
706
|
+
}());
|
|
751
707
|
function handleTerminate() {
|
|
752
708
|
return _handleTerminate.apply(this, arguments);
|
|
753
709
|
}
|
|
754
710
|
function _handleTerminate() {
|
|
755
|
-
_handleTerminate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
756
|
-
return _regenerator().w(function (
|
|
757
|
-
while (1) switch (
|
|
711
|
+
_handleTerminate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
712
|
+
return _regenerator().w(function (_context2) {
|
|
713
|
+
while (1) switch (_context2.n) {
|
|
758
714
|
case 0:
|
|
759
|
-
|
|
760
|
-
_context.n = 2;
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
_context.n = 1;
|
|
715
|
+
_context2.n = 1;
|
|
764
716
|
return builder.stopWatch();
|
|
765
717
|
case 1:
|
|
766
|
-
watching = false;
|
|
767
|
-
case 2:
|
|
768
718
|
process$1.exit(0);
|
|
769
|
-
case
|
|
770
|
-
return
|
|
719
|
+
case 2:
|
|
720
|
+
return _context2.a(2);
|
|
771
721
|
}
|
|
772
|
-
},
|
|
722
|
+
}, _callee2);
|
|
773
723
|
}));
|
|
774
724
|
return _handleTerminate.apply(this, arguments);
|
|
775
725
|
}
|
|
@@ -784,5 +734,3 @@ function startAsProcess() {
|
|
|
784
734
|
}
|
|
785
735
|
}
|
|
786
736
|
startAsProcess();
|
|
787
|
-
|
|
788
|
-
module.exports = DotCocoBuilder;
|
package/dist/index.js
CHANGED
|
@@ -300,7 +300,10 @@ var WorkFlow = /*#__PURE__*/function () {
|
|
|
300
300
|
return _regenerator().w(function (_context) {
|
|
301
301
|
while (1) switch (_context.n) {
|
|
302
302
|
case 0:
|
|
303
|
-
|
|
303
|
+
_context.n = 1;
|
|
304
|
+
return this.run('build-once');
|
|
305
|
+
case 1:
|
|
306
|
+
return _context.a(2, _context.v);
|
|
304
307
|
}
|
|
305
308
|
}, _callee, this);
|
|
306
309
|
}));
|
|
@@ -316,7 +319,10 @@ var WorkFlow = /*#__PURE__*/function () {
|
|
|
316
319
|
return _regenerator().w(function (_context2) {
|
|
317
320
|
while (1) switch (_context2.n) {
|
|
318
321
|
case 0:
|
|
319
|
-
|
|
322
|
+
_context2.n = 1;
|
|
323
|
+
return this.run('build-and-watch');
|
|
324
|
+
case 1:
|
|
325
|
+
return _context2.a(2, _context2.v);
|
|
320
326
|
}
|
|
321
327
|
}, _callee2, this);
|
|
322
328
|
}));
|
|
@@ -574,47 +580,68 @@ var _test_helper;
|
|
|
574
580
|
* coco app build 构建
|
|
575
581
|
* coco app dev 开发
|
|
576
582
|
*/
|
|
577
|
-
function execAppCmd(
|
|
578
|
-
|
|
579
|
-
case 'build':
|
|
580
|
-
{
|
|
581
|
-
buildApp();
|
|
582
|
-
break;
|
|
583
|
-
}
|
|
584
|
-
case 'dev':
|
|
585
|
-
{
|
|
586
|
-
devApp();
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
default:
|
|
590
|
-
{
|
|
591
|
-
console.log("Unknown app action: ".concat(action));
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
583
|
+
function execAppCmd(_x) {
|
|
584
|
+
return _execAppCmd.apply(this, arguments);
|
|
595
585
|
}
|
|
596
586
|
/**
|
|
597
587
|
* 组件库项目命令
|
|
598
588
|
* coco lib build 构建
|
|
599
589
|
*/
|
|
600
|
-
function
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
590
|
+
function _execAppCmd() {
|
|
591
|
+
_execAppCmd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(action) {
|
|
592
|
+
var _t;
|
|
593
|
+
return _regenerator().w(function (_context) {
|
|
594
|
+
while (1) switch (_context.n) {
|
|
595
|
+
case 0:
|
|
596
|
+
_t = action;
|
|
597
|
+
_context.n = _t === 'build' ? 1 : _t === 'dev' ? 3 : 5;
|
|
598
|
+
break;
|
|
599
|
+
case 1:
|
|
600
|
+
_context.n = 2;
|
|
601
|
+
return buildApp();
|
|
602
|
+
case 2:
|
|
603
|
+
return _context.a(3, 6);
|
|
604
|
+
case 3:
|
|
605
|
+
_context.n = 4;
|
|
606
|
+
return devApp();
|
|
607
|
+
case 4:
|
|
608
|
+
return _context.a(3, 6);
|
|
609
|
+
case 5:
|
|
610
|
+
console.log("Unknown app action: ".concat(action));
|
|
611
|
+
return _context.a(3, 6);
|
|
612
|
+
case 6:
|
|
613
|
+
return _context.a(2);
|
|
611
614
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
615
|
+
}, _callee);
|
|
616
|
+
}));
|
|
617
|
+
return _execAppCmd.apply(this, arguments);
|
|
618
|
+
}
|
|
619
|
+
function execLibCmd(_x2) {
|
|
620
|
+
return _execLibCmd.apply(this, arguments);
|
|
621
|
+
}
|
|
622
|
+
function _execLibCmd() {
|
|
623
|
+
_execLibCmd = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(action) {
|
|
624
|
+
var _t2;
|
|
625
|
+
return _regenerator().w(function (_context2) {
|
|
626
|
+
while (1) switch (_context2.n) {
|
|
627
|
+
case 0:
|
|
628
|
+
_t2 = action;
|
|
629
|
+
_context2.n = _t2 === 'build' ? 1 : 3;
|
|
630
|
+
break;
|
|
631
|
+
case 1:
|
|
632
|
+
_context2.n = 2;
|
|
633
|
+
return build();
|
|
634
|
+
case 2:
|
|
635
|
+
return _context2.a(3, 4);
|
|
636
|
+
case 3:
|
|
637
|
+
console.log("Unknown lib action: ".concat(action));
|
|
638
|
+
return _context2.a(3, 4);
|
|
639
|
+
case 4:
|
|
640
|
+
return _context2.a(2);
|
|
616
641
|
}
|
|
617
|
-
|
|
642
|
+
}, _callee2);
|
|
643
|
+
}));
|
|
644
|
+
return _execLibCmd.apply(this, arguments);
|
|
618
645
|
}
|
|
619
646
|
function cli(command, domain, rest) {
|
|
620
647
|
var _rest = _slicedToArray(rest, 1),
|