@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/cjs/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var promises = require('fs/promises');
4
- var path = require('path');
5
3
  var filePro = require('@dorabag/file-pro');
6
4
  var picocolors = require('picocolors');
7
5
  var configLoader = require('@dorabag/config-loader');
8
6
  var lang = require('@cclr/lang');
7
+ var path = require('path');
8
+ var utils = require('@cclr/utils');
9
+ var fs = require('fs');
10
+ var promises = require('fs/promises');
9
11
 
10
12
  function _arrayLikeToArray(r, a) {
11
13
  (null == a || a > r.length) && (a = r.length);
@@ -15,6 +17,13 @@ function _arrayLikeToArray(r, a) {
15
17
  function _arrayWithHoles(r) {
16
18
  if (Array.isArray(r)) return r;
17
19
  }
20
+ function _arrayWithoutHoles(r) {
21
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
22
+ }
23
+ function _assertThisInitialized(e) {
24
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
25
+ return e;
26
+ }
18
27
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
19
28
  try {
20
29
  var i = n[a](c),
@@ -40,6 +49,9 @@ function _asyncToGenerator(n) {
40
49
  });
41
50
  };
42
51
  }
52
+ function _callSuper(t, o, e) {
53
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
54
+ }
43
55
  function _classCallCheck(a, n) {
44
56
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
45
57
  }
@@ -50,7 +62,7 @@ function _defineProperties(e, r) {
50
62
  }
51
63
  }
52
64
  function _createClass(e, r, t) {
53
- return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
65
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
54
66
  writable: false
55
67
  }), e;
56
68
  }
@@ -62,6 +74,34 @@ function _defineProperty(e, r, t) {
62
74
  writable: true
63
75
  }) : e[r] = t, e;
64
76
  }
77
+ function _getPrototypeOf(t) {
78
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
79
+ return t.__proto__ || Object.getPrototypeOf(t);
80
+ }, _getPrototypeOf(t);
81
+ }
82
+ function _inherits(t, e) {
83
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
84
+ t.prototype = Object.create(e && e.prototype, {
85
+ constructor: {
86
+ value: t,
87
+ writable: true,
88
+ configurable: true
89
+ }
90
+ }), Object.defineProperty(t, "prototype", {
91
+ writable: false
92
+ }), e && _setPrototypeOf(t, e);
93
+ }
94
+ function _isNativeReflectConstruct() {
95
+ try {
96
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
97
+ } catch (t) {}
98
+ return (_isNativeReflectConstruct = function () {
99
+ return !!t;
100
+ })();
101
+ }
102
+ function _iterableToArray(r) {
103
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
104
+ }
65
105
  function _iterableToArrayLimit(r, l) {
66
106
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
67
107
  if (null != t) {
@@ -89,6 +129,9 @@ function _iterableToArrayLimit(r, l) {
89
129
  function _nonIterableRest() {
90
130
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
91
131
  }
132
+ function _nonIterableSpread() {
133
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
134
+ }
92
135
  function ownKeys(e, r) {
93
136
  var t = Object.keys(e);
94
137
  if (Object.getOwnPropertySymbols) {
@@ -130,6 +173,11 @@ function _objectWithoutPropertiesLoose(r, e) {
130
173
  }
131
174
  return t;
132
175
  }
176
+ function _possibleConstructorReturn(t, e) {
177
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
178
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
179
+ return _assertThisInitialized(t);
180
+ }
133
181
  function _regenerator() {
134
182
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
135
183
  var e,
@@ -238,9 +286,17 @@ function _regeneratorDefine(e, r, n, t) {
238
286
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
239
287
  }, _regeneratorDefine(e, r, n, t);
240
288
  }
289
+ function _setPrototypeOf(t, e) {
290
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
291
+ return t.__proto__ = e, t;
292
+ }, _setPrototypeOf(t, e);
293
+ }
241
294
  function _slicedToArray(r, e) {
242
295
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
243
296
  }
297
+ function _toConsumableArray(r) {
298
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
299
+ }
244
300
  function _toPrimitive(t, r) {
245
301
  if ("object" != typeof t || !t) return t;
246
302
  var e = t[Symbol.toPrimitive];
@@ -348,25 +404,8 @@ var ConfigCtx = /*#__PURE__*/function () {
348
404
  }]);
349
405
  }();
350
406
 
351
- var EnvEnum = /*#__PURE__*/function (EnvEnum) {
352
- EnvEnum["dev"] = "development";
353
- EnvEnum["prod"] = "production";
354
- return EnvEnum;
355
- }({});
356
-
357
- var CompilerBase = /*#__PURE__*/_createClass(function CompilerBase(initOptions) {
358
- _classCallCheck(this, CompilerBase);
359
- this.initOptions = initOptions;
360
- _defineProperty(this, "inOutMap", void 0);
361
- _defineProperty(this, "input", void 0);
362
- _defineProperty(this, "context", void 0);
363
- _defineProperty(this, "build", void 0);
364
- _defineProperty(this, "watch", void 0);
365
- _defineProperty(this, "server", void 0);
366
- });
367
-
368
407
  var mainSlogan = '@doracli';
369
- var level = 0;
408
+ var level = 10;
370
409
 
371
410
  /**
372
411
  * @params 日志等级
@@ -476,70 +515,69 @@ var cLog = {
476
515
  timeEnd: cLogTimeEnd
477
516
  };
478
517
 
479
- /**
480
- * 在制定目录下插入 tsconfig.json 文件
481
- * @param cwd
482
- */
483
- var insertTsconfig = /*#__PURE__*/function () {
484
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
485
- var cwd,
486
- tsconfigPath,
487
- tsconfigContent,
488
- _args = arguments;
489
- return _regenerator().w(function (_context) {
490
- while (1) switch (_context.n) {
518
+ var clearMw = function clearMw() {
519
+ return function (ctx) {
520
+ return function (next) {
521
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
522
+ return _regenerator().w(function (_context) {
523
+ while (1) switch (_context.n) {
524
+ case 0:
525
+ _context.n = 1;
526
+ return clear(ctx);
527
+ case 1:
528
+ return _context.a(2, next());
529
+ }
530
+ }, _callee);
531
+ }));
532
+ };
533
+ };
534
+ };
535
+ var clear = /*#__PURE__*/function () {
536
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(ctx) {
537
+ var _ctx$getDoraConfig, clear, output, _ref3, path;
538
+ return _regenerator().w(function (_context2) {
539
+ while (1) switch (_context2.p = _context2.n) {
491
540
  case 0:
492
- cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : filePro.getCwd();
493
- tsconfigPath = path.join(cwd, 'tsconfig.json');
494
- _context.n = 1;
495
- return filePro.isValidFilePath(tsconfigPath);
496
- case 1:
497
- if (_context.v) {
498
- _context.n = 3;
541
+ _ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
542
+ _ref3 = output || {}, path = _ref3.path;
543
+ _context2.p = 1;
544
+ if (clear) {
545
+ _context2.n = 2;
499
546
  break;
500
547
  }
501
- tsconfigContent = {
502
- $schema: 'https://json.schemastore.org/tsconfig',
503
- compilerOptions: {
504
- target: 'esnext',
505
- moduleResolution: 'node',
506
- module: 'esnext',
507
- noImplicitThis: false,
508
- noImplicitAny: false,
509
- noUnusedLocals: false,
510
- noImplicitReturns: true,
511
- noUnusedParameters: false,
512
- useUnknownInCatchVariables: false,
513
- allowSyntheticDefaultImports: true,
514
- esModuleInterop: true,
515
- emitDecoratorMetadata: true,
516
- experimentalDecorators: true,
517
- preserveConstEnums: true,
518
- strictNullChecks: true,
519
- strictFunctionTypes: true,
520
- strictPropertyInitialization: true,
521
- resolveJsonModule: true,
522
- skipLibCheck: true,
523
- alwaysStrict: true,
524
- sourceMap: false,
525
- paths: {
526
- '@/*': ['./src/*']
527
- }
528
- },
529
- exclude: ['lib/**'],
530
- include: ['**/*.ts', '**/*.json']
531
- };
532
- _context.n = 2;
533
- return promises.writeFile(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
548
+ return _context2.a(2);
534
549
  case 2:
535
- cLog.info('init', 'success', '自动注入 tsconfig.json');
550
+ if (path) {
551
+ _context2.n = 3;
552
+ break;
553
+ }
554
+ return _context2.a(2);
536
555
  case 3:
537
- return _context.a(2);
556
+ _context2.n = 4;
557
+ return filePro.isValidDir(path);
558
+ case 4:
559
+ if (_context2.v) {
560
+ _context2.n = 5;
561
+ break;
562
+ }
563
+ return _context2.a(2);
564
+ case 5:
565
+ _context2.n = 6;
566
+ return filePro.cleanTargets(path);
567
+ case 6:
568
+ _context2.n = 8;
569
+ break;
570
+ case 7:
571
+ _context2.p = 7;
572
+ _context2.v;
573
+ cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
574
+ case 8:
575
+ return _context2.a(2);
538
576
  }
539
- }, _callee);
577
+ }, _callee2, null, [[1, 7]]);
540
578
  }));
541
- return function insertTsconfig() {
542
- return _ref.apply(this, arguments);
579
+ return function clear(_x) {
580
+ return _ref2.apply(this, arguments);
543
581
  };
544
582
  }();
545
583
 
@@ -614,7 +652,7 @@ var getPackageJson = /*#__PURE__*/function () {
614
652
  _context.p = 3;
615
653
  _t = _context.v;
616
654
  cLog.error('file', 'fail', '引入 package.json 失败');
617
- console.error(_t);
655
+ cLog.debug('file', 'error', _t);
618
656
  case 4:
619
657
  return _context.a(2);
620
658
  }
@@ -642,7 +680,7 @@ var getTsconfigJson = /*#__PURE__*/function () {
642
680
  _context.p = 2;
643
681
  _t = _context.v;
644
682
  cLog.error('file', 'failed', '引入 tsconfig.json 失败');
645
- console.error(_t);
683
+ cLog.debug('file', 'error', _t);
646
684
  case 3:
647
685
  return _context.a(2);
648
686
  }
@@ -673,7 +711,7 @@ function _getUserCdn() {
673
711
  });
674
712
  case 1:
675
713
  json = _context.v;
676
- if (json) {
714
+ if (json !== null && json !== void 0 && json.default) {
677
715
  _context.n = 2;
678
716
  break;
679
717
  }
@@ -681,30 +719,22 @@ function _getUserCdn() {
681
719
  return _context.a(2, null);
682
720
  case 2:
683
721
  cLog.info('file', 'success', '引入 cdn 成功');
684
- return _context.a(2, json);
722
+ return _context.a(2, json.default);
685
723
  case 3:
686
724
  _context.p = 3;
687
725
  _t = _context.v;
688
726
  cLog.error('file', 'failed', '引入 cdn 失败');
689
- console.error(_t);
690
- return _context.a(2, Promise.reject(_t));
727
+ cLog.debug('file', 'failed', _t);
728
+ return _context.a(2, null);
691
729
  }
692
730
  }, _callee, null, [[0, 3]]);
693
731
  }));
694
732
  return _getUserCdn.apply(this, arguments);
695
733
  }
696
734
 
697
- var _excluded$2 = ["output"],
698
- _excluded2 = ["output"];
699
735
  var mergeDoraCliConfig = function mergeDoraCliConfig(target) {
700
736
  var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
701
- var targetOutput = target.output,
702
- targetRest = _objectWithoutProperties(target, _excluded$2);
703
- var sourceOutput = source.output,
704
- sourceRest = _objectWithoutProperties(source, _excluded2);
705
- return _objectSpread2(_objectSpread2(_objectSpread2({}, targetRest), sourceRest), {}, {
706
- output: _objectSpread2(_objectSpread2({}, targetOutput), sourceOutput)
707
- });
737
+ return _deepMergeObject(target, source);
708
738
  };
709
739
 
710
740
  /**
@@ -720,6 +750,19 @@ var mergeDoraCliConfigMutiple = function mergeDoraCliConfigMutiple() {
720
750
  return mergeDoraCliConfig(prev, curr);
721
751
  });
722
752
  };
753
+ var _deepMergeObject = function deepMergeObject(target, source) {
754
+ if (!source) return target;
755
+ if (!target) return source;
756
+ var result = _objectSpread2({}, target);
757
+ for (var key in source) {
758
+ if (lang.isObject(source[key])) {
759
+ result[key] = _deepMergeObject(target[key], source[key]);
760
+ } else {
761
+ result[key] = source[key];
762
+ }
763
+ }
764
+ return result;
765
+ };
723
766
 
724
767
  /**
725
768
  * 获取cdn文件配置
@@ -787,7 +830,7 @@ var parseDoracliConfig = /*#__PURE__*/function () {
787
830
  };
788
831
  }();
789
832
 
790
- var _excluded$1 = ["multiple"];
833
+ var _excluded$2 = ["multiple"];
791
834
 
792
835
  /**
793
836
  * 配置项多任务拆分
@@ -796,7 +839,7 @@ var _excluded$1 = ["multiple"];
796
839
  */
797
840
  var splitDoraCliConfig = function splitDoraCliConfig(config) {
798
841
  var multiple = config.multiple,
799
- neatConfig = _objectWithoutProperties(config, _excluded$1);
842
+ neatConfig = _objectWithoutProperties(config, _excluded$2);
800
843
  if (!lang.isArray(multiple)) return [neatConfig];
801
844
  if (multiple.length === 0) return [neatConfig];
802
845
  if (multiple.length === 1) return [mergeDoraCliConfigMutiple(neatConfig, multiple[0])];
@@ -816,6 +859,10 @@ var findInput = function findInput(workRootDir) {
816
859
  }, []);
817
860
  return filePro.lookupFile(pList, workRootDir);
818
861
  };
862
+ var inputHtmlFileDirList = ['index.html', 'public/index.html'];
863
+ var findInputHtml = function findInputHtml(workRootDir) {
864
+ return filePro.lookupFile(inputHtmlFileDirList, workRootDir);
865
+ };
819
866
 
820
867
  /**
821
868
  * 获取tsconfig.json里的paths,作为项目路径别名
@@ -846,7 +893,11 @@ var getTsPathAlias = function getTsPathAlias(tsConfig) {
846
893
 
847
894
  var wholeDoraConfig = function wholeDoraConfig(config) {
848
895
  var workRootDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : filePro.getCwd();
849
- var alias = config.alias,
896
+ var type = config.type,
897
+ name = config.name,
898
+ lib = config.lib,
899
+ libList = config.libList,
900
+ alias = config.alias,
850
901
  clear = config.clear,
851
902
  copy = config.copy,
852
903
  dts = config.dts,
@@ -862,11 +913,12 @@ var wholeDoraConfig = function wholeDoraConfig(config) {
862
913
  esbuildConfig = config.esbuildConfig,
863
914
  rspackConfig = config.rspackConfig;
864
915
  config.dtsConfig;
865
- config.format;
866
- var serviceConfig = config.serviceConfig;
916
+ var format = config.format,
917
+ serviceConfig = config.serviceConfig;
867
918
  var targetInput = input;
868
919
  var outPath = (output === null || output === void 0 ? void 0 : output.path) || './dist';
869
920
  var outFile = output === null || output === void 0 ? void 0 : output.file;
921
+ var newLibList = [];
870
922
  if (!multiple) {
871
923
  if (!filePro.isValidFilePathSync(targetInput || '')) {
872
924
  targetInput = findInput(workRootDir);
@@ -876,14 +928,32 @@ var wholeDoraConfig = function wholeDoraConfig(config) {
876
928
  }
877
929
  outFile = (output === null || output === void 0 ? void 0 : output.file) || filePro.getFilename(targetInput);
878
930
  }
931
+ if (!libList) {
932
+ if (lib) {
933
+ newLibList = [lib];
934
+ } else if (formatList !== null && formatList !== void 0 && formatList.length) {
935
+ newLibList = formatList.map(function (fmt) {
936
+ return {
937
+ format: fmt
938
+ };
939
+ });
940
+ } else {
941
+ newLibList = [{
942
+ format: format || 'cjs'
943
+ }];
944
+ }
945
+ }
879
946
  return {
880
947
  multiple: lang.isUndefinedOrNull(multiple) ? false : multiple,
948
+ type: type,
949
+ name: name,
881
950
  alias: alias || {},
882
951
  clear: lang.isUndefinedOrNull(clear) ? false : clear,
883
952
  copy: copy || [],
884
953
  dts: lang.isUndefinedOrNull(dts) ? {} : dts,
885
954
  externals: externals || [],
886
955
  formatList: formatList || ['cjs'],
956
+ libList: newLibList,
887
957
  input: input,
888
958
  internals: internals || [],
889
959
  minimize: lang.isUndefinedOrNull(minimize) ? false : minimize,
@@ -1047,6 +1117,669 @@ function _resolveCdnConfig() {
1047
1117
  return _resolveCdnConfig.apply(this, arguments);
1048
1118
  }
1049
1119
 
1120
+ var collectPackageJsonMw = function collectPackageJsonMw() {
1121
+ return function (ctx) {
1122
+ return function (next) {
1123
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1124
+ var json;
1125
+ return _regenerator().w(function (_context) {
1126
+ while (1) switch (_context.n) {
1127
+ case 0:
1128
+ _context.n = 1;
1129
+ return getPackageJson(ctx.getWorkRoot());
1130
+ case 1:
1131
+ json = _context.v;
1132
+ ctx.setPackageConfig(json || {});
1133
+ return _context.a(2, next());
1134
+ }
1135
+ }, _callee);
1136
+ }));
1137
+ };
1138
+ };
1139
+ };
1140
+ var collectTsconfigJsonMw = function collectTsconfigJsonMw() {
1141
+ return function (ctx) {
1142
+ return function (next) {
1143
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1144
+ var json;
1145
+ return _regenerator().w(function (_context2) {
1146
+ while (1) switch (_context2.n) {
1147
+ case 0:
1148
+ _context2.n = 1;
1149
+ return getTsconfigJson(ctx.getWorkRoot());
1150
+ case 1:
1151
+ json = _context2.v;
1152
+ ctx.setTsConfig(json || {});
1153
+ return _context2.a(2, next());
1154
+ }
1155
+ }, _callee2);
1156
+ }));
1157
+ };
1158
+ };
1159
+ };
1160
+ var collectCdnConfigMw = function collectCdnConfigMw(mode) {
1161
+ return function (ctx) {
1162
+ return function (next) {
1163
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
1164
+ var json;
1165
+ return _regenerator().w(function (_context3) {
1166
+ while (1) switch (_context3.n) {
1167
+ case 0:
1168
+ _context3.n = 1;
1169
+ return resolveCdnConfig(ctx.getWorkRoot(), mode);
1170
+ case 1:
1171
+ json = _context3.v;
1172
+ ctx.setCdnConfig(json || {
1173
+ bodyAfterScript: [],
1174
+ headAfterScript: [],
1175
+ headAfterStyle: [],
1176
+ bodyBeforeScript: []
1177
+ });
1178
+ return _context3.a(2, next());
1179
+ }
1180
+ }, _callee3);
1181
+ }));
1182
+ };
1183
+ };
1184
+ };
1185
+ var collectDoraConfigMw = function collectDoraConfigMw(mode) {
1186
+ return function (ctx) {
1187
+ return function (next) {
1188
+ return /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
1189
+ var json;
1190
+ return _regenerator().w(function (_context4) {
1191
+ while (1) switch (_context4.n) {
1192
+ case 0:
1193
+ _context4.n = 1;
1194
+ return resolveDoraConfig(ctx.getWorkRoot(), mode);
1195
+ case 1:
1196
+ json = _context4.v;
1197
+ ctx.setDoraConfig(json || {});
1198
+ return _context4.a(2, next());
1199
+ }
1200
+ }, _callee4);
1201
+ }));
1202
+ };
1203
+ };
1204
+ };
1205
+ var collectBaseConfigMw = function collectBaseConfigMw(workRoot, cmd) {
1206
+ return function (ctx) {
1207
+ return function (next) {
1208
+ return function () {
1209
+ ctx.setWorkRoot(workRoot);
1210
+ ctx.setCmd(cmd);
1211
+ return next();
1212
+ };
1213
+ };
1214
+ };
1215
+ };
1216
+
1217
+ var wholeDoraConfigMw = function wholeDoraConfigMw(defaultConfig) {
1218
+ return function (ctx) {
1219
+ return function (next) {
1220
+ return function () {
1221
+ var _mergeDoraCliConfig = mergeDoraCliConfig(defaultConfig, ctx.getDoraConfig()),
1222
+ alias = _mergeDoraCliConfig.alias,
1223
+ clear = _mergeDoraCliConfig.clear,
1224
+ copy = _mergeDoraCliConfig.copy,
1225
+ dts = _mergeDoraCliConfig.dts,
1226
+ lib = _mergeDoraCliConfig.lib,
1227
+ format = _mergeDoraCliConfig.format,
1228
+ libList = _mergeDoraCliConfig.libList,
1229
+ name = _mergeDoraCliConfig.name,
1230
+ type = _mergeDoraCliConfig.type,
1231
+ externals = _mergeDoraCliConfig.externals,
1232
+ formatList = _mergeDoraCliConfig.formatList,
1233
+ input = _mergeDoraCliConfig.input,
1234
+ internals = _mergeDoraCliConfig.internals,
1235
+ minimize = _mergeDoraCliConfig.minimize,
1236
+ multiple = _mergeDoraCliConfig.multiple,
1237
+ output = _mergeDoraCliConfig.output,
1238
+ rollupConfig = _mergeDoraCliConfig.rollupConfig,
1239
+ webpackConfig = _mergeDoraCliConfig.webpackConfig,
1240
+ esbuildConfig = _mergeDoraCliConfig.esbuildConfig,
1241
+ rspackConfig = _mergeDoraCliConfig.rspackConfig,
1242
+ serviceConfig = _mergeDoraCliConfig.serviceConfig,
1243
+ dtsConfig = _mergeDoraCliConfig.dtsConfig;
1244
+ ctx.setDoraConfig({
1245
+ multiple: lang.isUndefinedOrNull(multiple) ? false : multiple,
1246
+ name: name,
1247
+ type: type,
1248
+ format: format,
1249
+ formatList: formatList,
1250
+ lib: lib,
1251
+ libList: libList,
1252
+ alias: alias || {},
1253
+ clear: lang.isUndefinedOrNull(clear) ? false : clear,
1254
+ copy: copy || [],
1255
+ dts: lang.isUndefinedOrNull(dts) ? {} : dts,
1256
+ externals: externals || [],
1257
+ input: input,
1258
+ internals: internals || [],
1259
+ minimize: lang.isUndefinedOrNull(minimize) ? false : minimize,
1260
+ output: output,
1261
+ rollupConfig: rollupConfig || {},
1262
+ webpackConfig: webpackConfig || {},
1263
+ esbuildConfig: esbuildConfig || {},
1264
+ rspackConfig: rspackConfig || {},
1265
+ serviceConfig: serviceConfig || {},
1266
+ dtsConfig: dtsConfig
1267
+ });
1268
+ return next();
1269
+ };
1270
+ };
1271
+ };
1272
+ };
1273
+
1274
+ var _excluded$1 = ["input", "output", "multiple"];
1275
+ var wholeDoraInoutMw = function wholeDoraInoutMw() {
1276
+ return function (ctx) {
1277
+ return function (next) {
1278
+ return function () {
1279
+ var _ctx$getDoraConfig = ctx.getDoraConfig(),
1280
+ input = _ctx$getDoraConfig.input,
1281
+ output = _ctx$getDoraConfig.output,
1282
+ multiple = _ctx$getDoraConfig.multiple,
1283
+ extConfig = _objectWithoutProperties(_ctx$getDoraConfig, _excluded$1);
1284
+ var workRootDir = ctx.getWorkRoot();
1285
+ var targetInput = input;
1286
+ var outPath = (output === null || output === void 0 ? void 0 : output.path) || './dist';
1287
+ var outFile = output === null || output === void 0 ? void 0 : output.file;
1288
+ if (!multiple) {
1289
+ if (!filePro.isValidFilePathSync(targetInput || '')) {
1290
+ targetInput = findInput(workRootDir);
1291
+ }
1292
+ if (!targetInput) {
1293
+ cLog.error('init', 'not_found', '找不到入口文件');
1294
+ }
1295
+ outFile = (output === null || output === void 0 ? void 0 : output.file) || filePro.getFilename(targetInput);
1296
+ }
1297
+ ctx.setDoraConfig(_objectSpread2(_objectSpread2({}, extConfig), {}, {
1298
+ input: targetInput,
1299
+ output: output || {
1300
+ path: outPath,
1301
+ file: outFile
1302
+ },
1303
+ multiple: multiple
1304
+ }));
1305
+ return next();
1306
+ };
1307
+ };
1308
+ };
1309
+ };
1310
+
1311
+ var configCtxWorkflow = function configCtxWorkflow(config) {
1312
+ var middlewares = [];
1313
+ return {
1314
+ use: function use(middleware) {
1315
+ middlewares.push(middleware);
1316
+ return this;
1317
+ },
1318
+ getResult: function getResult() {
1319
+ return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1320
+ return _regenerator().w(function (_context) {
1321
+ while (1) switch (_context.n) {
1322
+ case 0:
1323
+ _context.n = 1;
1324
+ return utils.getOnionFun(config, middlewares)(lang.noop)();
1325
+ case 1:
1326
+ return _context.a(2, config);
1327
+ }
1328
+ }, _callee);
1329
+ }))();
1330
+ }
1331
+ };
1332
+ };
1333
+
1334
+ var EnvEnum = /*#__PURE__*/function (EnvEnum) {
1335
+ EnvEnum["dev"] = "development";
1336
+ EnvEnum["prod"] = "production";
1337
+ return EnvEnum;
1338
+ }({});
1339
+
1340
+ var CompilerBase = /*#__PURE__*/_createClass(function CompilerBase(initOptions) {
1341
+ _classCallCheck(this, CompilerBase);
1342
+ this.initOptions = initOptions;
1343
+ _defineProperty(this, "inOutMap", void 0);
1344
+ _defineProperty(this, "input", void 0);
1345
+ _defineProperty(this, "context", void 0);
1346
+ _defineProperty(this, "build", void 0);
1347
+ _defineProperty(this, "watch", void 0);
1348
+ _defineProperty(this, "server", void 0);
1349
+ });
1350
+
1351
+ /**
1352
+ * 动态html生成器
1353
+ */
1354
+ var DynamicHtml = /*#__PURE__*/function () {
1355
+ function DynamicHtml() {
1356
+ _classCallCheck(this, DynamicHtml);
1357
+ _defineProperty(this, "headScripts", []);
1358
+ _defineProperty(this, "bodyScripts", []);
1359
+ _defineProperty(this, "headStyles", []);
1360
+ _defineProperty(this, "headTags", []);
1361
+ _defineProperty(this, "bodyTags", ['<div id="main"></div>']);
1362
+ }
1363
+ return _createClass(DynamicHtml, [{
1364
+ key: "addHeadScripts",
1365
+ value: function addHeadScripts(scripts) {
1366
+ var _this$headScripts;
1367
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1368
+ if (force) this.headScripts = [];
1369
+ (_this$headScripts = this.headScripts).push.apply(_this$headScripts, _toConsumableArray(scripts));
1370
+ }
1371
+ }, {
1372
+ key: "addBodyScripts",
1373
+ value: function addBodyScripts(scripts) {
1374
+ var _this$bodyScripts;
1375
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1376
+ if (force) this.bodyScripts = [];
1377
+ (_this$bodyScripts = this.bodyScripts).push.apply(_this$bodyScripts, _toConsumableArray(scripts));
1378
+ }
1379
+ }, {
1380
+ key: "addHeadStyles",
1381
+ value: function addHeadStyles(styles) {
1382
+ var _this$headStyles;
1383
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1384
+ if (force) this.headStyles = [];
1385
+ (_this$headStyles = this.headStyles).push.apply(_this$headStyles, _toConsumableArray(styles));
1386
+ }
1387
+ }, {
1388
+ key: "addHeadTags",
1389
+ value: function addHeadTags(tags) {
1390
+ var _this$headTags;
1391
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1392
+ if (force) this.headTags = [];
1393
+ (_this$headTags = this.headTags).push.apply(_this$headTags, _toConsumableArray(tags));
1394
+ }
1395
+ }, {
1396
+ key: "addBodyTags",
1397
+ value: function addBodyTags(tags) {
1398
+ var _this$bodyTags;
1399
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1400
+ if (force) this.bodyTags = tags;
1401
+ (_this$bodyTags = this.bodyTags).push.apply(_this$bodyTags, _toConsumableArray(tags));
1402
+ }
1403
+ }, {
1404
+ key: "copy",
1405
+ value: function copy() {
1406
+ var dynamicHtml = new DynamicHtml();
1407
+ dynamicHtml.addHeadScripts(this.headScripts, true);
1408
+ dynamicHtml.addBodyScripts(this.bodyScripts, true);
1409
+ dynamicHtml.addHeadStyles(this.headStyles, true);
1410
+ return dynamicHtml;
1411
+ }
1412
+
1413
+ /**
1414
+ * 序列化为html模板
1415
+ * @param title
1416
+ * @returns
1417
+ */
1418
+ }, {
1419
+ key: "generateHtmlTemplate",
1420
+ value: function generateHtmlTemplate() {
1421
+ var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Document';
1422
+ /**
1423
+ * 生成header
1424
+ * 1. 排序
1425
+ * 2. 生成html
1426
+ */
1427
+ var headScriptsHtml = this.headScripts.sort(function (a, b) {
1428
+ return (a.order || 0) - (b.order || 0);
1429
+ }).map(function (script) {
1430
+ var attrs = ["src=\"".concat(script.src, "\""), script.async ? 'async' : '', script.defer ? 'defer' : ''].filter(Boolean).join(' ');
1431
+ return "<script ".concat(attrs, "></script>");
1432
+ }).join('\n');
1433
+ var bodyScriptsHtml = this.bodyScripts.sort(function (a, b) {
1434
+ return (a.order || 0) - (b.order || 0);
1435
+ }).map(function (script) {
1436
+ var attrs = ["src=\"".concat(script.src, "\""), script.async ? 'async' : '', script.defer ? 'defer' : ''].filter(Boolean).join(' ');
1437
+ return "<script ".concat(attrs, "></script>");
1438
+ }).join('\n');
1439
+ var headStylesHtml = this.headStyles.sort(function (a, b) {
1440
+ return (a.order || 0) - (b.order || 0);
1441
+ }).map(function (style) {
1442
+ var attrs = ["href=\"".concat(style.src, "\""), 'rel="stylesheet"', style.async ? 'async' : '', style.defer ? 'defer' : ''].filter(Boolean).join(' ');
1443
+ return "<link ".concat(attrs, ">");
1444
+ }).join('\n');
1445
+ var headTagsHtml = this.headTags.map(function (tag) {
1446
+ return tag;
1447
+ }).join('\n');
1448
+ var bodyTagsHtml = this.bodyTags.map(function (tag) {
1449
+ return tag;
1450
+ }).join('\n');
1451
+ return "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>".concat(title, "</title>\n ").concat(headTagsHtml, "\n ").concat(headStylesHtml, "\n ").concat(headScriptsHtml, "\n</head>\n<body>\n ").concat(bodyTagsHtml, "\n ").concat(bodyScriptsHtml, "\n</body>\n</html>");
1452
+ }
1453
+ }]);
1454
+ }();
1455
+
1456
+ var HtmlAssetManager = /*#__PURE__*/function () {
1457
+ function HtmlAssetManager() {
1458
+ var publicPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/';
1459
+ _classCallCheck(this, HtmlAssetManager);
1460
+ this.publicPath = publicPath;
1461
+ _defineProperty(this, "assetMap", {});
1462
+ _defineProperty(this, "dynamicHtml", new DynamicHtml());
1463
+ _defineProperty(this, "initAwaitList", []);
1464
+ _defineProperty(this, "assetList", []);
1465
+ }
1466
+ return _createClass(HtmlAssetManager, [{
1467
+ key: "updateAssetList",
1468
+ value: function updateAssetList(assetList) {
1469
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1470
+ this.assetList = force ? assetList : Array.from(new Set([].concat(_toConsumableArray(this.assetList), _toConsumableArray(assetList))));
1471
+ }
1472
+ }, {
1473
+ key: "setAssetList",
1474
+ value: function setAssetList(assetMap) {
1475
+ this.assetMap = assetMap;
1476
+ this.initAwaitList.forEach(function (cb) {
1477
+ return cb();
1478
+ });
1479
+ this.initAwaitList = [];
1480
+ }
1481
+ }, {
1482
+ key: "getAssetMap",
1483
+ value: function getAssetMap() {
1484
+ return this.assetMap;
1485
+ }
1486
+ }, {
1487
+ key: "getModuleAsset",
1488
+ value: function getModuleAsset(moduleName) {
1489
+ return this.assetMap[moduleName] || {
1490
+ name: moduleName,
1491
+ scripts: [],
1492
+ styles: [],
1493
+ runtimeChunks: []
1494
+ };
1495
+ }
1496
+ }, {
1497
+ key: "getModuleHtml",
1498
+ value: function () {
1499
+ var _getModuleHtml = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleName) {
1500
+ var _this = this;
1501
+ var asset, moduleHtml;
1502
+ return _regenerator().w(function (_context) {
1503
+ while (1) switch (_context.n) {
1504
+ case 0:
1505
+ if (!(Object.keys(this.assetMap).length === 0)) {
1506
+ _context.n = 1;
1507
+ break;
1508
+ }
1509
+ _context.n = 1;
1510
+ return new Promise(function (resolve) {
1511
+ _this.initAwaitList.push(function () {
1512
+ resolve();
1513
+ });
1514
+ });
1515
+ case 1:
1516
+ asset = this.assetMap[moduleName];
1517
+ if (asset) {
1518
+ _context.n = 2;
1519
+ break;
1520
+ }
1521
+ throw new Error("Module ".concat(moduleName, " asset not found."));
1522
+ case 2:
1523
+ moduleHtml = this.dynamicHtml.copy();
1524
+ moduleHtml.addBodyScripts(asset.scripts.map(function (src) {
1525
+ return {
1526
+ src: src,
1527
+ order: 0
1528
+ };
1529
+ }));
1530
+ moduleHtml.addHeadStyles(asset.styles.map(function (src) {
1531
+ return {
1532
+ src: src,
1533
+ order: 0
1534
+ };
1535
+ }));
1536
+ return _context.a(2, moduleHtml.generateHtmlTemplate());
1537
+ }
1538
+ }, _callee, this);
1539
+ }));
1540
+ function getModuleHtml(_x) {
1541
+ return _getModuleHtml.apply(this, arguments);
1542
+ }
1543
+ return getModuleHtml;
1544
+ }()
1545
+ }]);
1546
+ }();
1547
+
1548
+ var _generateTag = function generateTag(tag) {
1549
+ var _tag$attrs2;
1550
+ if (tag.selfClosing) {
1551
+ var _tag$attrs;
1552
+ return "<".concat(tag.tagName, " ").concat((_tag$attrs = tag.attrs) === null || _tag$attrs === void 0 ? void 0 : _tag$attrs.map(function (attr) {
1553
+ return "".concat(attr.name, "=\"").concat(attr.value, "\"");
1554
+ }).join(' '), " />");
1555
+ }
1556
+ return "<".concat(tag.tagName, " ").concat((_tag$attrs2 = tag.attrs) === null || _tag$attrs2 === void 0 ? void 0 : _tag$attrs2.map(function (attr) {
1557
+ return "".concat(attr.name, "=\"").concat(attr.value, "\"");
1558
+ }).join(' '), ">").concat((tag.children || []).map(function (child) {
1559
+ return typeof child === 'string' ? child : _generateTag(child);
1560
+ }).join(''), "</").concat(tag.tagName, ">");
1561
+ };
1562
+ var generateHtml = function generateHtml(options) {
1563
+ var head = options.head,
1564
+ body = options.body;
1565
+ return "\n <html>\n <head>\n ".concat(head.map(function (tag) {
1566
+ return _generateTag(tag);
1567
+ }).join('\n'), "\n </head>\n <body>\n ").concat(body.map(function (tag) {
1568
+ return _generateTag(tag);
1569
+ }).join('\n'), "\n </body>\n </html>\n ");
1570
+ };
1571
+
1572
+ /**
1573
+ * 解析html
1574
+ * 会解析 head body 下一层级的标签,子标签,已children保存
1575
+ */
1576
+ var parseHtml = function parseHtml(html) {
1577
+ var headMatch = /<head[^>]*>([\s\S]*?)<\/head>/i.exec(html);
1578
+ var bodyMatch = /<body[^>]*>([\s\S]*?)<\/body>/i.exec(html);
1579
+ var headHTML = headMatch ? headMatch[1] : '';
1580
+ var bodyHTML = bodyMatch ? bodyMatch[1] : '';
1581
+ var headTags = parseSection(headHTML);
1582
+ var bodyTags = parseSection(bodyHTML);
1583
+ return {
1584
+ head: headTags,
1585
+ body: bodyTags
1586
+ };
1587
+ };
1588
+
1589
+ /**
1590
+ * 解析一层标签
1591
+ * @param section
1592
+ * @returns
1593
+ */
1594
+ var parseSection = function parseSection(section) {
1595
+ var tags = [];
1596
+ var stack = [];
1597
+ if (!section) return tags;
1598
+
1599
+ // HTML 中的自闭合标签列表(没有显式的结束标签)
1600
+ var VOID_TAGS = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
1601
+
1602
+ // 解析属性字符串为 TParsedTagAttr[]
1603
+ var parseAttrs = function parseAttrs(attrStr) {
1604
+ var attrs = [];
1605
+ var attrRegex = /([^\s=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
1606
+ var match;
1607
+ while (match = attrRegex.exec(attrStr)) {
1608
+ var _ref, _match$;
1609
+ var name = match[1];
1610
+ var value = (_ref = (_match$ = match[2]) !== null && _match$ !== void 0 ? _match$ : match[3]) !== null && _ref !== void 0 ? _ref : match[4];
1611
+ if (value === undefined) {
1612
+ attrs.push({
1613
+ name: name,
1614
+ value: true
1615
+ });
1616
+ } else {
1617
+ attrs.push({
1618
+ name: name,
1619
+ value: value
1620
+ });
1621
+ }
1622
+ }
1623
+ return attrs;
1624
+ };
1625
+ var i = 0;
1626
+ var len = section.length;
1627
+ while (i < len) {
1628
+ var char = section[i];
1629
+
1630
+ // 处理标签
1631
+ if (char === '<') {
1632
+ var closeIndex = section.indexOf('>', i + 1);
1633
+ if (closeIndex === -1) break;
1634
+ var rawTagContent = section.slice(i + 1, closeIndex).trim();
1635
+
1636
+ // 跳过注释、DOCTYPE 等
1637
+ if (rawTagContent.startsWith('!') || rawTagContent.startsWith('?') || rawTagContent.startsWith('--')) {
1638
+ i = closeIndex + 1;
1639
+ continue;
1640
+ }
1641
+
1642
+ // 结束标签
1643
+ if (rawTagContent.startsWith('/')) {
1644
+ var endTagName = rawTagContent.slice(1).trim().split(/\s+/)[0].toLowerCase();
1645
+ if (stack.length) {
1646
+ var top = stack[stack.length - 1];
1647
+ // 标签名匹配才出栈,否则简单出栈防止死栈
1648
+ if (top.tagName.toLowerCase() === endTagName) {
1649
+ stack.pop();
1650
+ } else {
1651
+ stack.pop();
1652
+ }
1653
+ }
1654
+ i = closeIndex + 1;
1655
+ continue;
1656
+ }
1657
+
1658
+ // 开始标签 / 自闭合标签
1659
+ var isExplicitSelfClosing = rawTagContent.endsWith('/');
1660
+ var tagBody = rawTagContent.replace(/\/\s*$/, '').trim();
1661
+ var firstSpace = tagBody.search(/\s/);
1662
+ var tagName = (firstSpace === -1 ? tagBody : tagBody.slice(0, firstSpace)).toLowerCase();
1663
+ var attrStr = firstSpace === -1 ? '' : tagBody.slice(firstSpace + 1).trim();
1664
+ var selfClosing = isExplicitSelfClosing || VOID_TAGS.has(tagName);
1665
+ var attrs = parseAttrs(attrStr);
1666
+ var newTag = {
1667
+ tagName: tagName,
1668
+ attrs: attrs,
1669
+ selfClosing: selfClosing,
1670
+ children: []
1671
+ };
1672
+ if (stack.length === 0) {
1673
+ // 第一层标签
1674
+ tags.push(newTag);
1675
+ } else {
1676
+ // 作为父标签的子节点
1677
+ var parent = stack[stack.length - 1];
1678
+ if (!parent.children) parent.children = [];
1679
+ parent.children.push(newTag);
1680
+ }
1681
+ if (!selfClosing) {
1682
+ stack.push(newTag);
1683
+ }
1684
+ i = closeIndex + 1;
1685
+ continue;
1686
+ }
1687
+
1688
+ // 处理文本节点
1689
+ var nextTagIndex = section.indexOf('<', i);
1690
+ var textEnd = nextTagIndex === -1 ? len : nextTagIndex;
1691
+ var textContent = section.slice(i, textEnd);
1692
+ var trimmed = textContent.trim();
1693
+ if (trimmed) {
1694
+ if (stack.length) {
1695
+ var _parent = stack[stack.length - 1];
1696
+ if (!_parent.children) _parent.children = [];
1697
+ _parent.children.push(trimmed);
1698
+ }
1699
+ }
1700
+ i = textEnd;
1701
+ }
1702
+ return tags;
1703
+ };
1704
+
1705
+ var HtmlManage = /*#__PURE__*/function () {
1706
+ function HtmlManage(options) {
1707
+ var _options$head, _options$body;
1708
+ _classCallCheck(this, HtmlManage);
1709
+ _defineProperty(this, "head", []);
1710
+ _defineProperty(this, "body", []);
1711
+ this.head = (_options$head = options === null || options === void 0 ? void 0 : options.head) !== null && _options$head !== void 0 ? _options$head : [];
1712
+ this.body = (_options$body = options === null || options === void 0 ? void 0 : options.body) !== null && _options$body !== void 0 ? _options$body : [];
1713
+ }
1714
+ return _createClass(HtmlManage, [{
1715
+ key: "addHead",
1716
+ value: function addHead(tag) {
1717
+ if (!tag) return this;
1718
+ this.head.push(tag);
1719
+ return this;
1720
+ }
1721
+ }, {
1722
+ key: "addHeads",
1723
+ value: function addHeads(tags) {
1724
+ var _this$head;
1725
+ if (!tags) return this;
1726
+ (_this$head = this.head).push.apply(_this$head, _toConsumableArray(tags));
1727
+ return this;
1728
+ }
1729
+ }, {
1730
+ key: "addBody",
1731
+ value: function addBody(tag) {
1732
+ if (!tag) return this;
1733
+ this.body.push(tag);
1734
+ return this;
1735
+ }
1736
+ }, {
1737
+ key: "addBodys",
1738
+ value: function addBodys(tags) {
1739
+ var _this$body;
1740
+ if (!tags) return this;
1741
+ (_this$body = this.body).push.apply(_this$body, _toConsumableArray(tags));
1742
+ return this;
1743
+ }
1744
+ }, {
1745
+ key: "parseHtmlByFile",
1746
+ value: function parseHtmlByFile(filePath) {
1747
+ var html = fs.readFileSync(filePath, 'utf-8');
1748
+ var _HtmlManage$parseHtml = HtmlManage.parseHtml(html),
1749
+ head = _HtmlManage$parseHtml.head,
1750
+ body = _HtmlManage$parseHtml.body;
1751
+ this.head = head;
1752
+ this.body = body;
1753
+ return this;
1754
+ }
1755
+ }, {
1756
+ key: "generateHtml",
1757
+ value: function generateHtml$1() {
1758
+ return generateHtml({
1759
+ head: this.head,
1760
+ body: this.body
1761
+ });
1762
+ }
1763
+ }, {
1764
+ key: "copy",
1765
+ value: function copy() {
1766
+ return new HtmlManage({
1767
+ head: this.head.map(function (tag) {
1768
+ return _objectSpread2({}, tag);
1769
+ }),
1770
+ body: this.body.map(function (tag) {
1771
+ return _objectSpread2({}, tag);
1772
+ })
1773
+ });
1774
+ }
1775
+ }], [{
1776
+ key: "parseHtml",
1777
+ value: function parseHtml$1(html) {
1778
+ return parseHtml(html);
1779
+ }
1780
+ }]);
1781
+ }();
1782
+
1050
1783
  var collectConfigs = /*#__PURE__*/function () {
1051
1784
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workDir, need) {
1052
1785
  var results;
@@ -1153,9 +1886,20 @@ var configCtxCollect = /*#__PURE__*/function () {
1153
1886
  };
1154
1887
  }();
1155
1888
 
1156
- // 全局上下文变量
1889
+ /**
1890
+ * 创建环境参数
1891
+ * @description 会自动处理出绝对路径的 workRootDir
1892
+ * @param params 上下文变量
1893
+ * @returns
1894
+ */
1157
1895
  var createEnvParams = function createEnvParams(params) {
1158
- return params;
1896
+ var workRootDir = params.workRootDir || './';
1897
+ if (!path.isAbsolute(params.workRootDir)) {
1898
+ workRootDir = path.join(filePro.getCwd(), workRootDir);
1899
+ }
1900
+ return _objectSpread2(_objectSpread2({}, params), {}, {
1901
+ workRootDir: workRootDir
1902
+ });
1159
1903
  };
1160
1904
 
1161
1905
  var createOutputList = function createOutputList(config) {
@@ -1193,6 +1937,109 @@ var createOutputList = function createOutputList(config) {
1193
1937
  return outputList;
1194
1938
  };
1195
1939
 
1940
+ /**
1941
+ * 依赖项过滤
1942
+ * @param options 过滤选项
1943
+ * @param strategy 规则冲突时,过滤策略 include-包含 | exclude-排除,默认排除
1944
+ * @returns 依赖过滤函数 () => boolean 返回true表示 - 属于排除范围
1945
+ */
1946
+ var createDependFilter = function createDependFilter(options) {
1947
+ var strategy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'exclude';
1948
+ var dependencies = options.dependencies,
1949
+ peerDependencies = options.peerDependencies,
1950
+ devDependencies = options.devDependencies,
1951
+ externals = options.externals,
1952
+ internals = options.internals,
1953
+ compare = options.compare;
1954
+ var excludeMap = {};
1955
+ var includeMap = {};
1956
+ Object.keys(dependencies || {}).forEach(function (key) {
1957
+ excludeMap[key] = key;
1958
+ });
1959
+ Object.keys(peerDependencies || {}).forEach(function (key) {
1960
+ excludeMap[key] = key;
1961
+ });
1962
+ Object.keys(devDependencies || {}).forEach(function (key) {
1963
+ excludeMap[key] = key;
1964
+ });
1965
+ externals === null || externals === void 0 || externals.forEach(function (item) {
1966
+ if (lang.isString(item)) {
1967
+ excludeMap[item] = item;
1968
+ } else if (lang.isPlainObject(item)) {
1969
+ Object.keys(item).forEach(function (key) {
1970
+ excludeMap[key] = item[key];
1971
+ });
1972
+ }
1973
+ });
1974
+ internals === null || internals === void 0 || internals.forEach(function (item) {
1975
+ if (lang.isString(item)) {
1976
+ includeMap[item] = item;
1977
+ }
1978
+ });
1979
+ var isIncludeStrategy = strategy === 'include';
1980
+
1981
+ /**
1982
+ * 依赖过滤器
1983
+ * @param id 模块id
1984
+ * @returns boolean 返回true表示 - 属于排除范围
1985
+ */
1986
+ return function (id) {
1987
+ var res = false;
1988
+
1989
+ /** 判断排除 */
1990
+ var excludeTarget = Object.keys(excludeMap).find(function (externalModule) {
1991
+ if (lang.isFunction(compare)) return compare(id, externalModule);
1992
+ return id.startsWith(externalModule);
1993
+ });
1994
+
1995
+ /** 判断包含 */
1996
+ var includeTarget = Object.keys(includeMap).find(function (externalModule) {
1997
+ if (lang.isFunction(compare)) return compare(id, externalModule);
1998
+ return id.startsWith(externalModule);
1999
+ });
2000
+ if (isIncludeStrategy) {
2001
+ if (includeTarget) {
2002
+ res = false;
2003
+ } else if (excludeTarget) {
2004
+ res = excludeMap[excludeTarget];
2005
+ }
2006
+ } else {
2007
+ if (excludeTarget) {
2008
+ res = excludeMap[excludeTarget];
2009
+ } else if (includeTarget) {
2010
+ res = false;
2011
+ }
2012
+ }
2013
+ return res;
2014
+ };
2015
+ };
2016
+
2017
+ var htmlDefault = "\n<html lang=\"zh-CN\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>dora</title>\n </head>\n <body>\n <div id=\"main\">welcome use dora !!</div>\n </body>\n</html>\n";
2018
+ var getDefaultHtml = /*#__PURE__*/function () {
2019
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(workRootDir) {
2020
+ var userHtmlDir;
2021
+ return _regenerator().w(function (_context) {
2022
+ while (1) switch (_context.n) {
2023
+ case 0:
2024
+ _context.n = 1;
2025
+ return findInputHtml(workRootDir);
2026
+ case 1:
2027
+ userHtmlDir = _context.v;
2028
+ if (!userHtmlDir) {
2029
+ _context.n = 2;
2030
+ break;
2031
+ }
2032
+ return _context.a(2, fs.readFileSync(userHtmlDir, 'utf-8'));
2033
+ case 2:
2034
+ return _context.a(2, htmlDefault);
2035
+ }
2036
+ }, _callee);
2037
+ }));
2038
+ return function getDefaultHtml(_x) {
2039
+ return _ref.apply(this, arguments);
2040
+ };
2041
+ }();
2042
+
1196
2043
  var parsetConfig = /*#__PURE__*/function () {
1197
2044
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config, mode) {
1198
2045
  var _t, _t2, _t3, _t4;
@@ -1235,10 +2082,218 @@ var splitDoraConfig = function splitDoraConfig(config) {
1235
2082
  });
1236
2083
  };
1237
2084
 
2085
+ var GenerateConfigHtml = /*#__PURE__*/function (_HtmlManage) {
2086
+ function GenerateConfigHtml(configCtx) {
2087
+ var _this;
2088
+ _classCallCheck(this, GenerateConfigHtml);
2089
+ _this = _callSuper(this, GenerateConfigHtml);
2090
+ _this.configCtx = configCtx;
2091
+ return _this;
2092
+ }
2093
+ _inherits(GenerateConfigHtml, _HtmlManage);
2094
+ return _createClass(GenerateConfigHtml, [{
2095
+ key: "init",
2096
+ value: function () {
2097
+ var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2098
+ var defaultHtml, _HtmlManage$parseHtml, head, body;
2099
+ return _regenerator().w(function (_context) {
2100
+ while (1) switch (_context.n) {
2101
+ case 0:
2102
+ _context.n = 1;
2103
+ return getDefaultHtml(this.configCtx.getWorkRoot());
2104
+ case 1:
2105
+ defaultHtml = _context.v;
2106
+ _HtmlManage$parseHtml = HtmlManage.parseHtml(defaultHtml), head = _HtmlManage$parseHtml.head, body = _HtmlManage$parseHtml.body;
2107
+ this.addHeads(head);
2108
+ this.addBodys(body);
2109
+ return _context.a(2, this);
2110
+ }
2111
+ }, _callee, this);
2112
+ }));
2113
+ function init() {
2114
+ return _init.apply(this, arguments);
2115
+ }
2116
+ return init;
2117
+ }()
2118
+ }, {
2119
+ key: "addConfigCdn",
2120
+ value: function addConfigCdn() {
2121
+ var _cdnConfig$headAfterS, _cdnConfig$headAfterS2, _cdnConfig$bodyAfterS, _cdnConfig$bodyBefore;
2122
+ var cdnConfig = this.configCtx.getCdnConfig();
2123
+ this.addHeads((_cdnConfig$headAfterS = cdnConfig.headAfterScript) === null || _cdnConfig$headAfterS === void 0 ? void 0 : _cdnConfig$headAfterS.map(function (script) {
2124
+ return {
2125
+ tagName: 'script',
2126
+ attrs: [{
2127
+ name: 'src',
2128
+ value: script
2129
+ }]
2130
+ };
2131
+ }));
2132
+ this.addHeads((_cdnConfig$headAfterS2 = cdnConfig.headAfterStyle) === null || _cdnConfig$headAfterS2 === void 0 ? void 0 : _cdnConfig$headAfterS2.map(function (style) {
2133
+ return {
2134
+ tagName: 'link',
2135
+ attrs: [{
2136
+ name: 'href',
2137
+ value: style
2138
+ }, {
2139
+ name: 'rel',
2140
+ value: 'stylesheet'
2141
+ }]
2142
+ };
2143
+ }));
2144
+ this.addBodys((_cdnConfig$bodyAfterS = cdnConfig.bodyAfterScript) === null || _cdnConfig$bodyAfterS === void 0 ? void 0 : _cdnConfig$bodyAfterS.map(function (script) {
2145
+ return {
2146
+ tagName: 'script',
2147
+ attrs: [{
2148
+ name: 'src',
2149
+ value: script
2150
+ }]
2151
+ };
2152
+ }));
2153
+ this.addBodys((_cdnConfig$bodyBefore = cdnConfig.bodyBeforeScript) === null || _cdnConfig$bodyBefore === void 0 ? void 0 : _cdnConfig$bodyBefore.map(function (script) {
2154
+ return {
2155
+ tagName: 'script',
2156
+ attrs: [{
2157
+ name: 'src',
2158
+ value: script
2159
+ }]
2160
+ };
2161
+ }));
2162
+ return this;
2163
+ }
2164
+
2165
+ /**
2166
+ * 写入到文件,没有文件创建文件
2167
+ * @param filePath 文件路径
2168
+ * @returns
2169
+ */
2170
+ }, {
2171
+ key: "writeToFile",
2172
+ value: function writeToFile(filePath) {
2173
+ if (!fs.existsSync(filePath)) {
2174
+ fs.writeFileSync(filePath, this.generateHtml(), {});
2175
+ } else {
2176
+ fs.appendFileSync(filePath, this.generateHtml(), {});
2177
+ }
2178
+ return this;
2179
+ }
2180
+ }, {
2181
+ key: "addBodyScripts",
2182
+ value: function addBodyScripts(scripts) {
2183
+ this.addBodys(scripts.map(function (script) {
2184
+ return {
2185
+ tagName: 'script',
2186
+ attrs: [{
2187
+ name: 'src',
2188
+ value: script
2189
+ }]
2190
+ };
2191
+ }));
2192
+ return this;
2193
+ }
2194
+ }, {
2195
+ key: "addHeadStyles",
2196
+ value: function addHeadStyles(styles) {
2197
+ this.addHeads(styles.map(function (style) {
2198
+ return {
2199
+ tagName: 'link',
2200
+ attrs: [{
2201
+ name: 'href',
2202
+ value: style
2203
+ }, {
2204
+ name: 'rel',
2205
+ value: 'stylesheet'
2206
+ }]
2207
+ };
2208
+ }));
2209
+ return this;
2210
+ }
2211
+ }, {
2212
+ key: "copy",
2213
+ value: function copy() {
2214
+ var generateConfigHtml = new GenerateConfigHtml(this.configCtx);
2215
+ generateConfigHtml.addHeads(this.head);
2216
+ generateConfigHtml.addBodys(this.body);
2217
+ return generateConfigHtml;
2218
+ }
2219
+ }]);
2220
+ }(HtmlManage);
2221
+
2222
+ /**
2223
+ * 在制定目录下插入 tsconfig.json 文件
2224
+ * @param cwd
2225
+ */
2226
+ var insertTsconfig = /*#__PURE__*/function () {
2227
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
2228
+ var cwd,
2229
+ tsconfigPath,
2230
+ tsconfigContent,
2231
+ _args = arguments;
2232
+ return _regenerator().w(function (_context) {
2233
+ while (1) switch (_context.n) {
2234
+ case 0:
2235
+ cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : filePro.getCwd();
2236
+ tsconfigPath = path.join(cwd, 'tsconfig.json');
2237
+ _context.n = 1;
2238
+ return filePro.isValidFilePath(tsconfigPath);
2239
+ case 1:
2240
+ if (_context.v) {
2241
+ _context.n = 3;
2242
+ break;
2243
+ }
2244
+ tsconfigContent = {
2245
+ $schema: 'https://json.schemastore.org/tsconfig',
2246
+ compilerOptions: {
2247
+ target: 'esnext',
2248
+ moduleResolution: 'node',
2249
+ module: 'esnext',
2250
+ noImplicitThis: false,
2251
+ noImplicitAny: false,
2252
+ noUnusedLocals: false,
2253
+ noImplicitReturns: true,
2254
+ noUnusedParameters: false,
2255
+ useUnknownInCatchVariables: false,
2256
+ allowSyntheticDefaultImports: true,
2257
+ esModuleInterop: true,
2258
+ emitDecoratorMetadata: true,
2259
+ experimentalDecorators: true,
2260
+ preserveConstEnums: true,
2261
+ strictNullChecks: true,
2262
+ strictFunctionTypes: true,
2263
+ strictPropertyInitialization: true,
2264
+ resolveJsonModule: true,
2265
+ skipLibCheck: true,
2266
+ alwaysStrict: true,
2267
+ sourceMap: false,
2268
+ paths: {
2269
+ '@/*': ['./src/*']
2270
+ }
2271
+ },
2272
+ exclude: ['lib/**'],
2273
+ include: ['**/*.ts', '**/*.json']
2274
+ };
2275
+ _context.n = 2;
2276
+ return promises.writeFile(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
2277
+ case 2:
2278
+ cLog.info('init', 'success', '自动注入 tsconfig.json');
2279
+ case 3:
2280
+ return _context.a(2);
2281
+ }
2282
+ }, _callee);
2283
+ }));
2284
+ return function insertTsconfig() {
2285
+ return _ref.apply(this, arguments);
2286
+ };
2287
+ }();
2288
+
1238
2289
  exports.picocolors = picocolors;
1239
2290
  exports.CompilerBase = CompilerBase;
1240
2291
  exports.ConfigCtx = ConfigCtx;
2292
+ exports.DynamicHtml = DynamicHtml;
1241
2293
  exports.EnvEnum = EnvEnum;
2294
+ exports.GenerateConfigHtml = GenerateConfigHtml;
2295
+ exports.HtmlAssetManager = HtmlAssetManager;
2296
+ exports.HtmlManage = HtmlManage;
1242
2297
  exports.cLog = cLog;
1243
2298
  exports.cLogDebugger = cLogDebugger;
1244
2299
  exports.cLogError = cLogError;
@@ -1247,12 +2302,23 @@ exports.cLogSuccess = cLogSuccess;
1247
2302
  exports.cLogTime = cLogTime;
1248
2303
  exports.cLogTimeEnd = cLogTimeEnd;
1249
2304
  exports.cLogWarn = cLogWarn;
2305
+ exports.clearMw = clearMw;
2306
+ exports.collectBaseConfigMw = collectBaseConfigMw;
2307
+ exports.collectCdnConfigMw = collectCdnConfigMw;
1250
2308
  exports.collectConfig = collectConfig;
1251
2309
  exports.collectConfigs = collectConfigs;
2310
+ exports.collectDoraConfigMw = collectDoraConfigMw;
2311
+ exports.collectPackageJsonMw = collectPackageJsonMw;
2312
+ exports.collectTsconfigJsonMw = collectTsconfigJsonMw;
1252
2313
  exports.configCtxCollect = configCtxCollect;
2314
+ exports.configCtxWorkflow = configCtxWorkflow;
2315
+ exports.createDependFilter = createDependFilter;
1253
2316
  exports.createEnvParams = createEnvParams;
1254
2317
  exports.createOutputList = createOutputList;
2318
+ exports.deepMergeObject = _deepMergeObject;
1255
2319
  exports.findInput = findInput;
2320
+ exports.findInputHtml = findInputHtml;
2321
+ exports.getDefaultHtml = getDefaultHtml;
1256
2322
  exports.getDependencies = getDependencies;
1257
2323
  exports.getDoracliConfig = getDoracliConfig;
1258
2324
  exports.getPackageJson = getPackageJson;
@@ -1261,11 +2327,13 @@ exports.getTsconfigJson = getTsconfigJson;
1261
2327
  exports.getUserCdn = getUserCdn;
1262
2328
  exports.inputFileDirList = inputFileDirList;
1263
2329
  exports.inputFileTypeList = inputFileTypeList;
2330
+ exports.inputHtmlFileDirList = inputHtmlFileDirList;
1264
2331
  exports.insertTsconfig = insertTsconfig;
1265
2332
  exports.mergeDoraCliConfig = mergeDoraCliConfig;
1266
2333
  exports.mergeDoraCliConfigMutiple = mergeDoraCliConfigMutiple;
1267
2334
  exports.parseCdnConfig = parseCdnConfig;
1268
2335
  exports.parseDoracliConfig = parseDoracliConfig;
2336
+ exports.parseHtml = parseHtml;
1269
2337
  exports.parsetConfig = parsetConfig;
1270
2338
  exports.resolveCdnConfig = resolveCdnConfig;
1271
2339
  exports.resolveDoraConfig = resolveDoraConfig;
@@ -1275,3 +2343,5 @@ exports.setLogLevel = setLogLevel;
1275
2343
  exports.splitDoraCliConfig = splitDoraCliConfig;
1276
2344
  exports.splitDoraConfig = splitDoraConfig;
1277
2345
  exports.wholeDoraConfig = wholeDoraConfig;
2346
+ exports.wholeDoraConfigMw = wholeDoraConfigMw;
2347
+ exports.wholeDoraInoutMw = wholeDoraInoutMw;