@cocojs/cli 0.0.1-alpha202511172053 → 0.1.0-beta.20
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 +363 -449
- package/dist/index.js +255 -94
- package/dist/webpack-process/index.js +151 -96
- package/package.json +12 -8
|
@@ -5,9 +5,6 @@ var fs = require('fs');
|
|
|
5
5
|
var fse = require('fs-extra');
|
|
6
6
|
var path$1 = require('path');
|
|
7
7
|
var path = require('node:path');
|
|
8
|
-
var parser = require('@babel/parser');
|
|
9
|
-
var traverse = require('@babel/traverse');
|
|
10
|
-
var types = require('@babel/types');
|
|
11
8
|
var chokidar = require('chokidar');
|
|
12
9
|
|
|
13
10
|
function _interopNamespaceDefault(e) {
|
|
@@ -29,15 +26,31 @@ function _interopNamespaceDefault(e) {
|
|
|
29
26
|
|
|
30
27
|
var process__namespace = /*#__PURE__*/_interopNamespaceDefault(process$1);
|
|
31
28
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
32
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
33
29
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
31
|
+
try {
|
|
32
|
+
var i = n[a](c),
|
|
33
|
+
u = i.value;
|
|
34
|
+
} catch (n) {
|
|
35
|
+
return void e(n);
|
|
36
|
+
}
|
|
37
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
39
|
+
function _asyncToGenerator(n) {
|
|
40
|
+
return function () {
|
|
41
|
+
var t = this,
|
|
42
|
+
e = arguments;
|
|
43
|
+
return new Promise(function (r, o) {
|
|
44
|
+
var a = n.apply(t, e);
|
|
45
|
+
function _next(n) {
|
|
46
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
47
|
+
}
|
|
48
|
+
function _throw(n) {
|
|
49
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
50
|
+
}
|
|
51
|
+
_next(void 0);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
41
54
|
}
|
|
42
55
|
function _classCallCheck(a, n) {
|
|
43
56
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
@@ -53,59 +66,34 @@ function _createClass(e, r, t) {
|
|
|
53
66
|
writable: false
|
|
54
67
|
}), e;
|
|
55
68
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
s: F,
|
|
65
|
-
n: function () {
|
|
66
|
-
return n >= r.length ? {
|
|
67
|
-
done: true
|
|
68
|
-
} : {
|
|
69
|
-
done: false,
|
|
70
|
-
value: r[n++]
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
e: function (r) {
|
|
74
|
-
throw r;
|
|
75
|
-
},
|
|
76
|
-
f: F
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
80
|
-
}
|
|
81
|
-
var o,
|
|
82
|
-
a = true,
|
|
83
|
-
u = false;
|
|
84
|
-
return {
|
|
85
|
-
s: function () {
|
|
86
|
-
t = t.call(r);
|
|
87
|
-
},
|
|
88
|
-
n: function () {
|
|
89
|
-
var r = t.next();
|
|
90
|
-
return a = r.done, r;
|
|
91
|
-
},
|
|
92
|
-
e: function (r) {
|
|
93
|
-
u = true, o = r;
|
|
94
|
-
},
|
|
95
|
-
f: function () {
|
|
96
|
-
try {
|
|
97
|
-
a || null == t.return || t.return();
|
|
98
|
-
} finally {
|
|
99
|
-
if (u) throw o;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
69
|
+
function _defineProperty(e, r, t) {
|
|
70
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
71
|
+
value: t,
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true
|
|
75
|
+
}) : e[r] = t, e;
|
|
103
76
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
77
|
+
function ownKeys(e, r) {
|
|
78
|
+
var t = Object.keys(e);
|
|
79
|
+
if (Object.getOwnPropertySymbols) {
|
|
80
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
81
|
+
r && (o = o.filter(function (r) {
|
|
82
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
83
|
+
})), t.push.apply(t, o);
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
106
86
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
87
|
+
function _objectSpread2(e) {
|
|
88
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
89
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
90
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
91
|
+
_defineProperty(e, r, t[r]);
|
|
92
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
93
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return e;
|
|
109
97
|
}
|
|
110
98
|
function _regenerator() {
|
|
111
99
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
@@ -215,9 +203,6 @@ function _regeneratorDefine(e, r, n, t) {
|
|
|
215
203
|
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
216
204
|
}, _regeneratorDefine(e, r, n, t);
|
|
217
205
|
}
|
|
218
|
-
function _toConsumableArray(r) {
|
|
219
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
220
|
-
}
|
|
221
206
|
function _toPrimitive(t, r) {
|
|
222
207
|
if ("object" != typeof t || !t) return t;
|
|
223
208
|
var e = t[Symbol.toPrimitive];
|
|
@@ -226,7 +211,7 @@ function _toPrimitive(t, r) {
|
|
|
226
211
|
if ("object" != typeof i) return i;
|
|
227
212
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
228
213
|
}
|
|
229
|
-
return (String )(t);
|
|
214
|
+
return ("string" === r ? String : Number)(t);
|
|
230
215
|
}
|
|
231
216
|
function _toPropertyKey(t) {
|
|
232
217
|
var i = _toPrimitive(t, "string");
|
|
@@ -241,55 +226,16 @@ function _typeof(o) {
|
|
|
241
226
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
242
227
|
}, _typeof(o);
|
|
243
228
|
}
|
|
244
|
-
function _unsupportedIterableToArray(r, a) {
|
|
245
|
-
if (r) {
|
|
246
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
247
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
248
|
-
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;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
253
|
-
function adopt(value) {
|
|
254
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
255
|
-
resolve(value);
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
259
|
-
function fulfilled(value) {
|
|
260
|
-
try {
|
|
261
|
-
step(generator.next(value));
|
|
262
|
-
} catch (e) {
|
|
263
|
-
reject(e);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function rejected(value) {
|
|
267
|
-
try {
|
|
268
|
-
step(generator["throw"](value));
|
|
269
|
-
} catch (e) {
|
|
270
|
-
reject(e);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
function step(result) {
|
|
274
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
275
|
-
}
|
|
276
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
280
|
-
var e = new Error(message);
|
|
281
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
282
|
-
};
|
|
283
229
|
|
|
284
230
|
var Project = /*#__PURE__*/function () {
|
|
285
231
|
function Project(projectPath) {
|
|
286
232
|
var _this = this;
|
|
287
233
|
_classCallCheck(this, Project);
|
|
288
234
|
// 项目所在文件夹的绝对路径
|
|
289
|
-
this
|
|
290
|
-
this
|
|
235
|
+
_defineProperty(this, "absPath", '');
|
|
236
|
+
_defineProperty(this, "genFullPath", function (name) {
|
|
291
237
|
return path.join(_this.srcAbsPath, name);
|
|
292
|
-
};
|
|
238
|
+
});
|
|
293
239
|
this.absPath = path.join(process.cwd(), projectPath);
|
|
294
240
|
}
|
|
295
241
|
return _createClass(Project, [{
|
|
@@ -314,17 +260,17 @@ var Project = /*#__PURE__*/function () {
|
|
|
314
260
|
}
|
|
315
261
|
}]);
|
|
316
262
|
}();
|
|
317
|
-
Project
|
|
318
|
-
Project
|
|
319
|
-
Project
|
|
320
|
-
Project
|
|
321
|
-
Project
|
|
322
|
-
Project
|
|
323
|
-
Project
|
|
324
|
-
Project
|
|
325
|
-
Project
|
|
326
|
-
Project
|
|
327
|
-
Project
|
|
263
|
+
_defineProperty(Project, "DOT_COCO_DIR", '.coco');
|
|
264
|
+
_defineProperty(Project, "APPLICATION", 'application.ts');
|
|
265
|
+
_defineProperty(Project, "VIEW_DIR", 'view');
|
|
266
|
+
_defineProperty(Project, "CONFIG_DIR", 'config');
|
|
267
|
+
_defineProperty(Project, "PAGE_DIR", 'page');
|
|
268
|
+
_defineProperty(Project, "LAYOUT_DIR", 'layout');
|
|
269
|
+
_defineProperty(Project, "Flow_DIR", 'flow');
|
|
270
|
+
_defineProperty(Project, "API_DIR", 'api');
|
|
271
|
+
_defineProperty(Project, "STORE_DIR", 'store');
|
|
272
|
+
_defineProperty(Project, "GLOBAL_DATA_DIR", 'global-data');
|
|
273
|
+
_defineProperty(Project, "COMPONENTS_DIR", 'component');
|
|
328
274
|
|
|
329
275
|
/**
|
|
330
276
|
* 构建.coco文件夹
|
|
@@ -415,7 +361,7 @@ function doMerge(config1, config2) {
|
|
|
415
361
|
return config2;
|
|
416
362
|
}
|
|
417
363
|
var keys2 = Object.keys(config2);
|
|
418
|
-
var merged =
|
|
364
|
+
var merged = _objectSpread2({}, config1);
|
|
419
365
|
for (var _i = 0, _keys = keys2; _i < _keys.length; _i++) {
|
|
420
366
|
var key = _keys[_i];
|
|
421
367
|
merged[key] = doMerge(config1[key], config2[key]);
|
|
@@ -423,13 +369,18 @@ function doMerge(config1, config2) {
|
|
|
423
369
|
return merged;
|
|
424
370
|
}
|
|
425
371
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
+
*/
|
|
433
384
|
function numberToLetter(n) {
|
|
434
385
|
var result = '';
|
|
435
386
|
while (n >= 0) {
|
|
@@ -439,17 +390,9 @@ function numberToLetter(n) {
|
|
|
439
390
|
}
|
|
440
391
|
return result;
|
|
441
392
|
}
|
|
442
|
-
|
|
443
|
-
var PATH_TYPE;
|
|
444
|
-
(function (PATH_TYPE) {
|
|
445
|
-
PATH_TYPE[PATH_TYPE["FOLDER"] = 0] = "FOLDER";
|
|
446
|
-
PATH_TYPE[PATH_TYPE["FILE"] = 1] = "FILE";
|
|
447
|
-
})(PATH_TYPE || (PATH_TYPE = {}));
|
|
448
|
-
var number = 0;
|
|
449
|
-
var RE_DEFAULT_EXPORT = /export\s+default\s+(\w+);?\s?/;
|
|
450
|
-
function scanOneFile(filePath, decorator) {
|
|
393
|
+
function scanOneFile(filePath) {
|
|
451
394
|
var content = fs__namespace.readFileSync(filePath, 'utf-8');
|
|
452
|
-
if (
|
|
395
|
+
if (RE_DEFAULT_EXPORT.test(content)) {
|
|
453
396
|
// todo 需要校验export出来的class名称和注解的是否一致
|
|
454
397
|
// const className = RE_DEFAULT_EXPORT.exec(content)[1];
|
|
455
398
|
return {
|
|
@@ -459,353 +402,326 @@ function scanOneFile(filePath, decorator) {
|
|
|
459
402
|
}
|
|
460
403
|
return null;
|
|
461
404
|
}
|
|
462
|
-
function doScan(type, _path, fileExt, decorator) {
|
|
463
|
-
var result = [];
|
|
464
|
-
if (!fs__namespace.existsSync(_path)) {
|
|
465
|
-
return result;
|
|
466
|
-
}
|
|
467
|
-
if (type === PATH_TYPE.FOLDER) {
|
|
468
|
-
var files = fs__namespace.readdirSync(_path);
|
|
469
|
-
var _iterator = _createForOfIteratorHelper(files),
|
|
470
|
-
_step;
|
|
471
|
-
try {
|
|
472
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
473
|
-
var file = _step.value;
|
|
474
|
-
var filePath = path__namespace.join(_path, file);
|
|
475
|
-
var stat = fs__namespace.statSync(filePath);
|
|
476
|
-
if (stat.isDirectory()) {
|
|
477
|
-
var find = doScan(PATH_TYPE.FOLDER, filePath, fileExt, decorator);
|
|
478
|
-
if (find.length) {
|
|
479
|
-
result.push.apply(result, _toConsumableArray(find));
|
|
480
|
-
}
|
|
481
|
-
} else if (stat.isFile() && path__namespace.extname(filePath) === fileExt) {
|
|
482
|
-
var r = scanOneFile(filePath, decorator);
|
|
483
|
-
if (r) {
|
|
484
|
-
result.push(r);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
} catch (err) {
|
|
489
|
-
_iterator.e(err);
|
|
490
|
-
} finally {
|
|
491
|
-
_iterator.f();
|
|
492
|
-
}
|
|
493
|
-
} else if (type === PATH_TYPE.FILE) {
|
|
494
|
-
var _r = scanOneFile(_path, decorator);
|
|
495
|
-
if (_r) {
|
|
496
|
-
result.push(_r);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
return result;
|
|
500
|
-
}
|
|
501
|
-
var scanPathConfig = [{
|
|
502
|
-
// 配置项
|
|
503
|
-
type: PATH_TYPE.FOLDER,
|
|
504
|
-
path: Project.CONFIG_DIR,
|
|
505
|
-
fileExt: '.ts',
|
|
506
|
-
decorator: '@configuration'
|
|
507
|
-
}, {
|
|
508
|
-
// 布局
|
|
509
|
-
type: PATH_TYPE.FOLDER,
|
|
510
|
-
path: Project.LAYOUT_DIR,
|
|
511
|
-
fileExt: '.tsx',
|
|
512
|
-
decorator: '@layout'
|
|
513
|
-
}, {
|
|
514
|
-
// 页面
|
|
515
|
-
type: PATH_TYPE.FOLDER,
|
|
516
|
-
path: Project.PAGE_DIR,
|
|
517
|
-
fileExt: '.tsx',
|
|
518
|
-
decorator: '@page'
|
|
519
|
-
}, {
|
|
520
|
-
// 控制器
|
|
521
|
-
type: PATH_TYPE.FOLDER,
|
|
522
|
-
path: Project.Flow_DIR,
|
|
523
|
-
fileExt: '.ts',
|
|
524
|
-
decorator: '@flow'
|
|
525
|
-
}, {
|
|
526
|
-
// 通用组件
|
|
527
|
-
type: PATH_TYPE.FOLDER,
|
|
528
|
-
path: Project.COMPONENTS_DIR,
|
|
529
|
-
fileExt: '.ts',
|
|
530
|
-
decorator: '@component'
|
|
531
|
-
}, {
|
|
532
|
-
// 接口
|
|
533
|
-
type: PATH_TYPE.FOLDER,
|
|
534
|
-
path: Project.API_DIR,
|
|
535
|
-
fileExt: '.ts',
|
|
536
|
-
decorator: '@api'
|
|
537
|
-
}, {
|
|
538
|
-
// 视图
|
|
539
|
-
type: PATH_TYPE.FOLDER,
|
|
540
|
-
path: Project.VIEW_DIR,
|
|
541
|
-
fileExt: '.tsx',
|
|
542
|
-
decorator: '@view'
|
|
543
|
-
}, {
|
|
544
|
-
// 全局数据
|
|
545
|
-
type: PATH_TYPE.FOLDER,
|
|
546
|
-
path: Project.GLOBAL_DATA_DIR,
|
|
547
|
-
fileExt: '.ts',
|
|
548
|
-
decorator: '@globalData'
|
|
549
|
-
}, {
|
|
550
|
-
// 全局状态
|
|
551
|
-
type: PATH_TYPE.FOLDER,
|
|
552
|
-
path: Project.STORE_DIR,
|
|
553
|
-
fileExt: '.ts',
|
|
554
|
-
decorator: '@store'
|
|
555
|
-
}, {
|
|
556
|
-
// 入口文件
|
|
557
|
-
type: PATH_TYPE.FILE,
|
|
558
|
-
path: Project.APPLICATION,
|
|
559
|
-
fileExt: '.ts',
|
|
560
|
-
decorator: '@webApplication'
|
|
561
|
-
}];
|
|
562
|
-
var scan = function scan(project) {
|
|
563
|
-
return scanPathConfig.reduce(function (prev, curr) {
|
|
564
|
-
prev.push.apply(prev, _toConsumableArray(doScan(curr.type, project.genFullPath(curr.path), curr.fileExt, curr.decorator)));
|
|
565
|
-
return prev;
|
|
566
|
-
}, []);
|
|
567
|
-
};
|
|
568
405
|
|
|
569
|
-
function
|
|
570
|
-
|
|
571
|
-
var
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
return filePath;
|
|
577
|
-
});
|
|
578
|
-
var _iterator = _createForOfIteratorHelper(importStatements),
|
|
579
|
-
_step;
|
|
580
|
-
try {
|
|
581
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
582
|
-
var filePath = _step.value;
|
|
583
|
-
validate(filePath);
|
|
584
|
-
}
|
|
585
|
-
} catch (err) {
|
|
586
|
-
_iterator.e(err);
|
|
587
|
-
} finally {
|
|
588
|
-
_iterator.f();
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
function validate(filePath) {
|
|
592
|
-
var inputCode = fs.readFileSync(filePath, 'utf-8');
|
|
593
|
-
var ast = parser.parse(inputCode, {
|
|
594
|
-
sourceType: 'module',
|
|
595
|
-
plugins: ['jsx', 'typescript', 'decorators-legacy', 'classProperties']
|
|
596
|
-
});
|
|
597
|
-
traverse["default"](ast, {
|
|
598
|
-
ClassDeclaration: function ClassDeclaration(path) {
|
|
599
|
-
var body = path.node.body.body;
|
|
600
|
-
body.forEach(function (method) {
|
|
601
|
-
if (method.kind === 'constructor') {
|
|
602
|
-
var statements = method.body.body;
|
|
603
|
-
statements.forEach(function (statement) {
|
|
604
|
-
if (types.isExpressionStatement(statement) && types.isCallExpression(statement.expression)) {
|
|
605
|
-
if (statement.expression.callee.type === 'Super') {
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
var fnName;
|
|
609
|
-
if (statement.expression.callee.type === 'MemberExpression') {
|
|
610
|
-
// todo fix it
|
|
611
|
-
// @ts-ignore
|
|
612
|
-
fnName = statement.expression.callee.property.name;
|
|
613
|
-
} else if (statement.expression.callee.type === 'Identifier') {
|
|
614
|
-
fnName = statement.expression.callee.name;
|
|
615
|
-
} else {
|
|
616
|
-
console.warn('未知函数调用类型', statement.expression.callee);
|
|
617
|
-
fnName = JSON.stringify(statement.expression.callee);
|
|
618
|
-
}
|
|
619
|
-
throw new Error("\u4E0D\u5141\u8BB8\u5728\u6784\u9020\u51FD\u6570\u5185\u6267\u884C\u51FD\u6570\u8C03\u7528\u3010".concat(fnName, "\u3011\u3002"));
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
});
|
|
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];
|
|
624
413
|
}
|
|
625
|
-
|
|
414
|
+
// 每次触发,先清空之前的定时器(重置延迟)
|
|
415
|
+
if (timer) clearTimeout(timer);
|
|
416
|
+
// 重新设置定时器,延迟执行
|
|
417
|
+
timer = setTimeout(function () {
|
|
418
|
+
fn.apply(_this, args);
|
|
419
|
+
timer = null;
|
|
420
|
+
}, delay);
|
|
421
|
+
};
|
|
626
422
|
}
|
|
627
423
|
|
|
628
|
-
var
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
var monorepoPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.';
|
|
636
|
-
_classCallCheck(this, DotCocoBuilder);
|
|
637
|
-
this.ensureEmptyDotCocoFolder = function (project) {
|
|
638
|
-
if (fs.existsSync(project.dotCocoAbsPath)) {
|
|
639
|
-
fs.rmSync(project.dotCocoAbsPath, {
|
|
640
|
-
recursive: true
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
fs.mkdirSync(project.dotCocoAbsPath);
|
|
644
|
-
};
|
|
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 () {
|
|
645
431
|
/**
|
|
646
|
-
*
|
|
432
|
+
* 目前仅支持单体应用,为了单元测试,可以传入子应用相对项目根的路径
|
|
433
|
+
* @param monorepoPath
|
|
647
434
|
*/
|
|
648
|
-
|
|
649
|
-
_this
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
+
});
|
|
667
457
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
+
}
|
|
676
474
|
}
|
|
677
475
|
}
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
this.handleDeleteFile = function (filePath) {
|
|
681
|
-
if (_this.isTsTsxFile(filePath)) {
|
|
682
|
-
var fullPath = _this.project.genFullPath(filePath);
|
|
683
|
-
var index = _this.iocComponents.findIndex(function (i) {
|
|
684
|
-
return i.filePath === fullPath;
|
|
685
|
-
});
|
|
686
|
-
if (index > 0) {
|
|
687
|
-
_this.iocComponents.splice(index, 1);
|
|
688
|
-
genIndexTsx(_this.project, _this.iocComponents);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
};
|
|
692
|
-
this.watchSrc = function () {
|
|
693
|
-
_this.srcWatcher = chokidar.watch(_this.project.srcAbsPath, {
|
|
694
|
-
ignored: function ignored(absPath, stats) {
|
|
695
|
-
// 忽略.coco文件夹
|
|
696
|
-
var srcPath = path.relative(_this.project.srcAbsPath, absPath);
|
|
697
|
-
return srcPath.startsWith('.coco');
|
|
698
|
-
},
|
|
699
|
-
ignoreInitial: true,
|
|
700
|
-
cwd: _this.project.srcAbsPath
|
|
701
476
|
});
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
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);
|
|
712
486
|
}
|
|
713
|
-
|
|
714
|
-
},
|
|
715
|
-
ignoreInitial: true,
|
|
716
|
-
cwd: _this.project.srcAbsPath
|
|
487
|
+
}
|
|
717
488
|
});
|
|
718
|
-
|
|
719
|
-
|
|
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
|
+
}
|
|
720
501
|
});
|
|
721
|
-
|
|
722
|
-
|
|
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
|
+
});
|
|
723
535
|
});
|
|
724
|
-
|
|
725
|
-
|
|
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
|
+
});
|
|
726
561
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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);
|
|
586
|
+
}
|
|
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) {
|
|
736
596
|
case 0:
|
|
737
|
-
if (!
|
|
738
|
-
|
|
597
|
+
if (!(_this.status !== 'running')) {
|
|
598
|
+
_context2.n = 1;
|
|
739
599
|
break;
|
|
740
600
|
}
|
|
741
|
-
|
|
742
|
-
return this.srcWatcher.close();
|
|
601
|
+
return _context2.a(2);
|
|
743
602
|
case 1:
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (!this.propertiesWatcher) {
|
|
747
|
-
_context.n = 4;
|
|
603
|
+
if (!_this.srcWatcher) {
|
|
604
|
+
_context2.n = 3;
|
|
748
605
|
break;
|
|
749
606
|
}
|
|
750
|
-
|
|
751
|
-
return
|
|
607
|
+
_context2.n = 2;
|
|
608
|
+
return _this.srcWatcher.close();
|
|
609
|
+
case 2:
|
|
610
|
+
_this.srcWatcher = null;
|
|
752
611
|
case 3:
|
|
753
|
-
|
|
612
|
+
if (!_this.propertiesWatcher) {
|
|
613
|
+
_context2.n = 5;
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
_context2.n = 4;
|
|
617
|
+
return _this.propertiesWatcher.close();
|
|
754
618
|
case 4:
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
this.iocComponents = scan(this.project);
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
function startListening(builder) {
|
|
765
|
-
var watching = false;
|
|
766
|
-
process$1.on('message', function (msg) {
|
|
767
|
-
switch (msg) {
|
|
768
|
-
case 'build-once':
|
|
769
|
-
{
|
|
770
|
-
builder.build();
|
|
771
|
-
process$1.send('build-success');
|
|
772
|
-
break;
|
|
619
|
+
_this.propertiesWatcher = null;
|
|
620
|
+
case 5:
|
|
621
|
+
_this.stopPromiseResolved();
|
|
622
|
+
_this.reset();
|
|
623
|
+
case 6:
|
|
624
|
+
return _context2.a(2);
|
|
773
625
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
}
|
|
782
|
-
default:
|
|
783
|
-
{
|
|
784
|
-
process$1.send("dot coco process rcv msg:[".concat(msg, "]"));
|
|
785
|
-
break;
|
|
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));
|
|
786
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;
|
|
787
658
|
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
659
|
+
}, {
|
|
660
|
+
key: "addEventListener",
|
|
661
|
+
value: function addEventListener(listener) {
|
|
662
|
+
if (this.trigger) {
|
|
663
|
+
throw new Error('目前只需要支持一个listener');
|
|
664
|
+
}
|
|
665
|
+
this.trigger = listener;
|
|
666
|
+
}
|
|
667
|
+
}]);
|
|
668
|
+
}();
|
|
669
|
+
_defineProperty(DotCocoBuilder, "ignoredSrcFileExt", ['.js', '.jsx', '.css', '.less', '.sass', '.scss', '.json', '.node']);
|
|
670
|
+
|
|
671
|
+
function startListening(builder) {
|
|
672
|
+
process$1.on('message', /*#__PURE__*/function () {
|
|
673
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(msg) {
|
|
674
|
+
var _t;
|
|
791
675
|
return _regenerator().w(function (_context) {
|
|
792
676
|
while (1) switch (_context.n) {
|
|
793
677
|
case 0:
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
}
|
|
798
|
-
_context.n = 1;
|
|
799
|
-
return builder.stopWatch();
|
|
678
|
+
_t = msg;
|
|
679
|
+
_context.n = _t === 'build-once' ? 1 : _t === 'build-and-watch' ? 3 : 4;
|
|
680
|
+
break;
|
|
800
681
|
case 1:
|
|
801
|
-
|
|
682
|
+
_context.n = 2;
|
|
683
|
+
return builder.buildOnce();
|
|
802
684
|
case 2:
|
|
803
|
-
process$1.
|
|
685
|
+
process$1.send('build-success');
|
|
686
|
+
return _context.a(3, 5);
|
|
804
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:
|
|
805
699
|
return _context.a(2);
|
|
806
700
|
}
|
|
807
701
|
}, _callee);
|
|
808
702
|
}));
|
|
703
|
+
return function (_x) {
|
|
704
|
+
return _ref.apply(this, arguments);
|
|
705
|
+
};
|
|
706
|
+
}());
|
|
707
|
+
function handleTerminate() {
|
|
708
|
+
return _handleTerminate.apply(this, arguments);
|
|
709
|
+
}
|
|
710
|
+
function _handleTerminate() {
|
|
711
|
+
_handleTerminate = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
712
|
+
return _regenerator().w(function (_context2) {
|
|
713
|
+
while (1) switch (_context2.n) {
|
|
714
|
+
case 0:
|
|
715
|
+
_context2.n = 1;
|
|
716
|
+
return builder.stopWatch();
|
|
717
|
+
case 1:
|
|
718
|
+
process$1.exit(0);
|
|
719
|
+
case 2:
|
|
720
|
+
return _context2.a(2);
|
|
721
|
+
}
|
|
722
|
+
}, _callee2);
|
|
723
|
+
}));
|
|
724
|
+
return _handleTerminate.apply(this, arguments);
|
|
809
725
|
}
|
|
810
726
|
process$1.on('SIGTERM', handleTerminate);
|
|
811
727
|
process$1.on('SIGINT', handleTerminate);
|
|
@@ -818,5 +734,3 @@ function startAsProcess() {
|
|
|
818
734
|
}
|
|
819
735
|
}
|
|
820
736
|
startAsProcess();
|
|
821
|
-
|
|
822
|
-
module.exports = DotCocoBuilder;
|