@doracli/helper 0.0.2 → 0.0.4

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,10 +1,12 @@
1
- import { writeFile } from 'fs/promises';
2
- import { join, resolve } from 'path';
3
- import { getCwd, isValidFilePath, resolveCwd, lookupFile, isValidFilePathSync, getFilename } from '@dorabag/file-pro';
1
+ import { cleanTargets, isValidDir, resolveCwd, lookupFile, getCwd, isValidFilePathSync, getFilename, isValidFilePath } from '@dorabag/file-pro';
4
2
  import picocolors from 'picocolors';
5
3
  export { default as picocolors } from 'picocolors';
6
4
  import { loadConfigFuzzyExt, loadConfig } from '@dorabag/config-loader';
7
- import { isObject, isFunction, isArray, isUndefinedOrNull } from '@cclr/lang';
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';
8
10
 
9
11
  function _arrayLikeToArray(r, a) {
10
12
  (null == a || a > r.length) && (a = r.length);
@@ -14,6 +16,13 @@ function _arrayLikeToArray(r, a) {
14
16
  function _arrayWithHoles(r) {
15
17
  if (Array.isArray(r)) return r;
16
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
+ }
17
26
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
18
27
  try {
19
28
  var i = n[a](c),
@@ -39,6 +48,9 @@ function _asyncToGenerator(n) {
39
48
  });
40
49
  };
41
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
+ }
42
54
  function _classCallCheck(a, n) {
43
55
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
44
56
  }
@@ -49,7 +61,7 @@ function _defineProperties(e, r) {
49
61
  }
50
62
  }
51
63
  function _createClass(e, r, t) {
52
- return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
64
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
53
65
  writable: false
54
66
  }), e;
55
67
  }
@@ -61,6 +73,34 @@ function _defineProperty(e, r, t) {
61
73
  writable: true
62
74
  }) : e[r] = t, e;
63
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
+ }
64
104
  function _iterableToArrayLimit(r, l) {
65
105
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
66
106
  if (null != t) {
@@ -88,6 +128,9 @@ function _iterableToArrayLimit(r, l) {
88
128
  function _nonIterableRest() {
89
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.");
90
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
+ }
91
134
  function ownKeys(e, r) {
92
135
  var t = Object.keys(e);
93
136
  if (Object.getOwnPropertySymbols) {
@@ -129,6 +172,11 @@ function _objectWithoutPropertiesLoose(r, e) {
129
172
  }
130
173
  return t;
131
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
+ }
132
180
  function _regenerator() {
133
181
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
134
182
  var e,
@@ -237,9 +285,17 @@ function _regeneratorDefine(e, r, n, t) {
237
285
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
238
286
  }, _regeneratorDefine(e, r, n, t);
239
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
+ }
240
293
  function _slicedToArray(r, e) {
241
294
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
242
295
  }
296
+ function _toConsumableArray(r) {
297
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
298
+ }
243
299
  function _toPrimitive(t, r) {
244
300
  if ("object" != typeof t || !t) return t;
245
301
  var e = t[Symbol.toPrimitive];
@@ -347,25 +403,8 @@ var ConfigCtx = /*#__PURE__*/function () {
347
403
  }]);
348
404
  }();
349
405
 
350
- var EnvEnum = /*#__PURE__*/function (EnvEnum) {
351
- EnvEnum["dev"] = "development";
352
- EnvEnum["prod"] = "production";
353
- return EnvEnum;
354
- }({});
355
-
356
- var CompilerBase = /*#__PURE__*/_createClass(function CompilerBase(initOptions) {
357
- _classCallCheck(this, CompilerBase);
358
- this.initOptions = initOptions;
359
- _defineProperty(this, "inOutMap", void 0);
360
- _defineProperty(this, "input", void 0);
361
- _defineProperty(this, "context", void 0);
362
- _defineProperty(this, "build", void 0);
363
- _defineProperty(this, "watch", void 0);
364
- _defineProperty(this, "server", void 0);
365
- });
366
-
367
406
  var mainSlogan = '@doracli';
368
- var level = 0;
407
+ var level = 10;
369
408
 
370
409
  /**
371
410
  * @params 日志等级
@@ -475,70 +514,69 @@ var cLog = {
475
514
  timeEnd: cLogTimeEnd
476
515
  };
477
516
 
478
- /**
479
- * 在制定目录下插入 tsconfig.json 文件
480
- * @param cwd
481
- */
482
- var insertTsconfig = /*#__PURE__*/function () {
483
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
484
- var cwd,
485
- tsconfigPath,
486
- tsconfigContent,
487
- _args = arguments;
488
- return _regenerator().w(function (_context) {
489
- while (1) switch (_context.n) {
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) {
490
539
  case 0:
491
- cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : getCwd();
492
- tsconfigPath = join(cwd, 'tsconfig.json');
493
- _context.n = 1;
494
- return isValidFilePath(tsconfigPath);
495
- case 1:
496
- if (_context.v) {
497
- _context.n = 3;
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;
498
545
  break;
499
546
  }
500
- tsconfigContent = {
501
- $schema: 'https://json.schemastore.org/tsconfig',
502
- compilerOptions: {
503
- target: 'esnext',
504
- moduleResolution: 'node',
505
- module: 'esnext',
506
- noImplicitThis: false,
507
- noImplicitAny: false,
508
- noUnusedLocals: false,
509
- noImplicitReturns: true,
510
- noUnusedParameters: false,
511
- useUnknownInCatchVariables: false,
512
- allowSyntheticDefaultImports: true,
513
- esModuleInterop: true,
514
- emitDecoratorMetadata: true,
515
- experimentalDecorators: true,
516
- preserveConstEnums: true,
517
- strictNullChecks: true,
518
- strictFunctionTypes: true,
519
- strictPropertyInitialization: true,
520
- resolveJsonModule: true,
521
- skipLibCheck: true,
522
- alwaysStrict: true,
523
- sourceMap: false,
524
- paths: {
525
- '@/*': ['./src/*']
526
- }
527
- },
528
- exclude: ['lib/**'],
529
- include: ['**/*.ts', '**/*.json']
530
- };
531
- _context.n = 2;
532
- return writeFile(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
547
+ return _context2.a(2);
533
548
  case 2:
534
- cLog.info('init', 'success', '自动注入 tsconfig.json');
549
+ if (path) {
550
+ _context2.n = 3;
551
+ break;
552
+ }
553
+ return _context2.a(2);
535
554
  case 3:
536
- return _context.a(2);
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);
537
575
  }
538
- }, _callee);
576
+ }, _callee2, null, [[1, 7]]);
539
577
  }));
540
- return function insertTsconfig() {
541
- return _ref.apply(this, arguments);
578
+ return function clear(_x) {
579
+ return _ref2.apply(this, arguments);
542
580
  };
543
581
  }();
544
582
 
@@ -613,7 +651,7 @@ var getPackageJson = /*#__PURE__*/function () {
613
651
  _context.p = 3;
614
652
  _t = _context.v;
615
653
  cLog.error('file', 'fail', '引入 package.json 失败');
616
- console.error(_t);
654
+ cLog.debug('file', 'error', _t);
617
655
  case 4:
618
656
  return _context.a(2);
619
657
  }
@@ -641,7 +679,7 @@ var getTsconfigJson = /*#__PURE__*/function () {
641
679
  _context.p = 2;
642
680
  _t = _context.v;
643
681
  cLog.error('file', 'failed', '引入 tsconfig.json 失败');
644
- console.error(_t);
682
+ cLog.debug('file', 'error', _t);
645
683
  case 3:
646
684
  return _context.a(2);
647
685
  }
@@ -672,7 +710,7 @@ function _getUserCdn() {
672
710
  });
673
711
  case 1:
674
712
  json = _context.v;
675
- if (json) {
713
+ if (json !== null && json !== void 0 && json.default) {
676
714
  _context.n = 2;
677
715
  break;
678
716
  }
@@ -680,30 +718,22 @@ function _getUserCdn() {
680
718
  return _context.a(2, null);
681
719
  case 2:
682
720
  cLog.info('file', 'success', '引入 cdn 成功');
683
- return _context.a(2, json);
721
+ return _context.a(2, json.default);
684
722
  case 3:
685
723
  _context.p = 3;
686
724
  _t = _context.v;
687
725
  cLog.error('file', 'failed', '引入 cdn 失败');
688
- console.error(_t);
689
- return _context.a(2, Promise.reject(_t));
726
+ cLog.debug('file', 'failed', _t);
727
+ return _context.a(2, null);
690
728
  }
691
729
  }, _callee, null, [[0, 3]]);
692
730
  }));
693
731
  return _getUserCdn.apply(this, arguments);
694
732
  }
695
733
 
696
- var _excluded$2 = ["output"],
697
- _excluded2 = ["output"];
698
734
  var mergeDoraCliConfig = function mergeDoraCliConfig(target) {
699
735
  var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
700
- var targetOutput = target.output,
701
- targetRest = _objectWithoutProperties(target, _excluded$2);
702
- var sourceOutput = source.output,
703
- sourceRest = _objectWithoutProperties(source, _excluded2);
704
- return _objectSpread2(_objectSpread2(_objectSpread2({}, targetRest), sourceRest), {}, {
705
- output: _objectSpread2(_objectSpread2({}, targetOutput), sourceOutput)
706
- });
736
+ return _deepMergeObject(target, source);
707
737
  };
708
738
 
709
739
  /**
@@ -719,6 +749,19 @@ var mergeDoraCliConfigMutiple = function mergeDoraCliConfigMutiple() {
719
749
  return mergeDoraCliConfig(prev, curr);
720
750
  });
721
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
+ };
722
765
 
723
766
  /**
724
767
  * 获取cdn文件配置
@@ -786,7 +829,7 @@ var parseDoracliConfig = /*#__PURE__*/function () {
786
829
  };
787
830
  }();
788
831
 
789
- var _excluded$1 = ["multiple"];
832
+ var _excluded$2 = ["multiple"];
790
833
 
791
834
  /**
792
835
  * 配置项多任务拆分
@@ -795,7 +838,7 @@ var _excluded$1 = ["multiple"];
795
838
  */
796
839
  var splitDoraCliConfig = function splitDoraCliConfig(config) {
797
840
  var multiple = config.multiple,
798
- neatConfig = _objectWithoutProperties(config, _excluded$1);
841
+ neatConfig = _objectWithoutProperties(config, _excluded$2);
799
842
  if (!isArray(multiple)) return [neatConfig];
800
843
  if (multiple.length === 0) return [neatConfig];
801
844
  if (multiple.length === 1) return [mergeDoraCliConfigMutiple(neatConfig, multiple[0])];
@@ -815,6 +858,10 @@ var findInput = function findInput(workRootDir) {
815
858
  }, []);
816
859
  return lookupFile(pList, workRootDir);
817
860
  };
861
+ var inputHtmlFileDirList = ['index.html', 'public/index.html'];
862
+ var findInputHtml = function findInputHtml(workRootDir) {
863
+ return lookupFile(inputHtmlFileDirList, workRootDir);
864
+ };
818
865
 
819
866
  /**
820
867
  * 获取tsconfig.json里的paths,作为项目路径别名
@@ -845,7 +892,11 @@ var getTsPathAlias = function getTsPathAlias(tsConfig) {
845
892
 
846
893
  var wholeDoraConfig = function wholeDoraConfig(config) {
847
894
  var workRootDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getCwd();
848
- var alias = config.alias,
895
+ var type = config.type,
896
+ name = config.name,
897
+ lib = config.lib,
898
+ libList = config.libList,
899
+ alias = config.alias,
849
900
  clear = config.clear,
850
901
  copy = config.copy,
851
902
  dts = config.dts,
@@ -861,11 +912,12 @@ var wholeDoraConfig = function wholeDoraConfig(config) {
861
912
  esbuildConfig = config.esbuildConfig,
862
913
  rspackConfig = config.rspackConfig;
863
914
  config.dtsConfig;
864
- config.format;
865
- var serviceConfig = config.serviceConfig;
915
+ var format = config.format,
916
+ serviceConfig = config.serviceConfig;
866
917
  var targetInput = input;
867
918
  var outPath = (output === null || output === void 0 ? void 0 : output.path) || './dist';
868
919
  var outFile = output === null || output === void 0 ? void 0 : output.file;
920
+ var newLibList = [];
869
921
  if (!multiple) {
870
922
  if (!isValidFilePathSync(targetInput || '')) {
871
923
  targetInput = findInput(workRootDir);
@@ -875,14 +927,32 @@ var wholeDoraConfig = function wholeDoraConfig(config) {
875
927
  }
876
928
  outFile = (output === null || output === void 0 ? void 0 : output.file) || getFilename(targetInput);
877
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
+ }
878
945
  return {
879
946
  multiple: isUndefinedOrNull(multiple) ? false : multiple,
947
+ type: type,
948
+ name: name,
880
949
  alias: alias || {},
881
950
  clear: isUndefinedOrNull(clear) ? false : clear,
882
951
  copy: copy || [],
883
952
  dts: isUndefinedOrNull(dts) ? {} : dts,
884
953
  externals: externals || [],
885
954
  formatList: formatList || ['cjs'],
955
+ libList: newLibList,
886
956
  input: input,
887
957
  internals: internals || [],
888
958
  minimize: isUndefinedOrNull(minimize) ? false : minimize,
@@ -1046,6 +1116,669 @@ function _resolveCdnConfig() {
1046
1116
  return _resolveCdnConfig.apply(this, arguments);
1047
1117
  }
1048
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
+
1049
1782
  var collectConfigs = /*#__PURE__*/function () {
1050
1783
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workDir, need) {
1051
1784
  var results;
@@ -1152,9 +1885,20 @@ var configCtxCollect = /*#__PURE__*/function () {
1152
1885
  };
1153
1886
  }();
1154
1887
 
1155
- // 全局上下文变量
1888
+ /**
1889
+ * 创建环境参数
1890
+ * @description 会自动处理出绝对路径的 workRootDir
1891
+ * @param params 上下文变量
1892
+ * @returns
1893
+ */
1156
1894
  var createEnvParams = function createEnvParams(params) {
1157
- return 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
+ });
1158
1902
  };
1159
1903
 
1160
1904
  var createOutputList = function createOutputList(config) {
@@ -1192,6 +1936,109 @@ var createOutputList = function createOutputList(config) {
1192
1936
  return outputList;
1193
1937
  };
1194
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
+
1195
2042
  var parsetConfig = /*#__PURE__*/function () {
1196
2043
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config, mode) {
1197
2044
  var _t, _t2, _t3, _t4;
@@ -1234,4 +2081,208 @@ var splitDoraConfig = function splitDoraConfig(config) {
1234
2081
  });
1235
2082
  };
1236
2083
 
1237
- export { CompilerBase, ConfigCtx, EnvEnum, cLog, cLogDebugger, cLogError, cLogMessage, cLogSuccess, cLogTime, cLogTimeEnd, cLogWarn, collectConfig, collectConfigs, configCtxCollect, createEnvParams, createOutputList, findInput, getDependencies, getDoracliConfig, getPackageJson, getTsPathAlias, getTsconfigJson, getUserCdn, inputFileDirList, inputFileTypeList, insertTsconfig, mergeDoraCliConfig, mergeDoraCliConfigMutiple, parseCdnConfig, parseDoracliConfig, parsetConfig, resolveCdnConfig, resolveDoraConfig, resolvePackageJson, resolveTsconfigJson, setLogLevel, splitDoraCliConfig, splitDoraConfig, wholeDoraConfig };
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 };