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