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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 云游君
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# MEODP (Mystic Eyes of Death Perception)
|
|
2
|
+
|
|
3
|
+
Written by Typescript, based on [Playwright](https://playwright.dev/).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
You can use it like a lib or a cli.
|
|
8
|
+
|
|
9
|
+
Or like an application:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Create a config file: `meodp.config.ts` in your project root.
|
|
13
|
+
import { defineConfig } from 'meodp'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Ref
|
|
21
|
+
|
|
22
|
+
- [lychee](https://lychee.cli.rs/)
|
|
23
|
+
|
|
24
|
+
## Logs
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
logs/meodp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## FAQ
|
|
31
|
+
|
|
32
|
+
### 与 lychee 的区别
|
|
33
|
+
|
|
34
|
+
lychee 是一个使用 Rust 编写的快速检测链接的命令行。
|
|
35
|
+
它的命令行应该能满足你使用命令行的大部分需求。
|
|
36
|
+
|
|
37
|
+
但我希望能够通过脚本/配置自由地定制检测流程、日志,并记录相关内容,执行对应的函数。
|
|
38
|
+
因此我们需要一个类似 SDK 的库,来实现类似的功能。
|
|
39
|
+
同时基于 Typescript 可以获得更好的开发灵活性,而使用 Playwright 则可以模拟浏览器以检测页面中的资源加载。
|
|
40
|
+
|
|
41
|
+
如果可能,它未来也许可以支持插件或预置配置。
|
package/bin/index.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const c12 = require('c12');
|
|
5
|
+
const consola = require('consola');
|
|
6
|
+
const utils = require('consola/utils');
|
|
7
|
+
const yargs = require('yargs');
|
|
8
|
+
const helpers = require('yargs/helpers');
|
|
9
|
+
require('playwright');
|
|
10
|
+
const config = require('../shared/meodp.6ae77875.cjs');
|
|
11
|
+
require('node:path');
|
|
12
|
+
require('strip-ansi');
|
|
13
|
+
require('winston');
|
|
14
|
+
require('winston/lib/winston/transports');
|
|
15
|
+
require('p-queue');
|
|
16
|
+
require('date-fns');
|
|
17
|
+
require('fs-extra');
|
|
18
|
+
require('cli-progress');
|
|
19
|
+
require('cli-progress/lib/options');
|
|
20
|
+
require('cli-progress/lib/format-bar');
|
|
21
|
+
require('cli-progress/lib/format-time');
|
|
22
|
+
|
|
23
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
24
|
+
|
|
25
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
26
|
+
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
|
27
|
+
const yargs__default = /*#__PURE__*/_interopDefaultCompat(yargs);
|
|
28
|
+
|
|
29
|
+
function commonOptions(args) {
|
|
30
|
+
return args.positional("root", {
|
|
31
|
+
default: ".",
|
|
32
|
+
type: "string",
|
|
33
|
+
describe: "root folder of your source files"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const __DEV__ = false;
|
|
38
|
+
consola__default.level = 3;
|
|
39
|
+
function debug(name, ...args) {
|
|
40
|
+
consola__default.debug(utils.colors.dim(name), ...args);
|
|
41
|
+
}
|
|
42
|
+
const cli = yargs__default(helpers.hideBin(process__default.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
43
|
+
"* [root]",
|
|
44
|
+
"Run MEODP to check links",
|
|
45
|
+
(args) => commonOptions(args),
|
|
46
|
+
async (argv) => {
|
|
47
|
+
debug("argv", argv);
|
|
48
|
+
const { root = process__default.cwd() } = argv;
|
|
49
|
+
const { config: config$1, configFile } = await c12.loadConfig({
|
|
50
|
+
cwd: root,
|
|
51
|
+
name: "meodp",
|
|
52
|
+
defaultConfig: config.defaultMEODPConfig
|
|
53
|
+
});
|
|
54
|
+
await config.MEODP.init(config$1);
|
|
55
|
+
debug("config", config$1);
|
|
56
|
+
config.MEODP.logger.info(`\u{1F6E0}\uFE0F Config File: ${configFile}`);
|
|
57
|
+
config.MEODP.config = config$1;
|
|
58
|
+
config.MEODP.configFile = configFile || "";
|
|
59
|
+
config.MEODP.logger.start("\u{1F310} Start checking links...");
|
|
60
|
+
const startTime = Date.now();
|
|
61
|
+
await config.runByConfig(config$1);
|
|
62
|
+
const endTime = Date.now();
|
|
63
|
+
const duration = endTime - startTime;
|
|
64
|
+
console.log();
|
|
65
|
+
config.MEODP.logger.success(`All done! in ${utils.colors.yellow(duration / 1e3)}s.`);
|
|
66
|
+
process__default.exit(0);
|
|
67
|
+
}
|
|
68
|
+
).alias("h", "help").alias("v", "version").showHelpOnFail(false).help();
|
|
69
|
+
function run() {
|
|
70
|
+
cli.parse();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.__DEV__ = __DEV__;
|
|
74
|
+
exports.cli = cli;
|
|
75
|
+
exports.debug = debug;
|
|
76
|
+
exports.run = run;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as yargs from 'yargs';
|
|
2
|
+
|
|
3
|
+
declare const __DEV__ = false;
|
|
4
|
+
/**
|
|
5
|
+
* @inner
|
|
6
|
+
*/
|
|
7
|
+
declare function debug(name: string, ...args: any[]): void;
|
|
8
|
+
declare const cli: yargs.Argv<{}>;
|
|
9
|
+
declare function run(): void;
|
|
10
|
+
|
|
11
|
+
export { __DEV__, cli, debug, run };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as yargs from 'yargs';
|
|
2
|
+
|
|
3
|
+
declare const __DEV__ = false;
|
|
4
|
+
/**
|
|
5
|
+
* @inner
|
|
6
|
+
*/
|
|
7
|
+
declare function debug(name: string, ...args: any[]): void;
|
|
8
|
+
declare const cli: yargs.Argv<{}>;
|
|
9
|
+
declare function run(): void;
|
|
10
|
+
|
|
11
|
+
export { __DEV__, cli, debug, run };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as yargs from 'yargs';
|
|
2
|
+
|
|
3
|
+
declare const __DEV__ = false;
|
|
4
|
+
/**
|
|
5
|
+
* @inner
|
|
6
|
+
*/
|
|
7
|
+
declare function debug(name: string, ...args: any[]): void;
|
|
8
|
+
declare const cli: yargs.Argv<{}>;
|
|
9
|
+
declare function run(): void;
|
|
10
|
+
|
|
11
|
+
export { __DEV__, cli, debug, run };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { loadConfig } from 'c12';
|
|
3
|
+
import consola from 'consola';
|
|
4
|
+
import { colors } from 'consola/utils';
|
|
5
|
+
import yargs from 'yargs';
|
|
6
|
+
import { hideBin } from 'yargs/helpers';
|
|
7
|
+
import 'playwright';
|
|
8
|
+
import { h as defaultMEODPConfig, M as MEODP, r as runByConfig } from '../shared/meodp.faa3c78c.mjs';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import 'strip-ansi';
|
|
11
|
+
import 'winston';
|
|
12
|
+
import 'winston/lib/winston/transports';
|
|
13
|
+
import 'p-queue';
|
|
14
|
+
import 'date-fns';
|
|
15
|
+
import 'fs-extra';
|
|
16
|
+
import 'cli-progress';
|
|
17
|
+
import 'cli-progress/lib/options';
|
|
18
|
+
import 'cli-progress/lib/format-bar';
|
|
19
|
+
import 'cli-progress/lib/format-time';
|
|
20
|
+
|
|
21
|
+
function commonOptions(args) {
|
|
22
|
+
return args.positional("root", {
|
|
23
|
+
default: ".",
|
|
24
|
+
type: "string",
|
|
25
|
+
describe: "root folder of your source files"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const __DEV__ = false;
|
|
30
|
+
consola.level = 3;
|
|
31
|
+
function debug(name, ...args) {
|
|
32
|
+
consola.debug(colors.dim(name), ...args);
|
|
33
|
+
}
|
|
34
|
+
const cli = yargs(hideBin(process.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
35
|
+
"* [root]",
|
|
36
|
+
"Run MEODP to check links",
|
|
37
|
+
(args) => commonOptions(args),
|
|
38
|
+
async (argv) => {
|
|
39
|
+
debug("argv", argv);
|
|
40
|
+
const { root = process.cwd() } = argv;
|
|
41
|
+
const { config, configFile } = await loadConfig({
|
|
42
|
+
cwd: root,
|
|
43
|
+
name: "meodp",
|
|
44
|
+
defaultConfig: defaultMEODPConfig
|
|
45
|
+
});
|
|
46
|
+
await MEODP.init(config);
|
|
47
|
+
debug("config", config);
|
|
48
|
+
MEODP.logger.info(`\u{1F6E0}\uFE0F Config File: ${configFile}`);
|
|
49
|
+
MEODP.config = config;
|
|
50
|
+
MEODP.configFile = configFile || "";
|
|
51
|
+
MEODP.logger.start("\u{1F310} Start checking links...");
|
|
52
|
+
const startTime = Date.now();
|
|
53
|
+
await runByConfig(config);
|
|
54
|
+
const endTime = Date.now();
|
|
55
|
+
const duration = endTime - startTime;
|
|
56
|
+
console.log();
|
|
57
|
+
MEODP.logger.success(`All done! in ${colors.yellow(duration / 1e3)}s.`);
|
|
58
|
+
process.exit(0);
|
|
59
|
+
}
|
|
60
|
+
).alias("h", "help").alias("v", "version").showHelpOnFail(false).help();
|
|
61
|
+
function run() {
|
|
62
|
+
cli.parse();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { __DEV__, cli, debug, run };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const config = require('./shared/meodp.6ae77875.cjs');
|
|
4
|
+
require('consola');
|
|
5
|
+
require('p-queue');
|
|
6
|
+
require('consola/utils');
|
|
7
|
+
require('playwright');
|
|
8
|
+
require('node:path');
|
|
9
|
+
require('node:process');
|
|
10
|
+
require('date-fns');
|
|
11
|
+
require('fs-extra');
|
|
12
|
+
require('strip-ansi');
|
|
13
|
+
require('winston');
|
|
14
|
+
require('winston/lib/winston/transports');
|
|
15
|
+
require('cli-progress');
|
|
16
|
+
require('cli-progress/lib/options');
|
|
17
|
+
require('cli-progress/lib/format-bar');
|
|
18
|
+
require('cli-progress/lib/format-time');
|
|
19
|
+
|
|
20
|
+
async function checkSiteMap(urlItem) {
|
|
21
|
+
const { url } = urlItem;
|
|
22
|
+
const robotsUrl = new URL("/robots.txt", url).href;
|
|
23
|
+
const browser = await config.getBrowser();
|
|
24
|
+
const page = await browser.newPage();
|
|
25
|
+
await page.goto(robotsUrl);
|
|
26
|
+
const text = await page.textContent("pre");
|
|
27
|
+
const sitemap = text?.match(/Sitemap: (.*)/)?.[1];
|
|
28
|
+
let sitemapUrl = new URL(sitemap || "/sitemap.xml", url).href;
|
|
29
|
+
if (sitemap) {
|
|
30
|
+
sitemapUrl = sitemap.startsWith("http") ? sitemap : new URL(sitemap, url).href;
|
|
31
|
+
}
|
|
32
|
+
await page.goto(sitemapUrl);
|
|
33
|
+
const links = await page.$$eval("loc", (elements) => {
|
|
34
|
+
return elements.map((element) => element.textContent);
|
|
35
|
+
});
|
|
36
|
+
for (const link of links) {
|
|
37
|
+
if (link && !config.siteUrlMap.has(link)) {
|
|
38
|
+
config.siteUrlMap.set(link, {
|
|
39
|
+
statusCode: 0,
|
|
40
|
+
checkStatus: "pending"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.LocalLog = config.LocalLog;
|
|
47
|
+
exports.PQueueMap = config.PQueueMap;
|
|
48
|
+
exports.checkLink = config.checkLink;
|
|
49
|
+
exports.checkMEODPUrl = config.checkMEODPUrl;
|
|
50
|
+
exports.checkSite = config.checkSite;
|
|
51
|
+
exports.checkSiteUrl = config.checkSiteUrl;
|
|
52
|
+
exports.checkUrlNomoduleAssets = config.checkUrlNomoduleAssets;
|
|
53
|
+
exports.createMEODPLogger = config.createMEODPLogger;
|
|
54
|
+
exports.createWinstonLogger = config.createWinstonLogger;
|
|
55
|
+
exports.defaultMEODPConfig = config.defaultMEODPConfig;
|
|
56
|
+
exports.defineConfig = config.defineConfig;
|
|
57
|
+
exports.emojiMap = config.emojiMap;
|
|
58
|
+
exports.formatArgs = config.formatArgs;
|
|
59
|
+
exports.getBrowser = config.getBrowser;
|
|
60
|
+
exports.getFormattedDataFromResponse = config.getFormattedDataFromResponse;
|
|
61
|
+
exports.getMEODPUrlItemInfo = config.getMEODPUrlItemInfo;
|
|
62
|
+
exports.getSiteLinks = config.getSiteLinks;
|
|
63
|
+
exports.isLink = config.isLink;
|
|
64
|
+
exports.localLog = config.localLog;
|
|
65
|
+
exports.logUrlItemInfo = config.logUrlItemInfo;
|
|
66
|
+
exports.multiBar = config.multiBar;
|
|
67
|
+
exports.parseUrlMap = config.parseUrlMap;
|
|
68
|
+
exports.progressBarMap = config.progressBarMap;
|
|
69
|
+
exports.registerPageEvents = config.registerPageEvents;
|
|
70
|
+
exports.runByConfig = config.runByConfig;
|
|
71
|
+
exports.siteUrlMap = config.siteUrlMap;
|
|
72
|
+
exports.checkSiteMap = checkSiteMap;
|
package/dist/index.d.cts
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 };
|