@tnotesjs/core 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/README.md +84 -84
- package/dist/{chunk-LZQDLU3S.js → chunk-NI5B4S3T.js} +12 -2
- package/dist/cli/index.js +1 -1
- package/dist/vitepress/config/index.js +60 -17
- package/package.json +1 -1
- package/types/config.ts +61 -61
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- package/vitepress/assets/icons/icon__check.svg +3 -3
- package/vitepress/assets/icons/icon__clipboard.svg +7 -7
- package/vitepress/assets/icons/icon__close.svg +1 -1
- package/vitepress/assets/icons/icon__collapse.svg +1 -1
- package/vitepress/assets/icons/icon__confirm.svg +1 -1
- package/vitepress/assets/icons/icon__copy.svg +4 -4
- package/vitepress/assets/icons/icon__focus.svg +1 -1
- package/vitepress/assets/icons/icon__fold.svg +3 -3
- package/vitepress/assets/icons/icon__folder.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
- package/vitepress/assets/icons/icon__github.svg +3 -3
- package/vitepress/assets/icons/icon__mindmap.svg +1 -1
- package/vitepress/assets/icons/icon__next.svg +1 -1
- package/vitepress/assets/icons/icon__number_gray.svg +1 -1
- package/vitepress/assets/icons/icon__number_purple.svg +1 -1
- package/vitepress/assets/icons/icon__prev.svg +1 -1
- package/vitepress/assets/icons/icon__restore.svg +1 -1
- package/vitepress/assets/icons/icon__rotate.svg +4 -4
- package/vitepress/assets/icons/icon__search.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
- package/vitepress/assets/icons/icon__totop.svg +5 -5
- package/vitepress/assets/icons/icon__vscode.svg +5 -5
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
- package/vitepress/assets/icons/index.ts +38 -38
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -373
- package/vitepress/components/CodeBlockFullscreen/index.ts +115 -115
- package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
- package/vitepress/components/Discussions/Discussions.module.scss +32 -32
- package/vitepress/components/Discussions/Discussions.vue +211 -211
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
- package/vitepress/components/EnWordList/EnWordList.vue +543 -543
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
- package/vitepress/components/Footprints/Footprints.module.scss +93 -93
- package/vitepress/components/Footprints/Footprints.vue +377 -377
- package/vitepress/components/Layout/AboutModal.module.scss +233 -233
- package/vitepress/components/Layout/AboutModal.vue +105 -105
- package/vitepress/components/Layout/AboutPanel.vue +266 -266
- package/vitepress/components/Layout/ContentCollapse.vue +603 -603
- package/vitepress/components/Layout/CustomSidebar.vue +605 -605
- package/vitepress/components/Layout/DocBeforeControls.vue +139 -139
- package/vitepress/components/Layout/DocFooter.vue +233 -225
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
- package/vitepress/components/Layout/ImagePreview.vue +281 -281
- package/vitepress/components/Layout/Layout.module.scss +661 -661
- package/vitepress/components/Layout/Layout.vue +542 -542
- package/vitepress/components/Layout/NoteStatus.vue +140 -140
- package/vitepress/components/Layout/SidebarItems.vue +263 -263
- package/vitepress/components/Layout/SidebarNavBefore.vue +92 -92
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
- package/vitepress/components/Layout/ToggleFullContent.vue +34 -34
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
- package/vitepress/components/Layout/ToggleSidebar.vue +35 -35
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -121
- package/vitepress/components/Layout/composables/useNoteSave.ts +173 -173
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +110 -110
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/LoadingPage/LoadingPage.vue +192 -192
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
- package/vitepress/components/MarkMap/MarkMap.vue +404 -404
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
- package/vitepress/components/Mermaid/Mermaid.vue +364 -364
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
- package/vitepress/components/NotesTable/NotesTable.vue +98 -98
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.module.scss +433 -433
- package/vitepress/components/Settings/Settings.vue +306 -306
- package/vitepress/components/SidebarCard/MindMapView.vue +483 -483
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +948 -948
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +91 -91
- package/vitepress/components/notesConfig.data.ts +73 -73
- package/vitepress/components/sidebar.data.ts +59 -59
- package/vitepress/components/tnotes-config.data.ts +21 -21
- package/vitepress/components/utils.ts +26 -26
- package/vitepress/config/index.ts +141 -141
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -25
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -23
- package/vitepress/configs/markdown.config.ts +366 -366
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +466 -390
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
- package/vitepress/plugins/renameNotePlugin.ts +60 -60
- package/vitepress/plugins/updateConfigPlugin.ts +63 -63
- package/vitepress/theme/index.ts +95 -95
- package/vitepress/theme/styles/base.scss +50 -50
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +175 -175
- package/vitepress/theme/styles/components/markmap.scss +101 -101
- package/vitepress/theme/styles/components/swiper.scss +255 -255
- package/vitepress/theme/styles/index.scss +25 -25
- package/vitepress/theme/styles/layout.scss +62 -62
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
|
@@ -1,390 +1,466 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* .vitepress/tnotes/vitepress/plugins/buildProgressPlugin.ts
|
|
3
|
-
*
|
|
4
|
-
* 构建进度插件 - 仅在 build 模式下显示真实进度
|
|
5
|
-
*
|
|
6
|
-
* 基于 vite-plugin-progress 源码简化实现
|
|
7
|
-
* https://github.com/jeddygong/vite-plugin-progress
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { Plugin } from 'vite'
|
|
11
|
-
import {
|
|
12
|
-
existsSync,
|
|
13
|
-
readFileSync,
|
|
14
|
-
writeFileSync,
|
|
15
|
-
mkdirSync,
|
|
16
|
-
readdirSync,
|
|
17
|
-
} from 'fs'
|
|
18
|
-
import { join } from 'path'
|
|
19
|
-
|
|
20
|
-
/** 缓存目录和文件路径 */
|
|
21
|
-
const CACHE_DIR = join(process.cwd(), 'node_modules', '.tnotes-progress')
|
|
22
|
-
const CACHE_FILE = join(CACHE_DIR, 'build-cache.json')
|
|
23
|
-
|
|
24
|
-
/** 缓存数据结构 */
|
|
25
|
-
interface CacheData {
|
|
26
|
-
transformCount: number
|
|
27
|
-
chunkCount: number
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
entry.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let
|
|
100
|
-
let
|
|
101
|
-
let
|
|
102
|
-
let
|
|
103
|
-
let
|
|
104
|
-
let
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
str.includes('
|
|
147
|
-
str.includes('
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
globalLastPercent
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* .vitepress/tnotes/vitepress/plugins/buildProgressPlugin.ts
|
|
3
|
+
*
|
|
4
|
+
* 构建进度插件 - 仅在 build 模式下显示真实进度
|
|
5
|
+
*
|
|
6
|
+
* 基于 vite-plugin-progress 源码简化实现
|
|
7
|
+
* https://github.com/jeddygong/vite-plugin-progress
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Plugin } from 'vite'
|
|
11
|
+
import {
|
|
12
|
+
existsSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
writeFileSync,
|
|
15
|
+
mkdirSync,
|
|
16
|
+
readdirSync,
|
|
17
|
+
} from 'fs'
|
|
18
|
+
import { join } from 'path'
|
|
19
|
+
|
|
20
|
+
/** 缓存目录和文件路径 */
|
|
21
|
+
const CACHE_DIR = join(process.cwd(), 'node_modules', '.tnotes-progress')
|
|
22
|
+
const CACHE_FILE = join(CACHE_DIR, 'build-cache.json')
|
|
23
|
+
|
|
24
|
+
/** 缓存数据结构 */
|
|
25
|
+
interface CacheData {
|
|
26
|
+
transformCount: number
|
|
27
|
+
chunkCount: number
|
|
28
|
+
/** transform 阶段耗时占总构建时间的比例(0-1),用于下次按时间权重分配进度 */
|
|
29
|
+
transformEndRatio?: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 插件配置选项 */
|
|
33
|
+
interface BuildProgressOptions {
|
|
34
|
+
width?: number
|
|
35
|
+
complete?: string
|
|
36
|
+
incomplete?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 读取缓存数据
|
|
41
|
+
*/
|
|
42
|
+
function getCacheData(): CacheData {
|
|
43
|
+
try {
|
|
44
|
+
if (existsSync(CACHE_FILE)) {
|
|
45
|
+
return JSON.parse(readFileSync(CACHE_FILE, 'utf-8'))
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
// 忽略错误
|
|
49
|
+
}
|
|
50
|
+
return { transformCount: 0, chunkCount: 0 }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 写入缓存数据
|
|
55
|
+
*/
|
|
56
|
+
function setCacheData(data: CacheData): void {
|
|
57
|
+
try {
|
|
58
|
+
if (!existsSync(CACHE_DIR)) {
|
|
59
|
+
mkdirSync(CACHE_DIR, { recursive: true })
|
|
60
|
+
}
|
|
61
|
+
writeFileSync(CACHE_FILE, JSON.stringify(data), 'utf-8')
|
|
62
|
+
} catch {
|
|
63
|
+
// 忽略错误
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 扫描源目录文件数量
|
|
69
|
+
*/
|
|
70
|
+
function countSourceFiles(srcDir: string): number {
|
|
71
|
+
let count = 0
|
|
72
|
+
const extensions = /\.(vue|ts|js|jsx|tsx|css|scss|sass|styl|less|md)$/i
|
|
73
|
+
|
|
74
|
+
const scan = (dir: string) => {
|
|
75
|
+
try {
|
|
76
|
+
const entries = readdirSync(dir, { withFileTypes: true })
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const fullPath = join(dir, entry.name)
|
|
79
|
+
if (
|
|
80
|
+
entry.isDirectory() &&
|
|
81
|
+
!entry.name.startsWith('.') &&
|
|
82
|
+
entry.name !== 'node_modules'
|
|
83
|
+
) {
|
|
84
|
+
scan(fullPath)
|
|
85
|
+
} else if (entry.isFile() && extensions.test(entry.name)) {
|
|
86
|
+
count++
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
// 忽略错误
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
scan(srcDir)
|
|
95
|
+
return count
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ============ 全局状态 ============
|
|
99
|
+
let globalStartTime = 0
|
|
100
|
+
let globalTransformCount = 0
|
|
101
|
+
let globalChunkCount = 0
|
|
102
|
+
let globalHasError = false
|
|
103
|
+
let globalIsBuilding = false
|
|
104
|
+
let globalOutDir = ''
|
|
105
|
+
let globalLastPercent = 0
|
|
106
|
+
let globalFileCount = 0
|
|
107
|
+
let globalLastLoggedPercent = -1 // 非 TTY 环境下上次输出的百分比区间,初始为 -1 以便第一次输出
|
|
108
|
+
let globalLastOutputTime = 0 // 非 TTY 环境下上次输出时间戳,用于时间节流
|
|
109
|
+
let globalTransformEndTime = 0 // transform 阶段结束时间戳
|
|
110
|
+
let globalLastHookTime = 0 // 最后一次 Vite hook 触发时间
|
|
111
|
+
let globalStallTimer: ReturnType<typeof setInterval> | null = null
|
|
112
|
+
|
|
113
|
+
/** 检测是否支持单行刷新(交互式终端) */
|
|
114
|
+
const isTTY = !!(process.stdout.isTTY && process.stderr.isTTY)
|
|
115
|
+
|
|
116
|
+
/** 检测是否在 CI 环境中运行 */
|
|
117
|
+
const isCI = !!(
|
|
118
|
+
process.env.CI ||
|
|
119
|
+
process.env.GITHUB_ACTIONS ||
|
|
120
|
+
process.env.GITLAB_CI ||
|
|
121
|
+
process.env.CIRCLECI ||
|
|
122
|
+
process.env.TRAVIS ||
|
|
123
|
+
process.env.JENKINS_URL
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
/** 是否使用单行刷新模式(TTY 且非 CI) */
|
|
127
|
+
const useSingleLineMode = isTTY && !isCI
|
|
128
|
+
|
|
129
|
+
// 保存原始输出函数
|
|
130
|
+
let originalStdoutWrite: typeof process.stdout.write | null = null
|
|
131
|
+
let originalStderrWrite: typeof process.stderr.write | null = null
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 拦截输出
|
|
135
|
+
*/
|
|
136
|
+
function interceptOutput() {
|
|
137
|
+
if (originalStdoutWrite) return
|
|
138
|
+
|
|
139
|
+
originalStdoutWrite = process.stdout.write.bind(process.stdout)
|
|
140
|
+
originalStderrWrite = process.stderr.write.bind(process.stderr)
|
|
141
|
+
|
|
142
|
+
const filter = (chunk: string | Uint8Array): boolean => {
|
|
143
|
+
const str = chunk.toString()
|
|
144
|
+
// 只允许我们的输出
|
|
145
|
+
return (
|
|
146
|
+
str.includes('🔨') ||
|
|
147
|
+
str.includes('✅ 构建成功') ||
|
|
148
|
+
str.includes('❌ 构建失败') ||
|
|
149
|
+
str.includes('📁') ||
|
|
150
|
+
str.includes('📊') ||
|
|
151
|
+
str.includes('📦') ||
|
|
152
|
+
str.includes('⏱️') ||
|
|
153
|
+
str.includes('\x1b[2K') // 允许清屏指令
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
process.stdout.write = ((
|
|
158
|
+
chunk: string | Uint8Array,
|
|
159
|
+
encodingOrCallback?: BufferEncoding | ((err?: Error | null) => void),
|
|
160
|
+
callback?: (err?: Error | null) => void,
|
|
161
|
+
): boolean => {
|
|
162
|
+
if (filter(chunk)) {
|
|
163
|
+
return originalStdoutWrite!(chunk, encodingOrCallback as any, callback)
|
|
164
|
+
}
|
|
165
|
+
if (typeof encodingOrCallback === 'function') encodingOrCallback()
|
|
166
|
+
else if (callback) callback()
|
|
167
|
+
return true
|
|
168
|
+
}) as typeof process.stdout.write
|
|
169
|
+
|
|
170
|
+
process.stderr.write = ((
|
|
171
|
+
chunk: string | Uint8Array,
|
|
172
|
+
encodingOrCallback?: BufferEncoding | ((err?: Error | null) => void),
|
|
173
|
+
callback?: (err?: Error | null) => void,
|
|
174
|
+
): boolean => {
|
|
175
|
+
const str = chunk.toString()
|
|
176
|
+
// 允许进度条和真正的错误
|
|
177
|
+
if (filter(chunk) || str.toLowerCase().includes('error')) {
|
|
178
|
+
return originalStderrWrite!(chunk, encodingOrCallback as any, callback)
|
|
179
|
+
}
|
|
180
|
+
if (typeof encodingOrCallback === 'function') encodingOrCallback()
|
|
181
|
+
else if (callback) callback()
|
|
182
|
+
return true
|
|
183
|
+
}) as typeof process.stderr.write
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 恢复输出
|
|
188
|
+
*/
|
|
189
|
+
function restoreOutput() {
|
|
190
|
+
if (originalStdoutWrite) {
|
|
191
|
+
process.stdout.write = originalStdoutWrite
|
|
192
|
+
originalStdoutWrite = null
|
|
193
|
+
}
|
|
194
|
+
if (originalStderrWrite) {
|
|
195
|
+
process.stderr.write = originalStderrWrite
|
|
196
|
+
originalStderrWrite = null
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 渲染进度条
|
|
202
|
+
*/
|
|
203
|
+
function renderProgress(
|
|
204
|
+
percent: number,
|
|
205
|
+
transforms: string,
|
|
206
|
+
chunks: string,
|
|
207
|
+
width: number,
|
|
208
|
+
complete: string,
|
|
209
|
+
incomplete: string,
|
|
210
|
+
isFinal: boolean = false,
|
|
211
|
+
) {
|
|
212
|
+
if (!originalStderrWrite) return
|
|
213
|
+
|
|
214
|
+
// 非单行模式下,只在 10% 间隔输出进度,并附加时间节流避免多行显示相同耗时
|
|
215
|
+
if (!useSingleLineMode && !isFinal) {
|
|
216
|
+
const currentPercent = Math.floor(percent * 100)
|
|
217
|
+
const currentBucket = Math.floor(currentPercent / 10) * 10
|
|
218
|
+
const now = Date.now()
|
|
219
|
+
if (currentBucket <= globalLastLoggedPercent || (now - globalLastOutputTime < 500)) {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
globalLastLoggedPercent = currentBucket
|
|
223
|
+
globalLastOutputTime = now
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const filled = Math.floor(percent * width)
|
|
227
|
+
const empty = width - filled
|
|
228
|
+
const bar = complete.repeat(filled) + incomplete.repeat(empty)
|
|
229
|
+
const percentStr = (percent * 100).toFixed(0).padStart(3, ' ')
|
|
230
|
+
const elapsed = ((Date.now() - globalStartTime) / 1000).toFixed(1)
|
|
231
|
+
|
|
232
|
+
// 格式: Building [...] 100% | Transforms: x/y | Chunks: x/y | Time: xs
|
|
233
|
+
// 单行模式使用回车覆盖,否则直接换行
|
|
234
|
+
const prefix = useSingleLineMode ? '\r\x1b[2K' : ''
|
|
235
|
+
const ending = isFinal || !useSingleLineMode ? '\n' : ''
|
|
236
|
+
const line = `${prefix}Building [${bar}] ${percentStr}% | Transforms: ${transforms} | Chunks: ${chunks} | Time: ${elapsed}s${ending}`
|
|
237
|
+
originalStderrWrite(line)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 创建构建进度插件
|
|
242
|
+
*/
|
|
243
|
+
export function buildProgressPlugin(
|
|
244
|
+
options: BuildProgressOptions = {},
|
|
245
|
+
): Plugin {
|
|
246
|
+
const { width = 40, complete = '█', incomplete = '░' } = options
|
|
247
|
+
|
|
248
|
+
const cache = getCacheData()
|
|
249
|
+
const hasCache = cache.transformCount > 0
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
name: 'tnotes-build-progress',
|
|
253
|
+
enforce: 'pre',
|
|
254
|
+
apply: 'build',
|
|
255
|
+
|
|
256
|
+
config(config, { command }) {
|
|
257
|
+
if (command === 'build') {
|
|
258
|
+
config.logLevel = 'silent'
|
|
259
|
+
|
|
260
|
+
if (!globalIsBuilding) {
|
|
261
|
+
globalIsBuilding = true
|
|
262
|
+
globalStartTime = Date.now()
|
|
263
|
+
globalTransformCount = 0
|
|
264
|
+
globalChunkCount = 0
|
|
265
|
+
globalHasError = false
|
|
266
|
+
globalLastPercent = 0
|
|
267
|
+
globalLastLoggedPercent = -1
|
|
268
|
+
globalLastOutputTime = 0
|
|
269
|
+
globalTransformEndTime = 0
|
|
270
|
+
globalLastHookTime = Date.now()
|
|
271
|
+
globalOutDir = config.build?.outDir || 'dist'
|
|
272
|
+
|
|
273
|
+
if (!hasCache) {
|
|
274
|
+
globalFileCount = countSourceFiles(process.cwd())
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interceptOutput()
|
|
278
|
+
|
|
279
|
+
// 停滞填充计时器:当 Vite hook 超过 2 秒没触发时(如 VitePress 渲染页面阶段),
|
|
280
|
+
// 缓慢推进进度条,避免长时间卡住不动
|
|
281
|
+
globalStallTimer = setInterval(() => {
|
|
282
|
+
if (
|
|
283
|
+
!globalIsBuilding ||
|
|
284
|
+
globalLastPercent <= 0 ||
|
|
285
|
+
globalLastPercent >= 0.98
|
|
286
|
+
)
|
|
287
|
+
return
|
|
288
|
+
const now = Date.now()
|
|
289
|
+
if (now - globalLastHookTime < 2000) return
|
|
290
|
+
|
|
291
|
+
// 每次推进剩余距离的 2%,形成自然减速曲线
|
|
292
|
+
const remaining = 0.98 - globalLastPercent
|
|
293
|
+
globalLastPercent += remaining * 0.02
|
|
294
|
+
|
|
295
|
+
const transformsStr = hasCache
|
|
296
|
+
? `${globalTransformCount}/${cache.transformCount * 2}`
|
|
297
|
+
: `${globalTransformCount}`
|
|
298
|
+
const chunksStr = hasCache
|
|
299
|
+
? `${globalChunkCount}/${cache.chunkCount * 2}`
|
|
300
|
+
: `${globalChunkCount}`
|
|
301
|
+
|
|
302
|
+
renderProgress(
|
|
303
|
+
globalLastPercent,
|
|
304
|
+
transformsStr,
|
|
305
|
+
chunksStr,
|
|
306
|
+
width,
|
|
307
|
+
complete,
|
|
308
|
+
incomplete,
|
|
309
|
+
)
|
|
310
|
+
}, 1000)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
transform(_code, _id) {
|
|
316
|
+
globalTransformCount++
|
|
317
|
+
globalLastHookTime = Date.now()
|
|
318
|
+
|
|
319
|
+
// 根据缓存的时间比例确定 transform 阶段在进度条中的权重
|
|
320
|
+
// 例如 transform 占总时间 37% → 进度条 0-36%,chunk 占 63% → 进度条 36-98%
|
|
321
|
+
const transformWeight =
|
|
322
|
+
hasCache && cache.transformEndRatio != null
|
|
323
|
+
? Math.max(0.1, Math.min(0.85, cache.transformEndRatio * 0.98))
|
|
324
|
+
: 0.85
|
|
325
|
+
|
|
326
|
+
if (hasCache) {
|
|
327
|
+
const totalTransforms = cache.transformCount * 2
|
|
328
|
+
globalLastPercent = Math.min(
|
|
329
|
+
transformWeight,
|
|
330
|
+
(globalTransformCount / totalTransforms) * transformWeight,
|
|
331
|
+
)
|
|
332
|
+
} else {
|
|
333
|
+
// 无缓存模式:渐近曲线平滑逼近上限
|
|
334
|
+
const k = 500
|
|
335
|
+
globalLastPercent = Math.min(
|
|
336
|
+
transformWeight,
|
|
337
|
+
(transformWeight * globalTransformCount) / (globalTransformCount + k),
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const transformsStr = hasCache
|
|
342
|
+
? `${globalTransformCount}/${cache.transformCount * 2}`
|
|
343
|
+
: `${globalTransformCount}`
|
|
344
|
+
const chunksStr = hasCache
|
|
345
|
+
? `${globalChunkCount}/${cache.chunkCount * 2}`
|
|
346
|
+
: `${globalChunkCount}`
|
|
347
|
+
|
|
348
|
+
renderProgress(
|
|
349
|
+
globalLastPercent,
|
|
350
|
+
transformsStr,
|
|
351
|
+
chunksStr,
|
|
352
|
+
width,
|
|
353
|
+
complete,
|
|
354
|
+
incomplete,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
return null
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
renderChunk() {
|
|
361
|
+
globalChunkCount++
|
|
362
|
+
globalLastHookTime = Date.now()
|
|
363
|
+
|
|
364
|
+
// 记录 transform 阶段结束时间(第一次进入 renderChunk)
|
|
365
|
+
if (!globalTransformEndTime) {
|
|
366
|
+
globalTransformEndTime = Date.now()
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const transformWeight =
|
|
370
|
+
hasCache && cache.transformEndRatio != null
|
|
371
|
+
? Math.max(0.1, Math.min(0.85, cache.transformEndRatio * 0.98))
|
|
372
|
+
: 0.85
|
|
373
|
+
const chunkWeight = 0.98 - transformWeight
|
|
374
|
+
|
|
375
|
+
if (hasCache) {
|
|
376
|
+
const totalChunks = cache.chunkCount * 2
|
|
377
|
+
globalLastPercent = Math.min(
|
|
378
|
+
0.98,
|
|
379
|
+
transformWeight + (globalChunkCount / totalChunks) * chunkWeight,
|
|
380
|
+
)
|
|
381
|
+
} else {
|
|
382
|
+
globalLastPercent = Math.max(globalLastPercent, transformWeight)
|
|
383
|
+
globalLastPercent = Math.min(0.98, globalLastPercent + 0.00005)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const transformsStr = hasCache
|
|
387
|
+
? `${globalTransformCount}/${cache.transformCount * 2}`
|
|
388
|
+
: `${globalTransformCount}`
|
|
389
|
+
const chunksStr = hasCache
|
|
390
|
+
? `${globalChunkCount}/${cache.chunkCount * 2}`
|
|
391
|
+
: `${globalChunkCount}`
|
|
392
|
+
|
|
393
|
+
renderProgress(
|
|
394
|
+
globalLastPercent,
|
|
395
|
+
transformsStr,
|
|
396
|
+
chunksStr,
|
|
397
|
+
width,
|
|
398
|
+
complete,
|
|
399
|
+
incomplete,
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
return null
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
buildEnd(err) {
|
|
406
|
+
if (err) {
|
|
407
|
+
globalHasError = true
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
closeBundle() {
|
|
412
|
+
// 延迟检测是否是最后一次 closeBundle
|
|
413
|
+
setTimeout(() => {
|
|
414
|
+
if (!globalIsBuilding) return
|
|
415
|
+
|
|
416
|
+
if (globalStallTimer) {
|
|
417
|
+
clearInterval(globalStallTimer)
|
|
418
|
+
globalStallTimer = null
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const elapsed = ((Date.now() - globalStartTime) / 1000).toFixed(1)
|
|
422
|
+
|
|
423
|
+
// 显示 100%,带换行
|
|
424
|
+
// 100% 时应该显示总数/总数,而不是实际计数/总数
|
|
425
|
+
const totalTransforms = hasCache
|
|
426
|
+
? cache.transformCount * 2
|
|
427
|
+
: globalTransformCount
|
|
428
|
+
const totalChunks = hasCache ? cache.chunkCount * 2 : globalChunkCount
|
|
429
|
+
const transformsStr = `${totalTransforms}/${totalTransforms}`
|
|
430
|
+
const chunksStr = `${totalChunks}/${totalChunks}`
|
|
431
|
+
|
|
432
|
+
renderProgress(
|
|
433
|
+
1,
|
|
434
|
+
transformsStr,
|
|
435
|
+
chunksStr,
|
|
436
|
+
width,
|
|
437
|
+
complete,
|
|
438
|
+
incomplete,
|
|
439
|
+
true,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
restoreOutput()
|
|
443
|
+
|
|
444
|
+
if (!globalHasError) {
|
|
445
|
+
const totalTime = Date.now() - globalStartTime
|
|
446
|
+
const transformTime = globalTransformEndTime
|
|
447
|
+
? globalTransformEndTime - globalStartTime
|
|
448
|
+
: totalTime
|
|
449
|
+
setCacheData({
|
|
450
|
+
transformCount: Math.floor(globalTransformCount / 2),
|
|
451
|
+
chunkCount: Math.floor(globalChunkCount / 2),
|
|
452
|
+
transformEndRatio: transformTime / totalTime,
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
console.log(`✅ 构建成功!`)
|
|
456
|
+
console.log(` 📁 输出目录: ${globalOutDir}`)
|
|
457
|
+
console.log(` ⏱️ 耗时: ${elapsed}s`)
|
|
458
|
+
} else {
|
|
459
|
+
console.log(`\n❌ 构建失败,请检查错误信息`)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
globalIsBuilding = false
|
|
463
|
+
}, 500)
|
|
464
|
+
},
|
|
465
|
+
}
|
|
466
|
+
}
|