meodp 0.0.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.
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/bin/index.ts +6 -0
- package/dist/cli/index.cjs +76 -0
- package/dist/cli/index.d.cts +11 -0
- package/dist/cli/index.d.mts +11 -0
- package/dist/cli/index.d.ts +11 -0
- package/dist/cli/index.mjs +65 -0
- package/dist/index.cjs +72 -0
- package/dist/index.d.cts +360 -0
- package/dist/index.d.mts +360 -0
- package/dist/index.d.ts +360 -0
- package/dist/index.mjs +45 -0
- package/dist/shared/meodp.6ae77875.cjs +862 -0
- package/dist/shared/meodp.faa3c78c.mjs +819 -0
- package/package.json +82 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import * as PQueue from 'p-queue';
|
|
2
|
+
import PQueue__default from 'p-queue';
|
|
3
|
+
import * as playwright from 'playwright';
|
|
4
|
+
import { Response, Request, Page } from 'playwright';
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
import cliProgress from 'cli-progress';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 只检查内部链接
|
|
10
|
+
*/
|
|
11
|
+
declare const siteUrlMap: Map<string, {
|
|
12
|
+
response?: Response | null;
|
|
13
|
+
/**
|
|
14
|
+
* 状态码
|
|
15
|
+
*/
|
|
16
|
+
statusCode: number;
|
|
17
|
+
/**
|
|
18
|
+
* 检查状态
|
|
19
|
+
*/
|
|
20
|
+
checkStatus: "pending" | "passed" | "failed" | "goto";
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* site p-queue
|
|
24
|
+
*/
|
|
25
|
+
declare const PQueueMap: Map<string, PQueue__default<any, PQueue.QueueAddOptions>>;
|
|
26
|
+
|
|
27
|
+
interface PageUrlEvent {
|
|
28
|
+
/**
|
|
29
|
+
* @desc 是否被忽略
|
|
30
|
+
*/
|
|
31
|
+
ignored?: boolean;
|
|
32
|
+
request: Request;
|
|
33
|
+
response?: Response;
|
|
34
|
+
/**
|
|
35
|
+
* @desc 是否失败
|
|
36
|
+
*/
|
|
37
|
+
failed?: boolean;
|
|
38
|
+
}
|
|
39
|
+
type UrlMap = Map<string, PageUrlEvent>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* - site: 站点主页链接,将会检查对应的 sitemap
|
|
43
|
+
* - url: 单个页面链接
|
|
44
|
+
* - sitemap: sitemap.xml 链接,将会检查对应的 sitemap 中的链接
|
|
45
|
+
*/
|
|
46
|
+
type MEODPUrlType = 'site' | 'link' | 'sitemap';
|
|
47
|
+
interface MEODPUrlProps {
|
|
48
|
+
/**
|
|
49
|
+
* @desc emoji
|
|
50
|
+
*/
|
|
51
|
+
emoji?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @desc 日志名称
|
|
54
|
+
*/
|
|
55
|
+
name?: string;
|
|
56
|
+
/**
|
|
57
|
+
* - site: 站点主页链接,将会检查对应的 sitemap
|
|
58
|
+
* - url: 单个页面链接
|
|
59
|
+
* - sitemap: sitemap.xml 链接,将会检查对应的 sitemap 中的链接
|
|
60
|
+
* @default 'url'
|
|
61
|
+
*/
|
|
62
|
+
type: MEODPUrlType;
|
|
63
|
+
/**
|
|
64
|
+
* url 为 html 时,将会检查页面上的所有资源
|
|
65
|
+
*/
|
|
66
|
+
url: string;
|
|
67
|
+
/**
|
|
68
|
+
* @desc 站点 Headers
|
|
69
|
+
*/
|
|
70
|
+
headers?: Record<string, string> & {
|
|
71
|
+
/**
|
|
72
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Authorization
|
|
73
|
+
* 自定义 authorization 头
|
|
74
|
+
*/
|
|
75
|
+
Authorization?: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
type MEODPUrlItem = string | MEODPUrlProps;
|
|
79
|
+
interface MEODPConfig {
|
|
80
|
+
/**
|
|
81
|
+
* @desc 是否清理缓存日志
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
clean?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* @desc 是否开启 debug 模式
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* urls
|
|
92
|
+
* 可以是多种类型 @ref SiteUrlConfig
|
|
93
|
+
*/
|
|
94
|
+
urls: MEODPUrlItem[];
|
|
95
|
+
/**
|
|
96
|
+
* 日志形式
|
|
97
|
+
*/
|
|
98
|
+
log?: {
|
|
99
|
+
/**
|
|
100
|
+
* @default 'raw'
|
|
101
|
+
* @desc 日志类型
|
|
102
|
+
* - progress: 进度条
|
|
103
|
+
* - raw: 原始输出
|
|
104
|
+
*/
|
|
105
|
+
type: 'progress' | 'raw';
|
|
106
|
+
/**
|
|
107
|
+
* @desc 是否输出到文件
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
file?: boolean;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* @desc 是否检查页面上的资源,包括图片、CSS、JS等
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
checkAssets?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* @desc 是否检查外链中的资源
|
|
119
|
+
* @default true
|
|
120
|
+
*/
|
|
121
|
+
checkExternalLinks?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @todo
|
|
124
|
+
* @desc 忽略的链接
|
|
125
|
+
* @default []
|
|
126
|
+
* @example ignoreLinks: ['https://www.google.com']
|
|
127
|
+
* 被正则匹配成功或以字符串开头的链接将被忽略
|
|
128
|
+
*/
|
|
129
|
+
ignoreLinks?: (string | RegExp)[];
|
|
130
|
+
/**
|
|
131
|
+
* 忽略的后缀名
|
|
132
|
+
* @example ignoreExtensions: ['.mp3', '.mp4']
|
|
133
|
+
*/
|
|
134
|
+
ignoreExtensions?: string[];
|
|
135
|
+
/**
|
|
136
|
+
* @todo
|
|
137
|
+
* A List of accepted status codes for valid links
|
|
138
|
+
* @default [200, 204, 301, 302, 304]
|
|
139
|
+
*/
|
|
140
|
+
acceptedStatusCodes?: number[];
|
|
141
|
+
/**
|
|
142
|
+
* @todo
|
|
143
|
+
* An extra function to determine if an url is valid
|
|
144
|
+
* @default (link: string) => true
|
|
145
|
+
*/
|
|
146
|
+
isValidUrl?: (link: string) => boolean;
|
|
147
|
+
/**
|
|
148
|
+
* @todo
|
|
149
|
+
* @desc 是否检查 mail 链接
|
|
150
|
+
* @ref https://github.com/reacherhq/check-if-email-exists
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
includeMail?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* @todo
|
|
156
|
+
* 重试次数
|
|
157
|
+
* @default 1
|
|
158
|
+
*/
|
|
159
|
+
retryTimes?: number;
|
|
160
|
+
/**
|
|
161
|
+
* @todo
|
|
162
|
+
* 最大并发数
|
|
163
|
+
* @default 10
|
|
164
|
+
*/
|
|
165
|
+
concurrency?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* check one link
|
|
170
|
+
*/
|
|
171
|
+
declare function checkLink(urlItem: MEODPUrlProps): Promise<void>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 获取站点外链
|
|
175
|
+
*/
|
|
176
|
+
declare function getSiteLinks(page: Page, options: CheckSiteUrlOptions): Promise<string[]>;
|
|
177
|
+
/**
|
|
178
|
+
* <script nomodule=""></script> 不会被加载
|
|
179
|
+
* 手动匹配检测
|
|
180
|
+
*/
|
|
181
|
+
declare function checkUrlNomoduleAssets(page: Page): Promise<boolean>;
|
|
182
|
+
interface CheckSiteUrlOptions {
|
|
183
|
+
urlItem: MEODPUrlProps;
|
|
184
|
+
/**
|
|
185
|
+
* 检查 nomodule 资源
|
|
186
|
+
*/
|
|
187
|
+
checkNoModule?: boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* check url in site
|
|
191
|
+
* @param url
|
|
192
|
+
*/
|
|
193
|
+
declare function checkSiteUrl(url: string, options: CheckSiteUrlOptions): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* 检查站点可访问性
|
|
196
|
+
* - 死链
|
|
197
|
+
* - 所有内嵌资源
|
|
198
|
+
*/
|
|
199
|
+
declare function checkSite(props: MEODPUrlProps): Promise<void>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 检查站点地图
|
|
203
|
+
*/
|
|
204
|
+
declare function checkSiteMap(urlItem: MEODPUrlProps): Promise<void>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @desc 检查 MEODP 链接
|
|
208
|
+
*/
|
|
209
|
+
declare function checkMEODPUrl(meodpUrl: MEODPUrlItem): Promise<void>;
|
|
210
|
+
|
|
211
|
+
declare const defaultMEODPConfig: MEODPConfig;
|
|
212
|
+
declare function defineConfig(config: MEODPConfig): MEODPConfig;
|
|
213
|
+
/**
|
|
214
|
+
* 根据配置运行
|
|
215
|
+
*/
|
|
216
|
+
declare function runByConfig(config: MEODPConfig): Promise<boolean>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 获取浏览器实例
|
|
220
|
+
* - 单例模式
|
|
221
|
+
*/
|
|
222
|
+
declare function getBrowser(): Promise<playwright.Browser>;
|
|
223
|
+
|
|
224
|
+
declare function logUrlItemInfo(urlItem: MEODPUrlItem): void;
|
|
225
|
+
interface LocalLogOptions {
|
|
226
|
+
cwd?: string;
|
|
227
|
+
nameRule?: 'timestamp' | 'url';
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @desc 本地日志 instance
|
|
231
|
+
*/
|
|
232
|
+
declare class LocalLog {
|
|
233
|
+
/**
|
|
234
|
+
* 日志根目录
|
|
235
|
+
*/
|
|
236
|
+
static rootLogFolder: string;
|
|
237
|
+
/**
|
|
238
|
+
* rootLogFolder + yyyy-MM-dd-HH-mm-ss
|
|
239
|
+
*/
|
|
240
|
+
static logFolder: string;
|
|
241
|
+
/**
|
|
242
|
+
* rootLogFolder + site
|
|
243
|
+
*/
|
|
244
|
+
static siteLogFolder: string;
|
|
245
|
+
/**
|
|
246
|
+
* link.log
|
|
247
|
+
*/
|
|
248
|
+
static linkLogFile: string;
|
|
249
|
+
/**
|
|
250
|
+
* 日志命名规则
|
|
251
|
+
* - timestamp: yyyy-MM-dd-HH-mm-ss 每次都会建立一个以时间戳命名的文件夹
|
|
252
|
+
* - url: url 在同一个文件夹下
|
|
253
|
+
*/
|
|
254
|
+
static nameRule: 'timestamp' | 'url';
|
|
255
|
+
static options: LocalLogOptions;
|
|
256
|
+
constructor(options?: LocalLogOptions);
|
|
257
|
+
/**
|
|
258
|
+
* @desc init ensure dir
|
|
259
|
+
*/
|
|
260
|
+
static init(options?: LocalLogOptions): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* @desc clean log
|
|
263
|
+
*/
|
|
264
|
+
static clean(): Promise<void>;
|
|
265
|
+
static log(filePath: string, ...args: any[]): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* @desc append log
|
|
268
|
+
*/
|
|
269
|
+
static SiteLog(urlItem: MEODPUrlProps, ...args: any[]): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* console link log
|
|
272
|
+
*/
|
|
273
|
+
static linkLog(...args: any[]): Promise<void>;
|
|
274
|
+
static logByType(urlItem: MEODPUrlProps, ...args: any[]): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* @desc create log
|
|
277
|
+
*/
|
|
278
|
+
static createLog(urlItem: MEODPUrlProps): (...args: any[]) => void;
|
|
279
|
+
}
|
|
280
|
+
declare const localLog: LocalLog;
|
|
281
|
+
|
|
282
|
+
declare function createMEODPLogger(): {
|
|
283
|
+
_log: (...args: any[]) => void;
|
|
284
|
+
log: (...args: any[]) => void;
|
|
285
|
+
inner: (...args: any[]) => void;
|
|
286
|
+
start: (...args: any[]) => void;
|
|
287
|
+
success: (...args: any[]) => void;
|
|
288
|
+
info: (...args: any[]) => void;
|
|
289
|
+
warn: (...args: any[]) => void;
|
|
290
|
+
error: (...args: any[]) => void;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* - winston
|
|
295
|
+
*/
|
|
296
|
+
declare function createWinstonLogger(): winston.Logger;
|
|
297
|
+
|
|
298
|
+
declare const multiBar: cliProgress.MultiBar;
|
|
299
|
+
/**
|
|
300
|
+
* Progress bar map
|
|
301
|
+
* created by multiBar.create
|
|
302
|
+
*/
|
|
303
|
+
declare const progressBarMap: Map<string, cliProgress.SingleBar>;
|
|
304
|
+
|
|
305
|
+
declare function registerPageEvents(page: Page, urlItem: MEODPUrlProps): Map<string, PageUrlEvent>;
|
|
306
|
+
|
|
307
|
+
declare function formatArgs(args: any[]): string;
|
|
308
|
+
/**
|
|
309
|
+
* get formatted data from response
|
|
310
|
+
*/
|
|
311
|
+
declare function getFormattedDataFromResponse(res: Response): {
|
|
312
|
+
duration: number;
|
|
313
|
+
durationText: string;
|
|
314
|
+
statusCode: number;
|
|
315
|
+
statusText: string;
|
|
316
|
+
statusInfo: string;
|
|
317
|
+
linkText: string;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 是否为链接
|
|
322
|
+
*/
|
|
323
|
+
declare function isLink(url: string): boolean;
|
|
324
|
+
|
|
325
|
+
interface UrlCategoryInfo {
|
|
326
|
+
count: number;
|
|
327
|
+
text: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* get info from urlMap
|
|
331
|
+
*/
|
|
332
|
+
declare function parseUrlMap(urlMap: UrlMap): {
|
|
333
|
+
success: UrlCategoryInfo;
|
|
334
|
+
failed: UrlCategoryInfo;
|
|
335
|
+
/**
|
|
336
|
+
* Ignored links, controlled by `ignoreLinks` and `ignoreExtensions`
|
|
337
|
+
*/
|
|
338
|
+
ignored: UrlCategoryInfo;
|
|
339
|
+
timeout: UrlCategoryInfo;
|
|
340
|
+
total: {
|
|
341
|
+
count: number;
|
|
342
|
+
text: string;
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
declare const emojiMap: {
|
|
347
|
+
site: string;
|
|
348
|
+
link: string;
|
|
349
|
+
sitemap: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* get MEODPUrlItem info
|
|
353
|
+
*/
|
|
354
|
+
declare function getMEODPUrlItemInfo(urlItem: MEODPUrlItem): {
|
|
355
|
+
type: MEODPUrlType;
|
|
356
|
+
url: string;
|
|
357
|
+
emoji: string;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export { type CheckSiteUrlOptions, LocalLog, type LocalLogOptions, type MEODPConfig, type MEODPUrlItem, type MEODPUrlProps, type MEODPUrlType, PQueueMap, type PageUrlEvent, type UrlCategoryInfo, type UrlMap, checkLink, checkMEODPUrl, checkSite, checkSiteMap, checkSiteUrl, checkUrlNomoduleAssets, createMEODPLogger, createWinstonLogger, defaultMEODPConfig, defineConfig, emojiMap, formatArgs, getBrowser, getFormattedDataFromResponse, getMEODPUrlItemInfo, getSiteLinks, isLink, localLog, logUrlItemInfo, multiBar, parseUrlMap, progressBarMap, registerPageEvents, runByConfig, siteUrlMap };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import * as PQueue from 'p-queue';
|
|
2
|
+
import PQueue__default from 'p-queue';
|
|
3
|
+
import * as playwright from 'playwright';
|
|
4
|
+
import { Response, Request, Page } from 'playwright';
|
|
5
|
+
import winston from 'winston';
|
|
6
|
+
import cliProgress from 'cli-progress';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 只检查内部链接
|
|
10
|
+
*/
|
|
11
|
+
declare const siteUrlMap: Map<string, {
|
|
12
|
+
response?: Response | null;
|
|
13
|
+
/**
|
|
14
|
+
* 状态码
|
|
15
|
+
*/
|
|
16
|
+
statusCode: number;
|
|
17
|
+
/**
|
|
18
|
+
* 检查状态
|
|
19
|
+
*/
|
|
20
|
+
checkStatus: "pending" | "passed" | "failed" | "goto";
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* site p-queue
|
|
24
|
+
*/
|
|
25
|
+
declare const PQueueMap: Map<string, PQueue__default<any, PQueue.QueueAddOptions>>;
|
|
26
|
+
|
|
27
|
+
interface PageUrlEvent {
|
|
28
|
+
/**
|
|
29
|
+
* @desc 是否被忽略
|
|
30
|
+
*/
|
|
31
|
+
ignored?: boolean;
|
|
32
|
+
request: Request;
|
|
33
|
+
response?: Response;
|
|
34
|
+
/**
|
|
35
|
+
* @desc 是否失败
|
|
36
|
+
*/
|
|
37
|
+
failed?: boolean;
|
|
38
|
+
}
|
|
39
|
+
type UrlMap = Map<string, PageUrlEvent>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* - site: 站点主页链接,将会检查对应的 sitemap
|
|
43
|
+
* - url: 单个页面链接
|
|
44
|
+
* - sitemap: sitemap.xml 链接,将会检查对应的 sitemap 中的链接
|
|
45
|
+
*/
|
|
46
|
+
type MEODPUrlType = 'site' | 'link' | 'sitemap';
|
|
47
|
+
interface MEODPUrlProps {
|
|
48
|
+
/**
|
|
49
|
+
* @desc emoji
|
|
50
|
+
*/
|
|
51
|
+
emoji?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @desc 日志名称
|
|
54
|
+
*/
|
|
55
|
+
name?: string;
|
|
56
|
+
/**
|
|
57
|
+
* - site: 站点主页链接,将会检查对应的 sitemap
|
|
58
|
+
* - url: 单个页面链接
|
|
59
|
+
* - sitemap: sitemap.xml 链接,将会检查对应的 sitemap 中的链接
|
|
60
|
+
* @default 'url'
|
|
61
|
+
*/
|
|
62
|
+
type: MEODPUrlType;
|
|
63
|
+
/**
|
|
64
|
+
* url 为 html 时,将会检查页面上的所有资源
|
|
65
|
+
*/
|
|
66
|
+
url: string;
|
|
67
|
+
/**
|
|
68
|
+
* @desc 站点 Headers
|
|
69
|
+
*/
|
|
70
|
+
headers?: Record<string, string> & {
|
|
71
|
+
/**
|
|
72
|
+
* https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Authorization
|
|
73
|
+
* 自定义 authorization 头
|
|
74
|
+
*/
|
|
75
|
+
Authorization?: string;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
type MEODPUrlItem = string | MEODPUrlProps;
|
|
79
|
+
interface MEODPConfig {
|
|
80
|
+
/**
|
|
81
|
+
* @desc 是否清理缓存日志
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
clean?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* @desc 是否开启 debug 模式
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* urls
|
|
92
|
+
* 可以是多种类型 @ref SiteUrlConfig
|
|
93
|
+
*/
|
|
94
|
+
urls: MEODPUrlItem[];
|
|
95
|
+
/**
|
|
96
|
+
* 日志形式
|
|
97
|
+
*/
|
|
98
|
+
log?: {
|
|
99
|
+
/**
|
|
100
|
+
* @default 'raw'
|
|
101
|
+
* @desc 日志类型
|
|
102
|
+
* - progress: 进度条
|
|
103
|
+
* - raw: 原始输出
|
|
104
|
+
*/
|
|
105
|
+
type: 'progress' | 'raw';
|
|
106
|
+
/**
|
|
107
|
+
* @desc 是否输出到文件
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
file?: boolean;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* @desc 是否检查页面上的资源,包括图片、CSS、JS等
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
checkAssets?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* @desc 是否检查外链中的资源
|
|
119
|
+
* @default true
|
|
120
|
+
*/
|
|
121
|
+
checkExternalLinks?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @todo
|
|
124
|
+
* @desc 忽略的链接
|
|
125
|
+
* @default []
|
|
126
|
+
* @example ignoreLinks: ['https://www.google.com']
|
|
127
|
+
* 被正则匹配成功或以字符串开头的链接将被忽略
|
|
128
|
+
*/
|
|
129
|
+
ignoreLinks?: (string | RegExp)[];
|
|
130
|
+
/**
|
|
131
|
+
* 忽略的后缀名
|
|
132
|
+
* @example ignoreExtensions: ['.mp3', '.mp4']
|
|
133
|
+
*/
|
|
134
|
+
ignoreExtensions?: string[];
|
|
135
|
+
/**
|
|
136
|
+
* @todo
|
|
137
|
+
* A List of accepted status codes for valid links
|
|
138
|
+
* @default [200, 204, 301, 302, 304]
|
|
139
|
+
*/
|
|
140
|
+
acceptedStatusCodes?: number[];
|
|
141
|
+
/**
|
|
142
|
+
* @todo
|
|
143
|
+
* An extra function to determine if an url is valid
|
|
144
|
+
* @default (link: string) => true
|
|
145
|
+
*/
|
|
146
|
+
isValidUrl?: (link: string) => boolean;
|
|
147
|
+
/**
|
|
148
|
+
* @todo
|
|
149
|
+
* @desc 是否检查 mail 链接
|
|
150
|
+
* @ref https://github.com/reacherhq/check-if-email-exists
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
includeMail?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* @todo
|
|
156
|
+
* 重试次数
|
|
157
|
+
* @default 1
|
|
158
|
+
*/
|
|
159
|
+
retryTimes?: number;
|
|
160
|
+
/**
|
|
161
|
+
* @todo
|
|
162
|
+
* 最大并发数
|
|
163
|
+
* @default 10
|
|
164
|
+
*/
|
|
165
|
+
concurrency?: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* check one link
|
|
170
|
+
*/
|
|
171
|
+
declare function checkLink(urlItem: MEODPUrlProps): Promise<void>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 获取站点外链
|
|
175
|
+
*/
|
|
176
|
+
declare function getSiteLinks(page: Page, options: CheckSiteUrlOptions): Promise<string[]>;
|
|
177
|
+
/**
|
|
178
|
+
* <script nomodule=""></script> 不会被加载
|
|
179
|
+
* 手动匹配检测
|
|
180
|
+
*/
|
|
181
|
+
declare function checkUrlNomoduleAssets(page: Page): Promise<boolean>;
|
|
182
|
+
interface CheckSiteUrlOptions {
|
|
183
|
+
urlItem: MEODPUrlProps;
|
|
184
|
+
/**
|
|
185
|
+
* 检查 nomodule 资源
|
|
186
|
+
*/
|
|
187
|
+
checkNoModule?: boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* check url in site
|
|
191
|
+
* @param url
|
|
192
|
+
*/
|
|
193
|
+
declare function checkSiteUrl(url: string, options: CheckSiteUrlOptions): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* 检查站点可访问性
|
|
196
|
+
* - 死链
|
|
197
|
+
* - 所有内嵌资源
|
|
198
|
+
*/
|
|
199
|
+
declare function checkSite(props: MEODPUrlProps): Promise<void>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 检查站点地图
|
|
203
|
+
*/
|
|
204
|
+
declare function checkSiteMap(urlItem: MEODPUrlProps): Promise<void>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @desc 检查 MEODP 链接
|
|
208
|
+
*/
|
|
209
|
+
declare function checkMEODPUrl(meodpUrl: MEODPUrlItem): Promise<void>;
|
|
210
|
+
|
|
211
|
+
declare const defaultMEODPConfig: MEODPConfig;
|
|
212
|
+
declare function defineConfig(config: MEODPConfig): MEODPConfig;
|
|
213
|
+
/**
|
|
214
|
+
* 根据配置运行
|
|
215
|
+
*/
|
|
216
|
+
declare function runByConfig(config: MEODPConfig): Promise<boolean>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 获取浏览器实例
|
|
220
|
+
* - 单例模式
|
|
221
|
+
*/
|
|
222
|
+
declare function getBrowser(): Promise<playwright.Browser>;
|
|
223
|
+
|
|
224
|
+
declare function logUrlItemInfo(urlItem: MEODPUrlItem): void;
|
|
225
|
+
interface LocalLogOptions {
|
|
226
|
+
cwd?: string;
|
|
227
|
+
nameRule?: 'timestamp' | 'url';
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @desc 本地日志 instance
|
|
231
|
+
*/
|
|
232
|
+
declare class LocalLog {
|
|
233
|
+
/**
|
|
234
|
+
* 日志根目录
|
|
235
|
+
*/
|
|
236
|
+
static rootLogFolder: string;
|
|
237
|
+
/**
|
|
238
|
+
* rootLogFolder + yyyy-MM-dd-HH-mm-ss
|
|
239
|
+
*/
|
|
240
|
+
static logFolder: string;
|
|
241
|
+
/**
|
|
242
|
+
* rootLogFolder + site
|
|
243
|
+
*/
|
|
244
|
+
static siteLogFolder: string;
|
|
245
|
+
/**
|
|
246
|
+
* link.log
|
|
247
|
+
*/
|
|
248
|
+
static linkLogFile: string;
|
|
249
|
+
/**
|
|
250
|
+
* 日志命名规则
|
|
251
|
+
* - timestamp: yyyy-MM-dd-HH-mm-ss 每次都会建立一个以时间戳命名的文件夹
|
|
252
|
+
* - url: url 在同一个文件夹下
|
|
253
|
+
*/
|
|
254
|
+
static nameRule: 'timestamp' | 'url';
|
|
255
|
+
static options: LocalLogOptions;
|
|
256
|
+
constructor(options?: LocalLogOptions);
|
|
257
|
+
/**
|
|
258
|
+
* @desc init ensure dir
|
|
259
|
+
*/
|
|
260
|
+
static init(options?: LocalLogOptions): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* @desc clean log
|
|
263
|
+
*/
|
|
264
|
+
static clean(): Promise<void>;
|
|
265
|
+
static log(filePath: string, ...args: any[]): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* @desc append log
|
|
268
|
+
*/
|
|
269
|
+
static SiteLog(urlItem: MEODPUrlProps, ...args: any[]): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* console link log
|
|
272
|
+
*/
|
|
273
|
+
static linkLog(...args: any[]): Promise<void>;
|
|
274
|
+
static logByType(urlItem: MEODPUrlProps, ...args: any[]): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* @desc create log
|
|
277
|
+
*/
|
|
278
|
+
static createLog(urlItem: MEODPUrlProps): (...args: any[]) => void;
|
|
279
|
+
}
|
|
280
|
+
declare const localLog: LocalLog;
|
|
281
|
+
|
|
282
|
+
declare function createMEODPLogger(): {
|
|
283
|
+
_log: (...args: any[]) => void;
|
|
284
|
+
log: (...args: any[]) => void;
|
|
285
|
+
inner: (...args: any[]) => void;
|
|
286
|
+
start: (...args: any[]) => void;
|
|
287
|
+
success: (...args: any[]) => void;
|
|
288
|
+
info: (...args: any[]) => void;
|
|
289
|
+
warn: (...args: any[]) => void;
|
|
290
|
+
error: (...args: any[]) => void;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* - winston
|
|
295
|
+
*/
|
|
296
|
+
declare function createWinstonLogger(): winston.Logger;
|
|
297
|
+
|
|
298
|
+
declare const multiBar: cliProgress.MultiBar;
|
|
299
|
+
/**
|
|
300
|
+
* Progress bar map
|
|
301
|
+
* created by multiBar.create
|
|
302
|
+
*/
|
|
303
|
+
declare const progressBarMap: Map<string, cliProgress.SingleBar>;
|
|
304
|
+
|
|
305
|
+
declare function registerPageEvents(page: Page, urlItem: MEODPUrlProps): Map<string, PageUrlEvent>;
|
|
306
|
+
|
|
307
|
+
declare function formatArgs(args: any[]): string;
|
|
308
|
+
/**
|
|
309
|
+
* get formatted data from response
|
|
310
|
+
*/
|
|
311
|
+
declare function getFormattedDataFromResponse(res: Response): {
|
|
312
|
+
duration: number;
|
|
313
|
+
durationText: string;
|
|
314
|
+
statusCode: number;
|
|
315
|
+
statusText: string;
|
|
316
|
+
statusInfo: string;
|
|
317
|
+
linkText: string;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 是否为链接
|
|
322
|
+
*/
|
|
323
|
+
declare function isLink(url: string): boolean;
|
|
324
|
+
|
|
325
|
+
interface UrlCategoryInfo {
|
|
326
|
+
count: number;
|
|
327
|
+
text: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* get info from urlMap
|
|
331
|
+
*/
|
|
332
|
+
declare function parseUrlMap(urlMap: UrlMap): {
|
|
333
|
+
success: UrlCategoryInfo;
|
|
334
|
+
failed: UrlCategoryInfo;
|
|
335
|
+
/**
|
|
336
|
+
* Ignored links, controlled by `ignoreLinks` and `ignoreExtensions`
|
|
337
|
+
*/
|
|
338
|
+
ignored: UrlCategoryInfo;
|
|
339
|
+
timeout: UrlCategoryInfo;
|
|
340
|
+
total: {
|
|
341
|
+
count: number;
|
|
342
|
+
text: string;
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
declare const emojiMap: {
|
|
347
|
+
site: string;
|
|
348
|
+
link: string;
|
|
349
|
+
sitemap: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* get MEODPUrlItem info
|
|
353
|
+
*/
|
|
354
|
+
declare function getMEODPUrlItemInfo(urlItem: MEODPUrlItem): {
|
|
355
|
+
type: MEODPUrlType;
|
|
356
|
+
url: string;
|
|
357
|
+
emoji: string;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export { type CheckSiteUrlOptions, LocalLog, type LocalLogOptions, type MEODPConfig, type MEODPUrlItem, type MEODPUrlProps, type MEODPUrlType, PQueueMap, type PageUrlEvent, type UrlCategoryInfo, type UrlMap, checkLink, checkMEODPUrl, checkSite, checkSiteMap, checkSiteUrl, checkUrlNomoduleAssets, createMEODPLogger, createWinstonLogger, defaultMEODPConfig, defineConfig, emojiMap, formatArgs, getBrowser, getFormattedDataFromResponse, getMEODPUrlItemInfo, getSiteLinks, isLink, localLog, logUrlItemInfo, multiBar, parseUrlMap, progressBarMap, registerPageEvents, runByConfig, siteUrlMap };
|