@doracli/helper 0.0.4 → 0.0.5

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/cjs/index.js CHANGED
@@ -1,2347 +1,3 @@
1
- 'use strict';
2
-
3
- var filePro = require('@dorabag/file-pro');
4
- var picocolors = require('picocolors');
5
- var configLoader = require('@dorabag/config-loader');
6
- var lang = require('@cclr/lang');
7
- var path = require('path');
8
- var utils = require('@cclr/utils');
9
- var fs = require('fs');
10
- var promises = require('fs/promises');
11
-
12
- function _arrayLikeToArray(r, a) {
13
- (null == a || a > r.length) && (a = r.length);
14
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
15
- return n;
16
- }
17
- function _arrayWithHoles(r) {
18
- if (Array.isArray(r)) return r;
19
- }
20
- function _arrayWithoutHoles(r) {
21
- if (Array.isArray(r)) return _arrayLikeToArray(r);
22
- }
23
- function _assertThisInitialized(e) {
24
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
25
- return e;
26
- }
27
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
28
- try {
29
- var i = n[a](c),
30
- u = i.value;
31
- } catch (n) {
32
- return void e(n);
33
- }
34
- i.done ? t(u) : Promise.resolve(u).then(r, o);
35
- }
36
- function _asyncToGenerator(n) {
37
- return function () {
38
- var t = this,
39
- e = arguments;
40
- return new Promise(function (r, o) {
41
- var a = n.apply(t, e);
42
- function _next(n) {
43
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
44
- }
45
- function _throw(n) {
46
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
47
- }
48
- _next(void 0);
49
- });
50
- };
51
- }
52
- function _callSuper(t, o, e) {
53
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
54
- }
55
- function _classCallCheck(a, n) {
56
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
57
- }
58
- function _defineProperties(e, r) {
59
- for (var t = 0; t < r.length; t++) {
60
- var o = r[t];
61
- o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
62
- }
63
- }
64
- function _createClass(e, r, t) {
65
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
66
- writable: false
67
- }), e;
68
- }
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;
76
- }
77
- function _getPrototypeOf(t) {
78
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
79
- return t.__proto__ || Object.getPrototypeOf(t);
80
- }, _getPrototypeOf(t);
81
- }
82
- function _inherits(t, e) {
83
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
84
- t.prototype = Object.create(e && e.prototype, {
85
- constructor: {
86
- value: t,
87
- writable: true,
88
- configurable: true
89
- }
90
- }), Object.defineProperty(t, "prototype", {
91
- writable: false
92
- }), e && _setPrototypeOf(t, e);
93
- }
94
- function _isNativeReflectConstruct() {
95
- try {
96
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
97
- } catch (t) {}
98
- return (_isNativeReflectConstruct = function () {
99
- return !!t;
100
- })();
101
- }
102
- function _iterableToArray(r) {
103
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
104
- }
105
- function _iterableToArrayLimit(r, l) {
106
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
107
- if (null != t) {
108
- var e,
109
- n,
110
- i,
111
- u,
112
- a = [],
113
- f = true,
114
- o = false;
115
- try {
116
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
117
- } catch (r) {
118
- o = true, n = r;
119
- } finally {
120
- try {
121
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
122
- } finally {
123
- if (o) throw n;
124
- }
125
- }
126
- return a;
127
- }
128
- }
129
- function _nonIterableRest() {
130
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
131
- }
132
- function _nonIterableSpread() {
133
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
134
- }
135
- function ownKeys(e, r) {
136
- var t = Object.keys(e);
137
- if (Object.getOwnPropertySymbols) {
138
- var o = Object.getOwnPropertySymbols(e);
139
- r && (o = o.filter(function (r) {
140
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
141
- })), t.push.apply(t, o);
142
- }
143
- return t;
144
- }
145
- function _objectSpread2(e) {
146
- for (var r = 1; r < arguments.length; r++) {
147
- var t = null != arguments[r] ? arguments[r] : {};
148
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
149
- _defineProperty(e, r, t[r]);
150
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
151
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
152
- });
153
- }
154
- return e;
155
- }
156
- function _objectWithoutProperties(e, t) {
157
- if (null == e) return {};
158
- var o,
159
- r,
160
- i = _objectWithoutPropertiesLoose(e, t);
161
- if (Object.getOwnPropertySymbols) {
162
- var n = Object.getOwnPropertySymbols(e);
163
- for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
164
- }
165
- return i;
166
- }
167
- function _objectWithoutPropertiesLoose(r, e) {
168
- if (null == r) return {};
169
- var t = {};
170
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
171
- if (-1 !== e.indexOf(n)) continue;
172
- t[n] = r[n];
173
- }
174
- return t;
175
- }
176
- function _possibleConstructorReturn(t, e) {
177
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
178
- if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
179
- return _assertThisInitialized(t);
180
- }
181
- function _regenerator() {
182
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
183
- var e,
184
- t,
185
- r = "function" == typeof Symbol ? Symbol : {},
186
- n = r.iterator || "@@iterator",
187
- o = r.toStringTag || "@@toStringTag";
188
- function i(r, n, o, i) {
189
- var c = n && n.prototype instanceof Generator ? n : Generator,
190
- u = Object.create(c.prototype);
191
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
192
- var i,
193
- c,
194
- u,
195
- f = 0,
196
- p = o || [],
197
- y = false,
198
- G = {
199
- p: 0,
200
- n: 0,
201
- v: e,
202
- a: d,
203
- f: d.bind(e, 4),
204
- d: function (t, r) {
205
- return i = t, c = 0, u = e, G.n = r, a;
206
- }
207
- };
208
- function d(r, n) {
209
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
210
- var o,
211
- i = p[t],
212
- d = G.p,
213
- l = i[2];
214
- r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
215
- }
216
- if (o || r > 1) return a;
217
- throw y = true, n;
218
- }
219
- return function (o, p, l) {
220
- if (f > 1) throw TypeError("Generator is already running");
221
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
222
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
223
- try {
224
- if (f = 2, i) {
225
- if (c || (o = "next"), t = i[o]) {
226
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
227
- if (!t.done) return t;
228
- u = t.value, c < 2 && (c = 0);
229
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
230
- i = e;
231
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
232
- } catch (t) {
233
- i = e, c = 1, u = t;
234
- } finally {
235
- f = 1;
236
- }
237
- }
238
- return {
239
- value: t,
240
- done: y
241
- };
242
- };
243
- }(r, o, i), true), u;
244
- }
245
- var a = {};
246
- function Generator() {}
247
- function GeneratorFunction() {}
248
- function GeneratorFunctionPrototype() {}
249
- t = Object.getPrototypeOf;
250
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
251
- return this;
252
- }), t),
253
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
254
- function f(e) {
255
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
256
- }
257
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
258
- return this;
259
- }), _regeneratorDefine(u, "toString", function () {
260
- return "[object Generator]";
261
- }), (_regenerator = function () {
262
- return {
263
- w: i,
264
- m: f
265
- };
266
- })();
267
- }
268
- function _regeneratorDefine(e, r, n, t) {
269
- var i = Object.defineProperty;
270
- try {
271
- i({}, "", {});
272
- } catch (e) {
273
- i = 0;
274
- }
275
- _regeneratorDefine = function (e, r, n, t) {
276
- function o(r, n) {
277
- _regeneratorDefine(e, r, function (e) {
278
- return this._invoke(r, n, e);
279
- });
280
- }
281
- r ? i ? i(e, r, {
282
- value: n,
283
- enumerable: !t,
284
- configurable: !t,
285
- writable: !t
286
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
287
- }, _regeneratorDefine(e, r, n, t);
288
- }
289
- function _setPrototypeOf(t, e) {
290
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
291
- return t.__proto__ = e, t;
292
- }, _setPrototypeOf(t, e);
293
- }
294
- function _slicedToArray(r, e) {
295
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
296
- }
297
- function _toConsumableArray(r) {
298
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
299
- }
300
- function _toPrimitive(t, r) {
301
- if ("object" != typeof t || !t) return t;
302
- var e = t[Symbol.toPrimitive];
303
- if (void 0 !== e) {
304
- var i = e.call(t, r);
305
- if ("object" != typeof i) return i;
306
- throw new TypeError("@@toPrimitive must return a primitive value.");
307
- }
308
- return ("string" === r ? String : Number)(t);
309
- }
310
- function _toPropertyKey(t) {
311
- var i = _toPrimitive(t, "string");
312
- return "symbol" == typeof i ? i : i + "";
313
- }
314
- function _unsupportedIterableToArray(r, a) {
315
- if (r) {
316
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
317
- var t = {}.toString.call(r).slice(8, -1);
318
- 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;
319
- }
320
- }
321
-
322
- var ConfigCtx = /*#__PURE__*/function () {
323
- function ConfigCtx() {
324
- _classCallCheck(this, ConfigCtx);
325
- _defineProperty(this, "tsConfig", {});
326
- _defineProperty(this, "doraConfig", {});
327
- _defineProperty(this, "packageConfig", {});
328
- _defineProperty(this, "cdnConfig", {});
329
- _defineProperty(this, "cmd", {});
330
- _defineProperty(this, "workRoot", './');
331
- }
332
- return _createClass(ConfigCtx, [{
333
- key: "setCmd",
334
- value: function setCmd(cmd) {
335
- this.cmd = cmd;
336
- }
337
- }, {
338
- key: "getCmd",
339
- value: function getCmd() {
340
- return this.cmd;
341
- }
342
- }, {
343
- key: "setWorkRoot",
344
- value: function setWorkRoot(root) {
345
- this.workRoot = root;
346
- }
347
- }, {
348
- key: "getWorkRoot",
349
- value: function getWorkRoot() {
350
- return this.workRoot;
351
- }
352
- }, {
353
- key: "setTsConfig",
354
- value: function setTsConfig(config) {
355
- this.tsConfig = config;
356
- }
357
- }, {
358
- key: "getTsConfig",
359
- value: function getTsConfig() {
360
- return this.tsConfig;
361
- }
362
- }, {
363
- key: "setDoraConfig",
364
- value: function setDoraConfig(config) {
365
- this.doraConfig = config;
366
- }
367
- }, {
368
- key: "getDoraConfig",
369
- value: function getDoraConfig() {
370
- return this.doraConfig;
371
- }
372
- }, {
373
- key: "setCdnConfig",
374
- value: function setCdnConfig(config) {
375
- this.cdnConfig = config;
376
- }
377
- }, {
378
- key: "getCdnConfig",
379
- value: function getCdnConfig() {
380
- return this.cdnConfig;
381
- }
382
- }, {
383
- key: "setPackageConfig",
384
- value: function setPackageConfig(config) {
385
- this.packageConfig = config;
386
- }
387
- }, {
388
- key: "getPackageConfig",
389
- value: function getPackageConfig() {
390
- return this.packageConfig;
391
- }
392
- }, {
393
- key: "copy",
394
- value: function copy() {
395
- var newCtx = new ConfigCtx();
396
- newCtx.setWorkRoot(this.getWorkRoot());
397
- newCtx.setTsConfig(this.getTsConfig());
398
- newCtx.setDoraConfig(this.getDoraConfig());
399
- newCtx.setPackageConfig(this.getPackageConfig());
400
- newCtx.setCdnConfig(this.getCdnConfig());
401
- newCtx.setCmd(this.getCmd());
402
- return newCtx;
403
- }
404
- }]);
405
- }();
406
-
407
- var mainSlogan = '@doracli';
408
- var level = 10;
409
-
410
- /**
411
- * @params 日志等级
412
- * 0 - debug
413
- * 10 - log
414
- * 100 - info
415
- * 1000 - warn
416
- * 10000 - error
417
- * 100000 - nolog
418
- */
419
- var setLogLevel = function setLogLevel(lvl) {
420
- level = lvl;
421
- };
422
- var stringFormat = function stringFormat(str, length) {
423
- if (str.length >= length) return str;
424
- return str + ' '.repeat(length - str.length);
425
- // const pre = (length - str.length) >> 1;
426
- // const suf = length - str.length - pre;
427
- // return ' '.repeat(pre) + str + ' '.repeat(suf);
428
- };
429
-
430
- /** 格式化模式,如果小于5个字符,就补充空格 */
431
- var foramtMode = function foramtMode(mode) {
432
- return stringFormat(mode, 5);
433
- };
434
-
435
- /** 格式化模式,如果小于5个字符,就补充空格 */
436
- var foramtStatus = function foramtStatus(mode) {
437
- return stringFormat(mode, 9).toUpperCase();
438
- };
439
-
440
- /**
441
- * @param mode 模式
442
- * @param status 状态
443
- * @param msg 消息
444
- * @returns
445
- */
446
- var cLogDebugger = function cLogDebugger(mode, status) {
447
- var _console;
448
- if (level > 0) return;
449
- var title = picocolors.bgBlack("[".concat(picocolors.magenta(mainSlogan), ":").concat(picocolors.bold(" ".concat(foramtMode(mode))), "]"));
450
- for (var _len = arguments.length, msg = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
451
- msg[_key - 2] = arguments[_key];
452
- }
453
- return (_console = console).debug.apply(_console, ["".concat(title, " [").concat(foramtStatus(status), "]")].concat(msg));
454
- };
455
-
456
- /**
457
- * @param mode 模式
458
- * @param status 状态
459
- * @param msg 消息
460
- * @returns
461
- */
462
- var cLogMessage = function cLogMessage(mode, status) {
463
- var _console2;
464
- if (level > 10) return;
465
- var title = picocolors.bgBlack("[".concat(picocolors.magenta(mainSlogan), ":").concat(picocolors.bold(" ".concat(foramtMode(mode))), "]"));
466
- for (var _len2 = arguments.length, msg = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
467
- msg[_key2 - 2] = arguments[_key2];
468
- }
469
- return (_console2 = console).log.apply(_console2, ["".concat(title, " [").concat(picocolors.yellow(foramtStatus(status)), "]")].concat(msg));
470
- };
471
- var cLogSuccess = function cLogSuccess(mode, status) {
472
- var _console3;
473
- if (level > 100) return;
474
- var title = picocolors.bgBlack("[".concat(picocolors.magenta(mainSlogan), ":").concat(picocolors.bold(" ".concat(foramtMode(mode))), "]"));
475
- for (var _len3 = arguments.length, msg = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
476
- msg[_key3 - 2] = arguments[_key3];
477
- }
478
- return (_console3 = console).log.apply(_console3, ["".concat(title, " [").concat(picocolors.green(foramtStatus(status)), "]")].concat(msg));
479
- };
480
- var cLogWarn = function cLogWarn(mode, status) {
481
- var _console4;
482
- if (level > 1000) return;
483
- for (var _len4 = arguments.length, msg = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
484
- msg[_key4 - 2] = arguments[_key4];
485
- }
486
- return (_console4 = console).log.apply(_console4, [picocolors.bgYellow("[".concat(mainSlogan, ": ").concat(foramtMode(mode), "] [").concat(foramtStatus(status), "]"))].concat(msg));
487
- };
488
- var cLogError = function cLogError(mode, status) {
489
- var _console5;
490
- if (level > 10000) return;
491
- for (var _len5 = arguments.length, msg = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
492
- msg[_key5 - 2] = arguments[_key5];
493
- }
494
- return (_console5 = console).log.apply(_console5, [picocolors.bgRed("[".concat(mainSlogan, ": ").concat(foramtMode(mode), "] [").concat(foramtStatus(status), "]"))].concat(msg));
495
- };
496
- var start = 0;
497
- var cLogTime = function cLogTime() {
498
- var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "cLogTimeStart-".concat(start);
499
- start++;
500
- console.time(key);
501
- return function () {
502
- console.timeEnd(key);
503
- };
504
- };
505
- var cLogTimeEnd = function cLogTimeEnd(key) {
506
- console.timeEnd(key);
507
- };
508
- var cLog = {
509
- log: cLogMessage,
510
- debug: cLogDebugger,
511
- error: cLogError,
512
- warn: cLogWarn,
513
- info: cLogSuccess,
514
- time: cLogTime,
515
- timeEnd: cLogTimeEnd
516
- };
517
-
518
- var clearMw = function clearMw() {
519
- return function (ctx) {
520
- return function (next) {
521
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
522
- return _regenerator().w(function (_context) {
523
- while (1) switch (_context.n) {
524
- case 0:
525
- _context.n = 1;
526
- return clear(ctx);
527
- case 1:
528
- return _context.a(2, next());
529
- }
530
- }, _callee);
531
- }));
532
- };
533
- };
534
- };
535
- var clear = /*#__PURE__*/function () {
536
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(ctx) {
537
- var _ctx$getDoraConfig, clear, output, _ref3, path;
538
- return _regenerator().w(function (_context2) {
539
- while (1) switch (_context2.p = _context2.n) {
540
- case 0:
541
- _ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
542
- _ref3 = output || {}, path = _ref3.path;
543
- _context2.p = 1;
544
- if (clear) {
545
- _context2.n = 2;
546
- break;
547
- }
548
- return _context2.a(2);
549
- case 2:
550
- if (path) {
551
- _context2.n = 3;
552
- break;
553
- }
554
- return _context2.a(2);
555
- case 3:
556
- _context2.n = 4;
557
- return filePro.isValidDir(path);
558
- case 4:
559
- if (_context2.v) {
560
- _context2.n = 5;
561
- break;
562
- }
563
- return _context2.a(2);
564
- case 5:
565
- _context2.n = 6;
566
- return filePro.cleanTargets(path);
567
- case 6:
568
- _context2.n = 8;
569
- break;
570
- case 7:
571
- _context2.p = 7;
572
- _context2.v;
573
- cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
574
- case 8:
575
- return _context2.a(2);
576
- }
577
- }, _callee2, null, [[1, 7]]);
578
- }));
579
- return function clear(_x) {
580
- return _ref2.apply(this, arguments);
581
- };
582
- }();
583
-
584
- var getDependencies = function getDependencies(packageJson) {
585
- return _objectSpread2(_objectSpread2(_objectSpread2({}, packageJson.dependencies), packageJson.peerDependencies), packageJson.devDependencies);
586
- };
587
-
588
- // package.json
589
- var packageJsonDir = 'package.json';
590
- var doracliConfigFileName = 'doracli.config';
591
- var cdnConfigFileName = 'cdn';
592
-
593
- var getDoracliConfig = /*#__PURE__*/function () {
594
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(root) {
595
- var userConfig, _t;
596
- return _regenerator().w(function (_context) {
597
- while (1) switch (_context.p = _context.n) {
598
- case 0:
599
- _context.p = 0;
600
- _context.n = 1;
601
- return configLoader.loadConfigFuzzyExt(doracliConfigFileName, {
602
- rootDir: filePro.resolveCwd(root)
603
- });
604
- case 1:
605
- userConfig = _context.v;
606
- if (userConfig) {
607
- _context.n = 2;
608
- break;
609
- }
610
- cLog.warn('file', 'undefined', '未定义 doracli 配置文件');
611
- return _context.a(2, null);
612
- case 2:
613
- cLog.debug('file', 'success', '引入 doracli 配置文件成功');
614
- return _context.a(2, userConfig.default || userConfig);
615
- case 3:
616
- _context.p = 3;
617
- _t = _context.v;
618
- cLog.error('file', 'fail', '引入 doracli 配置文件失败');
619
- console.error(_t);
620
- return _context.a(2, Promise.reject(_t));
621
- }
622
- }, _callee, null, [[0, 3]]);
623
- }));
624
- return function getDoracliConfig(_x) {
625
- return _ref.apply(this, arguments);
626
- };
627
- }();
628
-
629
- /**
630
- * 获取json文件
631
- * @param root
632
- * @returns
633
- */
634
- var getPackageJson = /*#__PURE__*/function () {
635
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
636
- var root,
637
- json,
638
- _args = arguments,
639
- _t;
640
- return _regenerator().w(function (_context) {
641
- while (1) switch (_context.p = _context.n) {
642
- case 0:
643
- root = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
644
- _context.p = 1;
645
- _context.n = 2;
646
- return configLoader.loadConfig(filePro.resolveCwd(root, packageJsonDir));
647
- case 2:
648
- json = _context.v;
649
- cLog.debug('file', 'success', '引入 package.json 成功');
650
- return _context.a(2, json);
651
- case 3:
652
- _context.p = 3;
653
- _t = _context.v;
654
- cLog.error('file', 'fail', '引入 package.json 失败');
655
- cLog.debug('file', 'error', _t);
656
- case 4:
657
- return _context.a(2);
658
- }
659
- }, _callee, null, [[1, 3]]);
660
- }));
661
- return function getPackageJson() {
662
- return _ref.apply(this, arguments);
663
- };
664
- }();
665
-
666
- var getTsconfigJson = /*#__PURE__*/function () {
667
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(root) {
668
- var json, _t;
669
- return _regenerator().w(function (_context) {
670
- while (1) switch (_context.p = _context.n) {
671
- case 0:
672
- _context.p = 0;
673
- _context.n = 1;
674
- return configLoader.loadConfig(filePro.resolveCwd(root, './tsconfig.json'));
675
- case 1:
676
- json = _context.v;
677
- cLog.debug('file', 'success', '引入 tsconfig.json 成功');
678
- return _context.a(2, json);
679
- case 2:
680
- _context.p = 2;
681
- _t = _context.v;
682
- cLog.error('file', 'failed', '引入 tsconfig.json 失败');
683
- cLog.debug('file', 'error', _t);
684
- case 3:
685
- return _context.a(2);
686
- }
687
- }, _callee, null, [[0, 2]]);
688
- }));
689
- return function getTsconfigJson(_x) {
690
- return _ref.apply(this, arguments);
691
- };
692
- }();
693
-
694
- /**
695
- * 获取cdn文件配置
696
- * @returns
697
- */
698
- function getUserCdn(_x) {
699
- return _getUserCdn.apply(this, arguments);
700
- }
701
- function _getUserCdn() {
702
- _getUserCdn = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(root) {
703
- var json, _t;
704
- return _regenerator().w(function (_context) {
705
- while (1) switch (_context.p = _context.n) {
706
- case 0:
707
- _context.p = 0;
708
- _context.n = 1;
709
- return configLoader.loadConfigFuzzyExt(cdnConfigFileName, {
710
- rootDir: filePro.resolveCwd(root)
711
- });
712
- case 1:
713
- json = _context.v;
714
- if (json !== null && json !== void 0 && json.default) {
715
- _context.n = 2;
716
- break;
717
- }
718
- cLog.log('file', 'undefined', '未定义 cdn 配置文件');
719
- return _context.a(2, null);
720
- case 2:
721
- cLog.info('file', 'success', '引入 cdn 成功');
722
- return _context.a(2, json.default);
723
- case 3:
724
- _context.p = 3;
725
- _t = _context.v;
726
- cLog.error('file', 'failed', '引入 cdn 失败');
727
- cLog.debug('file', 'failed', _t);
728
- return _context.a(2, null);
729
- }
730
- }, _callee, null, [[0, 3]]);
731
- }));
732
- return _getUserCdn.apply(this, arguments);
733
- }
734
-
735
- var mergeDoraCliConfig = function mergeDoraCliConfig(target) {
736
- var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
737
- return _deepMergeObject(target, source);
738
- };
739
-
740
- /**
741
- * 合并多个配置项
742
- * @param target 配置项,可多个,后面的配置项会覆盖前面的配置项
743
- * @returns
744
- */
745
- var mergeDoraCliConfigMutiple = function mergeDoraCliConfigMutiple() {
746
- for (var _len = arguments.length, target = new Array(_len), _key = 0; _key < _len; _key++) {
747
- target[_key] = arguments[_key];
748
- }
749
- return target.reduce(function (prev, curr) {
750
- return mergeDoraCliConfig(prev, curr);
751
- });
752
- };
753
- var _deepMergeObject = function deepMergeObject(target, source) {
754
- if (!source) return target;
755
- if (!target) return source;
756
- var result = _objectSpread2({}, target);
757
- for (var key in source) {
758
- if (lang.isObject(source[key])) {
759
- result[key] = _deepMergeObject(target[key], source[key]);
760
- } else {
761
- result[key] = source[key];
762
- }
763
- }
764
- return result;
765
- };
766
-
767
- /**
768
- * 获取cdn文件配置
769
- * @param workRootDir
770
- * @param mode
771
- * @returns
772
- */
773
- function parseCdnConfig(cdnConfig, mode) {
774
- try {
775
- if (!lang.isObject(cdnConfig)) return;
776
- var cdn = Object.entries(cdnConfig).reduce(function (pre, _ref) {
777
- var _ref2 = _slicedToArray(_ref, 2),
778
- name = _ref2[0],
779
- v = _ref2[1];
780
- if (lang.isFunction(v)) {
781
- pre[name] = v(mode) || [];
782
- } else if (lang.isArray(v)) {
783
- pre[name] = v;
784
- }
785
- return pre;
786
- }, {});
787
- return cdn;
788
- } catch (err) {
789
- cLog.error('parse', 'parseCdnConfig', '解析用户cdn配置失败');
790
- throw new Error(err);
791
- }
792
- }
793
-
794
- /**
795
- * 解析doracli配置
796
- * @param workRootDir
797
- * @param mode
798
- * @returns
799
- */
800
- var parseDoracliConfig = /*#__PURE__*/function () {
801
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(userConfig, mode) {
802
- var config, _t;
803
- return _regenerator().w(function (_context) {
804
- while (1) switch (_context.p = _context.n) {
805
- case 0:
806
- _context.p = 0;
807
- config = userConfig;
808
- if (!lang.isFunction(userConfig)) {
809
- _context.n = 2;
810
- break;
811
- }
812
- _context.n = 1;
813
- return userConfig(mode);
814
- case 1:
815
- config = _context.v;
816
- case 2:
817
- return _context.a(2, config);
818
- case 3:
819
- _context.p = 3;
820
- _t = _context.v;
821
- cLog.error('resolve ', 'resolveUserConfigJson', '解析用户配置失败');
822
- throw new Error(_t);
823
- case 4:
824
- return _context.a(2);
825
- }
826
- }, _callee, null, [[0, 3]]);
827
- }));
828
- return function parseDoracliConfig(_x, _x2) {
829
- return _ref.apply(this, arguments);
830
- };
831
- }();
832
-
833
- var _excluded$2 = ["multiple"];
834
-
835
- /**
836
- * 配置项多任务拆分
837
- * @param config 配置项
838
- * @returns
839
- */
840
- var splitDoraCliConfig = function splitDoraCliConfig(config) {
841
- var multiple = config.multiple,
842
- neatConfig = _objectWithoutProperties(config, _excluded$2);
843
- if (!lang.isArray(multiple)) return [neatConfig];
844
- if (multiple.length === 0) return [neatConfig];
845
- if (multiple.length === 1) return [mergeDoraCliConfigMutiple(neatConfig, multiple[0])];
846
- return multiple.map(function (item) {
847
- return mergeDoraCliConfigMutiple(neatConfig, item);
848
- });
849
- };
850
-
851
- var inputFileDirList = ['src/index', 'index'];
852
- var inputFileTypeList = ['.ts', '.js', '.tsx', '.jsx'];
853
- var findInput = function findInput(workRootDir) {
854
- var pList = inputFileDirList.reduce(function (pre, f) {
855
- inputFileTypeList.forEach(function (e) {
856
- pre.push('./' + f + e);
857
- });
858
- return pre;
859
- }, []);
860
- return filePro.lookupFile(pList, workRootDir);
861
- };
862
- var inputHtmlFileDirList = ['index.html', 'public/index.html'];
863
- var findInputHtml = function findInputHtml(workRootDir) {
864
- return filePro.lookupFile(inputHtmlFileDirList, workRootDir);
865
- };
866
-
867
- /**
868
- * 获取tsconfig.json里的paths,作为项目路径别名
869
- * @param tsConfig
870
- * @returns
871
- */
872
- var getTsPathAlias = function getTsPathAlias(tsConfig) {
873
- var _ref = (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.compilerOptions) || {},
874
- tsConfigPaths = _ref.paths;
875
- if (!tsConfigPaths) return {};
876
- var alias = {};
877
-
878
- /**
879
- * 拼接tsconfig.json里的paths,作为项目别名
880
- */
881
- Object.entries(tsConfigPaths).forEach(function (_ref2) {
882
- var _ref3 = _slicedToArray(_ref2, 2),
883
- pathKey = _ref3[0],
884
- pathArr = _ref3[1];
885
- var key = pathKey.replace(/\/\*$/, '');
886
- if (pathArr !== null && pathArr !== void 0 && pathArr.length && !alias[key]) {
887
- var val = pathArr[0].replace(/\/\*$/, '');
888
- alias[key] = path.resolve(val);
889
- }
890
- });
891
- return alias;
892
- };
893
-
894
- var wholeDoraConfig = function wholeDoraConfig(config) {
895
- var workRootDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : filePro.getCwd();
896
- var type = config.type,
897
- name = config.name,
898
- lib = config.lib,
899
- libList = config.libList,
900
- alias = config.alias,
901
- clear = config.clear,
902
- copy = config.copy,
903
- dts = config.dts,
904
- externals = config.externals,
905
- formatList = config.formatList,
906
- input = config.input,
907
- internals = config.internals,
908
- minimize = config.minimize,
909
- multiple = config.multiple,
910
- output = config.output,
911
- rollupConfig = config.rollupConfig,
912
- webpackConfig = config.webpackConfig,
913
- esbuildConfig = config.esbuildConfig,
914
- rspackConfig = config.rspackConfig;
915
- config.dtsConfig;
916
- var format = config.format,
917
- serviceConfig = config.serviceConfig;
918
- var targetInput = input;
919
- var outPath = (output === null || output === void 0 ? void 0 : output.path) || './dist';
920
- var outFile = output === null || output === void 0 ? void 0 : output.file;
921
- var newLibList = [];
922
- if (!multiple) {
923
- if (!filePro.isValidFilePathSync(targetInput || '')) {
924
- targetInput = findInput(workRootDir);
925
- }
926
- if (!targetInput) {
927
- cLog.error('init', 'not_found', '找不到入口文件');
928
- }
929
- outFile = (output === null || output === void 0 ? void 0 : output.file) || filePro.getFilename(targetInput);
930
- }
931
- if (!libList) {
932
- if (lib) {
933
- newLibList = [lib];
934
- } else if (formatList !== null && formatList !== void 0 && formatList.length) {
935
- newLibList = formatList.map(function (fmt) {
936
- return {
937
- format: fmt
938
- };
939
- });
940
- } else {
941
- newLibList = [{
942
- format: format || 'cjs'
943
- }];
944
- }
945
- }
946
- return {
947
- multiple: lang.isUndefinedOrNull(multiple) ? false : multiple,
948
- type: type,
949
- name: name,
950
- alias: alias || {},
951
- clear: lang.isUndefinedOrNull(clear) ? false : clear,
952
- copy: copy || [],
953
- dts: lang.isUndefinedOrNull(dts) ? {} : dts,
954
- externals: externals || [],
955
- formatList: formatList || ['cjs'],
956
- libList: newLibList,
957
- input: input,
958
- internals: internals || [],
959
- minimize: lang.isUndefinedOrNull(minimize) ? false : minimize,
960
- output: output || {
961
- path: outPath,
962
- file: outFile
963
- },
964
- rollupConfig: rollupConfig || {},
965
- webpackConfig: webpackConfig || {},
966
- esbuildConfig: esbuildConfig || {},
967
- rspackConfig: rspackConfig || {},
968
- serviceConfig: serviceConfig || {}
969
- };
970
- };
971
-
972
- var resolveDoraConfig = /*#__PURE__*/function () {
973
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir, mode) {
974
- var userConfigOrange;
975
- return _regenerator().w(function (_context) {
976
- while (1) switch (_context.p = _context.n) {
977
- case 0:
978
- _context.p = 0;
979
- _context.n = 1;
980
- return getDoracliConfig(workRootDir);
981
- case 1:
982
- userConfigOrange = _context.v;
983
- return _context.a(2, parseDoracliConfig(userConfigOrange, mode));
984
- case 2:
985
- _context.p = 2;
986
- _context.v;
987
- cLog.log('resolve ', 'error', 'doracli.config 解析用户配置失败');
988
- return _context.a(2, {});
989
- }
990
- }, _callee, null, [[0, 2]]);
991
- }));
992
- return function resolveDoraConfig(_x, _x2) {
993
- return _ref.apply(this, arguments);
994
- };
995
- }();
996
-
997
- /**
998
- * 获取json文件
999
- * @param root
1000
- * @returns
1001
- */
1002
- var resolvePackageJson = /*#__PURE__*/function () {
1003
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir) {
1004
- var packageJson;
1005
- return _regenerator().w(function (_context) {
1006
- while (1) switch (_context.p = _context.n) {
1007
- case 0:
1008
- _context.p = 0;
1009
- _context.n = 1;
1010
- return getPackageJson(workRootDir);
1011
- case 1:
1012
- packageJson = _context.v;
1013
- return _context.a(2, packageJson);
1014
- case 2:
1015
- _context.p = 2;
1016
- _context.v;
1017
- cLog.log('resolve ', 'error', 'package.json 解析用户配置失败');
1018
- return _context.a(2, {});
1019
- }
1020
- }, _callee, null, [[0, 2]]);
1021
- }));
1022
- return function resolvePackageJson(_x) {
1023
- return _ref.apply(this, arguments);
1024
- };
1025
- }();
1026
-
1027
- var resolveTsconfigJson = /*#__PURE__*/function () {
1028
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir) {
1029
- var tsConfig;
1030
- return _regenerator().w(function (_context) {
1031
- while (1) switch (_context.p = _context.n) {
1032
- case 0:
1033
- _context.p = 0;
1034
- _context.n = 1;
1035
- return getTsconfigJson(workRootDir);
1036
- case 1:
1037
- tsConfig = _context.v;
1038
- return _context.a(2, tsConfig);
1039
- case 2:
1040
- _context.p = 2;
1041
- _context.v;
1042
- cLog.log('resolve ', 'error', 'tsconfig.json 解析用户配置失败');
1043
- return _context.a(2, {});
1044
- }
1045
- }, _callee, null, [[0, 2]]);
1046
- }));
1047
- return function resolveTsconfigJson(_x) {
1048
- return _ref.apply(this, arguments);
1049
- };
1050
- }();
1051
-
1052
- /**
1053
- * 收集用户配置
1054
- * @param configCtx ConfigCtx
1055
- * @param mode 开发 or 生产
1056
- * @param presetConfig 预设配置
1057
- */
1058
- var collectConfig = /*#__PURE__*/function () {
1059
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, mode, presetConfig) {
1060
- var wordDir, tsConfig, doraConfig, packageConfig;
1061
- return _regenerator().w(function (_context) {
1062
- while (1) switch (_context.n) {
1063
- case 0:
1064
- wordDir = configCtx.getWorkRoot();
1065
- _context.n = 1;
1066
- return resolveTsconfigJson(wordDir);
1067
- case 1:
1068
- tsConfig = _context.v;
1069
- _context.n = 2;
1070
- return resolveDoraConfig(wordDir, mode);
1071
- case 2:
1072
- doraConfig = _context.v;
1073
- _context.n = 3;
1074
- return resolvePackageJson(wordDir);
1075
- case 3:
1076
- packageConfig = _context.v;
1077
- configCtx.setPackageConfig(packageConfig);
1078
- configCtx.setDoraConfig(wholeDoraConfig(mergeDoraCliConfig((presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.doraConfig) || {}, doraConfig || {}), wordDir));
1079
- configCtx.setTsConfig(tsConfig);
1080
- case 4:
1081
- return _context.a(2);
1082
- }
1083
- }, _callee);
1084
- }));
1085
- return function collectConfig(_x, _x2, _x3) {
1086
- return _ref.apply(this, arguments);
1087
- };
1088
- }();
1089
-
1090
- /**
1091
- * 获取cdn文件配置
1092
- * @returns
1093
- */
1094
- function resolveCdnConfig(_x, _x2) {
1095
- return _resolveCdnConfig.apply(this, arguments);
1096
- }
1097
- function _resolveCdnConfig() {
1098
- _resolveCdnConfig = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir, mode) {
1099
- var userConfig;
1100
- return _regenerator().w(function (_context) {
1101
- while (1) switch (_context.p = _context.n) {
1102
- case 0:
1103
- _context.p = 0;
1104
- _context.n = 1;
1105
- return getUserCdn(workRootDir);
1106
- case 1:
1107
- userConfig = _context.v;
1108
- return _context.a(2, parseCdnConfig(userConfig, mode));
1109
- case 2:
1110
- _context.p = 2;
1111
- _context.v;
1112
- cLog.log('resolve ', 'resolveUserCdn', '解析用户cdn配置失败');
1113
- return _context.a(2, {});
1114
- }
1115
- }, _callee, null, [[0, 2]]);
1116
- }));
1117
- return _resolveCdnConfig.apply(this, arguments);
1118
- }
1119
-
1120
- var collectPackageJsonMw = function collectPackageJsonMw() {
1121
- return function (ctx) {
1122
- return function (next) {
1123
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1124
- var json;
1125
- return _regenerator().w(function (_context) {
1126
- while (1) switch (_context.n) {
1127
- case 0:
1128
- _context.n = 1;
1129
- return getPackageJson(ctx.getWorkRoot());
1130
- case 1:
1131
- json = _context.v;
1132
- ctx.setPackageConfig(json || {});
1133
- return _context.a(2, next());
1134
- }
1135
- }, _callee);
1136
- }));
1137
- };
1138
- };
1139
- };
1140
- var collectTsconfigJsonMw = function collectTsconfigJsonMw() {
1141
- return function (ctx) {
1142
- return function (next) {
1143
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1144
- var json;
1145
- return _regenerator().w(function (_context2) {
1146
- while (1) switch (_context2.n) {
1147
- case 0:
1148
- _context2.n = 1;
1149
- return getTsconfigJson(ctx.getWorkRoot());
1150
- case 1:
1151
- json = _context2.v;
1152
- ctx.setTsConfig(json || {});
1153
- return _context2.a(2, next());
1154
- }
1155
- }, _callee2);
1156
- }));
1157
- };
1158
- };
1159
- };
1160
- var collectCdnConfigMw = function collectCdnConfigMw(mode) {
1161
- return function (ctx) {
1162
- return function (next) {
1163
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
1164
- var json;
1165
- return _regenerator().w(function (_context3) {
1166
- while (1) switch (_context3.n) {
1167
- case 0:
1168
- _context3.n = 1;
1169
- return resolveCdnConfig(ctx.getWorkRoot(), mode);
1170
- case 1:
1171
- json = _context3.v;
1172
- ctx.setCdnConfig(json || {
1173
- bodyAfterScript: [],
1174
- headAfterScript: [],
1175
- headAfterStyle: [],
1176
- bodyBeforeScript: []
1177
- });
1178
- return _context3.a(2, next());
1179
- }
1180
- }, _callee3);
1181
- }));
1182
- };
1183
- };
1184
- };
1185
- var collectDoraConfigMw = function collectDoraConfigMw(mode) {
1186
- return function (ctx) {
1187
- return function (next) {
1188
- return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
1189
- var json;
1190
- return _regenerator().w(function (_context4) {
1191
- while (1) switch (_context4.n) {
1192
- case 0:
1193
- _context4.n = 1;
1194
- return resolveDoraConfig(ctx.getWorkRoot(), mode);
1195
- case 1:
1196
- json = _context4.v;
1197
- ctx.setDoraConfig(json || {});
1198
- return _context4.a(2, next());
1199
- }
1200
- }, _callee4);
1201
- }));
1202
- };
1203
- };
1204
- };
1205
- var collectBaseConfigMw = function collectBaseConfigMw(workRoot, cmd) {
1206
- return function (ctx) {
1207
- return function (next) {
1208
- return function () {
1209
- ctx.setWorkRoot(workRoot);
1210
- ctx.setCmd(cmd);
1211
- return next();
1212
- };
1213
- };
1214
- };
1215
- };
1216
-
1217
- var wholeDoraConfigMw = function wholeDoraConfigMw(defaultConfig) {
1218
- return function (ctx) {
1219
- return function (next) {
1220
- return function () {
1221
- var _mergeDoraCliConfig = mergeDoraCliConfig(defaultConfig, ctx.getDoraConfig()),
1222
- alias = _mergeDoraCliConfig.alias,
1223
- clear = _mergeDoraCliConfig.clear,
1224
- copy = _mergeDoraCliConfig.copy,
1225
- dts = _mergeDoraCliConfig.dts,
1226
- lib = _mergeDoraCliConfig.lib,
1227
- format = _mergeDoraCliConfig.format,
1228
- libList = _mergeDoraCliConfig.libList,
1229
- name = _mergeDoraCliConfig.name,
1230
- type = _mergeDoraCliConfig.type,
1231
- externals = _mergeDoraCliConfig.externals,
1232
- formatList = _mergeDoraCliConfig.formatList,
1233
- input = _mergeDoraCliConfig.input,
1234
- internals = _mergeDoraCliConfig.internals,
1235
- minimize = _mergeDoraCliConfig.minimize,
1236
- multiple = _mergeDoraCliConfig.multiple,
1237
- output = _mergeDoraCliConfig.output,
1238
- rollupConfig = _mergeDoraCliConfig.rollupConfig,
1239
- webpackConfig = _mergeDoraCliConfig.webpackConfig,
1240
- esbuildConfig = _mergeDoraCliConfig.esbuildConfig,
1241
- rspackConfig = _mergeDoraCliConfig.rspackConfig,
1242
- serviceConfig = _mergeDoraCliConfig.serviceConfig,
1243
- dtsConfig = _mergeDoraCliConfig.dtsConfig;
1244
- ctx.setDoraConfig({
1245
- multiple: lang.isUndefinedOrNull(multiple) ? false : multiple,
1246
- name: name,
1247
- type: type,
1248
- format: format,
1249
- formatList: formatList,
1250
- lib: lib,
1251
- libList: libList,
1252
- alias: alias || {},
1253
- clear: lang.isUndefinedOrNull(clear) ? false : clear,
1254
- copy: copy || [],
1255
- dts: lang.isUndefinedOrNull(dts) ? {} : dts,
1256
- externals: externals || [],
1257
- input: input,
1258
- internals: internals || [],
1259
- minimize: lang.isUndefinedOrNull(minimize) ? false : minimize,
1260
- output: output,
1261
- rollupConfig: rollupConfig || {},
1262
- webpackConfig: webpackConfig || {},
1263
- esbuildConfig: esbuildConfig || {},
1264
- rspackConfig: rspackConfig || {},
1265
- serviceConfig: serviceConfig || {},
1266
- dtsConfig: dtsConfig
1267
- });
1268
- return next();
1269
- };
1270
- };
1271
- };
1272
- };
1273
-
1274
- var _excluded$1 = ["input", "output", "multiple"];
1275
- var wholeDoraInoutMw = function wholeDoraInoutMw() {
1276
- return function (ctx) {
1277
- return function (next) {
1278
- return function () {
1279
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
1280
- input = _ctx$getDoraConfig.input,
1281
- output = _ctx$getDoraConfig.output,
1282
- multiple = _ctx$getDoraConfig.multiple,
1283
- extConfig = _objectWithoutProperties(_ctx$getDoraConfig, _excluded$1);
1284
- var workRootDir = ctx.getWorkRoot();
1285
- var targetInput = input;
1286
- var outPath = (output === null || output === void 0 ? void 0 : output.path) || './dist';
1287
- var outFile = output === null || output === void 0 ? void 0 : output.file;
1288
- if (!multiple) {
1289
- if (!filePro.isValidFilePathSync(targetInput || '')) {
1290
- targetInput = findInput(workRootDir);
1291
- }
1292
- if (!targetInput) {
1293
- cLog.error('init', 'not_found', '找不到入口文件');
1294
- }
1295
- outFile = (output === null || output === void 0 ? void 0 : output.file) || filePro.getFilename(targetInput);
1296
- }
1297
- ctx.setDoraConfig(_objectSpread2(_objectSpread2({}, extConfig), {}, {
1298
- input: targetInput,
1299
- output: output || {
1300
- path: outPath,
1301
- file: outFile
1302
- },
1303
- multiple: multiple
1304
- }));
1305
- return next();
1306
- };
1307
- };
1308
- };
1309
- };
1310
-
1311
- var configCtxWorkflow = function configCtxWorkflow(config) {
1312
- var middlewares = [];
1313
- return {
1314
- use: function use(middleware) {
1315
- middlewares.push(middleware);
1316
- return this;
1317
- },
1318
- getResult: function getResult() {
1319
- return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1320
- return _regenerator().w(function (_context) {
1321
- while (1) switch (_context.n) {
1322
- case 0:
1323
- _context.n = 1;
1324
- return utils.getOnionFun(config, middlewares)(lang.noop)();
1325
- case 1:
1326
- return _context.a(2, config);
1327
- }
1328
- }, _callee);
1329
- }))();
1330
- }
1331
- };
1332
- };
1333
-
1334
- var EnvEnum = /*#__PURE__*/function (EnvEnum) {
1335
- EnvEnum["dev"] = "development";
1336
- EnvEnum["prod"] = "production";
1337
- return EnvEnum;
1338
- }({});
1339
-
1340
- var CompilerBase = /*#__PURE__*/_createClass(function CompilerBase(initOptions) {
1341
- _classCallCheck(this, CompilerBase);
1342
- this.initOptions = initOptions;
1343
- _defineProperty(this, "inOutMap", void 0);
1344
- _defineProperty(this, "input", void 0);
1345
- _defineProperty(this, "context", void 0);
1346
- _defineProperty(this, "build", void 0);
1347
- _defineProperty(this, "watch", void 0);
1348
- _defineProperty(this, "server", void 0);
1349
- });
1350
-
1351
- /**
1352
- * 动态html生成器
1353
- */
1354
- var DynamicHtml = /*#__PURE__*/function () {
1355
- function DynamicHtml() {
1356
- _classCallCheck(this, DynamicHtml);
1357
- _defineProperty(this, "headScripts", []);
1358
- _defineProperty(this, "bodyScripts", []);
1359
- _defineProperty(this, "headStyles", []);
1360
- _defineProperty(this, "headTags", []);
1361
- _defineProperty(this, "bodyTags", ['<div id="main"></div>']);
1362
- }
1363
- return _createClass(DynamicHtml, [{
1364
- key: "addHeadScripts",
1365
- value: function addHeadScripts(scripts) {
1366
- var _this$headScripts;
1367
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1368
- if (force) this.headScripts = [];
1369
- (_this$headScripts = this.headScripts).push.apply(_this$headScripts, _toConsumableArray(scripts));
1370
- }
1371
- }, {
1372
- key: "addBodyScripts",
1373
- value: function addBodyScripts(scripts) {
1374
- var _this$bodyScripts;
1375
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1376
- if (force) this.bodyScripts = [];
1377
- (_this$bodyScripts = this.bodyScripts).push.apply(_this$bodyScripts, _toConsumableArray(scripts));
1378
- }
1379
- }, {
1380
- key: "addHeadStyles",
1381
- value: function addHeadStyles(styles) {
1382
- var _this$headStyles;
1383
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1384
- if (force) this.headStyles = [];
1385
- (_this$headStyles = this.headStyles).push.apply(_this$headStyles, _toConsumableArray(styles));
1386
- }
1387
- }, {
1388
- key: "addHeadTags",
1389
- value: function addHeadTags(tags) {
1390
- var _this$headTags;
1391
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1392
- if (force) this.headTags = [];
1393
- (_this$headTags = this.headTags).push.apply(_this$headTags, _toConsumableArray(tags));
1394
- }
1395
- }, {
1396
- key: "addBodyTags",
1397
- value: function addBodyTags(tags) {
1398
- var _this$bodyTags;
1399
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1400
- if (force) this.bodyTags = tags;
1401
- (_this$bodyTags = this.bodyTags).push.apply(_this$bodyTags, _toConsumableArray(tags));
1402
- }
1403
- }, {
1404
- key: "copy",
1405
- value: function copy() {
1406
- var dynamicHtml = new DynamicHtml();
1407
- dynamicHtml.addHeadScripts(this.headScripts, true);
1408
- dynamicHtml.addBodyScripts(this.bodyScripts, true);
1409
- dynamicHtml.addHeadStyles(this.headStyles, true);
1410
- return dynamicHtml;
1411
- }
1412
-
1413
- /**
1414
- * 序列化为html模板
1415
- * @param title
1416
- * @returns
1417
- */
1418
- }, {
1419
- key: "generateHtmlTemplate",
1420
- value: function generateHtmlTemplate() {
1421
- var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Document';
1422
- /**
1423
- * 生成header
1424
- * 1. 排序
1425
- * 2. 生成html
1426
- */
1427
- var headScriptsHtml = this.headScripts.sort(function (a, b) {
1428
- return (a.order || 0) - (b.order || 0);
1429
- }).map(function (script) {
1430
- var attrs = ["src=\"".concat(script.src, "\""), script.async ? 'async' : '', script.defer ? 'defer' : ''].filter(Boolean).join(' ');
1431
- return "<script ".concat(attrs, "></script>");
1432
- }).join('\n');
1433
- var bodyScriptsHtml = this.bodyScripts.sort(function (a, b) {
1434
- return (a.order || 0) - (b.order || 0);
1435
- }).map(function (script) {
1436
- var attrs = ["src=\"".concat(script.src, "\""), script.async ? 'async' : '', script.defer ? 'defer' : ''].filter(Boolean).join(' ');
1437
- return "<script ".concat(attrs, "></script>");
1438
- }).join('\n');
1439
- var headStylesHtml = this.headStyles.sort(function (a, b) {
1440
- return (a.order || 0) - (b.order || 0);
1441
- }).map(function (style) {
1442
- var attrs = ["href=\"".concat(style.src, "\""), 'rel="stylesheet"', style.async ? 'async' : '', style.defer ? 'defer' : ''].filter(Boolean).join(' ');
1443
- return "<link ".concat(attrs, ">");
1444
- }).join('\n');
1445
- var headTagsHtml = this.headTags.map(function (tag) {
1446
- return tag;
1447
- }).join('\n');
1448
- var bodyTagsHtml = this.bodyTags.map(function (tag) {
1449
- return tag;
1450
- }).join('\n');
1451
- return "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>".concat(title, "</title>\n ").concat(headTagsHtml, "\n ").concat(headStylesHtml, "\n ").concat(headScriptsHtml, "\n</head>\n<body>\n ").concat(bodyTagsHtml, "\n ").concat(bodyScriptsHtml, "\n</body>\n</html>");
1452
- }
1453
- }]);
1454
- }();
1455
-
1456
- var HtmlAssetManager = /*#__PURE__*/function () {
1457
- function HtmlAssetManager() {
1458
- var publicPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/';
1459
- _classCallCheck(this, HtmlAssetManager);
1460
- this.publicPath = publicPath;
1461
- _defineProperty(this, "assetMap", {});
1462
- _defineProperty(this, "dynamicHtml", new DynamicHtml());
1463
- _defineProperty(this, "initAwaitList", []);
1464
- _defineProperty(this, "assetList", []);
1465
- }
1466
- return _createClass(HtmlAssetManager, [{
1467
- key: "updateAssetList",
1468
- value: function updateAssetList(assetList) {
1469
- var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1470
- this.assetList = force ? assetList : Array.from(new Set([].concat(_toConsumableArray(this.assetList), _toConsumableArray(assetList))));
1471
- }
1472
- }, {
1473
- key: "setAssetList",
1474
- value: function setAssetList(assetMap) {
1475
- this.assetMap = assetMap;
1476
- this.initAwaitList.forEach(function (cb) {
1477
- return cb();
1478
- });
1479
- this.initAwaitList = [];
1480
- }
1481
- }, {
1482
- key: "getAssetMap",
1483
- value: function getAssetMap() {
1484
- return this.assetMap;
1485
- }
1486
- }, {
1487
- key: "getModuleAsset",
1488
- value: function getModuleAsset(moduleName) {
1489
- return this.assetMap[moduleName] || {
1490
- name: moduleName,
1491
- scripts: [],
1492
- styles: [],
1493
- runtimeChunks: []
1494
- };
1495
- }
1496
- }, {
1497
- key: "getModuleHtml",
1498
- value: function () {
1499
- var _getModuleHtml = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleName) {
1500
- var _this = this;
1501
- var asset, moduleHtml;
1502
- return _regenerator().w(function (_context) {
1503
- while (1) switch (_context.n) {
1504
- case 0:
1505
- if (!(Object.keys(this.assetMap).length === 0)) {
1506
- _context.n = 1;
1507
- break;
1508
- }
1509
- _context.n = 1;
1510
- return new Promise(function (resolve) {
1511
- _this.initAwaitList.push(function () {
1512
- resolve();
1513
- });
1514
- });
1515
- case 1:
1516
- asset = this.assetMap[moduleName];
1517
- if (asset) {
1518
- _context.n = 2;
1519
- break;
1520
- }
1521
- throw new Error("Module ".concat(moduleName, " asset not found."));
1522
- case 2:
1523
- moduleHtml = this.dynamicHtml.copy();
1524
- moduleHtml.addBodyScripts(asset.scripts.map(function (src) {
1525
- return {
1526
- src: src,
1527
- order: 0
1528
- };
1529
- }));
1530
- moduleHtml.addHeadStyles(asset.styles.map(function (src) {
1531
- return {
1532
- src: src,
1533
- order: 0
1534
- };
1535
- }));
1536
- return _context.a(2, moduleHtml.generateHtmlTemplate());
1537
- }
1538
- }, _callee, this);
1539
- }));
1540
- function getModuleHtml(_x) {
1541
- return _getModuleHtml.apply(this, arguments);
1542
- }
1543
- return getModuleHtml;
1544
- }()
1545
- }]);
1546
- }();
1547
-
1548
- var _generateTag = function generateTag(tag) {
1549
- var _tag$attrs2;
1550
- if (tag.selfClosing) {
1551
- var _tag$attrs;
1552
- return "<".concat(tag.tagName, " ").concat((_tag$attrs = tag.attrs) === null || _tag$attrs === void 0 ? void 0 : _tag$attrs.map(function (attr) {
1553
- return "".concat(attr.name, "=\"").concat(attr.value, "\"");
1554
- }).join(' '), " />");
1555
- }
1556
- return "<".concat(tag.tagName, " ").concat((_tag$attrs2 = tag.attrs) === null || _tag$attrs2 === void 0 ? void 0 : _tag$attrs2.map(function (attr) {
1557
- return "".concat(attr.name, "=\"").concat(attr.value, "\"");
1558
- }).join(' '), ">").concat((tag.children || []).map(function (child) {
1559
- return typeof child === 'string' ? child : _generateTag(child);
1560
- }).join(''), "</").concat(tag.tagName, ">");
1561
- };
1562
- var generateHtml = function generateHtml(options) {
1563
- var head = options.head,
1564
- body = options.body;
1565
- return "\n <html>\n <head>\n ".concat(head.map(function (tag) {
1566
- return _generateTag(tag);
1567
- }).join('\n'), "\n </head>\n <body>\n ").concat(body.map(function (tag) {
1568
- return _generateTag(tag);
1569
- }).join('\n'), "\n </body>\n </html>\n ");
1570
- };
1571
-
1572
- /**
1573
- * 解析html
1574
- * 会解析 head body 下一层级的标签,子标签,已children保存
1575
- */
1576
- var parseHtml = function parseHtml(html) {
1577
- var headMatch = /<head[^>]*>([\s\S]*?)<\/head>/i.exec(html);
1578
- var bodyMatch = /<body[^>]*>([\s\S]*?)<\/body>/i.exec(html);
1579
- var headHTML = headMatch ? headMatch[1] : '';
1580
- var bodyHTML = bodyMatch ? bodyMatch[1] : '';
1581
- var headTags = parseSection(headHTML);
1582
- var bodyTags = parseSection(bodyHTML);
1583
- return {
1584
- head: headTags,
1585
- body: bodyTags
1586
- };
1587
- };
1588
-
1589
- /**
1590
- * 解析一层标签
1591
- * @param section
1592
- * @returns
1593
- */
1594
- var parseSection = function parseSection(section) {
1595
- var tags = [];
1596
- var stack = [];
1597
- if (!section) return tags;
1598
-
1599
- // HTML 中的自闭合标签列表(没有显式的结束标签)
1600
- var VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
1601
-
1602
- // 解析属性字符串为 TParsedTagAttr[]
1603
- var parseAttrs = function parseAttrs(attrStr) {
1604
- var attrs = [];
1605
- var attrRegex = /([^\s=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
1606
- var match;
1607
- while (match = attrRegex.exec(attrStr)) {
1608
- var _ref, _match$;
1609
- var name = match[1];
1610
- var value = (_ref = (_match$ = match[2]) !== null && _match$ !== void 0 ? _match$ : match[3]) !== null && _ref !== void 0 ? _ref : match[4];
1611
- if (value === undefined) {
1612
- attrs.push({
1613
- name: name,
1614
- value: true
1615
- });
1616
- } else {
1617
- attrs.push({
1618
- name: name,
1619
- value: value
1620
- });
1621
- }
1622
- }
1623
- return attrs;
1624
- };
1625
- var i = 0;
1626
- var len = section.length;
1627
- while (i < len) {
1628
- var char = section[i];
1629
-
1630
- // 处理标签
1631
- if (char === '<') {
1632
- var closeIndex = section.indexOf('>', i + 1);
1633
- if (closeIndex === -1) break;
1634
- var rawTagContent = section.slice(i + 1, closeIndex).trim();
1635
-
1636
- // 跳过注释、DOCTYPE 等
1637
- if (rawTagContent.startsWith('!') || rawTagContent.startsWith('?') || rawTagContent.startsWith('--')) {
1638
- i = closeIndex + 1;
1639
- continue;
1640
- }
1641
-
1642
- // 结束标签
1643
- if (rawTagContent.startsWith('/')) {
1644
- var endTagName = rawTagContent.slice(1).trim().split(/\s+/)[0].toLowerCase();
1645
- if (stack.length) {
1646
- var top = stack[stack.length - 1];
1647
- // 标签名匹配才出栈,否则简单出栈防止死栈
1648
- if (top.tagName.toLowerCase() === endTagName) {
1649
- stack.pop();
1650
- } else {
1651
- stack.pop();
1652
- }
1653
- }
1654
- i = closeIndex + 1;
1655
- continue;
1656
- }
1657
-
1658
- // 开始标签 / 自闭合标签
1659
- var isExplicitSelfClosing = rawTagContent.endsWith('/');
1660
- var tagBody = rawTagContent.replace(/\/\s*$/, '').trim();
1661
- var firstSpace = tagBody.search(/\s/);
1662
- var tagName = (firstSpace === -1 ? tagBody : tagBody.slice(0, firstSpace)).toLowerCase();
1663
- var attrStr = firstSpace === -1 ? '' : tagBody.slice(firstSpace + 1).trim();
1664
- var selfClosing = isExplicitSelfClosing || VOID_TAGS.has(tagName);
1665
- var attrs = parseAttrs(attrStr);
1666
- var newTag = {
1667
- tagName: tagName,
1668
- attrs: attrs,
1669
- selfClosing: selfClosing,
1670
- children: []
1671
- };
1672
- if (stack.length === 0) {
1673
- // 第一层标签
1674
- tags.push(newTag);
1675
- } else {
1676
- // 作为父标签的子节点
1677
- var parent = stack[stack.length - 1];
1678
- if (!parent.children) parent.children = [];
1679
- parent.children.push(newTag);
1680
- }
1681
- if (!selfClosing) {
1682
- stack.push(newTag);
1683
- }
1684
- i = closeIndex + 1;
1685
- continue;
1686
- }
1687
-
1688
- // 处理文本节点
1689
- var nextTagIndex = section.indexOf('<', i);
1690
- var textEnd = nextTagIndex === -1 ? len : nextTagIndex;
1691
- var textContent = section.slice(i, textEnd);
1692
- var trimmed = textContent.trim();
1693
- if (trimmed) {
1694
- if (stack.length) {
1695
- var _parent = stack[stack.length - 1];
1696
- if (!_parent.children) _parent.children = [];
1697
- _parent.children.push(trimmed);
1698
- }
1699
- }
1700
- i = textEnd;
1701
- }
1702
- return tags;
1703
- };
1704
-
1705
- var HtmlManage = /*#__PURE__*/function () {
1706
- function HtmlManage(options) {
1707
- var _options$head, _options$body;
1708
- _classCallCheck(this, HtmlManage);
1709
- _defineProperty(this, "head", []);
1710
- _defineProperty(this, "body", []);
1711
- this.head = (_options$head = options === null || options === void 0 ? void 0 : options.head) !== null && _options$head !== void 0 ? _options$head : [];
1712
- this.body = (_options$body = options === null || options === void 0 ? void 0 : options.body) !== null && _options$body !== void 0 ? _options$body : [];
1713
- }
1714
- return _createClass(HtmlManage, [{
1715
- key: "addHead",
1716
- value: function addHead(tag) {
1717
- if (!tag) return this;
1718
- this.head.push(tag);
1719
- return this;
1720
- }
1721
- }, {
1722
- key: "addHeads",
1723
- value: function addHeads(tags) {
1724
- var _this$head;
1725
- if (!tags) return this;
1726
- (_this$head = this.head).push.apply(_this$head, _toConsumableArray(tags));
1727
- return this;
1728
- }
1729
- }, {
1730
- key: "addBody",
1731
- value: function addBody(tag) {
1732
- if (!tag) return this;
1733
- this.body.push(tag);
1734
- return this;
1735
- }
1736
- }, {
1737
- key: "addBodys",
1738
- value: function addBodys(tags) {
1739
- var _this$body;
1740
- if (!tags) return this;
1741
- (_this$body = this.body).push.apply(_this$body, _toConsumableArray(tags));
1742
- return this;
1743
- }
1744
- }, {
1745
- key: "parseHtmlByFile",
1746
- value: function parseHtmlByFile(filePath) {
1747
- var html = fs.readFileSync(filePath, 'utf-8');
1748
- var _HtmlManage$parseHtml = HtmlManage.parseHtml(html),
1749
- head = _HtmlManage$parseHtml.head,
1750
- body = _HtmlManage$parseHtml.body;
1751
- this.head = head;
1752
- this.body = body;
1753
- return this;
1754
- }
1755
- }, {
1756
- key: "generateHtml",
1757
- value: function generateHtml$1() {
1758
- return generateHtml({
1759
- head: this.head,
1760
- body: this.body
1761
- });
1762
- }
1763
- }, {
1764
- key: "copy",
1765
- value: function copy() {
1766
- return new HtmlManage({
1767
- head: this.head.map(function (tag) {
1768
- return _objectSpread2({}, tag);
1769
- }),
1770
- body: this.body.map(function (tag) {
1771
- return _objectSpread2({}, tag);
1772
- })
1773
- });
1774
- }
1775
- }], [{
1776
- key: "parseHtml",
1777
- value: function parseHtml$1(html) {
1778
- return parseHtml(html);
1779
- }
1780
- }]);
1781
- }();
1782
-
1783
- var collectConfigs = /*#__PURE__*/function () {
1784
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workDir, need) {
1785
- var results;
1786
- return _regenerator().w(function (_context) {
1787
- while (1) switch (_context.p = _context.n) {
1788
- case 0:
1789
- results = {
1790
- doraConfig: null,
1791
- packageConfig: null,
1792
- tsconfigConfig: null,
1793
- cdnConfig: null
1794
- };
1795
- _context.p = 1;
1796
- if (!((need === null || need === void 0 ? void 0 : need.doraConfig) !== false)) {
1797
- _context.n = 3;
1798
- break;
1799
- }
1800
- _context.n = 2;
1801
- return getDoracliConfig(workDir);
1802
- case 2:
1803
- results.doraConfig = _context.v;
1804
- case 3:
1805
- _context.n = 5;
1806
- break;
1807
- case 4:
1808
- _context.p = 4;
1809
- _context.v;
1810
- case 5:
1811
- _context.p = 5;
1812
- if (!((need === null || need === void 0 ? void 0 : need.packageConfig) !== false)) {
1813
- _context.n = 7;
1814
- break;
1815
- }
1816
- _context.n = 6;
1817
- return getPackageJson(workDir);
1818
- case 6:
1819
- results.packageConfig = _context.v;
1820
- case 7:
1821
- _context.n = 9;
1822
- break;
1823
- case 8:
1824
- _context.p = 8;
1825
- _context.v;
1826
- case 9:
1827
- _context.p = 9;
1828
- if (!((need === null || need === void 0 ? void 0 : need.tsconfigConfig) !== false)) {
1829
- _context.n = 11;
1830
- break;
1831
- }
1832
- _context.n = 10;
1833
- return getTsconfigJson(workDir);
1834
- case 10:
1835
- results.tsconfigConfig = _context.v;
1836
- case 11:
1837
- _context.n = 13;
1838
- break;
1839
- case 12:
1840
- _context.p = 12;
1841
- _context.v;
1842
- case 13:
1843
- _context.p = 13;
1844
- if (!((need === null || need === void 0 ? void 0 : need.cdnConfig) !== false)) {
1845
- _context.n = 15;
1846
- break;
1847
- }
1848
- _context.n = 14;
1849
- return getUserCdn(workDir);
1850
- case 14:
1851
- results.cdnConfig = _context.v;
1852
- case 15:
1853
- _context.n = 17;
1854
- break;
1855
- case 16:
1856
- _context.p = 16;
1857
- _context.v;
1858
- case 17:
1859
- return _context.a(2, results);
1860
- }
1861
- }, _callee, null, [[13, 16], [9, 12], [5, 8], [1, 4]]);
1862
- }));
1863
- return function collectConfigs(_x, _x2) {
1864
- return _ref.apply(this, arguments);
1865
- };
1866
- }();
1867
-
1868
- var configCtxCollect = /*#__PURE__*/function () {
1869
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(configCtx, params) {
1870
- return _regenerator().w(function (_context) {
1871
- while (1) switch (_context.n) {
1872
- case 0:
1873
- configCtx.setCdnConfig(params.cdnConfig);
1874
- configCtx.setDoraConfig(params.doraConfig);
1875
- configCtx.setTsConfig(params.tsConfig);
1876
- configCtx.setPackageConfig(params.packageConfig);
1877
- configCtx.setWorkRoot(params.workRootDir || filePro.getCwd());
1878
- configCtx.setCmd(params.cmd || {});
1879
- case 1:
1880
- return _context.a(2);
1881
- }
1882
- }, _callee);
1883
- }));
1884
- return function configCtxCollect(_x, _x2) {
1885
- return _ref.apply(this, arguments);
1886
- };
1887
- }();
1888
-
1889
- /**
1890
- * 创建环境参数
1891
- * @description 会自动处理出绝对路径的 workRootDir
1892
- * @param params 上下文变量
1893
- * @returns
1894
- */
1895
- var createEnvParams = function createEnvParams(params) {
1896
- var workRootDir = params.workRootDir || './';
1897
- if (!path.isAbsolute(params.workRootDir)) {
1898
- workRootDir = path.join(filePro.getCwd(), workRootDir);
1899
- }
1900
- return _objectSpread2(_objectSpread2({}, params), {}, {
1901
- workRootDir: workRootDir
1902
- });
1903
- };
1904
-
1905
- var createOutputList = function createOutputList(config) {
1906
- var input = config.input,
1907
- output = config.output,
1908
- formatList = config.formatList,
1909
- format = config.format;
1910
- var path = output.path,
1911
- file = output.file;
1912
- var outputList = [];
1913
- if (format) {
1914
- outputList.push({
1915
- input: input,
1916
- format: format,
1917
- outputFile: file || filePro.getFilename(input) || 'index.js',
1918
- outputPath: path || 'dist'
1919
- });
1920
- } else if (lang.isArray(formatList)) {
1921
- formatList.forEach(function (fmt) {
1922
- outputList.push({
1923
- input: input,
1924
- format: fmt,
1925
- outputFile: file || filePro.getFilename(input) || 'index.js',
1926
- outputPath: path || 'dist'
1927
- });
1928
- });
1929
- } else {
1930
- outputList.push({
1931
- input: input,
1932
- format: 'iife',
1933
- outputFile: file || filePro.getFilename(input) || 'index.js',
1934
- outputPath: path || 'dist'
1935
- });
1936
- }
1937
- return outputList;
1938
- };
1939
-
1940
- /**
1941
- * 依赖项过滤
1942
- * @param options 过滤选项
1943
- * @param strategy 规则冲突时,过滤策略 include-包含 | exclude-排除,默认排除
1944
- * @returns 依赖过滤函数 () => boolean 返回true表示 - 属于排除范围
1945
- */
1946
- var createDependFilter = function createDependFilter(options) {
1947
- var strategy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'exclude';
1948
- var dependencies = options.dependencies,
1949
- peerDependencies = options.peerDependencies,
1950
- devDependencies = options.devDependencies,
1951
- externals = options.externals,
1952
- internals = options.internals,
1953
- compare = options.compare;
1954
- var excludeMap = {};
1955
- var includeMap = {};
1956
- Object.keys(dependencies || {}).forEach(function (key) {
1957
- excludeMap[key] = key;
1958
- });
1959
- Object.keys(peerDependencies || {}).forEach(function (key) {
1960
- excludeMap[key] = key;
1961
- });
1962
- Object.keys(devDependencies || {}).forEach(function (key) {
1963
- excludeMap[key] = key;
1964
- });
1965
- externals === null || externals === void 0 || externals.forEach(function (item) {
1966
- if (lang.isString(item)) {
1967
- excludeMap[item] = item;
1968
- } else if (lang.isPlainObject(item)) {
1969
- Object.keys(item).forEach(function (key) {
1970
- excludeMap[key] = item[key];
1971
- });
1972
- }
1973
- });
1974
- internals === null || internals === void 0 || internals.forEach(function (item) {
1975
- if (lang.isString(item)) {
1976
- includeMap[item] = item;
1977
- }
1978
- });
1979
- var isIncludeStrategy = strategy === 'include';
1980
-
1981
- /**
1982
- * 依赖过滤器
1983
- * @param id 模块id
1984
- * @returns boolean 返回true表示 - 属于排除范围
1985
- */
1986
- return function (id) {
1987
- var res = false;
1988
-
1989
- /** 判断排除 */
1990
- var excludeTarget = Object.keys(excludeMap).find(function (externalModule) {
1991
- if (lang.isFunction(compare)) return compare(id, externalModule);
1992
- return id.startsWith(externalModule);
1993
- });
1994
-
1995
- /** 判断包含 */
1996
- var includeTarget = Object.keys(includeMap).find(function (externalModule) {
1997
- if (lang.isFunction(compare)) return compare(id, externalModule);
1998
- return id.startsWith(externalModule);
1999
- });
2000
- if (isIncludeStrategy) {
2001
- if (includeTarget) {
2002
- res = false;
2003
- } else if (excludeTarget) {
2004
- res = excludeMap[excludeTarget];
2005
- }
2006
- } else {
2007
- if (excludeTarget) {
2008
- res = excludeMap[excludeTarget];
2009
- } else if (includeTarget) {
2010
- res = false;
2011
- }
2012
- }
2013
- return res;
2014
- };
2015
- };
2016
-
2017
- var htmlDefault = "\n<html lang=\"zh-CN\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>dora</title>\n </head>\n <body>\n <div id=\"main\">welcome use dora !!</div>\n </body>\n</html>\n";
2018
- var getDefaultHtml = /*#__PURE__*/function () {
2019
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir) {
2020
- var userHtmlDir;
2021
- return _regenerator().w(function (_context) {
2022
- while (1) switch (_context.n) {
2023
- case 0:
2024
- _context.n = 1;
2025
- return findInputHtml(workRootDir);
2026
- case 1:
2027
- userHtmlDir = _context.v;
2028
- if (!userHtmlDir) {
2029
- _context.n = 2;
2030
- break;
2031
- }
2032
- return _context.a(2, fs.readFileSync(userHtmlDir, 'utf-8'));
2033
- case 2:
2034
- return _context.a(2, htmlDefault);
2035
- }
2036
- }, _callee);
2037
- }));
2038
- return function getDefaultHtml(_x) {
2039
- return _ref.apply(this, arguments);
2040
- };
2041
- }();
2042
-
2043
- var parsetConfig = /*#__PURE__*/function () {
2044
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config, mode) {
2045
- var _t, _t2, _t3, _t4;
2046
- return _regenerator().w(function (_context) {
2047
- while (1) switch (_context.n) {
2048
- case 0:
2049
- _context.n = 1;
2050
- return parseDoracliConfig(config.doraConfig, mode);
2051
- case 1:
2052
- _t = _context.v;
2053
- _t2 = config.packageConfig || {};
2054
- _t3 = config.tsconfigConfig || {};
2055
- _context.n = 2;
2056
- return parseCdnConfig(config.cdnConfig, mode);
2057
- case 2:
2058
- _t4 = _context.v;
2059
- return _context.a(2, {
2060
- doraConfig: _t,
2061
- packageConfig: _t2,
2062
- tsConfig: _t3,
2063
- cdnConfig: _t4
2064
- });
2065
- }
2066
- }, _callee);
2067
- }));
2068
- return function parsetConfig(_x, _x2) {
2069
- return _ref.apply(this, arguments);
2070
- };
2071
- }();
2072
-
2073
- var _excluded = ["multiple"];
2074
- var splitDoraConfig = function splitDoraConfig(config) {
2075
- var multiple = config.multiple,
2076
- neatConfig = _objectWithoutProperties(config, _excluded);
2077
- if (!lang.isArray(multiple)) return [neatConfig];
2078
- if (multiple.length === 0) return [neatConfig];
2079
- if (multiple.length === 1) return [mergeDoraCliConfigMutiple(multiple[0], neatConfig)];
2080
- return multiple.map(function (item) {
2081
- return mergeDoraCliConfigMutiple(neatConfig, item);
2082
- });
2083
- };
2084
-
2085
- var GenerateConfigHtml = /*#__PURE__*/function (_HtmlManage) {
2086
- function GenerateConfigHtml(configCtx) {
2087
- var _this;
2088
- _classCallCheck(this, GenerateConfigHtml);
2089
- _this = _callSuper(this, GenerateConfigHtml);
2090
- _this.configCtx = configCtx;
2091
- return _this;
2092
- }
2093
- _inherits(GenerateConfigHtml, _HtmlManage);
2094
- return _createClass(GenerateConfigHtml, [{
2095
- key: "init",
2096
- value: function () {
2097
- var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2098
- var defaultHtml, _HtmlManage$parseHtml, head, body;
2099
- return _regenerator().w(function (_context) {
2100
- while (1) switch (_context.n) {
2101
- case 0:
2102
- _context.n = 1;
2103
- return getDefaultHtml(this.configCtx.getWorkRoot());
2104
- case 1:
2105
- defaultHtml = _context.v;
2106
- _HtmlManage$parseHtml = HtmlManage.parseHtml(defaultHtml), head = _HtmlManage$parseHtml.head, body = _HtmlManage$parseHtml.body;
2107
- this.addHeads(head);
2108
- this.addBodys(body);
2109
- return _context.a(2, this);
2110
- }
2111
- }, _callee, this);
2112
- }));
2113
- function init() {
2114
- return _init.apply(this, arguments);
2115
- }
2116
- return init;
2117
- }()
2118
- }, {
2119
- key: "addConfigCdn",
2120
- value: function addConfigCdn() {
2121
- var _cdnConfig$headAfterS, _cdnConfig$headAfterS2, _cdnConfig$bodyAfterS, _cdnConfig$bodyBefore;
2122
- var cdnConfig = this.configCtx.getCdnConfig();
2123
- this.addHeads((_cdnConfig$headAfterS = cdnConfig.headAfterScript) === null || _cdnConfig$headAfterS === void 0 ? void 0 : _cdnConfig$headAfterS.map(function (script) {
2124
- return {
2125
- tagName: 'script',
2126
- attrs: [{
2127
- name: 'src',
2128
- value: script
2129
- }]
2130
- };
2131
- }));
2132
- this.addHeads((_cdnConfig$headAfterS2 = cdnConfig.headAfterStyle) === null || _cdnConfig$headAfterS2 === void 0 ? void 0 : _cdnConfig$headAfterS2.map(function (style) {
2133
- return {
2134
- tagName: 'link',
2135
- attrs: [{
2136
- name: 'href',
2137
- value: style
2138
- }, {
2139
- name: 'rel',
2140
- value: 'stylesheet'
2141
- }]
2142
- };
2143
- }));
2144
- this.addBodys((_cdnConfig$bodyAfterS = cdnConfig.bodyAfterScript) === null || _cdnConfig$bodyAfterS === void 0 ? void 0 : _cdnConfig$bodyAfterS.map(function (script) {
2145
- return {
2146
- tagName: 'script',
2147
- attrs: [{
2148
- name: 'src',
2149
- value: script
2150
- }]
2151
- };
2152
- }));
2153
- this.addBodys((_cdnConfig$bodyBefore = cdnConfig.bodyBeforeScript) === null || _cdnConfig$bodyBefore === void 0 ? void 0 : _cdnConfig$bodyBefore.map(function (script) {
2154
- return {
2155
- tagName: 'script',
2156
- attrs: [{
2157
- name: 'src',
2158
- value: script
2159
- }]
2160
- };
2161
- }));
2162
- return this;
2163
- }
2164
-
2165
- /**
2166
- * 写入到文件,没有文件创建文件
2167
- * @param filePath 文件路径
2168
- * @returns
2169
- */
2170
- }, {
2171
- key: "writeToFile",
2172
- value: function writeToFile(filePath) {
2173
- if (!fs.existsSync(filePath)) {
2174
- fs.writeFileSync(filePath, this.generateHtml(), {});
2175
- } else {
2176
- fs.appendFileSync(filePath, this.generateHtml(), {});
2177
- }
2178
- return this;
2179
- }
2180
- }, {
2181
- key: "addBodyScripts",
2182
- value: function addBodyScripts(scripts) {
2183
- this.addBodys(scripts.map(function (script) {
2184
- return {
2185
- tagName: 'script',
2186
- attrs: [{
2187
- name: 'src',
2188
- value: script
2189
- }]
2190
- };
2191
- }));
2192
- return this;
2193
- }
2194
- }, {
2195
- key: "addHeadStyles",
2196
- value: function addHeadStyles(styles) {
2197
- this.addHeads(styles.map(function (style) {
2198
- return {
2199
- tagName: 'link',
2200
- attrs: [{
2201
- name: 'href',
2202
- value: style
2203
- }, {
2204
- name: 'rel',
2205
- value: 'stylesheet'
2206
- }]
2207
- };
2208
- }));
2209
- return this;
2210
- }
2211
- }, {
2212
- key: "copy",
2213
- value: function copy() {
2214
- var generateConfigHtml = new GenerateConfigHtml(this.configCtx);
2215
- generateConfigHtml.addHeads(this.head);
2216
- generateConfigHtml.addBodys(this.body);
2217
- return generateConfigHtml;
2218
- }
2219
- }]);
2220
- }(HtmlManage);
2221
-
2222
- /**
2223
- * 在制定目录下插入 tsconfig.json 文件
2224
- * @param cwd
2225
- */
2226
- var insertTsconfig = /*#__PURE__*/function () {
2227
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2228
- var cwd,
2229
- tsconfigPath,
2230
- tsconfigContent,
2231
- _args = arguments;
2232
- return _regenerator().w(function (_context) {
2233
- while (1) switch (_context.n) {
2234
- case 0:
2235
- cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : filePro.getCwd();
2236
- tsconfigPath = path.join(cwd, 'tsconfig.json');
2237
- _context.n = 1;
2238
- return filePro.isValidFilePath(tsconfigPath);
2239
- case 1:
2240
- if (_context.v) {
2241
- _context.n = 3;
2242
- break;
2243
- }
2244
- tsconfigContent = {
2245
- $schema: 'https://json.schemastore.org/tsconfig',
2246
- compilerOptions: {
2247
- target: 'esnext',
2248
- moduleResolution: 'node',
2249
- module: 'esnext',
2250
- noImplicitThis: false,
2251
- noImplicitAny: false,
2252
- noUnusedLocals: false,
2253
- noImplicitReturns: true,
2254
- noUnusedParameters: false,
2255
- useUnknownInCatchVariables: false,
2256
- allowSyntheticDefaultImports: true,
2257
- esModuleInterop: true,
2258
- emitDecoratorMetadata: true,
2259
- experimentalDecorators: true,
2260
- preserveConstEnums: true,
2261
- strictNullChecks: true,
2262
- strictFunctionTypes: true,
2263
- strictPropertyInitialization: true,
2264
- resolveJsonModule: true,
2265
- skipLibCheck: true,
2266
- alwaysStrict: true,
2267
- sourceMap: false,
2268
- paths: {
2269
- '@/*': ['./src/*']
2270
- }
2271
- },
2272
- exclude: ['lib/**'],
2273
- include: ['**/*.ts', '**/*.json']
2274
- };
2275
- _context.n = 2;
2276
- return promises.writeFile(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
2277
- case 2:
2278
- cLog.info('init', 'success', '自动注入 tsconfig.json');
2279
- case 3:
2280
- return _context.a(2);
2281
- }
2282
- }, _callee);
2283
- }));
2284
- return function insertTsconfig() {
2285
- return _ref.apply(this, arguments);
2286
- };
2287
- }();
2288
-
2289
- exports.picocolors = picocolors;
2290
- exports.CompilerBase = CompilerBase;
2291
- exports.ConfigCtx = ConfigCtx;
2292
- exports.DynamicHtml = DynamicHtml;
2293
- exports.EnvEnum = EnvEnum;
2294
- exports.GenerateConfigHtml = GenerateConfigHtml;
2295
- exports.HtmlAssetManager = HtmlAssetManager;
2296
- exports.HtmlManage = HtmlManage;
2297
- exports.cLog = cLog;
2298
- exports.cLogDebugger = cLogDebugger;
2299
- exports.cLogError = cLogError;
2300
- exports.cLogMessage = cLogMessage;
2301
- exports.cLogSuccess = cLogSuccess;
2302
- exports.cLogTime = cLogTime;
2303
- exports.cLogTimeEnd = cLogTimeEnd;
2304
- exports.cLogWarn = cLogWarn;
2305
- exports.clearMw = clearMw;
2306
- exports.collectBaseConfigMw = collectBaseConfigMw;
2307
- exports.collectCdnConfigMw = collectCdnConfigMw;
2308
- exports.collectConfig = collectConfig;
2309
- exports.collectConfigs = collectConfigs;
2310
- exports.collectDoraConfigMw = collectDoraConfigMw;
2311
- exports.collectPackageJsonMw = collectPackageJsonMw;
2312
- exports.collectTsconfigJsonMw = collectTsconfigJsonMw;
2313
- exports.configCtxCollect = configCtxCollect;
2314
- exports.configCtxWorkflow = configCtxWorkflow;
2315
- exports.createDependFilter = createDependFilter;
2316
- exports.createEnvParams = createEnvParams;
2317
- exports.createOutputList = createOutputList;
2318
- exports.deepMergeObject = _deepMergeObject;
2319
- exports.findInput = findInput;
2320
- exports.findInputHtml = findInputHtml;
2321
- exports.getDefaultHtml = getDefaultHtml;
2322
- exports.getDependencies = getDependencies;
2323
- exports.getDoracliConfig = getDoracliConfig;
2324
- exports.getPackageJson = getPackageJson;
2325
- exports.getTsPathAlias = getTsPathAlias;
2326
- exports.getTsconfigJson = getTsconfigJson;
2327
- exports.getUserCdn = getUserCdn;
2328
- exports.inputFileDirList = inputFileDirList;
2329
- exports.inputFileTypeList = inputFileTypeList;
2330
- exports.inputHtmlFileDirList = inputHtmlFileDirList;
2331
- exports.insertTsconfig = insertTsconfig;
2332
- exports.mergeDoraCliConfig = mergeDoraCliConfig;
2333
- exports.mergeDoraCliConfigMutiple = mergeDoraCliConfigMutiple;
2334
- exports.parseCdnConfig = parseCdnConfig;
2335
- exports.parseDoracliConfig = parseDoracliConfig;
2336
- exports.parseHtml = parseHtml;
2337
- exports.parsetConfig = parsetConfig;
2338
- exports.resolveCdnConfig = resolveCdnConfig;
2339
- exports.resolveDoraConfig = resolveDoraConfig;
2340
- exports.resolvePackageJson = resolvePackageJson;
2341
- exports.resolveTsconfigJson = resolveTsconfigJson;
2342
- exports.setLogLevel = setLogLevel;
2343
- exports.splitDoraCliConfig = splitDoraCliConfig;
2344
- exports.splitDoraConfig = splitDoraConfig;
2345
- exports.wholeDoraConfig = wholeDoraConfig;
2346
- exports.wholeDoraConfigMw = wholeDoraConfigMw;
2347
- exports.wholeDoraInoutMw = wholeDoraInoutMw;
1
+ "use strict";var t=require("@dorabag/file-pro"),n=require("picocolors"),e=require("@dorabag/config-loader"),r=require("@cclr/lang"),o=require("path"),i=require("@cclr/utils"),a=require("fs"),c=require("fs/promises");function u(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=Array(n);e<n;e++)r[e]=t[e];return r}function s(t,n,e,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?n(u):Promise.resolve(u).then(r,o)}function l(t){return function(){var n=this,e=arguments;return new Promise(function(r,o){var i=t.apply(n,e);function a(t){s(i,r,o,a,c,"next",t)}function c(t){s(i,r,o,a,c,"throw",t)}a(void 0)})}}function f(t,n,e){return n=v(n),function(t,n){if(n&&("object"==typeof n||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,y()?Reflect.construct(n,[],v(t).constructor):n.apply(t,e))}function p(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function d(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,S(r.key),r)}}function h(t,n,e){return n&&d(t.prototype,n),e&&d(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function g(t,n,e){return(n=S(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},v(t)}function y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(y=function(){return!!t})()}function m(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,r)}return e}function b(t){for(var n=1;n<arguments.length;n++){var e=null!=arguments[n]?arguments[n]:{};n%2?m(Object(e),!0).forEach(function(n){g(t,n,e[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):m(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})}return t}function C(t,n){if(null==t)return{};var e,r,o=function(t,n){if(null==t)return{};var e={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==n.indexOf(r))continue;e[r]=t[r]}return e}(t,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)e=i[r],-1===n.indexOf(e)&&{}.propertyIsEnumerable.call(t,e)&&(o[e]=t[e])}return o}function w(){
2
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
+ var t,n,e="function"==typeof Symbol?Symbol:{},r=e.iterator||"@@iterator",o=e.toStringTag||"@@toStringTag";function i(e,r,o,i){var u=r&&r.prototype instanceof c?r:c,s=Object.create(u.prototype);return k(s,"_invoke",function(e,r,o){var i,c,u,s=0,l=o||[],f=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(n,e){return i=n,c=0,u=t,p.n=e,a}};function d(e,r){for(c=e,u=r,n=0;!f&&s&&!o&&n<l.length;n++){var o,i=l[n],d=p.p,h=i[2];e>3?(o=h===r)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=d&&((o=e<2&&d<i[1])?(c=0,p.v=r,p.n=i[1]):d<h&&(o=e<3||i[0]>r||r>h)&&(i[4]=e,i[5]=r,p.n=h,c=0))}if(o||e>1)return a;throw f=!0,r}return function(o,l,h){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&d(l,h),c=l,u=h;(n=c<2?t:u)||!f;){i||(c?c<3?(c>1&&(p.n=-1),d(c,u)):p.n=u:p.v=u);try{if(s=2,i){if(c||(o="next"),n=i[o]){if(!(n=n.call(i,u)))throw TypeError("iterator result is not an object");if(!n.done)return n;u=n.value,c<2&&(c=0)}else 1===c&&(n=i.return)&&n.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((n=(f=p.n<0)?u:e.call(r,p))!==a)break}catch(n){i=t,c=1,u=n}finally{s=1}}return{value:n,done:f}}}(e,o,i),!0),s}var a={};function c(){}function u(){}function s(){}n=Object.getPrototypeOf;var l=[][r]?n(n([][r]())):(k(n={},r,function(){return this}),n),f=s.prototype=c.prototype=Object.create(l);function p(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,k(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return u.prototype=s,k(f,"constructor",s),k(s,"constructor",u),u.displayName="GeneratorFunction",k(s,o,"GeneratorFunction"),k(f),k(f,o,"Generator"),k(f,r,function(){return this}),k(f,"toString",function(){return"[object Generator]"}),(w=function(){return{w:i,m:p}})()}function k(t,n,e,r){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}k=function(t,n,e,r){function i(n,e){k(t,n,function(t){return this._invoke(n,e,t)})}n?o?o(t,n,{value:e,enumerable:!r,configurable:!r,writable:!r}):t[n]=e:(i("next",0),i("throw",1),i("return",2))},k(t,n,e,r)}function x(t,n){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},x(t,n)}function j(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var r,o,i,a,c=[],u=!0,s=!1;try{if(i=(e=e.call(t)).next,0===n);else for(;!(u=(r=i.call(e)).done)&&(c.push(r.value),c.length!==n);u=!0);}catch(t){s=!0,o=t}finally{try{if(!u&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(t,n)||P(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||P(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(t){var n=function(t,n){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,n);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:n+""}function P(t,n){if(t){if("string"==typeof t)return u(t,n);var e={}.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?u(t,n):void 0}}var D=function(){function t(){p(this,t),g(this,"tsConfig",{}),g(this,"doraConfig",{}),g(this,"packageConfig",{}),g(this,"cdnConfig",{}),g(this,"cmd",{}),g(this,"workRoot","./")}return h(t,[{key:"setCmd",value:function(t){this.cmd=t}},{key:"getCmd",value:function(){return this.cmd}},{key:"setWorkRoot",value:function(t){this.workRoot=t}},{key:"getWorkRoot",value:function(){return this.workRoot}},{key:"setTsConfig",value:function(t){this.tsConfig=t}},{key:"getTsConfig",value:function(){return this.tsConfig}},{key:"setDoraConfig",value:function(t){this.doraConfig=t}},{key:"getDoraConfig",value:function(){return this.doraConfig}},{key:"setCdnConfig",value:function(t){this.cdnConfig=t}},{key:"getCdnConfig",value:function(){return this.cdnConfig}},{key:"setPackageConfig",value:function(t){this.packageConfig=t}},{key:"getPackageConfig",value:function(){return this.packageConfig}},{key:"copy",value:function(){var n=new t;return n.setWorkRoot(this.getWorkRoot()),n.setTsConfig(this.getTsConfig()),n.setDoraConfig(this.getDoraConfig()),n.setPackageConfig(this.getPackageConfig()),n.setCdnConfig(this.getCdnConfig()),n.setCmd(this.getCmd()),n}}])}(),T="@doracli",A=10,E=function(t,n){return t.length>=n?t:t+" ".repeat(n-t.length)},F=function(t){return E(t,5)},L=function(t){return E(t,9).toUpperCase()},H=function(t,e){var r;if(!(A>0)){for(var o=n.bgBlack("[".concat(n.magenta(T),":").concat(n.bold(" ".concat(F(t))),"]")),i=arguments.length,a=new Array(i>2?i-2:0),c=2;c<i;c++)a[c-2]=arguments[c];return(r=console).debug.apply(r,["".concat(o," [").concat(L(e),"]")].concat(a))}},M=function(t,e){var r;if(!(A>10)){for(var o=n.bgBlack("[".concat(n.magenta(T),":").concat(n.bold(" ".concat(F(t))),"]")),i=arguments.length,a=new Array(i>2?i-2:0),c=2;c<i;c++)a[c-2]=arguments[c];return(r=console).log.apply(r,["".concat(o," [").concat(n.yellow(L(e)),"]")].concat(a))}},R=function(t,e){var r;if(!(A>100)){for(var o=n.bgBlack("[".concat(n.magenta(T),":").concat(n.bold(" ".concat(F(t))),"]")),i=arguments.length,a=new Array(i>2?i-2:0),c=2;c<i;c++)a[c-2]=arguments[c];return(r=console).log.apply(r,["".concat(o," [").concat(n.green(L(e)),"]")].concat(a))}},B=function(t,e){var r;if(!(A>1e3)){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];return(r=console).log.apply(r,[n.bgYellow("[".concat(T,": ").concat(F(t),"] [").concat(L(e),"]"))].concat(i))}},N=function(t,e){var r;if(!(A>1e4)){for(var o=arguments.length,i=new Array(o>2?o-2:0),a=2;a<o;a++)i[a-2]=arguments[a];return(r=console).log.apply(r,[n.bgRed("[".concat(T,": ").concat(F(t),"] [").concat(L(e),"]"))].concat(i))}},W=0,U=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"cLogTimeStart-".concat(W);return W++,console.time(t),function(){console.timeEnd(t)}},I=function(t){console.timeEnd(t)},_={log:M,debug:H,error:N,warn:B,info:R,time:U,timeEnd:I},z=function(){var n=l(w().m(function n(e){var r,o,i,a;return w().w(function(n){for(;;)switch(n.p=n.n){case 0:if(r=e.getDoraConfig(),o=r.clear,i=r.output,a=(i||{}).path,n.p=1,o){n.n=2;break}return n.a(2);case 2:if(a){n.n=3;break}return n.a(2);case 3:return n.n=4,t.isValidDir(a);case 4:if(n.v){n.n=5;break}return n.a(2);case 5:return n.n=6,t.cleanTargets(a);case 6:n.n=8;break;case 7:n.p=7,n.v,_.warn("clear","warn","清空目标文件夹失败: ".concat(a));case 8:return n.a(2)}},n,null,[[1,7]])}));return function(t){return n.apply(this,arguments)}}(),q=function(){var n=l(w().m(function n(r){var o,i;return w().w(function(n){for(;;)switch(n.p=n.n){case 0:return n.p=0,n.n=1,e.loadConfigFuzzyExt("doracli.config",{rootDir:t.resolveCwd(r)});case 1:if(o=n.v){n.n=2;break}return _.warn("file","undefined","未定义 doracli 配置文件"),n.a(2,null);case 2:return _.debug("file","success","引入 doracli 配置文件成功"),n.a(2,o.default||o);case 3:return n.p=3,i=n.v,_.error("file","fail","引入 doracli 配置文件失败"),console.error(i),n.a(2,Promise.reject(i))}},n,null,[[0,3]])}));return function(t){return n.apply(this,arguments)}}(),J=function(){var n=l(w().m(function n(){var r,o,i,a=arguments;return w().w(function(n){for(;;)switch(n.p=n.n){case 0:return r=a.length>0&&void 0!==a[0]?a[0]:"",n.p=1,n.n=2,e.loadConfig(t.resolveCwd(r,"package.json"));case 2:return o=n.v,_.debug("file","success","引入 package.json 成功"),n.a(2,o);case 3:n.p=3,i=n.v,_.error("file","fail","引入 package.json 失败"),_.debug("file","error",i);case 4:return n.a(2)}},n,null,[[1,3]])}));return function(){return n.apply(this,arguments)}}(),G=function(){var n=l(w().m(function n(r){var o,i;return w().w(function(n){for(;;)switch(n.p=n.n){case 0:return n.p=0,n.n=1,e.loadConfig(t.resolveCwd(r,"./tsconfig.json"));case 1:return o=n.v,_.debug("file","success","引入 tsconfig.json 成功"),n.a(2,o);case 2:n.p=2,i=n.v,_.error("file","failed","引入 tsconfig.json 失败"),_.debug("file","error",i);case 3:return n.a(2)}},n,null,[[0,2]])}));return function(t){return n.apply(this,arguments)}}();function V(t){return $.apply(this,arguments)}function $(){return($=l(w().m(function n(r){var o,i;return w().w(function(n){for(;;)switch(n.p=n.n){case 0:return n.p=0,n.n=1,e.loadConfigFuzzyExt("cdn",{rootDir:t.resolveCwd(r)});case 1:if(null!=(o=n.v)&&o.default){n.n=2;break}return _.log("file","undefined","未定义 cdn 配置文件"),n.a(2,null);case 2:return _.info("file","success","引入 cdn 成功"),n.a(2,o.default);case 3:return n.p=3,i=n.v,_.error("file","failed","引入 cdn 失败"),_.debug("file","failed",i),n.a(2,null)}},n,null,[[0,3]])}))).apply(this,arguments)}var Y=function(t){return K(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{})},X=function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];return n.reduce(function(t,n){return Y(t,n)})},K=function(t,n){if(!n)return t;if(!t)return n;var e=b({},t);for(var o in n)r.isObject(n[o])?e[o]=K(t[o],n[o]):e[o]=n[o];return e};function Q(t,n){try{if(!r.isObject(t))return;return Object.entries(t).reduce(function(t,e){var o=j(e,2),i=o[0],a=o[1];return r.isFunction(a)?t[i]=a(n)||[]:r.isArray(a)&&(t[i]=a),t},{})}catch(t){throw _.error("parse","parseCdnConfig","解析用户cdn配置失败"),new Error(t)}}var Z=function(){var t=l(w().m(function t(n,e){var o,i;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,o=n,!r.isFunction(n)){t.n=2;break}return t.n=1,n(e);case 1:o=t.v;case 2:return t.a(2,o);case 3:throw t.p=3,i=t.v,_.error("resolve ","resolveUserConfigJson","解析用户配置失败"),new Error(i);case 4:return t.a(2)}},t,null,[[0,3]])}));return function(n,e){return t.apply(this,arguments)}}(),tt=["multiple"],nt=["src/index","index"],et=[".ts",".js",".tsx",".jsx"],rt=function(n){var e=nt.reduce(function(t,n){return et.forEach(function(e){t.push("./"+n+e)}),t},[]);return t.lookupFile(e,n)},ot=["index.html","public/index.html"],it=function(n){return t.lookupFile(ot,n)},at=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t.getCwd(),o=n.type,i=n.name,a=n.lib,c=n.libList,u=n.alias,s=n.clear,l=n.copy,f=n.dts,p=n.externals,d=n.formatList,h=n.input,g=n.internals,v=n.minimize,y=n.multiple,m=n.output,b=n.rollupConfig,C=n.webpackConfig,w=n.esbuildConfig,k=n.rspackConfig,x=n.format,j=n.serviceConfig,O=h,S=(null==m?void 0:m.path)||"./dist",P=null==m?void 0:m.file,D=[];return y||(t.isValidFilePathSync(O||"")||(O=rt(e)),O||_.error("init","not_found","找不到入口文件"),P=(null==m?void 0:m.file)||t.getFilename(O)),c||(D=a?[a]:null!=d&&d.length?d.map(function(t){return{format:t}}):[{format:x||"cjs"}]),{multiple:!r.isUndefinedOrNull(y)&&y,type:o,name:i,alias:u||{},clear:!r.isUndefinedOrNull(s)&&s,copy:l||[],dts:r.isUndefinedOrNull(f)?{}:f,externals:p||[],formatList:d||["cjs"],libList:D,input:h,internals:g||[],minimize:!r.isUndefinedOrNull(v)&&v,output:m||{path:S,file:P},rollupConfig:b||{},webpackConfig:C||{},esbuildConfig:w||{},rspackConfig:k||{},serviceConfig:j||{}}},ct=function(){var t=l(w().m(function t(n,e){var r;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,q(n);case 1:return r=t.v,t.a(2,Z(r,e));case 2:return t.p=2,t.v,_.log("resolve ","error","doracli.config 解析用户配置失败"),t.a(2,{})}},t,null,[[0,2]])}));return function(n,e){return t.apply(this,arguments)}}(),ut=function(){var t=l(w().m(function t(n){var e;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,J(n);case 1:return e=t.v,t.a(2,e);case 2:return t.p=2,t.v,_.log("resolve ","error","package.json 解析用户配置失败"),t.a(2,{})}},t,null,[[0,2]])}));return function(n){return t.apply(this,arguments)}}(),st=function(){var t=l(w().m(function t(n){var e;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,G(n);case 1:return e=t.v,t.a(2,e);case 2:return t.p=2,t.v,_.log("resolve ","error","tsconfig.json 解析用户配置失败"),t.a(2,{})}},t,null,[[0,2]])}));return function(n){return t.apply(this,arguments)}}(),lt=function(){var t=l(w().m(function t(n,e,r){var o,i,a,c;return w().w(function(t){for(;;)switch(t.n){case 0:return o=n.getWorkRoot(),t.n=1,st(o);case 1:return i=t.v,t.n=2,ct(o,e);case 2:return a=t.v,t.n=3,ut(o);case 3:c=t.v,n.setPackageConfig(c),n.setDoraConfig(at(Y((null==r?void 0:r.doraConfig)||{},a||{}),o)),n.setTsConfig(i);case 4:return t.a(2)}},t)}));return function(n,e,r){return t.apply(this,arguments)}}();function ft(t,n){return pt.apply(this,arguments)}function pt(){return(pt=l(w().m(function t(n,e){var r;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,V(n);case 1:return r=t.v,t.a(2,Q(r,e));case 2:return t.p=2,t.v,_.log("resolve ","resolveUserCdn","解析用户cdn配置失败"),t.a(2,{})}},t,null,[[0,2]])}))).apply(this,arguments)}var dt=["input","output","multiple"],ht=function(t){return t.dev="development",t.prod="production",t}({}),gt=h(function t(n){p(this,t),this.initOptions=n,g(this,"inOutMap",void 0),g(this,"input",void 0),g(this,"context",void 0),g(this,"build",void 0),g(this,"watch",void 0),g(this,"server",void 0)}),vt=function(){function t(){p(this,t),g(this,"headScripts",[]),g(this,"bodyScripts",[]),g(this,"headStyles",[]),g(this,"headTags",[]),g(this,"bodyTags",['<div id="main"></div>'])}return h(t,[{key:"addHeadScripts",value:function(t){var n;arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(this.headScripts=[]),(n=this.headScripts).push.apply(n,O(t))}},{key:"addBodyScripts",value:function(t){var n;arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(this.bodyScripts=[]),(n=this.bodyScripts).push.apply(n,O(t))}},{key:"addHeadStyles",value:function(t){var n;arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(this.headStyles=[]),(n=this.headStyles).push.apply(n,O(t))}},{key:"addHeadTags",value:function(t){var n;arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(this.headTags=[]),(n=this.headTags).push.apply(n,O(t))}},{key:"addBodyTags",value:function(t){var n;arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(this.bodyTags=t),(n=this.bodyTags).push.apply(n,O(t))}},{key:"copy",value:function(){var n=new t;return n.addHeadScripts(this.headScripts,!0),n.addBodyScripts(this.bodyScripts,!0),n.addHeadStyles(this.headStyles,!0),n}},{key:"generateHtmlTemplate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Document",n=this.headScripts.sort(function(t,n){return(t.order||0)-(n.order||0)}).map(function(t){var n=['src="'.concat(t.src,'"'),t.async?"async":"",t.defer?"defer":""].filter(Boolean).join(" ");return"<script ".concat(n,"><\/script>")}).join("\n"),e=this.bodyScripts.sort(function(t,n){return(t.order||0)-(n.order||0)}).map(function(t){var n=['src="'.concat(t.src,'"'),t.async?"async":"",t.defer?"defer":""].filter(Boolean).join(" ");return"<script ".concat(n,"><\/script>")}).join("\n"),r=this.headStyles.sort(function(t,n){return(t.order||0)-(n.order||0)}).map(function(t){var n=['href="'.concat(t.src,'"'),'rel="stylesheet"',t.async?"async":"",t.defer?"defer":""].filter(Boolean).join(" ");return"<link ".concat(n,">")}).join("\n"),o=this.headTags.map(function(t){return t}).join("\n"),i=this.bodyTags.map(function(t){return t}).join("\n");return'<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>'.concat(t,"</title>\n ").concat(o,"\n ").concat(r,"\n ").concat(n,"\n</head>\n<body>\n ").concat(i,"\n ").concat(e,"\n</body>\n</html>")}}])}(),yt=function(){return h(function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/";p(this,t),this.publicPath=n,g(this,"assetMap",{}),g(this,"dynamicHtml",new vt),g(this,"initAwaitList",[]),g(this,"assetList",[])},[{key:"updateAssetList",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.assetList=n?t:Array.from(new Set([].concat(O(this.assetList),O(t))))}},{key:"updateAssetMap",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.assetMap=n?t:b(b({},this.assetMap),t),this.initAwaitList.forEach(function(t){return t()}),this.initAwaitList=[]}},{key:"getAssetMap",value:function(){return this.assetMap}},{key:"getModuleAsset",value:function(t){return this.assetMap[t]||{name:t,scripts:[],styles:[],runtimeChunks:[]}}},{key:"getModuleHtml",value:(t=l(w().m(function t(n){var e,r,o=this;return w().w(function(t){for(;;)switch(t.n){case 0:if(0!==Object.keys(this.assetMap).length){t.n=1;break}return t.n=1,new Promise(function(t){o.initAwaitList.push(function(){t()})});case 1:if(e=this.assetMap[n]){t.n=2;break}throw new Error("Module ".concat(n," asset not found."));case 2:return(r=this.dynamicHtml.copy()).addBodyScripts(e.scripts.map(function(t){return{src:t,order:0}})),r.addHeadStyles(e.styles.map(function(t){return{src:t,order:0}})),t.a(2,r.generateHtmlTemplate())}},t,this)})),function(n){return t.apply(this,arguments)})}]);var t}(),mt=function(t){var n,e;return t.selfClosing?"<".concat(t.tagName," ").concat(null===(e=t.attrs)||void 0===e?void 0:e.map(function(t){return"".concat(t.name,'="').concat(t.value,'"')}).join(" ")," />"):"<".concat(t.tagName," ").concat(null===(n=t.attrs)||void 0===n?void 0:n.map(function(t){return"".concat(t.name,'="').concat(t.value,'"')}).join(" "),">").concat((t.children||[]).map(function(t){return"string"==typeof t?t:mt(t)}).join(""),"</").concat(t.tagName,">")},bt=function(t){var n=/<head[^>]*>([\s\S]*?)<\/head>/i.exec(t),e=/<body[^>]*>([\s\S]*?)<\/body>/i.exec(t),r=n?n[1]:"",o=e?e[1]:"";return{head:Ct(r),body:Ct(o)}},Ct=function(t){var n=[],e=[];if(!t)return n;for(var r=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),o=function(t){for(var n,e=[],r=/([^\s=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;n=r.exec(t);){var o,i,a=n[1],c=null!==(o=null!==(i=n[2])&&void 0!==i?i:n[3])&&void 0!==o?o:n[4];void 0===c?e.push({name:a,value:!0}):e.push({name:a,value:c})}return e},i=0,a=t.length;i<a;){if("<"!==t[i]){var c=t.indexOf("<",i),u=-1===c?a:c,s=t.slice(i,u).trim();if(s&&e.length){var l=e[e.length-1];l.children||(l.children=[]),l.children.push(s)}i=u}else{var f=t.indexOf(">",i+1);if(-1===f)break;var p=t.slice(i+1,f).trim();if(p.startsWith("!")||p.startsWith("?")||p.startsWith("--")){i=f+1;continue}if(p.startsWith("/")){p.slice(1).trim().split(/\s+/)[0].toLowerCase();if(e.length)e[e.length-1].tagName.toLowerCase(),e.pop();i=f+1;continue}var d=p.endsWith("/"),h=p.replace(/\/\s*$/,"").trim(),g=h.search(/\s/),v=(-1===g?h:h.slice(0,g)).toLowerCase(),y=-1===g?"":h.slice(g+1).trim(),m=d||r.has(v),b={tagName:v,attrs:o(y),selfClosing:m,children:[]};if(0===e.length)n.push(b);else{var C=e[e.length-1];C.children||(C.children=[]),C.children.push(b)}m||e.push(b),i=f+1}}return n},wt=function(){function t(n){var e,r;p(this,t),g(this,"head",[]),g(this,"body",[]),this.head=null!==(e=null==n?void 0:n.head)&&void 0!==e?e:[],this.body=null!==(r=null==n?void 0:n.body)&&void 0!==r?r:[]}return h(t,[{key:"addHead",value:function(t){return t?(this.head.push(t),this):this}},{key:"addHeads",value:function(t){var n;return t?((n=this.head).push.apply(n,O(t)),this):this}},{key:"addBody",value:function(t){return t?(this.body.push(t),this):this}},{key:"addBodys",value:function(t){var n;return t?((n=this.body).push.apply(n,O(t)),this):this}},{key:"parseHtmlByFile",value:function(n){var e=a.readFileSync(n,"utf-8"),r=t.parseHtml(e),o=r.head,i=r.body;return this.head=o,this.body=i,this}},{key:"generateHtml",value:function(){return t={head:this.head,body:this.body},n=t.head,e=t.body,"\n <html>\n <head>\n ".concat(n.map(function(t){return mt(t)}).join("\n"),"\n </head>\n <body>\n ").concat(e.map(function(t){return mt(t)}).join("\n"),"\n </body>\n </html>\n ");var t,n,e}},{key:"copy",value:function(){return new t({head:this.head.map(function(t){return b({},t)}),body:this.body.map(function(t){return b({},t)})})}}],[{key:"parseHtml",value:function(t){return bt(t)}}])}(),kt=function(){var t=l(w().m(function t(n,e){var r;return w().w(function(t){for(;;)switch(t.p=t.n){case 0:if(r={doraConfig:null,packageConfig:null,tsconfigConfig:null,cdnConfig:null},t.p=1,!1===(null==e?void 0:e.doraConfig)){t.n=3;break}return t.n=2,q(n);case 2:r.doraConfig=t.v;case 3:t.n=5;break;case 4:t.p=4,t.v;case 5:if(t.p=5,!1===(null==e?void 0:e.packageConfig)){t.n=7;break}return t.n=6,J(n);case 6:r.packageConfig=t.v;case 7:t.n=9;break;case 8:t.p=8,t.v;case 9:if(t.p=9,!1===(null==e?void 0:e.tsconfigConfig)){t.n=11;break}return t.n=10,G(n);case 10:r.tsconfigConfig=t.v;case 11:t.n=13;break;case 12:t.p=12,t.v;case 13:if(t.p=13,!1===(null==e?void 0:e.cdnConfig)){t.n=15;break}return t.n=14,V(n);case 14:r.cdnConfig=t.v;case 15:t.n=17;break;case 16:t.p=16,t.v;case 17:return t.a(2,r)}},t,null,[[13,16],[9,12],[5,8],[1,4]])}));return function(n,e){return t.apply(this,arguments)}}(),xt=function(){var n=l(w().m(function n(e,r){return w().w(function(n){for(;;)switch(n.n){case 0:e.setCdnConfig(r.cdnConfig),e.setDoraConfig(r.doraConfig),e.setTsConfig(r.tsConfig),e.setPackageConfig(r.packageConfig),e.setWorkRoot(r.workRootDir||t.getCwd()),e.setCmd(r.cmd||{});case 1:return n.a(2)}},n)}));return function(t,e){return n.apply(this,arguments)}}(),jt=function(){var t=l(w().m(function t(n){var e;return w().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,it(n);case 1:if(!(e=t.v)){t.n=2;break}return t.a(2,a.readFileSync(e,"utf-8"));case 2:return t.a(2,'\n<html lang="zh-CN">\n <head>\n <meta charset="UTF-8" />\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>dora</title>\n </head>\n <body>\n <div id="main">welcome use dora !!</div>\n </body>\n</html>\n')}},t)}));return function(n){return t.apply(this,arguments)}}(),Ot=function(){var t=l(w().m(function t(n,e){var r,o,i,a;return w().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,Z(n.doraConfig,e);case 1:return r=t.v,o=n.packageConfig||{},i=n.tsconfigConfig||{},t.n=2,Q(n.cdnConfig,e);case 2:return a=t.v,t.a(2,{doraConfig:r,packageConfig:o,tsConfig:i,cdnConfig:a})}},t)}));return function(n,e){return t.apply(this,arguments)}}(),St=["multiple"],Pt=function(){function t(n){var e;return p(this,t),(e=f(this,t)).configCtx=n,e}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),n&&x(t,n)}(t,wt),h(t,[{key:"init",value:(n=l(w().m(function t(){var n,e,r,o;return w().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,jt(this.configCtx.getWorkRoot());case 1:return n=t.v,e=wt.parseHtml(n),r=e.head,o=e.body,this.addHeads(r),this.addBodys(o),t.a(2,this)}},t,this)})),function(){return n.apply(this,arguments)})},{key:"addConfigCdn",value:function(){var t,n,e,r,o=this.configCtx.getCdnConfig();return this.addHeads(null===(t=o.headAfterScript)||void 0===t?void 0:t.map(function(t){return{tagName:"script",attrs:[{name:"src",value:t}]}})),this.addHeads(null===(n=o.headAfterStyle)||void 0===n?void 0:n.map(function(t){return{tagName:"link",attrs:[{name:"href",value:t},{name:"rel",value:"stylesheet"}]}})),this.addBodys(null===(e=o.bodyAfterScript)||void 0===e?void 0:e.map(function(t){return{tagName:"script",attrs:[{name:"src",value:t}]}})),this.addBodys(null===(r=o.bodyBeforeScript)||void 0===r?void 0:r.map(function(t){return{tagName:"script",attrs:[{name:"src",value:t}]}})),this}},{key:"writeToFile",value:function(t){return a.existsSync(t)?a.appendFileSync(t,this.generateHtml(),{}):a.writeFileSync(t,this.generateHtml(),{}),this}},{key:"addBodyScripts",value:function(t){return this.addBodys(t.map(function(t){return{tagName:"script",attrs:[{name:"src",value:t}]}})),this}},{key:"addHeadStyles",value:function(t){return this.addHeads(t.map(function(t){return{tagName:"link",attrs:[{name:"href",value:t},{name:"rel",value:"stylesheet"}]}})),this}},{key:"copy",value:function(){var n=new t(this.configCtx);return n.addHeads(this.head),n.addBodys(this.body),n}}]);var n}(),Dt=function(){var n=l(w().m(function n(){var e,r,i,a=arguments;return w().w(function(n){for(;;)switch(n.n){case 0:return e=a.length>0&&void 0!==a[0]?a[0]:t.getCwd(),r=o.join(e,"tsconfig.json"),n.n=1,t.isValidFilePath(r);case 1:if(n.v){n.n=3;break}return i={$schema:"https://json.schemastore.org/tsconfig",compilerOptions:{target:"esnext",moduleResolution:"node",module:"esnext",noImplicitThis:!1,noImplicitAny:!1,noUnusedLocals:!1,noImplicitReturns:!0,noUnusedParameters:!1,useUnknownInCatchVariables:!1,allowSyntheticDefaultImports:!0,esModuleInterop:!0,emitDecoratorMetadata:!0,experimentalDecorators:!0,preserveConstEnums:!0,strictNullChecks:!0,strictFunctionTypes:!0,strictPropertyInitialization:!0,resolveJsonModule:!0,skipLibCheck:!0,alwaysStrict:!0,sourceMap:!1,paths:{"@/*":["./src/*"]}},exclude:["lib/**"],include:["**/*.ts","**/*.json"]},n.n=2,c.writeFile(r,JSON.stringify(i,null,2));case 2:_.info("init","success","自动注入 tsconfig.json");case 3:return n.a(2)}},n)}));return function(){return n.apply(this,arguments)}}();exports.picocolors=n,exports.CompilerBase=gt,exports.ConfigCtx=D,exports.DynamicHtml=vt,exports.EnvEnum=ht,exports.GenerateConfigHtml=Pt,exports.HtmlAssetManager=yt,exports.HtmlManage=wt,exports.cLog=_,exports.cLogDebugger=H,exports.cLogError=N,exports.cLogMessage=M,exports.cLogSuccess=R,exports.cLogTime=U,exports.cLogTimeEnd=I,exports.cLogWarn=B,exports.clearMw=function(){return function(t){return function(n){return l(w().m(function e(){return w().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,z(t);case 1:return e.a(2,n())}},e)}))}}},exports.collectBaseConfigMw=function(t,n){return function(e){return function(r){return function(){return e.setWorkRoot(t),e.setCmd(n),r()}}}},exports.collectCdnConfigMw=function(t){return function(n){return function(e){return l(w().m(function r(){var o;return w().w(function(r){for(;;)switch(r.n){case 0:return r.n=1,ft(n.getWorkRoot(),t);case 1:return o=r.v,n.setCdnConfig(o||{bodyAfterScript:[],headAfterScript:[],headAfterStyle:[],bodyBeforeScript:[]}),r.a(2,e())}},r)}))}}},exports.collectConfig=lt,exports.collectConfigs=kt,exports.collectDoraConfigMw=function(t){return function(n){return function(e){return l(w().m(function r(){var o;return w().w(function(r){for(;;)switch(r.n){case 0:return r.n=1,ct(n.getWorkRoot(),t);case 1:return o=r.v,n.setDoraConfig(o||{}),r.a(2,e())}},r)}))}}},exports.collectPackageJsonMw=function(){return function(t){return function(n){return l(w().m(function e(){var r;return w().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,J(t.getWorkRoot());case 1:return r=e.v,t.setPackageConfig(r||{}),e.a(2,n())}},e)}))}}},exports.collectTsconfigJsonMw=function(){return function(t){return function(n){return l(w().m(function e(){var r;return w().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,G(t.getWorkRoot());case 1:return r=e.v,t.setTsConfig(r||{}),e.a(2,n())}},e)}))}}},exports.configCtxCollect=xt,exports.configCtxWorkflow=function(t){var n=[];return{use:function(t){return n.push(t),this},getResult:function(){return l(w().m(function e(){return w().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,i.getOnionFun(t,n)(r.noop)();case 1:return e.a(2,t)}},e)}))()}}},exports.createDependFilter=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"exclude",e=t.dependencies,o=t.peerDependencies,i=t.devDependencies,a=t.externals,c=t.internals,u=t.compare,s={},l={};Object.keys(e||{}).forEach(function(t){s[t]=t}),Object.keys(o||{}).forEach(function(t){s[t]=t}),Object.keys(i||{}).forEach(function(t){s[t]=t}),null==a||a.forEach(function(t){r.isString(t)?s[t]=t:r.isPlainObject(t)&&Object.keys(t).forEach(function(n){s[n]=t[n]})}),null==c||c.forEach(function(t){r.isString(t)&&(l[t]=t)});var f="include"===n;return function(t){var n=!1,e=Object.keys(s).find(function(n){return r.isFunction(u)?u(t,n):t.startsWith(n)}),o=Object.keys(l).find(function(n){return r.isFunction(u)?u(t,n):t.startsWith(n)});return f?o?n=!1:e&&(n=s[e]):e?n=s[e]:o&&(n=!1),n}},exports.createEnvParams=function(n){var e=n.workRootDir||"./";return o.isAbsolute(n.workRootDir)||(e=o.join(t.getCwd(),e)),b(b({},n),{},{workRootDir:e})},exports.createOutputList=function(n){var e=n.input,o=n.output,i=n.formatList,a=n.format,c=o.path,u=o.file,s=[];return a?s.push({input:e,format:a,outputFile:u||t.getFilename(e)||"index.js",outputPath:c||"dist"}):r.isArray(i)?i.forEach(function(n){s.push({input:e,format:n,outputFile:u||t.getFilename(e)||"index.js",outputPath:c||"dist"})}):s.push({input:e,format:"iife",outputFile:u||t.getFilename(e)||"index.js",outputPath:c||"dist"}),s},exports.deepMergeObject=K,exports.findInput=rt,exports.findInputHtml=it,exports.getDefaultHtml=jt,exports.getDependencies=function(t){return b(b(b({},t.dependencies),t.peerDependencies),t.devDependencies)},exports.getDoracliConfig=q,exports.getPackageJson=J,exports.getTsPathAlias=function(t){var n=((null==t?void 0:t.compilerOptions)||{}).paths;if(!n)return{};var e={};return Object.entries(n).forEach(function(t){var n=j(t,2),r=n[0],i=n[1],a=r.replace(/\/\*$/,"");if(null!=i&&i.length&&!e[a]){var c=i[0].replace(/\/\*$/,"");e[a]=o.resolve(c)}}),e},exports.getTsconfigJson=G,exports.getUserCdn=V,exports.inputFileDirList=nt,exports.inputFileTypeList=et,exports.inputHtmlFileDirList=ot,exports.insertTsconfig=Dt,exports.mergeDoraCliConfig=Y,exports.mergeDoraCliConfigMutiple=X,exports.parseCdnConfig=Q,exports.parseDoracliConfig=Z,exports.parseHtml=bt,exports.parsetConfig=Ot,exports.resolveCdnConfig=ft,exports.resolveDoraConfig=ct,exports.resolvePackageJson=ut,exports.resolveTsconfigJson=st,exports.setLogLevel=function(t){A=t},exports.splitDoraCliConfig=function(t){var n=t.multiple,e=C(t,tt);return r.isArray(n)?0===n.length?[e]:1===n.length?[X(e,n[0])]:n.map(function(t){return X(e,t)}):[e]},exports.splitDoraConfig=function(t){var n=t.multiple,e=C(t,St);return r.isArray(n)?0===n.length?[e]:1===n.length?[X(n[0],e)]:n.map(function(t){return X(e,t)}):[e]},exports.wholeDoraConfig=at,exports.wholeDoraConfigMw=function(t){return function(n){return function(e){return function(){var o=Y(t,n.getDoraConfig()),i=o.alias,a=o.clear,c=o.copy,u=o.dts,s=o.lib,l=o.format,f=o.libList,p=o.name,d=o.type,h=o.externals,g=o.formatList,v=o.input,y=o.internals,m=o.minimize,b=o.multiple,C=o.output,w=o.rollupConfig,k=o.webpackConfig,x=o.esbuildConfig,j=o.rspackConfig,O=o.serviceConfig,S=o.dtsConfig;return n.setDoraConfig({multiple:!r.isUndefinedOrNull(b)&&b,name:p,type:d,format:l,formatList:g,lib:s,libList:f,alias:i||{},clear:!r.isUndefinedOrNull(a)&&a,copy:c||[],dts:r.isUndefinedOrNull(u)?{}:u,externals:h||[],input:v,internals:y||[],minimize:!r.isUndefinedOrNull(m)&&m,output:C,rollupConfig:w||{},webpackConfig:k||{},esbuildConfig:x||{},rspackConfig:j||{},serviceConfig:O||{},dtsConfig:S}),e()}}}},exports.wholeDoraInoutMw=function(){return function(n){return function(e){return function(){var r=n.getDoraConfig(),o=r.input,i=r.output,a=r.multiple,c=C(r,dt),u=n.getWorkRoot(),s=o,l=(null==i?void 0:i.path)||"./dist",f=null==i?void 0:i.file;return a||(t.isValidFilePathSync(s||"")||(s=rt(u)),s||_.error("init","not_found","找不到入口文件"),f=(null==i?void 0:i.file)||t.getFilename(s)),n.setDoraConfig(b(b({},c),{},{input:s,output:i||{path:l,file:f},multiple:a})),e()}}}};