meodp 0.0.6 → 0.0.7
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 +1 -0
- package/bin/index.mjs +0 -0
- package/dist/cli/index.cjs +168 -18
- package/dist/cli/index.mjs +154 -7
- package/dist/index.cjs +39 -37
- package/dist/index.d.cts +87 -3
- package/dist/index.d.mts +87 -3
- package/dist/index.d.ts +87 -3
- package/dist/index.mjs +9 -8
- package/dist/shared/{meodp.9c5df07b.mjs → meodp.5489574b.mjs} +275 -186
- package/dist/shared/{meodp.c2959ba5.cjs → meodp.9bf8b8ff.cjs} +280 -190
- package/package.json +6 -2
package/README.md
CHANGED
package/bin/index.mjs
CHANGED
|
File without changes
|
package/dist/cli/index.cjs
CHANGED
|
@@ -1,29 +1,164 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const process = require('node:process');
|
|
3
|
+
const process$1 = require('node:process');
|
|
4
4
|
const c12 = require('c12');
|
|
5
5
|
const consola = require('consola');
|
|
6
6
|
const utils = require('consola/utils');
|
|
7
7
|
const yargs = require('yargs');
|
|
8
8
|
const helpers = require('yargs/helpers');
|
|
9
9
|
require('playwright');
|
|
10
|
-
const
|
|
10
|
+
const index = require('../shared/meodp.9bf8b8ff.cjs');
|
|
11
11
|
require('node:path');
|
|
12
12
|
require('strip-ansi');
|
|
13
13
|
require('winston');
|
|
14
14
|
require('p-queue');
|
|
15
|
-
require('
|
|
16
|
-
require('
|
|
15
|
+
require('lowdb/node');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const process = require('process');
|
|
18
|
+
const fs = require('fs-extra');
|
|
19
|
+
const markdownTable = require('markdown-table');
|
|
17
20
|
require('cli-progress');
|
|
18
21
|
require('cli-progress/lib/options.js');
|
|
19
22
|
require('cli-progress/lib/format-bar.js');
|
|
20
23
|
require('cli-progress/lib/format-time.js');
|
|
24
|
+
require('date-fns');
|
|
21
25
|
|
|
22
26
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
23
27
|
|
|
24
|
-
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
28
|
+
const process__default$1 = /*#__PURE__*/_interopDefaultCompat(process$1);
|
|
25
29
|
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
|
26
30
|
const yargs__default = /*#__PURE__*/_interopDefaultCompat(yargs);
|
|
31
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
32
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
33
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
34
|
+
|
|
35
|
+
const successIcon = '<font color="green">\u2714</font>';
|
|
36
|
+
const errorIcon = '<font color="red">\u2716</font>';
|
|
37
|
+
function getCheckStatusEmoji(checkStatus) {
|
|
38
|
+
switch (checkStatus) {
|
|
39
|
+
case "passed":
|
|
40
|
+
return "\u2705";
|
|
41
|
+
case "failed":
|
|
42
|
+
return "\u274C";
|
|
43
|
+
case "timeout":
|
|
44
|
+
return "\u23F0";
|
|
45
|
+
case "ignored":
|
|
46
|
+
return "\u{1F47B}";
|
|
47
|
+
case "goto":
|
|
48
|
+
return "\u{1F517}";
|
|
49
|
+
case "pending":
|
|
50
|
+
return "\u23F3";
|
|
51
|
+
default:
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function getErrorMdContent(sites) {
|
|
56
|
+
const errorSites = Object.entries(sites).filter(([key, value]) => {
|
|
57
|
+
return ["failed", "timeout"].includes(value.checkStatus);
|
|
58
|
+
});
|
|
59
|
+
if (!errorSites.length) {
|
|
60
|
+
return "No error found.";
|
|
61
|
+
}
|
|
62
|
+
let md = "";
|
|
63
|
+
for (const [key, value] of errorSites) {
|
|
64
|
+
md += `- [${value.name || value.url}](${value.url})
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
return md;
|
|
68
|
+
}
|
|
69
|
+
async function generateContentFromSiteData(site) {
|
|
70
|
+
let md = "";
|
|
71
|
+
const successLength = site.links.filter((link) => link.checkStatus === "passed").length;
|
|
72
|
+
const failedLength = site.links.filter((link) => link.checkStatus === "failed").length;
|
|
73
|
+
const timeoutLength = site.links.filter((link) => link.checkStatus === "timeout").length;
|
|
74
|
+
const summary = `
|
|
75
|
+
> \u{1F517} Links ${site.links.length} | ${successIcon} ${successLength} Passed | ${errorIcon} ${failedLength} Failed | \u23F0 ${timeoutLength} Timeout | \u{1F47B} ${site.ignored.length} Ignored
|
|
76
|
+
|
|
77
|
+
`;
|
|
78
|
+
md += summary;
|
|
79
|
+
const siteArr = [
|
|
80
|
+
["", "CheckInfo", "Duration", "URL"]
|
|
81
|
+
];
|
|
82
|
+
site.links?.forEach((link) => {
|
|
83
|
+
let checkStr = getCheckStatusEmoji(link.checkStatus);
|
|
84
|
+
let checkInfo = [
|
|
85
|
+
"<span>**" + link.total + " Requests**</span><br>"
|
|
86
|
+
];
|
|
87
|
+
if (link.success) {
|
|
88
|
+
checkInfo.push('<font color="green">\u2714</font> ' + link.success);
|
|
89
|
+
}
|
|
90
|
+
if (link.failed) {
|
|
91
|
+
checkInfo.push(errorIcon + " " + link.failed);
|
|
92
|
+
}
|
|
93
|
+
if (link.timeout) {
|
|
94
|
+
checkInfo.push("\u23F0 " + link.timeout);
|
|
95
|
+
}
|
|
96
|
+
if (link.ignored) {
|
|
97
|
+
checkInfo.push("\u{1F47B} " + link.ignored);
|
|
98
|
+
}
|
|
99
|
+
(link.statusText ? `${link.statusCode} ${link.statusText}` : link.statusCode).toString();
|
|
100
|
+
siteArr.push([
|
|
101
|
+
checkStr,
|
|
102
|
+
checkInfo.join(" "),
|
|
103
|
+
// statusStr,
|
|
104
|
+
link.duration ? `${link.duration}ms` : "",
|
|
105
|
+
`[${link.url}](${link.url})`
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
md += markdownTable.markdownTable(siteArr, {
|
|
109
|
+
align: ["l", "l", "r", "l"]
|
|
110
|
+
});
|
|
111
|
+
md += "\n";
|
|
112
|
+
return md;
|
|
113
|
+
}
|
|
114
|
+
async function outputMarkdown(options = {
|
|
115
|
+
/**
|
|
116
|
+
* Show config in markdown
|
|
117
|
+
*/
|
|
118
|
+
showConfig: false
|
|
119
|
+
}) {
|
|
120
|
+
const db = await index.createLowDB();
|
|
121
|
+
await db.read();
|
|
122
|
+
const rootDir = process__default.cwd();
|
|
123
|
+
const mdPath = path__default.resolve(rootDir, "logs/meodp/result.md");
|
|
124
|
+
await fs__default.ensureFile(mdPath);
|
|
125
|
+
let mdContent = "# MEODP Report\n";
|
|
126
|
+
if (options.showConfig) {
|
|
127
|
+
mdContent += `
|
|
128
|
+
<details>
|
|
129
|
+
<summary>Config</summary>
|
|
130
|
+
|
|
131
|
+
\`\`\`json
|
|
132
|
+
${JSON.stringify(db.data.config, null, 2)}
|
|
133
|
+
\`\`\`
|
|
134
|
+
|
|
135
|
+
</details>
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
mdContent += `
|
|
139
|
+
## Errors
|
|
140
|
+
|
|
141
|
+
${getErrorMdContent(db.data.sites)}
|
|
142
|
+
`;
|
|
143
|
+
mdContent += "\n## Sites\n";
|
|
144
|
+
for (const [key, value] of Object.entries(db.data.sites)) {
|
|
145
|
+
const site = value;
|
|
146
|
+
mdContent += `
|
|
147
|
+
### ${getCheckStatusEmoji(site.checkStatus)} [${site.name || site.url}](${site.url})
|
|
148
|
+
`;
|
|
149
|
+
mdContent += await generateContentFromSiteData(value);
|
|
150
|
+
}
|
|
151
|
+
await fs__default.writeFile(mdPath, mdContent);
|
|
152
|
+
consola__default.success(`${utils.colors.cyan("Report Markdown File:")} ${utils.colors.gray(mdPath)}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function output(type = "md") {
|
|
156
|
+
switch (type) {
|
|
157
|
+
case "md":
|
|
158
|
+
await outputMarkdown();
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
27
162
|
|
|
28
163
|
function commonOptions(args) {
|
|
29
164
|
return args.positional("root", {
|
|
@@ -38,31 +173,46 @@ consola__default.level = 3;
|
|
|
38
173
|
function debug(name, ...args) {
|
|
39
174
|
consola__default.debug(utils.colors.dim(name), ...args);
|
|
40
175
|
}
|
|
41
|
-
const cli = yargs__default(helpers.hideBin(process__default.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
176
|
+
const cli = yargs__default(helpers.hideBin(process__default$1.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
42
177
|
"* [root]",
|
|
43
178
|
"Run MEODP to check links",
|
|
44
179
|
(args) => commonOptions(args),
|
|
45
180
|
async (argv) => {
|
|
46
181
|
debug("argv", argv);
|
|
47
|
-
const { root = process__default.cwd() } = argv;
|
|
48
|
-
const { config
|
|
182
|
+
const { root = process__default$1.cwd() } = argv;
|
|
183
|
+
const { config, configFile } = await c12.loadConfig({
|
|
49
184
|
cwd: root,
|
|
50
185
|
name: "meodp",
|
|
51
|
-
defaultConfig:
|
|
186
|
+
defaultConfig: index.defaultMEODPConfig
|
|
52
187
|
});
|
|
53
|
-
await
|
|
54
|
-
debug("config", config
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
188
|
+
await index.MEODP.init(config);
|
|
189
|
+
debug("config", config);
|
|
190
|
+
index.MEODP.logger.info(`\u{1F6E0}\uFE0F Config File: ${configFile}`);
|
|
191
|
+
index.MEODP.config = config;
|
|
192
|
+
index.MEODP.configFile = configFile || "";
|
|
193
|
+
index.MEODP.logger.start("\u{1F310} Start checking links...");
|
|
59
194
|
const startTime = Date.now();
|
|
60
|
-
await
|
|
195
|
+
await index.runByConfig(config);
|
|
61
196
|
const endTime = Date.now();
|
|
62
197
|
const duration = endTime - startTime;
|
|
63
198
|
console.log();
|
|
64
|
-
|
|
65
|
-
|
|
199
|
+
index.MEODP.logger.success(`All done! in ${utils.colors.yellow(duration / 1e3)}s.`);
|
|
200
|
+
console.log();
|
|
201
|
+
consola__default.start("\u{1F680} Start exporting Markdown Report...");
|
|
202
|
+
await output(argv.type);
|
|
203
|
+
process__default$1.exit(0);
|
|
204
|
+
}
|
|
205
|
+
).command(
|
|
206
|
+
"export [root]",
|
|
207
|
+
"Export MEODP Report",
|
|
208
|
+
(args) => commonOptions(args).option("type", {
|
|
209
|
+
alias: "t",
|
|
210
|
+
describe: "Export type",
|
|
211
|
+
choices: ["html", "md"],
|
|
212
|
+
default: "md"
|
|
213
|
+
}),
|
|
214
|
+
async (argv) => {
|
|
215
|
+
await output(argv.type);
|
|
66
216
|
}
|
|
67
217
|
).alias("h", "help").alias("v", "version").showHelpOnFail(false).help();
|
|
68
218
|
function run() {
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,21 +1,153 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
1
|
+
import process$1 from 'node:process';
|
|
2
2
|
import { loadConfig } from 'c12';
|
|
3
3
|
import consola from 'consola';
|
|
4
4
|
import { colors } from 'consola/utils';
|
|
5
5
|
import yargs from 'yargs';
|
|
6
6
|
import { hideBin } from 'yargs/helpers';
|
|
7
7
|
import 'playwright';
|
|
8
|
-
import { h as defaultMEODPConfig, M as MEODP, r as runByConfig } from '../shared/meodp.
|
|
8
|
+
import { j as createLowDB, h as defaultMEODPConfig, M as MEODP, r as runByConfig } from '../shared/meodp.5489574b.mjs';
|
|
9
9
|
import 'node:path';
|
|
10
10
|
import 'strip-ansi';
|
|
11
11
|
import 'winston';
|
|
12
12
|
import 'p-queue';
|
|
13
|
-
import '
|
|
14
|
-
import '
|
|
13
|
+
import 'lowdb/node';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import process from 'process';
|
|
16
|
+
import fs from 'fs-extra';
|
|
17
|
+
import { markdownTable } from 'markdown-table';
|
|
15
18
|
import 'cli-progress';
|
|
16
19
|
import 'cli-progress/lib/options.js';
|
|
17
20
|
import 'cli-progress/lib/format-bar.js';
|
|
18
21
|
import 'cli-progress/lib/format-time.js';
|
|
22
|
+
import 'date-fns';
|
|
23
|
+
|
|
24
|
+
const successIcon = '<font color="green">\u2714</font>';
|
|
25
|
+
const errorIcon = '<font color="red">\u2716</font>';
|
|
26
|
+
function getCheckStatusEmoji(checkStatus) {
|
|
27
|
+
switch (checkStatus) {
|
|
28
|
+
case "passed":
|
|
29
|
+
return "\u2705";
|
|
30
|
+
case "failed":
|
|
31
|
+
return "\u274C";
|
|
32
|
+
case "timeout":
|
|
33
|
+
return "\u23F0";
|
|
34
|
+
case "ignored":
|
|
35
|
+
return "\u{1F47B}";
|
|
36
|
+
case "goto":
|
|
37
|
+
return "\u{1F517}";
|
|
38
|
+
case "pending":
|
|
39
|
+
return "\u23F3";
|
|
40
|
+
default:
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function getErrorMdContent(sites) {
|
|
45
|
+
const errorSites = Object.entries(sites).filter(([key, value]) => {
|
|
46
|
+
return ["failed", "timeout"].includes(value.checkStatus);
|
|
47
|
+
});
|
|
48
|
+
if (!errorSites.length) {
|
|
49
|
+
return "No error found.";
|
|
50
|
+
}
|
|
51
|
+
let md = "";
|
|
52
|
+
for (const [key, value] of errorSites) {
|
|
53
|
+
md += `- [${value.name || value.url}](${value.url})
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
return md;
|
|
57
|
+
}
|
|
58
|
+
async function generateContentFromSiteData(site) {
|
|
59
|
+
let md = "";
|
|
60
|
+
const successLength = site.links.filter((link) => link.checkStatus === "passed").length;
|
|
61
|
+
const failedLength = site.links.filter((link) => link.checkStatus === "failed").length;
|
|
62
|
+
const timeoutLength = site.links.filter((link) => link.checkStatus === "timeout").length;
|
|
63
|
+
const summary = `
|
|
64
|
+
> \u{1F517} Links ${site.links.length} | ${successIcon} ${successLength} Passed | ${errorIcon} ${failedLength} Failed | \u23F0 ${timeoutLength} Timeout | \u{1F47B} ${site.ignored.length} Ignored
|
|
65
|
+
|
|
66
|
+
`;
|
|
67
|
+
md += summary;
|
|
68
|
+
const siteArr = [
|
|
69
|
+
["", "CheckInfo", "Duration", "URL"]
|
|
70
|
+
];
|
|
71
|
+
site.links?.forEach((link) => {
|
|
72
|
+
let checkStr = getCheckStatusEmoji(link.checkStatus);
|
|
73
|
+
let checkInfo = [
|
|
74
|
+
"<span>**" + link.total + " Requests**</span><br>"
|
|
75
|
+
];
|
|
76
|
+
if (link.success) {
|
|
77
|
+
checkInfo.push('<font color="green">\u2714</font> ' + link.success);
|
|
78
|
+
}
|
|
79
|
+
if (link.failed) {
|
|
80
|
+
checkInfo.push(errorIcon + " " + link.failed);
|
|
81
|
+
}
|
|
82
|
+
if (link.timeout) {
|
|
83
|
+
checkInfo.push("\u23F0 " + link.timeout);
|
|
84
|
+
}
|
|
85
|
+
if (link.ignored) {
|
|
86
|
+
checkInfo.push("\u{1F47B} " + link.ignored);
|
|
87
|
+
}
|
|
88
|
+
(link.statusText ? `${link.statusCode} ${link.statusText}` : link.statusCode).toString();
|
|
89
|
+
siteArr.push([
|
|
90
|
+
checkStr,
|
|
91
|
+
checkInfo.join(" "),
|
|
92
|
+
// statusStr,
|
|
93
|
+
link.duration ? `${link.duration}ms` : "",
|
|
94
|
+
`[${link.url}](${link.url})`
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
md += markdownTable(siteArr, {
|
|
98
|
+
align: ["l", "l", "r", "l"]
|
|
99
|
+
});
|
|
100
|
+
md += "\n";
|
|
101
|
+
return md;
|
|
102
|
+
}
|
|
103
|
+
async function outputMarkdown(options = {
|
|
104
|
+
/**
|
|
105
|
+
* Show config in markdown
|
|
106
|
+
*/
|
|
107
|
+
showConfig: false
|
|
108
|
+
}) {
|
|
109
|
+
const db = await createLowDB();
|
|
110
|
+
await db.read();
|
|
111
|
+
const rootDir = process.cwd();
|
|
112
|
+
const mdPath = path.resolve(rootDir, "logs/meodp/result.md");
|
|
113
|
+
await fs.ensureFile(mdPath);
|
|
114
|
+
let mdContent = "# MEODP Report\n";
|
|
115
|
+
if (options.showConfig) {
|
|
116
|
+
mdContent += `
|
|
117
|
+
<details>
|
|
118
|
+
<summary>Config</summary>
|
|
119
|
+
|
|
120
|
+
\`\`\`json
|
|
121
|
+
${JSON.stringify(db.data.config, null, 2)}
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
</details>
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
mdContent += `
|
|
128
|
+
## Errors
|
|
129
|
+
|
|
130
|
+
${getErrorMdContent(db.data.sites)}
|
|
131
|
+
`;
|
|
132
|
+
mdContent += "\n## Sites\n";
|
|
133
|
+
for (const [key, value] of Object.entries(db.data.sites)) {
|
|
134
|
+
const site = value;
|
|
135
|
+
mdContent += `
|
|
136
|
+
### ${getCheckStatusEmoji(site.checkStatus)} [${site.name || site.url}](${site.url})
|
|
137
|
+
`;
|
|
138
|
+
mdContent += await generateContentFromSiteData(value);
|
|
139
|
+
}
|
|
140
|
+
await fs.writeFile(mdPath, mdContent);
|
|
141
|
+
consola.success(`${colors.cyan("Report Markdown File:")} ${colors.gray(mdPath)}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function output(type = "md") {
|
|
145
|
+
switch (type) {
|
|
146
|
+
case "md":
|
|
147
|
+
await outputMarkdown();
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
19
151
|
|
|
20
152
|
function commonOptions(args) {
|
|
21
153
|
return args.positional("root", {
|
|
@@ -30,13 +162,13 @@ consola.level = 3;
|
|
|
30
162
|
function debug(name, ...args) {
|
|
31
163
|
consola.debug(colors.dim(name), ...args);
|
|
32
164
|
}
|
|
33
|
-
const cli = yargs(hideBin(process.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
165
|
+
const cli = yargs(hideBin(process$1.argv)).scriptName("meodp").usage("$0 \u68C0\u6D4B\u94FE\u63A5").command(
|
|
34
166
|
"* [root]",
|
|
35
167
|
"Run MEODP to check links",
|
|
36
168
|
(args) => commonOptions(args),
|
|
37
169
|
async (argv) => {
|
|
38
170
|
debug("argv", argv);
|
|
39
|
-
const { root = process.cwd() } = argv;
|
|
171
|
+
const { root = process$1.cwd() } = argv;
|
|
40
172
|
const { config, configFile } = await loadConfig({
|
|
41
173
|
cwd: root,
|
|
42
174
|
name: "meodp",
|
|
@@ -54,7 +186,22 @@ const cli = yargs(hideBin(process.argv)).scriptName("meodp").usage("$0 \u68C0\u6
|
|
|
54
186
|
const duration = endTime - startTime;
|
|
55
187
|
console.log();
|
|
56
188
|
MEODP.logger.success(`All done! in ${colors.yellow(duration / 1e3)}s.`);
|
|
57
|
-
|
|
189
|
+
console.log();
|
|
190
|
+
consola.start("\u{1F680} Start exporting Markdown Report...");
|
|
191
|
+
await output(argv.type);
|
|
192
|
+
process$1.exit(0);
|
|
193
|
+
}
|
|
194
|
+
).command(
|
|
195
|
+
"export [root]",
|
|
196
|
+
"Export MEODP Report",
|
|
197
|
+
(args) => commonOptions(args).option("type", {
|
|
198
|
+
alias: "t",
|
|
199
|
+
describe: "Export type",
|
|
200
|
+
choices: ["html", "md"],
|
|
201
|
+
default: "md"
|
|
202
|
+
}),
|
|
203
|
+
async (argv) => {
|
|
204
|
+
await output(argv.type);
|
|
58
205
|
}
|
|
59
206
|
).alias("h", "help").alias("v", "version").showHelpOnFail(false).help();
|
|
60
207
|
function run() {
|
package/dist/index.cjs
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
require('consola');
|
|
5
|
-
require('p-queue');
|
|
3
|
+
const index = require('./shared/meodp.9bf8b8ff.cjs');
|
|
6
4
|
require('consola/utils');
|
|
7
5
|
require('playwright');
|
|
8
6
|
require('node:path');
|
|
9
7
|
require('node:process');
|
|
10
|
-
require('
|
|
11
|
-
require('
|
|
12
|
-
require('
|
|
13
|
-
require('winston');
|
|
8
|
+
require('consola');
|
|
9
|
+
require('lowdb/node');
|
|
10
|
+
require('p-queue');
|
|
14
11
|
require('cli-progress');
|
|
15
12
|
require('cli-progress/lib/options.js');
|
|
16
13
|
require('cli-progress/lib/format-bar.js');
|
|
17
14
|
require('cli-progress/lib/format-time.js');
|
|
15
|
+
require('date-fns');
|
|
16
|
+
require('fs-extra');
|
|
17
|
+
require('strip-ansi');
|
|
18
|
+
require('winston');
|
|
18
19
|
|
|
19
20
|
async function checkSiteMap(urlItem) {
|
|
20
21
|
const { url } = urlItem;
|
|
21
22
|
const robotsUrl = new URL("/robots.txt", url).href;
|
|
22
|
-
const browser = await
|
|
23
|
+
const browser = await index.getBrowser();
|
|
23
24
|
const page = await browser.newPage();
|
|
24
25
|
await page.goto(robotsUrl);
|
|
25
26
|
const text = await page.textContent("pre");
|
|
@@ -33,8 +34,8 @@ async function checkSiteMap(urlItem) {
|
|
|
33
34
|
return elements.map((element) => element.textContent);
|
|
34
35
|
});
|
|
35
36
|
for (const link of links) {
|
|
36
|
-
if (link && !
|
|
37
|
-
|
|
37
|
+
if (link && !index.siteUrlMap.has(link)) {
|
|
38
|
+
index.siteUrlMap.set(link, {
|
|
38
39
|
statusCode: 0,
|
|
39
40
|
checkStatus: "pending"
|
|
40
41
|
});
|
|
@@ -42,31 +43,32 @@ async function checkSiteMap(urlItem) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
exports.LocalLog =
|
|
46
|
-
exports.PQueueMap =
|
|
47
|
-
exports.checkLink =
|
|
48
|
-
exports.checkMEODPUrl =
|
|
49
|
-
exports.checkSite =
|
|
50
|
-
exports.checkSiteUrl =
|
|
51
|
-
exports.checkUrlNomoduleAssets =
|
|
52
|
-
exports.
|
|
53
|
-
exports.
|
|
54
|
-
exports.
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.
|
|
58
|
-
exports.
|
|
59
|
-
exports.
|
|
60
|
-
exports.
|
|
61
|
-
exports.
|
|
62
|
-
exports.
|
|
63
|
-
exports.
|
|
64
|
-
exports.
|
|
65
|
-
exports.
|
|
66
|
-
exports.
|
|
67
|
-
exports.
|
|
68
|
-
exports.
|
|
69
|
-
exports.
|
|
70
|
-
exports.
|
|
71
|
-
exports.
|
|
46
|
+
exports.LocalLog = index.LocalLog;
|
|
47
|
+
exports.PQueueMap = index.PQueueMap;
|
|
48
|
+
exports.checkLink = index.checkLink;
|
|
49
|
+
exports.checkMEODPUrl = index.checkMEODPUrl;
|
|
50
|
+
exports.checkSite = index.checkSite;
|
|
51
|
+
exports.checkSiteUrl = index.checkSiteUrl;
|
|
52
|
+
exports.checkUrlNomoduleAssets = index.checkUrlNomoduleAssets;
|
|
53
|
+
exports.createLowDB = index.createLowDB;
|
|
54
|
+
exports.createMEODPLogger = index.createMEODPLogger;
|
|
55
|
+
exports.createWinstonLogger = index.createWinstonLogger;
|
|
56
|
+
exports.defaultMEODPConfig = index.defaultMEODPConfig;
|
|
57
|
+
exports.defineConfig = index.defineConfig;
|
|
58
|
+
exports.emojiMap = index.emojiMap;
|
|
59
|
+
exports.formatArgs = index.formatArgs;
|
|
60
|
+
exports.getBrowser = index.getBrowser;
|
|
61
|
+
exports.getFormattedDataFromResponse = index.getFormattedDataFromResponse;
|
|
62
|
+
exports.getFormattedDuration = index.getFormattedDuration;
|
|
63
|
+
exports.getMEODPUrlItemInfo = index.getMEODPUrlItemInfo;
|
|
64
|
+
exports.getSiteLinks = index.getSiteLinks;
|
|
65
|
+
exports.isLink = index.isLink;
|
|
66
|
+
exports.localLog = index.localLog;
|
|
67
|
+
exports.logUrlItemInfo = index.logUrlItemInfo;
|
|
68
|
+
exports.multiBar = index.multiBar;
|
|
69
|
+
exports.parseUrlMap = index.parseUrlMap;
|
|
70
|
+
exports.progressBarMap = index.progressBarMap;
|
|
71
|
+
exports.registerPageEvents = index.registerPageEvents;
|
|
72
|
+
exports.runByConfig = index.runByConfig;
|
|
73
|
+
exports.siteUrlMap = index.siteUrlMap;
|
|
72
74
|
exports.checkSiteMap = checkSiteMap;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import * as PQueue from 'p-queue';
|
|
|
2
2
|
import PQueue__default from 'p-queue';
|
|
3
3
|
import * as playwright from 'playwright';
|
|
4
4
|
import { Response, Request, Page } from 'playwright';
|
|
5
|
+
import * as lowdb from 'lowdb';
|
|
5
6
|
import winston from 'winston';
|
|
6
7
|
import cliProgress from 'cli-progress';
|
|
7
8
|
|
|
@@ -17,7 +18,7 @@ declare const siteUrlMap: Map<string, {
|
|
|
17
18
|
/**
|
|
18
19
|
* 检查状态
|
|
19
20
|
*/
|
|
20
|
-
checkStatus: "pending" | "passed" | "failed" | "goto";
|
|
21
|
+
checkStatus: "pending" | "passed" | "failed" | "goto" | "ignored";
|
|
21
22
|
}>;
|
|
22
23
|
/**
|
|
23
24
|
* site p-queue
|
|
@@ -170,6 +171,86 @@ interface MEODPConfig {
|
|
|
170
171
|
*/
|
|
171
172
|
declare function checkLink(urlItem: MEODPUrlProps): Promise<void>;
|
|
172
173
|
|
|
174
|
+
/**
|
|
175
|
+
* 站点中的链接
|
|
176
|
+
*/
|
|
177
|
+
interface MEODPSiteLinkItem {
|
|
178
|
+
url: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
statusCode: number;
|
|
181
|
+
statusText?: string;
|
|
182
|
+
checkStatus: 'pending' | 'passed' | 'failed' | 'goto' | 'ignored' | 'timeout';
|
|
183
|
+
/**
|
|
184
|
+
* success requests
|
|
185
|
+
*/
|
|
186
|
+
success: number;
|
|
187
|
+
/**
|
|
188
|
+
* failed requests
|
|
189
|
+
*/
|
|
190
|
+
failed: number;
|
|
191
|
+
timeout: number;
|
|
192
|
+
/**
|
|
193
|
+
* ignored requests
|
|
194
|
+
*/
|
|
195
|
+
ignored: number;
|
|
196
|
+
/**
|
|
197
|
+
* duration in ms
|
|
198
|
+
*/
|
|
199
|
+
duration: number;
|
|
200
|
+
/**
|
|
201
|
+
* total requests
|
|
202
|
+
*/
|
|
203
|
+
total: number;
|
|
204
|
+
requests: MEODPRequestItem[];
|
|
205
|
+
}
|
|
206
|
+
interface MEODPRequestItem {
|
|
207
|
+
/**
|
|
208
|
+
* @desc 是否失败
|
|
209
|
+
*/
|
|
210
|
+
failed?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* @desc 是否被忽略
|
|
213
|
+
*/
|
|
214
|
+
ignored?: boolean;
|
|
215
|
+
url?: string;
|
|
216
|
+
statusCode?: number;
|
|
217
|
+
statusText?: string;
|
|
218
|
+
}
|
|
219
|
+
interface MEODPSiteItem {
|
|
220
|
+
/**
|
|
221
|
+
* @desc 站点名称
|
|
222
|
+
*/
|
|
223
|
+
name?: string;
|
|
224
|
+
/**
|
|
225
|
+
* url 内容为 html 时,将会检查页面上的所有资源
|
|
226
|
+
*/
|
|
227
|
+
url: string;
|
|
228
|
+
/**
|
|
229
|
+
* @desc 站点标题
|
|
230
|
+
*/
|
|
231
|
+
title?: string;
|
|
232
|
+
/**
|
|
233
|
+
* site links 站点其他链接
|
|
234
|
+
*/
|
|
235
|
+
links: MEODPSiteLinkItem[];
|
|
236
|
+
/**
|
|
237
|
+
* 本次总体检查状态
|
|
238
|
+
*/
|
|
239
|
+
checkStatus: 'passed' | 'failed' | 'pending';
|
|
240
|
+
/**
|
|
241
|
+
* all ignored urls
|
|
242
|
+
*/
|
|
243
|
+
ignored: string[];
|
|
244
|
+
}
|
|
245
|
+
interface DBData {
|
|
246
|
+
config: MEODPConfig;
|
|
247
|
+
sites: Record<string, MEODPSiteItem>;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* create json db
|
|
251
|
+
*/
|
|
252
|
+
declare function createLowDB(rootDir?: string): Promise<lowdb.Low<DBData>>;
|
|
253
|
+
|
|
173
254
|
/**
|
|
174
255
|
* 获取站点外链
|
|
175
256
|
*/
|
|
@@ -190,7 +271,7 @@ interface CheckSiteUrlOptions {
|
|
|
190
271
|
* check url in site
|
|
191
272
|
* @param url
|
|
192
273
|
*/
|
|
193
|
-
declare function checkSiteUrl(url: string, options: CheckSiteUrlOptions): Promise<
|
|
274
|
+
declare function checkSiteUrl(url: string, options: CheckSiteUrlOptions): Promise<MEODPSiteLinkItem | undefined>;
|
|
194
275
|
/**
|
|
195
276
|
* 检查站点可访问性
|
|
196
277
|
* - 死链
|
|
@@ -310,6 +391,9 @@ declare function getFormattedDuration(duration: number): string;
|
|
|
310
391
|
* get formatted data from response
|
|
311
392
|
*/
|
|
312
393
|
declare function getFormattedDataFromResponse(res: Response): {
|
|
394
|
+
/**
|
|
395
|
+
* 四舍五入 ms
|
|
396
|
+
*/
|
|
313
397
|
duration: number;
|
|
314
398
|
durationText: string;
|
|
315
399
|
statusCode: number;
|
|
@@ -359,4 +443,4 @@ declare function getMEODPUrlItemInfo(urlItem: MEODPUrlItem): {
|
|
|
359
443
|
emoji: string;
|
|
360
444
|
};
|
|
361
445
|
|
|
362
|
-
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, getFormattedDuration, getMEODPUrlItemInfo, getSiteLinks, isLink, localLog, logUrlItemInfo, multiBar, parseUrlMap, progressBarMap, registerPageEvents, runByConfig, siteUrlMap };
|
|
446
|
+
export { type CheckSiteUrlOptions, type DBData, LocalLog, type LocalLogOptions, type MEODPConfig, type MEODPRequestItem, type MEODPSiteItem, type MEODPSiteLinkItem, type MEODPUrlItem, type MEODPUrlProps, type MEODPUrlType, PQueueMap, type PageUrlEvent, type UrlCategoryInfo, type UrlMap, checkLink, checkMEODPUrl, checkSite, checkSiteMap, checkSiteUrl, checkUrlNomoduleAssets, createLowDB, createMEODPLogger, createWinstonLogger, defaultMEODPConfig, defineConfig, emojiMap, formatArgs, getBrowser, getFormattedDataFromResponse, getFormattedDuration, getMEODPUrlItemInfo, getSiteLinks, isLink, localLog, logUrlItemInfo, multiBar, parseUrlMap, progressBarMap, registerPageEvents, runByConfig, siteUrlMap };
|