@meng-xi/vite-plugin 0.1.0 → 0.1.1

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.
Files changed (105) hide show
  1. package/README-en.md +170 -49
  2. package/README.md +149 -29
  3. package/dist/common/format/index.cjs +1 -0
  4. package/dist/common/format/index.d.cts +156 -0
  5. package/dist/common/format/index.d.mts +156 -0
  6. package/dist/common/format/index.d.ts +156 -0
  7. package/dist/common/format/index.mjs +1 -0
  8. package/dist/common/fs/index.cjs +1 -0
  9. package/dist/common/fs/index.d.cts +150 -0
  10. package/dist/common/fs/index.d.mts +150 -0
  11. package/dist/common/fs/index.d.ts +150 -0
  12. package/dist/common/fs/index.mjs +1 -0
  13. package/dist/common/html/index.cjs +2 -0
  14. package/dist/common/html/index.d.cts +109 -0
  15. package/dist/common/html/index.d.mts +109 -0
  16. package/dist/common/html/index.d.ts +109 -0
  17. package/dist/common/html/index.mjs +2 -0
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +7 -417
  20. package/dist/common/index.d.mts +7 -417
  21. package/dist/common/index.d.ts +7 -417
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/object/index.cjs +1 -0
  24. package/dist/common/object/index.d.cts +30 -0
  25. package/dist/common/object/index.d.mts +30 -0
  26. package/dist/common/object/index.d.ts +30 -0
  27. package/dist/common/object/index.mjs +1 -0
  28. package/dist/common/script/index.cjs +1 -0
  29. package/dist/common/script/index.d.cts +54 -0
  30. package/dist/common/script/index.d.mts +54 -0
  31. package/dist/common/script/index.d.ts +54 -0
  32. package/dist/common/script/index.mjs +1 -0
  33. package/dist/common/validation/index.cjs +1 -0
  34. package/dist/common/validation/index.d.cts +93 -0
  35. package/dist/common/validation/index.d.mts +93 -0
  36. package/dist/common/validation/index.d.ts +93 -0
  37. package/dist/common/validation/index.mjs +1 -0
  38. package/dist/factory/index.cjs +1 -1
  39. package/dist/factory/index.d.cts +1 -1
  40. package/dist/factory/index.d.mts +1 -1
  41. package/dist/factory/index.d.ts +1 -1
  42. package/dist/factory/index.mjs +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.cts +15 -3
  45. package/dist/index.d.mts +15 -3
  46. package/dist/index.d.ts +15 -3
  47. package/dist/index.mjs +1 -1
  48. package/dist/plugins/buildProgress/index.cjs +2 -0
  49. package/dist/plugins/buildProgress/index.d.cts +187 -0
  50. package/dist/plugins/buildProgress/index.d.mts +187 -0
  51. package/dist/plugins/buildProgress/index.d.ts +187 -0
  52. package/dist/plugins/buildProgress/index.mjs +2 -0
  53. package/dist/plugins/copyFile/index.cjs +1 -0
  54. package/dist/plugins/copyFile/index.d.cts +78 -0
  55. package/dist/plugins/copyFile/index.d.mts +78 -0
  56. package/dist/plugins/copyFile/index.d.ts +78 -0
  57. package/dist/plugins/copyFile/index.mjs +1 -0
  58. package/dist/plugins/faviconManager/index.cjs +1 -0
  59. package/dist/plugins/faviconManager/index.d.cts +143 -0
  60. package/dist/plugins/faviconManager/index.d.mts +143 -0
  61. package/dist/plugins/faviconManager/index.d.ts +143 -0
  62. package/dist/plugins/faviconManager/index.mjs +1 -0
  63. package/dist/plugins/generateRouter/index.cjs +35 -0
  64. package/dist/plugins/generateRouter/index.d.cts +215 -0
  65. package/dist/plugins/generateRouter/index.d.mts +215 -0
  66. package/dist/plugins/generateRouter/index.d.ts +215 -0
  67. package/dist/plugins/generateRouter/index.mjs +35 -0
  68. package/dist/plugins/generateVersion/index.cjs +1 -0
  69. package/dist/plugins/generateVersion/index.d.cts +184 -0
  70. package/dist/plugins/generateVersion/index.d.mts +184 -0
  71. package/dist/plugins/generateVersion/index.d.ts +184 -0
  72. package/dist/plugins/generateVersion/index.mjs +1 -0
  73. package/dist/plugins/htmlInject/index.cjs +7 -0
  74. package/dist/plugins/htmlInject/index.d.cts +278 -0
  75. package/dist/plugins/htmlInject/index.d.mts +278 -0
  76. package/dist/plugins/htmlInject/index.d.ts +278 -0
  77. package/dist/plugins/htmlInject/index.mjs +7 -0
  78. package/dist/plugins/index.cjs +1 -1
  79. package/dist/plugins/index.d.cts +10 -1714
  80. package/dist/plugins/index.d.mts +10 -1714
  81. package/dist/plugins/index.d.ts +10 -1714
  82. package/dist/plugins/index.mjs +1 -1
  83. package/dist/plugins/loadingManager/index.cjs +487 -0
  84. package/dist/plugins/loadingManager/index.d.cts +769 -0
  85. package/dist/plugins/loadingManager/index.d.mts +769 -0
  86. package/dist/plugins/loadingManager/index.d.ts +769 -0
  87. package/dist/plugins/loadingManager/index.mjs +487 -0
  88. package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
  89. package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
  90. package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
  91. package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
  92. package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
  93. package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
  94. package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.cts} +50 -0
  95. package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.mts} +50 -0
  96. package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.ts} +50 -0
  97. package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
  98. package/package.json +72 -2
  99. package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
  100. package/dist/shared/vite-plugin.D6Law9Ke.mjs +0 -706
  101. package/dist/shared/vite-plugin.D8L9KzuW.cjs +0 -706
  102. package/dist/shared/vite-plugin.DFjf9wFM.mjs +0 -2
  103. package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
  104. package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
  105. package/dist/shared/vite-plugin.Tab4qcIM.cjs +0 -2
@@ -0,0 +1,187 @@
1
+ import { BasePluginOptions, PluginFactory } from '../../factory/index.cjs';
2
+ import 'vite';
3
+ import '../../shared/vite-plugin.CLr0ttuO.cjs';
4
+ import '../../shared/vite-plugin.DRRlWY8P.cjs';
5
+
6
+ /**
7
+ * 进度条显示格式类型
8
+ *
9
+ * @description
10
+ * - 'bar': 完整进度条模式,显示旋转动画 + 阶段标签 + 进度条 + 百分比 + 模块名
11
+ * - 'spinner': 旋转动画模式,显示旋转动画 + 阶段标签 + 百分比
12
+ * - 'minimal': 精简模式,仅显示阶段标签 + 百分比
13
+ */
14
+ type ProgressFormat = 'bar' | 'spinner' | 'minimal';
15
+ /**
16
+ * 构建进度插件的配置选项接口
17
+ *
18
+ * @interface BuildProgressOptions
19
+ */
20
+ interface BuildProgressOptions extends BasePluginOptions {
21
+ /**
22
+ * 进度条宽度(字符数)
23
+ *
24
+ * @default 30
25
+ */
26
+ width?: number;
27
+ /**
28
+ * 进度条显示格式
29
+ *
30
+ * @default 'bar'
31
+ */
32
+ format?: ProgressFormat;
33
+ /**
34
+ * 已完成部分的填充字符
35
+ *
36
+ * @default '█'
37
+ * @example '█'、'■'、'='
38
+ */
39
+ completeChar?: string;
40
+ /**
41
+ * 未完成部分的填充字符
42
+ *
43
+ * @default '░'
44
+ * @example '░'、'□'、'-'
45
+ */
46
+ incompleteChar?: string;
47
+ /**
48
+ * 构建完成后是否清除进度条
49
+ *
50
+ * @default true
51
+ * @description 设为 false 时,构建完成后保留 100% 进度条在终端中
52
+ */
53
+ clearOnComplete?: boolean;
54
+ /**
55
+ * 是否显示当前正在处理的模块名称
56
+ *
57
+ * @default true
58
+ * @description 仅在 transform 阶段显示,模块名超长时自动截断
59
+ */
60
+ showModuleName?: boolean;
61
+ /**
62
+ * 自定义颜色主题
63
+ *
64
+ * @remarks
65
+ * 每个属性是一个接受字符串并返回带 ANSI 颜色码字符串的函数。
66
+ * 未提供的属性将使用默认主题。
67
+ */
68
+ theme?: ProgressTheme;
69
+ }
70
+ /**
71
+ * 进度条颜色主题接口
72
+ *
73
+ * @interface ProgressTheme
74
+ * @description 定义进度条各部分的颜色渲染函数,每个函数接受文本并返回带 ANSI 颜色码的字符串
75
+ */
76
+ interface ProgressTheme {
77
+ /**
78
+ * 已完成部分的颜色渲染函数
79
+ *
80
+ * @param text - 需要着色的文本
81
+ * @returns 带 ANSI 颜色码的字符串
82
+ */
83
+ completeColor: (text: string) => string;
84
+ /**
85
+ * 未完成部分的颜色渲染函数
86
+ *
87
+ * @param text - 需要着色的文本
88
+ * @returns 带 ANSI 颜色码的字符串
89
+ */
90
+ incompleteColor: (text: string) => string;
91
+ /**
92
+ * 百分比数字的颜色渲染函数
93
+ *
94
+ * @param text - 需要着色的文本
95
+ * @returns 带 ANSI 颜色码的字符串
96
+ */
97
+ percentageColor: (text: string) => string;
98
+ /**
99
+ * 阶段标签的颜色渲染函数
100
+ *
101
+ * @param text - 需要着色的文本
102
+ * @returns 带 ANSI 颜色码的字符串
103
+ */
104
+ phaseColor: (text: string) => string;
105
+ /**
106
+ * 模块名称的颜色渲染函数
107
+ *
108
+ * @param text - 需要着色的文本
109
+ * @returns 带 ANSI 颜色码的字符串
110
+ */
111
+ moduleColor: (text: string) => string;
112
+ }
113
+ /**
114
+ * 构建阶段类型
115
+ *
116
+ * @description
117
+ * - 'idle': 空闲状态,插件尚未开始工作
118
+ * - 'config': 读取配置阶段
119
+ * - 'resolve': 解析模块依赖阶段
120
+ * - 'transform': 转换模块阶段
121
+ * - 'bundle': 打包阶段(仅生产构建)
122
+ * - 'write': 写入文件阶段
123
+ * - 'done': 构建完成
124
+ */
125
+ type BuildPhase = 'idle' | 'config' | 'resolve' | 'transform' | 'bundle' | 'write' | 'done';
126
+
127
+ /**
128
+ * 构建进度条插件
129
+ *
130
+ * @param {BuildProgressOptions} options - 插件配置选项
131
+ * @returns {Plugin} 一个 Vite 插件实例
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // 基本使用 - 默认进度条格式
136
+ * buildProgress()
137
+ *
138
+ * // 旋转动画格式
139
+ * buildProgress({
140
+ * format: 'spinner'
141
+ * })
142
+ *
143
+ * // 精简格式
144
+ * buildProgress({
145
+ * format: 'minimal'
146
+ * })
147
+ *
148
+ * // 自定义进度条外观
149
+ * buildProgress({
150
+ * width: 40,
151
+ * completeChar: '■',
152
+ * incompleteChar: '□',
153
+ * clearOnComplete: false
154
+ * })
155
+ *
156
+ * // 自定义颜色主题
157
+ * buildProgress({
158
+ * theme: {
159
+ * completeColor: (t) => `\x1b[32m${t}\x1b[39m`,
160
+ * incompleteColor: (t) => `\x1b[90m${t}\x1b[39m`,
161
+ * percentageColor: (t) => `\x1b[1m${t}\x1b[22m`,
162
+ * phaseColor: (t) => `\x1b[36m${t}\x1b[39m`,
163
+ * moduleColor: (t) => `\x1b[90m${t}\x1b[39m`
164
+ * }
165
+ * })
166
+ *
167
+ * // 禁用模块名显示
168
+ * buildProgress({
169
+ * showModuleName: false
170
+ * })
171
+ * ```
172
+ *
173
+ * @remarks
174
+ * 该插件在 Vite 构建过程中实时显示终端进度条,支持三种显示格式:
175
+ * - bar: 完整进度条(默认),包含旋转动画、阶段标签、进度条和百分比
176
+ * - spinner: 旋转动画模式,仅显示动画、阶段标签和百分比
177
+ * - minimal: 精简模式,仅显示阶段标签和百分比
178
+ *
179
+ * 进度计算基于 Vite 构建生命周期:
180
+ * 1. config 阶段(5%)→ resolve 阶段(10%)→ transform 阶段(15%-85%)→ bundle 阶段(+10%)→ write 阶段(+5%)→ 完成(100%)
181
+ *
182
+ * 在非 TTY 终端环境下(如 CI/CD),自动降级为日志输出模式。
183
+ */
184
+ declare const buildProgress: PluginFactory<BuildProgressOptions, BuildProgressOptions>;
185
+
186
+ export { buildProgress };
187
+ export type { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme };
@@ -0,0 +1,187 @@
1
+ import { BasePluginOptions, PluginFactory } from '../../factory/index.mjs';
2
+ import 'vite';
3
+ import '../../shared/vite-plugin.CLr0ttuO.mjs';
4
+ import '../../shared/vite-plugin.DRRlWY8P.mjs';
5
+
6
+ /**
7
+ * 进度条显示格式类型
8
+ *
9
+ * @description
10
+ * - 'bar': 完整进度条模式,显示旋转动画 + 阶段标签 + 进度条 + 百分比 + 模块名
11
+ * - 'spinner': 旋转动画模式,显示旋转动画 + 阶段标签 + 百分比
12
+ * - 'minimal': 精简模式,仅显示阶段标签 + 百分比
13
+ */
14
+ type ProgressFormat = 'bar' | 'spinner' | 'minimal';
15
+ /**
16
+ * 构建进度插件的配置选项接口
17
+ *
18
+ * @interface BuildProgressOptions
19
+ */
20
+ interface BuildProgressOptions extends BasePluginOptions {
21
+ /**
22
+ * 进度条宽度(字符数)
23
+ *
24
+ * @default 30
25
+ */
26
+ width?: number;
27
+ /**
28
+ * 进度条显示格式
29
+ *
30
+ * @default 'bar'
31
+ */
32
+ format?: ProgressFormat;
33
+ /**
34
+ * 已完成部分的填充字符
35
+ *
36
+ * @default '█'
37
+ * @example '█'、'■'、'='
38
+ */
39
+ completeChar?: string;
40
+ /**
41
+ * 未完成部分的填充字符
42
+ *
43
+ * @default '░'
44
+ * @example '░'、'□'、'-'
45
+ */
46
+ incompleteChar?: string;
47
+ /**
48
+ * 构建完成后是否清除进度条
49
+ *
50
+ * @default true
51
+ * @description 设为 false 时,构建完成后保留 100% 进度条在终端中
52
+ */
53
+ clearOnComplete?: boolean;
54
+ /**
55
+ * 是否显示当前正在处理的模块名称
56
+ *
57
+ * @default true
58
+ * @description 仅在 transform 阶段显示,模块名超长时自动截断
59
+ */
60
+ showModuleName?: boolean;
61
+ /**
62
+ * 自定义颜色主题
63
+ *
64
+ * @remarks
65
+ * 每个属性是一个接受字符串并返回带 ANSI 颜色码字符串的函数。
66
+ * 未提供的属性将使用默认主题。
67
+ */
68
+ theme?: ProgressTheme;
69
+ }
70
+ /**
71
+ * 进度条颜色主题接口
72
+ *
73
+ * @interface ProgressTheme
74
+ * @description 定义进度条各部分的颜色渲染函数,每个函数接受文本并返回带 ANSI 颜色码的字符串
75
+ */
76
+ interface ProgressTheme {
77
+ /**
78
+ * 已完成部分的颜色渲染函数
79
+ *
80
+ * @param text - 需要着色的文本
81
+ * @returns 带 ANSI 颜色码的字符串
82
+ */
83
+ completeColor: (text: string) => string;
84
+ /**
85
+ * 未完成部分的颜色渲染函数
86
+ *
87
+ * @param text - 需要着色的文本
88
+ * @returns 带 ANSI 颜色码的字符串
89
+ */
90
+ incompleteColor: (text: string) => string;
91
+ /**
92
+ * 百分比数字的颜色渲染函数
93
+ *
94
+ * @param text - 需要着色的文本
95
+ * @returns 带 ANSI 颜色码的字符串
96
+ */
97
+ percentageColor: (text: string) => string;
98
+ /**
99
+ * 阶段标签的颜色渲染函数
100
+ *
101
+ * @param text - 需要着色的文本
102
+ * @returns 带 ANSI 颜色码的字符串
103
+ */
104
+ phaseColor: (text: string) => string;
105
+ /**
106
+ * 模块名称的颜色渲染函数
107
+ *
108
+ * @param text - 需要着色的文本
109
+ * @returns 带 ANSI 颜色码的字符串
110
+ */
111
+ moduleColor: (text: string) => string;
112
+ }
113
+ /**
114
+ * 构建阶段类型
115
+ *
116
+ * @description
117
+ * - 'idle': 空闲状态,插件尚未开始工作
118
+ * - 'config': 读取配置阶段
119
+ * - 'resolve': 解析模块依赖阶段
120
+ * - 'transform': 转换模块阶段
121
+ * - 'bundle': 打包阶段(仅生产构建)
122
+ * - 'write': 写入文件阶段
123
+ * - 'done': 构建完成
124
+ */
125
+ type BuildPhase = 'idle' | 'config' | 'resolve' | 'transform' | 'bundle' | 'write' | 'done';
126
+
127
+ /**
128
+ * 构建进度条插件
129
+ *
130
+ * @param {BuildProgressOptions} options - 插件配置选项
131
+ * @returns {Plugin} 一个 Vite 插件实例
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // 基本使用 - 默认进度条格式
136
+ * buildProgress()
137
+ *
138
+ * // 旋转动画格式
139
+ * buildProgress({
140
+ * format: 'spinner'
141
+ * })
142
+ *
143
+ * // 精简格式
144
+ * buildProgress({
145
+ * format: 'minimal'
146
+ * })
147
+ *
148
+ * // 自定义进度条外观
149
+ * buildProgress({
150
+ * width: 40,
151
+ * completeChar: '■',
152
+ * incompleteChar: '□',
153
+ * clearOnComplete: false
154
+ * })
155
+ *
156
+ * // 自定义颜色主题
157
+ * buildProgress({
158
+ * theme: {
159
+ * completeColor: (t) => `\x1b[32m${t}\x1b[39m`,
160
+ * incompleteColor: (t) => `\x1b[90m${t}\x1b[39m`,
161
+ * percentageColor: (t) => `\x1b[1m${t}\x1b[22m`,
162
+ * phaseColor: (t) => `\x1b[36m${t}\x1b[39m`,
163
+ * moduleColor: (t) => `\x1b[90m${t}\x1b[39m`
164
+ * }
165
+ * })
166
+ *
167
+ * // 禁用模块名显示
168
+ * buildProgress({
169
+ * showModuleName: false
170
+ * })
171
+ * ```
172
+ *
173
+ * @remarks
174
+ * 该插件在 Vite 构建过程中实时显示终端进度条,支持三种显示格式:
175
+ * - bar: 完整进度条(默认),包含旋转动画、阶段标签、进度条和百分比
176
+ * - spinner: 旋转动画模式,仅显示动画、阶段标签和百分比
177
+ * - minimal: 精简模式,仅显示阶段标签和百分比
178
+ *
179
+ * 进度计算基于 Vite 构建生命周期:
180
+ * 1. config 阶段(5%)→ resolve 阶段(10%)→ transform 阶段(15%-85%)→ bundle 阶段(+10%)→ write 阶段(+5%)→ 完成(100%)
181
+ *
182
+ * 在非 TTY 终端环境下(如 CI/CD),自动降级为日志输出模式。
183
+ */
184
+ declare const buildProgress: PluginFactory<BuildProgressOptions, BuildProgressOptions>;
185
+
186
+ export { buildProgress };
187
+ export type { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme };
@@ -0,0 +1,187 @@
1
+ import { BasePluginOptions, PluginFactory } from '../../factory/index.js';
2
+ import 'vite';
3
+ import '../../shared/vite-plugin.CLr0ttuO.js';
4
+ import '../../shared/vite-plugin.DRRlWY8P.js';
5
+
6
+ /**
7
+ * 进度条显示格式类型
8
+ *
9
+ * @description
10
+ * - 'bar': 完整进度条模式,显示旋转动画 + 阶段标签 + 进度条 + 百分比 + 模块名
11
+ * - 'spinner': 旋转动画模式,显示旋转动画 + 阶段标签 + 百分比
12
+ * - 'minimal': 精简模式,仅显示阶段标签 + 百分比
13
+ */
14
+ type ProgressFormat = 'bar' | 'spinner' | 'minimal';
15
+ /**
16
+ * 构建进度插件的配置选项接口
17
+ *
18
+ * @interface BuildProgressOptions
19
+ */
20
+ interface BuildProgressOptions extends BasePluginOptions {
21
+ /**
22
+ * 进度条宽度(字符数)
23
+ *
24
+ * @default 30
25
+ */
26
+ width?: number;
27
+ /**
28
+ * 进度条显示格式
29
+ *
30
+ * @default 'bar'
31
+ */
32
+ format?: ProgressFormat;
33
+ /**
34
+ * 已完成部分的填充字符
35
+ *
36
+ * @default '█'
37
+ * @example '█'、'■'、'='
38
+ */
39
+ completeChar?: string;
40
+ /**
41
+ * 未完成部分的填充字符
42
+ *
43
+ * @default '░'
44
+ * @example '░'、'□'、'-'
45
+ */
46
+ incompleteChar?: string;
47
+ /**
48
+ * 构建完成后是否清除进度条
49
+ *
50
+ * @default true
51
+ * @description 设为 false 时,构建完成后保留 100% 进度条在终端中
52
+ */
53
+ clearOnComplete?: boolean;
54
+ /**
55
+ * 是否显示当前正在处理的模块名称
56
+ *
57
+ * @default true
58
+ * @description 仅在 transform 阶段显示,模块名超长时自动截断
59
+ */
60
+ showModuleName?: boolean;
61
+ /**
62
+ * 自定义颜色主题
63
+ *
64
+ * @remarks
65
+ * 每个属性是一个接受字符串并返回带 ANSI 颜色码字符串的函数。
66
+ * 未提供的属性将使用默认主题。
67
+ */
68
+ theme?: ProgressTheme;
69
+ }
70
+ /**
71
+ * 进度条颜色主题接口
72
+ *
73
+ * @interface ProgressTheme
74
+ * @description 定义进度条各部分的颜色渲染函数,每个函数接受文本并返回带 ANSI 颜色码的字符串
75
+ */
76
+ interface ProgressTheme {
77
+ /**
78
+ * 已完成部分的颜色渲染函数
79
+ *
80
+ * @param text - 需要着色的文本
81
+ * @returns 带 ANSI 颜色码的字符串
82
+ */
83
+ completeColor: (text: string) => string;
84
+ /**
85
+ * 未完成部分的颜色渲染函数
86
+ *
87
+ * @param text - 需要着色的文本
88
+ * @returns 带 ANSI 颜色码的字符串
89
+ */
90
+ incompleteColor: (text: string) => string;
91
+ /**
92
+ * 百分比数字的颜色渲染函数
93
+ *
94
+ * @param text - 需要着色的文本
95
+ * @returns 带 ANSI 颜色码的字符串
96
+ */
97
+ percentageColor: (text: string) => string;
98
+ /**
99
+ * 阶段标签的颜色渲染函数
100
+ *
101
+ * @param text - 需要着色的文本
102
+ * @returns 带 ANSI 颜色码的字符串
103
+ */
104
+ phaseColor: (text: string) => string;
105
+ /**
106
+ * 模块名称的颜色渲染函数
107
+ *
108
+ * @param text - 需要着色的文本
109
+ * @returns 带 ANSI 颜色码的字符串
110
+ */
111
+ moduleColor: (text: string) => string;
112
+ }
113
+ /**
114
+ * 构建阶段类型
115
+ *
116
+ * @description
117
+ * - 'idle': 空闲状态,插件尚未开始工作
118
+ * - 'config': 读取配置阶段
119
+ * - 'resolve': 解析模块依赖阶段
120
+ * - 'transform': 转换模块阶段
121
+ * - 'bundle': 打包阶段(仅生产构建)
122
+ * - 'write': 写入文件阶段
123
+ * - 'done': 构建完成
124
+ */
125
+ type BuildPhase = 'idle' | 'config' | 'resolve' | 'transform' | 'bundle' | 'write' | 'done';
126
+
127
+ /**
128
+ * 构建进度条插件
129
+ *
130
+ * @param {BuildProgressOptions} options - 插件配置选项
131
+ * @returns {Plugin} 一个 Vite 插件实例
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // 基本使用 - 默认进度条格式
136
+ * buildProgress()
137
+ *
138
+ * // 旋转动画格式
139
+ * buildProgress({
140
+ * format: 'spinner'
141
+ * })
142
+ *
143
+ * // 精简格式
144
+ * buildProgress({
145
+ * format: 'minimal'
146
+ * })
147
+ *
148
+ * // 自定义进度条外观
149
+ * buildProgress({
150
+ * width: 40,
151
+ * completeChar: '■',
152
+ * incompleteChar: '□',
153
+ * clearOnComplete: false
154
+ * })
155
+ *
156
+ * // 自定义颜色主题
157
+ * buildProgress({
158
+ * theme: {
159
+ * completeColor: (t) => `\x1b[32m${t}\x1b[39m`,
160
+ * incompleteColor: (t) => `\x1b[90m${t}\x1b[39m`,
161
+ * percentageColor: (t) => `\x1b[1m${t}\x1b[22m`,
162
+ * phaseColor: (t) => `\x1b[36m${t}\x1b[39m`,
163
+ * moduleColor: (t) => `\x1b[90m${t}\x1b[39m`
164
+ * }
165
+ * })
166
+ *
167
+ * // 禁用模块名显示
168
+ * buildProgress({
169
+ * showModuleName: false
170
+ * })
171
+ * ```
172
+ *
173
+ * @remarks
174
+ * 该插件在 Vite 构建过程中实时显示终端进度条,支持三种显示格式:
175
+ * - bar: 完整进度条(默认),包含旋转动画、阶段标签、进度条和百分比
176
+ * - spinner: 旋转动画模式,仅显示动画、阶段标签和百分比
177
+ * - minimal: 精简模式,仅显示阶段标签和百分比
178
+ *
179
+ * 进度计算基于 Vite 构建生命周期:
180
+ * 1. config 阶段(5%)→ resolve 阶段(10%)→ transform 阶段(15%-85%)→ bundle 阶段(+10%)→ write 阶段(+5%)→ 完成(100%)
181
+ *
182
+ * 在非 TTY 终端环境下(如 CI/CD),自动降级为日志输出模式。
183
+ */
184
+ declare const buildProgress: PluginFactory<BuildProgressOptions, BuildProgressOptions>;
185
+
186
+ export { buildProgress };
187
+ export type { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme };
@@ -0,0 +1,2 @@
1
+ import{createPluginFactory as c,BasePlugin as m}from"../../factory/index.mjs";import"../../logger/index.mjs";import"../../common/object/index.mjs";import"../../shared/vite-plugin.DcExl6jd.mjs";const h=process.platform==="win32"?["|","/","-","\\"]:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],s={reset:"\x1B[0G",clearLine:"\x1B[2K",hideCursor:"\x1B[?25l",showCursor:"\x1B[?25h",green:o=>`\x1B[32m${o}\x1B[39m`,cyan:o=>`\x1B[36m${o}\x1B[39m`,gray:o=>`\x1B[90m${o}\x1B[39m`,bold:o=>`\x1B[1m${o}\x1B[22m`},d={completeColor:s.green,incompleteColor:s.gray,percentageColor:s.bold,phaseColor:s.cyan,moduleColor:s.gray},f={idle:"\u7B49\u5F85\u4E2D",config:"\u8BFB\u53D6\u914D\u7F6E",resolve:"\u89E3\u6790\u6A21\u5757",transform:"\u8F6C\u6362\u6A21\u5757",bundle:"\u6253\u5305\u4E2D",write:"\u5199\u5165\u6587\u4EF6",done:"\u6784\u5EFA\u5B8C\u6210"};class u extends m{totalModules=0;transformedModules=0;currentModule="";phase="idle";spinnerIndex=0;spinnerTimer=null;isDev=!1;theme=d;lastPercentage=0;static ANSI_REGEX=/\x1b\[[0-9;]*m/g;static stripAnsi(e){return e.replace(u.ANSI_REGEX,"")}getDefaultOptions(){return{width:30,format:"bar",completeChar:"\u2588",incompleteChar:"\u2591",clearOnComplete:!0,showModuleName:!0}}validateOptions(){this.validator.field("width").number().minValue(1).field("format").enum(["bar","spinner","minimal"]).field("completeChar").string().field("incompleteChar").string().field("clearOnComplete").boolean().field("showModuleName").boolean().validate()}getPluginName(){return"build-progress"}onConfigResolved(e){super.onConfigResolved(e),this.theme=this.options.theme||d}getPercentage(){if(this.phase==="done")return this.lastPercentage=100;if(this.phase==="config")return this.lastPercentage=5;if(this.phase==="resolve")return this.lastPercentage=10;if(this.totalModules===0)return this.lastPercentage=15;const e=Math.min(this.transformedModules/this.totalModules*70,70),t=this.phase==="bundle"?10:0,r=this.phase==="write"?5:0,n=Math.min(Math.floor(15+e+t+r),99);return this.lastPercentage=Math.max(n,this.lastPercentage),this.lastPercentage}renderBar(e){const t=this.options.width||30,r=this.options.completeChar||"\u2588",n=this.options.incompleteChar||"\u2591",i=Math.round(e/100*t),l=t-i;return this.theme.completeColor(r.repeat(i))+this.theme.incompleteColor(n.repeat(l))}renderSpinner(){const e=h[this.spinnerIndex%h.length];return this.spinnerIndex++,this.theme.phaseColor(e)}render(e){const t=this.options.format||"bar",r=this.theme.phaseColor(f[this.phase]),n=this.theme.percentageColor(`${e}%`);let i="";if(t==="bar"?i=`${this.renderSpinner()} ${r} ${this.renderBar(e)} ${n}`:t==="spinner"?i=`${this.renderSpinner()} ${r} ${n}`:i=`${r} ${n}`,this.options.showModuleName&&this.currentModule&&this.phase==="transform"){const l=u.stripAnsi(i).length,a=Math.max((process.stdout.columns||80)-l-3,20),p=this.currentModule.length>a?"..."+this.currentModule.slice(-a+3):this.currentModule;i+=` ${this.theme.moduleColor(p)}`}return i}update(){if(!process.stdout.isTTY)return;const e=this.getPercentage(),t=this.render(e);this.safeExecuteSync(()=>{process.stdout.write(s.clearLine+s.reset+t)},"\u66F4\u65B0\u8FDB\u5EA6\u663E\u793A")}startSpinner(){this.spinnerTimer||process.stdout.isTTY&&(this.spinnerTimer=setInterval(()=>this.update(),80))}stopSpinner(){this.spinnerTimer&&(clearInterval(this.spinnerTimer),this.spinnerTimer=null)}complete(){if(this.phase="done",this.stopSpinner(),!process.stdout.isTTY){this.logger.success("\u6784\u5EFA\u5B8C\u6210");return}if(this.options.clearOnComplete)this.safeExecuteSync(()=>{process.stdout.write(s.clearLine+s.reset)},"\u6E05\u9664\u8FDB\u5EA6\u884C");else{const e=this.render(100);this.safeExecuteSync(()=>{process.stdout.write(s.clearLine+s.reset+e+`
2
+ `)},"\u8F93\u51FA\u5B8C\u6210\u8FDB\u5EA6")}this.safeExecuteSync(()=>{process.stdout.write(s.showCursor)},"\u6062\u590D\u5149\u6807\u663E\u793A")}addPluginHooks(e){e.config=(t,{command:r})=>(this.isDev=r==="serve",null),e.configResolved=()=>{this.options.enabled&&(this.phase="config",process.stdout.isTTY&&this.safeExecuteSync(()=>{process.stdout.write(s.hideCursor)},"\u9690\u85CF\u5149\u6807"),this.startSpinner())},e.buildStart=()=>{this.options.enabled&&(this.phase="resolve",this.totalModules=0,this.transformedModules=0)},e.resolveId={handler:t=>{this.options.enabled&&(t.includes("node_modules")||t.includes(".virtual")||this.totalModules++)}},e.transform={handler:(t,r)=>{this.options.enabled&&(r.includes("node_modules")||r.includes(".virtual")||(this.phase="transform",this.transformedModules++,this.currentModule=r))}},e.writeBundle=()=>{this.options.enabled&&(this.phase="write",this.update())},e.closeBundle=()=>{this.options.enabled&&this.complete()},e.buildEnd=()=>{this.options.enabled&&(this.isDev||(this.phase="bundle",this.update()))},e.configureServer=()=>{this.options.enabled&&this.isDev&&this.complete()}}destroy(){super.destroy(),this.stopSpinner(),process.stdout.isTTY&&this.safeExecuteSync(()=>{process.stdout.write(s.showCursor)},"\u6062\u590D\u5149\u6807\u663E\u793A")}}const g=c(u);export{g as buildProgress};
@@ -0,0 +1 @@
1
+ "use strict";const factory_index=require("../../factory/index.cjs"),common_fs_index=require("../../common/fs/index.cjs");require("../../logger/index.cjs"),require("../../common/object/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("fs"),require("path");class p extends factory_index.BasePlugin{getDefaultOptions(){return{overwrite:!0,recursive:!0,incremental:!0}}validateOptions(){this.validator.field("sourceDir").required().string().custom(e=>e.trim()!=="","sourceDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("targetDir").required().string().custom(e=>e.trim()!=="","targetDir \u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32").field("overwrite").boolean().field("recursive").boolean().field("incremental").boolean().validate()}getPluginName(){return"copy-file"}getEnforce(){return"post"}async copyFiles(){const{sourceDir:e,targetDir:u,overwrite:i=!0,recursive:t=!0,incremental:s=!0,enabled:o=!0}=this.options;if(!o){this.logger.info(`\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6267\u884C\uFF1A\u4ECE ${e} \u590D\u5236\u5230 ${u}`);return}await common_fs_index.checkSourceExists(e);const r=await common_fs_index.copySourceToTarget(e,u,{recursive:t,overwrite:i,incremental:s});this.logger.success(`\u590D\u5236\u6587\u4EF6\u6210\u529F\uFF1A\u4ECE ${e} \u5230 ${u}`,`\u590D\u5236\u4E86 ${r.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${r.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${r.executionTime}ms`)}addPluginHooks(e){e.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u590D\u5236\u6587\u4EF6")}}}const copyFile=factory_index.createPluginFactory(p);exports.copyFile=copyFile;
@@ -0,0 +1,78 @@
1
+ import { BasePluginOptions, PluginFactory } from '../../factory/index.cjs';
2
+ import 'vite';
3
+ import '../../shared/vite-plugin.CLr0ttuO.cjs';
4
+ import '../../shared/vite-plugin.DRRlWY8P.cjs';
5
+
6
+ /**
7
+ * 复制文件插件的配置选项接口
8
+ *
9
+ * @interface CopyFileOptions
10
+ */
11
+ interface CopyFileOptions extends BasePluginOptions {
12
+ /**
13
+ * 源文件目录的路径
14
+ *
15
+ * @example 'src/assets'
16
+ */
17
+ sourceDir: string;
18
+ /**
19
+ * 目标文件目录的路径
20
+ *
21
+ * @example 'dist/assets'
22
+ */
23
+ targetDir: string;
24
+ /**
25
+ * 是否覆盖同名文件
26
+ *
27
+ * @default true
28
+ */
29
+ overwrite?: boolean;
30
+ /**
31
+ * 是否支持递归复制
32
+ *
33
+ * @default true
34
+ */
35
+ recursive?: boolean;
36
+ /**
37
+ * 是否启用增量复制
38
+ *
39
+ * @default true
40
+ */
41
+ incremental?: boolean;
42
+ }
43
+
44
+ /**
45
+ * 复制文件插件
46
+ *
47
+ * @param {CopyFileOptions} options - 插件配置选项
48
+ * @returns {Plugin} 一个 Vite 插件实例
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // 基本使用
53
+ * copyFile({
54
+ * sourceDir: 'src/assets',
55
+ * targetDir: 'dist/assets'
56
+ * })
57
+ *
58
+ * // 高级配置
59
+ * copyFile({
60
+ * sourceDir: 'src/static',
61
+ * targetDir: 'dist/static',
62
+ * overwrite: false,
63
+ * recursive: true,
64
+ * incremental: true,
65
+ * enabled: true,
66
+ * verbose: true,
67
+ * errorStrategy: 'throw'
68
+ * })
69
+ * ```
70
+ *
71
+ * @remarks
72
+ * 该插件会在 Vite 构建完成后执行,将指定源目录的所有文件和子目录复制到目标目录。
73
+ * 支持增量复制、递归复制和覆盖控制等功能。
74
+ */
75
+ declare const copyFile: PluginFactory<CopyFileOptions, CopyFileOptions>;
76
+
77
+ export { copyFile };
78
+ export type { CopyFileOptions };