@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.
@@ -1,10 +1,12 @@
1
- import * as _doracli_type from '@doracli/type';
2
- import { TTsConfig, TDoraConfig, TCdnConfigDefine, TPackageConfig, TDoraConfigDefine, TMode, TCdn, TModule } from '@doracli/type';
3
1
  import * as _cclr_lang from '@cclr/lang';
4
- import { TPlainObject, TAny, PartialRecursive } from '@cclr/lang';
2
+ import { TPlainObject, PartialRecursive, TAny } from '@cclr/lang';
3
+ import * as _doracli_type from '@doracli/type';
4
+ import { TTsConfig, TDoraConfig, TCdn, TPackageConfig, TMode, TDoraConfigDefine, TCdnConfigDefine, TModule } from '@doracli/type';
5
+ import { TOnionFun } from '@cclr/utils';
5
6
  import * as _doracli_type_src_dora_config_dts from '@doracli/type/src/dora-config-dts';
6
- import * as _doracli_type_src_dora_config_service from '@doracli/type/src/dora-config-service';
7
7
  import * as _doracli_type_src_dora_config_esbuild from '@doracli/type/src/dora-config-esbuild';
8
+ import * as _doracli_type_src_common from '@doracli/type/src/common';
9
+ import * as _doracli_type_src_dora_config_multiple from '@doracli/type/src/dora-config-multiple';
8
10
  export { default as picocolors } from 'picocolors';
9
11
 
10
12
  declare class ConfigCtx {
@@ -22,13 +24,31 @@ declare class ConfigCtx {
22
24
  getTsConfig(): TTsConfig;
23
25
  setDoraConfig(config: TDoraConfig): void;
24
26
  getDoraConfig(): TDoraConfig;
25
- setCdnConfig(config: TCdnConfigDefine): void;
26
- getCdnConfig(): Partial<Record<"headAfterScript" | "headAfterStyle" | "bodyBeforeScript" | "bodyAfterScript", string[] | ((mode: _doracli_type.TMode) => string[])>>;
27
+ setCdnConfig(config: TCdn): void;
28
+ getCdnConfig(): TCdn;
27
29
  setPackageConfig(config: TPackageConfig): void;
28
30
  getPackageConfig(): TPackageConfig;
29
31
  copy(): ConfigCtx;
30
32
  }
31
33
 
34
+ declare const clearMw: () => TOnionFun<ConfigCtx>;
35
+
36
+ declare const collectPackageJsonMw: () => TOnionFun<ConfigCtx>;
37
+ declare const collectTsconfigJsonMw: () => TOnionFun<ConfigCtx>;
38
+ declare const collectCdnConfigMw: (mode: TMode) => TOnionFun<ConfigCtx>;
39
+ declare const collectDoraConfigMw: (mode: TMode) => TOnionFun<ConfigCtx>;
40
+ declare const collectBaseConfigMw: (workRoot: string, cmd: TPlainObject) => TOnionFun<ConfigCtx>;
41
+
42
+ declare const wholeDoraConfigMw: (defaultConfig: PartialRecursive<TDoraConfig>) => TOnionFun<ConfigCtx>;
43
+
44
+ declare const wholeDoraInoutMw: () => TOnionFun<ConfigCtx>;
45
+
46
+ declare const configCtxWorkflow: <T extends TPlainObject>(config: T) => {
47
+ use(middleware: TOnionFun<T>): any;
48
+ getResult(): Promise<T>;
49
+ };
50
+ type TWorkflowApi<T extends TPlainObject> = ReturnType<typeof configCtxWorkflow<T>>;
51
+
32
52
  declare enum EnvEnum {
33
53
  dev = "development",
34
54
  prod = "production"
@@ -46,6 +66,7 @@ declare abstract class CompilerBase<T extends TPlainObject, R extends {
46
66
  output: (output: TPlainObject) => R['build'];
47
67
  }>;
48
68
  abstract context: (options: T) => Promise<{
69
+ compiler?: unknown;
49
70
  rebuild: () => R['build'];
50
71
  cancel: () => Promise<void>;
51
72
  }>;
@@ -54,6 +75,114 @@ declare abstract class CompilerBase<T extends TPlainObject, R extends {
54
75
  abstract server: (server: TPlainObject) => R['server'];
55
76
  }
56
77
 
78
+ interface IScriptOptions {
79
+ src: string;
80
+ async?: boolean;
81
+ defer?: boolean;
82
+ order?: number;
83
+ }
84
+ /**
85
+ * 动态html生成器
86
+ */
87
+ declare class DynamicHtml {
88
+ headScripts: IScriptOptions[];
89
+ bodyScripts: IScriptOptions[];
90
+ headStyles: IScriptOptions[];
91
+ headTags: string[];
92
+ bodyTags: string[];
93
+ addHeadScripts(scripts: IScriptOptions[], force?: boolean): void;
94
+ addBodyScripts(scripts: IScriptOptions[], force?: boolean): void;
95
+ addHeadStyles(styles: IScriptOptions[], force?: boolean): void;
96
+ addHeadTags(tags: string[], force?: boolean): void;
97
+ addBodyTags(tags: string[], force?: boolean): void;
98
+ copy(): DynamicHtml;
99
+ /**
100
+ * 序列化为html模板
101
+ * @param title
102
+ * @returns
103
+ */
104
+ generateHtmlTemplate(title?: string): string;
105
+ }
106
+
107
+ type TBundleAsset = {
108
+ name: string;
109
+ scripts: string[];
110
+ styles: string[];
111
+ runtimeChunks: string[];
112
+ };
113
+ declare class HtmlAssetManager {
114
+ publicPath: string;
115
+ private assetMap;
116
+ private dynamicHtml;
117
+ private initAwaitList;
118
+ assetList: string[];
119
+ constructor(publicPath?: string);
120
+ updateAssetList(assetList: string[], force?: boolean): void;
121
+ setAssetList(assetMap: Record<string, TBundleAsset>): void;
122
+ getAssetMap(): Record<string, TBundleAsset>;
123
+ getModuleAsset(moduleName: string): TBundleAsset;
124
+ getModuleHtml(moduleName: string): Promise<string>;
125
+ }
126
+
127
+ interface TParsedTagAttr {
128
+ name: string;
129
+ value: string | boolean;
130
+ }
131
+ interface TParsedTag {
132
+ tagName: string;
133
+ attrs?: TParsedTagAttr[];
134
+ selfClosing?: boolean;
135
+ /**
136
+ * 1. 标签内的文本
137
+ * 2. 子标签集合
138
+ */
139
+ children?: (TParsedTag | string)[];
140
+ }
141
+ declare class HtmlManage {
142
+ head: TParsedTag[];
143
+ body: TParsedTag[];
144
+ constructor(options?: {
145
+ head?: TParsedTag[];
146
+ body?: TParsedTag[];
147
+ });
148
+ addHead(tag: TParsedTag): this;
149
+ addHeads(tags: TParsedTag[]): this;
150
+ addBody(tag: TParsedTag): this;
151
+ addBodys(tags: TParsedTag[]): this;
152
+ parseHtmlByFile(filePath: string): this;
153
+ generateHtml(): string;
154
+ copy(): HtmlManage;
155
+ static parseHtml(html: string): {
156
+ head: TParsedTag[];
157
+ body: TParsedTag[];
158
+ };
159
+ }
160
+
161
+ /**
162
+ * 解析html
163
+ * 会解析 head body 下一层级的标签,子标签,已children保存
164
+ */
165
+ declare const parseHtml: (html: string) => {
166
+ head: TParsedTag[];
167
+ body: TParsedTag[];
168
+ };
169
+
170
+ declare class GenerateConfigHtml extends HtmlManage {
171
+ configCtx: ConfigCtx;
172
+ constructor(configCtx: ConfigCtx);
173
+ init(): Promise<this>;
174
+ addConfigCdn(): this;
175
+ /**
176
+ * 写入到文件,没有文件创建文件
177
+ * @param filePath 文件路径
178
+ * @returns
179
+ */
180
+ writeToFile(filePath: string): this;
181
+ addBodyScripts(scripts: string[]): this;
182
+ addHeadStyles(styles: string[]): this;
183
+ copy(): GenerateConfigHtml;
184
+ }
185
+
57
186
  /**
58
187
  * 在制定目录下插入 tsconfig.json 文件
59
188
  * @param cwd
@@ -76,25 +205,25 @@ declare const setLogLevel: (lvl: number) => void;
76
205
  * @param msg 消息
77
206
  * @returns
78
207
  */
79
- declare const cLogDebugger: (mode: string, status: string, ...msg: string[]) => void;
208
+ declare const cLogDebugger: (mode: string, status: string, ...msg: TAny[]) => void;
80
209
  /**
81
210
  * @param mode 模式
82
211
  * @param status 状态
83
212
  * @param msg 消息
84
213
  * @returns
85
214
  */
86
- declare const cLogMessage: (mode: string, status: string, ...msg: string[]) => void;
87
- declare const cLogSuccess: (mode: string, status: string, ...msg: string[]) => void;
88
- declare const cLogWarn: (mode: "serve" | "build" | string, status: string, ...msg: string[]) => void;
89
- declare const cLogError: (mode: string, status: string, ...msg: string[]) => void;
215
+ declare const cLogMessage: (mode: string, status: string, ...msg: TAny[]) => void;
216
+ declare const cLogSuccess: (mode: string, status: string, ...msg: TAny[]) => void;
217
+ declare const cLogWarn: (mode: "serve" | "build" | string, status: string, ...msg: TAny[]) => void;
218
+ declare const cLogError: (mode: string, status: string, ...msg: TAny[]) => void;
90
219
  declare const cLogTime: (key?: string) => () => void;
91
220
  declare const cLogTimeEnd: (key: string) => void;
92
221
  declare const cLog: {
93
- log: (mode: string, status: string, ...msg: string[]) => void;
94
- debug: (mode: string, status: string, ...msg: string[]) => void;
95
- error: (mode: string, status: string, ...msg: string[]) => void;
96
- warn: (mode: "serve" | "build" | string, status: string, ...msg: string[]) => void;
97
- info: (mode: string, status: string, ...msg: string[]) => void;
222
+ log: (mode: string, status: string, ...msg: TAny[]) => void;
223
+ debug: (mode: string, status: string, ...msg: TAny[]) => void;
224
+ error: (mode: string, status: string, ...msg: TAny[]) => void;
225
+ warn: (mode: "serve" | "build" | string, status: string, ...msg: TAny[]) => void;
226
+ info: (mode: string, status: string, ...msg: TAny[]) => void;
98
227
  time: (key?: string) => () => void;
99
228
  timeEnd: (key: string) => void;
100
229
  };
@@ -120,18 +249,14 @@ declare const getTsconfigJson: (root: string) => Promise<any>;
120
249
  */
121
250
  declare function getUserCdn(root: string): Promise<TCdnConfigDefine | null>;
122
251
 
123
- declare const mergeDoraCliConfig: <T extends PartialRecursive<TDoraConfig>>(target: T, source?: T) => Omit<T, "output"> & {
124
- output: {
125
- file?: string;
126
- path?: string | undefined;
127
- };
128
- };
252
+ declare const mergeDoraCliConfig: <T extends PartialRecursive<TDoraConfig>>(target: T, source?: T) => T;
129
253
  /**
130
254
  * 合并多个配置项
131
255
  * @param target 配置项,可多个,后面的配置项会覆盖前面的配置项
132
256
  * @returns
133
257
  */
134
258
  declare const mergeDoraCliConfigMutiple: <T extends PartialRecursive<TDoraConfig>>(...target: T[]) => T;
259
+ declare const deepMergeObject: <T extends TPlainObject>(target: T, source: T) => T;
135
260
 
136
261
  /**
137
262
  * 获取cdn文件配置
@@ -155,13 +280,17 @@ declare const parseDoracliConfig: (userConfig: TDoraConfigDefine | null, mode: T
155
280
  * @returns
156
281
  */
157
282
  declare const splitDoraCliConfig: (config: TDoraConfig) => {
283
+ name: string;
284
+ type: _doracli_type.TConfigType;
158
285
  input: string;
159
286
  output: _doracli_type.TOutput;
160
- formatList: _doracli_type.TModule[];
287
+ lib: _doracli_type.TLib;
161
288
  format: _doracli_type.TModule;
289
+ libList: _doracli_type.TLib[];
290
+ formatList: _doracli_type.TModule[];
162
291
  clear: boolean;
163
292
  minimize: boolean;
164
- externals: string[];
293
+ externals: string[] | _doracli_type_src_common.TPlainObject[];
165
294
  internals: string[];
166
295
  alias: Record<string, string>;
167
296
  dts: {
@@ -176,7 +305,7 @@ declare const splitDoraCliConfig: (config: TDoraConfig) => {
176
305
  rspackConfig?: _doracli_type.TDoraConfigWebpack;
177
306
  rollupConfig?: _doracli_type.TDoraConfigRollup;
178
307
  esbuildConfig?: _doracli_type_src_dora_config_esbuild.TDoraConfigEsbuild;
179
- serviceConfig?: _doracli_type_src_dora_config_service.TDoraConfigService;
308
+ serviceConfig?: Partial<_doracli_type.TDoraConfigService>;
180
309
  dtsConfig?: _doracli_type_src_dora_config_dts.TDoraConfigDts;
181
310
  }[] | PartialRecursive<TDoraConfig>[];
182
311
 
@@ -185,6 +314,8 @@ declare const wholeDoraConfig: (config: PartialRecursive<TDoraConfig>, workRootD
185
314
  declare const inputFileDirList: string[];
186
315
  declare const inputFileTypeList: string[];
187
316
  declare const findInput: (workRootDir: string) => string;
317
+ declare const inputHtmlFileDirList: string[];
318
+ declare const findInputHtml: (workRootDir: string) => string;
188
319
 
189
320
  /**
190
321
  * 获取tsconfig.json里的paths,作为项目路径别名
@@ -207,7 +338,7 @@ declare const collectConfig: (configCtx: ConfigCtx, mode: TMode, presetConfig?:
207
338
  * 获取cdn文件配置
208
339
  * @returns
209
340
  */
210
- declare function resolveCdnConfig(workRootDir: string, mode: TMode): Promise<{} | undefined>;
341
+ declare function resolveCdnConfig(workRootDir: string, mode: TMode): Promise<TCdn | undefined>;
211
342
 
212
343
  declare const resolveDoraConfig: (workRootDir: string, mode: TMode) => Promise<_cclr_lang.PartialRecursive<_doracli_type.TDoraConfig> | null>;
213
344
 
@@ -246,6 +377,12 @@ declare const configCtxCollect: (configCtx: ConfigCtx, params: {
246
377
  cmd?: TPlainObject;
247
378
  } & TParseConfigResult) => Promise<void>;
248
379
 
380
+ /**
381
+ * 创建环境参数
382
+ * @description 会自动处理出绝对路径的 workRootDir
383
+ * @param params 上下文变量
384
+ * @returns
385
+ */
249
386
  declare const createEnvParams: <T extends TPlainObject>(params: T) => T;
250
387
 
251
388
  type TOutputSingle = {
@@ -260,14 +397,41 @@ type TOutputSingle = {
260
397
  };
261
398
  declare const createOutputList: (config: TDoraConfig) => TOutputSingle[];
262
399
 
263
- declare const splitDoraConfig: (config: TDoraConfig) => PartialRecursive<TDoraConfig>[] | {
400
+ /**
401
+ * 依赖项过滤
402
+ * @param options 过滤选项
403
+ * @param strategy 规则冲突时,过滤策略 include-包含 | exclude-排除,默认排除
404
+ * @returns 依赖过滤函数 () => boolean 返回true表示 - 属于排除范围
405
+ */
406
+ declare const createDependFilter: (options: {
407
+ externals?: TDoraConfig["externals"];
408
+ internals?: TDoraConfig["internals"];
409
+ dependencies?: Record<string, string>;
410
+ peerDependencies?: Record<string, string>;
411
+ devDependencies?: Record<string, string>;
412
+ /**
413
+ * 判断模块名是否相等,默认是使用 targetId.startsWith(moduleRuleId) 进行判断
414
+ * @param targetId 代码中使用的模块名
415
+ * @param moduleRuleId 规则中的模块名
416
+ * @returns true 相等
417
+ */
418
+ compare?: (targetId: string, moduleRuleId: string) => boolean;
419
+ }, strategy?: "include" | "exclude") => (id: string) => string | false;
420
+
421
+ declare const getDefaultHtml: (workRootDir: string) => Promise<string>;
422
+
423
+ declare const splitDoraConfig: (config: TDoraConfig) => PartialRecursive<TDoraConfig>[] | _doracli_type_src_dora_config_multiple.TDoraConfigMultiple[] | {
424
+ name: string;
425
+ type: _doracli_type.TConfigType;
264
426
  input: string;
265
427
  output: _doracli_type.TOutput;
266
- formatList: _doracli_type.TModule[];
428
+ lib: _doracli_type.TLib;
267
429
  format: _doracli_type.TModule;
430
+ libList: _doracli_type.TLib[];
431
+ formatList: _doracli_type.TModule[];
268
432
  clear: boolean;
269
433
  minimize: boolean;
270
- externals: string[];
434
+ externals: string[] | _doracli_type_src_common.TPlainObject[];
271
435
  internals: string[];
272
436
  alias: Record<string, string>;
273
437
  dts: {
@@ -282,9 +446,9 @@ declare const splitDoraConfig: (config: TDoraConfig) => PartialRecursive<TDoraCo
282
446
  rspackConfig?: _doracli_type.TDoraConfigWebpack;
283
447
  rollupConfig?: _doracli_type.TDoraConfigRollup;
284
448
  esbuildConfig?: _doracli_type_src_dora_config_esbuild.TDoraConfigEsbuild;
285
- serviceConfig?: _doracli_type_src_dora_config_service.TDoraConfigService;
449
+ serviceConfig?: Partial<_doracli_type.TDoraConfigService>;
286
450
  dtsConfig?: _doracli_type_src_dora_config_dts.TDoraConfigDts;
287
451
  }[];
288
452
 
289
- 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 };
290
- export type { TCollectType, TOutputSingle, TParseConfigResult };
453
+ 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, 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 };
454
+ export type { IScriptOptions, TBundleAsset, TCollectType, TOutputSingle, TParseConfigResult, TParsedTag, TParsedTagAttr, TWorkflowApi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doracli/helper",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "use helper",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -29,16 +29,16 @@
29
29
  "g:build": "drn build"
30
30
  },
31
31
  "dependencies": {
32
- "@cclr/lang": "^0.1.28",
33
- "@cclr/utils": "^0.1.28",
34
- "@dorabag/config-loader": "^1.0.11",
32
+ "@cclr/lang": "^0.1.44",
33
+ "@cclr/utils": "^0.1.44",
34
+ "@dorabag/config-loader": "^1.0.16",
35
35
  "@dorabag/file-pro": "^1.0.10",
36
- "@dorabag/open-browser": "^1.0.10",
37
- "@dorabag/srv-tool": "^1.0.10",
38
- "@doracli/type": "^0.0.2",
36
+ "@dorabag/open-browser": "^1.0.16",
37
+ "@dorabag/srv-tool": "^1.0.16",
38
+ "@doracli/type": "^0.0.4",
39
39
  "picocolors": "^1.1.1",
40
- "webpack": "^5.102.1",
40
+ "webpack": "^5.104.0",
41
41
  "webpack-dev-server": "^5.2.2"
42
42
  },
43
- "gitHead": "912cb44292b64679630a799974d18c22b2e69738"
43
+ "gitHead": "a978bb7e7b32c192b1eb527dae5f25bbe1a2af86"
44
44
  }