@doracli/helper 0.0.3 → 0.0.5

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