@nitpicker/report-html 0.20.0
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 +191 -0
- package/README.md +19 -0
- package/lib/collect-html-report-pages.d.ts +12 -0
- package/lib/collect-html-report-pages.js +31 -0
- package/lib/html-report-cancelled-error.d.ts +16 -0
- package/lib/html-report-cancelled-error.js +19 -0
- package/lib/open-report-archive.d.ts +12 -0
- package/lib/open-report-archive.js +21 -0
- package/lib/parse-directory-input.d.ts +17 -0
- package/lib/parse-directory-input.js +62 -0
- package/lib/report-html.d.ts +3 -0
- package/lib/report-html.js +2 -0
- package/lib/report.d.ts +20 -0
- package/lib/report.js +80 -0
- package/lib/resolve-directory-prefixes.d.ts +21 -0
- package/lib/resolve-directory-prefixes.js +85 -0
- package/lib/resolve-output-path.d.ts +9 -0
- package/lib/resolve-output-path.js +16 -0
- package/lib/types.d.ts +32 -0
- package/lib/types.js +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 D-ZERO Co., Ltd.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @nitpicker/report-html
|
|
2
|
+
|
|
3
|
+
Generates a self-contained HTML report from a completed Nitpicker archive.
|
|
4
|
+
The document contains the viewer summary and a bounded internal-page table,
|
|
5
|
+
requires no Google credentials, and can be opened directly with `file://`.
|
|
6
|
+
|
|
7
|
+
Use the CLI for interactive directory selection:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn cli report ./site.nitpicker --html
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The package API is also available:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { report } from '@nitpicker/report-html';
|
|
17
|
+
|
|
18
|
+
await report({ filePath: './site.nitpicker' });
|
|
19
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
|
+
import type { HtmlReportPage } from '@nitpicker/viewer/report-ui';
|
|
3
|
+
/**
|
|
4
|
+
* Collects inner-page rows for a static HTML report in `natural_url_rank`
|
|
5
|
+
* order, attaching redirect sources and per-page resource-file tallies.
|
|
6
|
+
* @param accessor - Archive whose viewer read model is already current.
|
|
7
|
+
* @param directories - Directory-prefix filters. Empty or omitted lists every inner page.
|
|
8
|
+
* @returns Page rows ready for `renderHtmlReport`.
|
|
9
|
+
* @example
|
|
10
|
+
* const pages = await collectHtmlReportPages(accessor, ['/docs']);
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectHtmlReportPages(accessor: ArchiveAccessor, directories?: readonly string[]): Promise<HtmlReportPage[]>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildRedirectFromUrlsByDestId, getResourceFileCountsByPageIds, streamPageListRows, } from '@nitpicker/query';
|
|
2
|
+
/**
|
|
3
|
+
* Collects inner-page rows for a static HTML report in `natural_url_rank`
|
|
4
|
+
* order, attaching redirect sources and per-page resource-file tallies.
|
|
5
|
+
* @param accessor - Archive whose viewer read model is already current.
|
|
6
|
+
* @param directories - Directory-prefix filters. Empty or omitted lists every inner page.
|
|
7
|
+
* @returns Page rows ready for `renderHtmlReport`.
|
|
8
|
+
* @example
|
|
9
|
+
* const pages = await collectHtmlReportPages(accessor, ['/docs']);
|
|
10
|
+
*/
|
|
11
|
+
export async function collectHtmlReportPages(accessor, directories = []) {
|
|
12
|
+
const redirectFrom = await buildRedirectFromUrlsByDestId(accessor);
|
|
13
|
+
const pages = [];
|
|
14
|
+
for await (const chunk of streamPageListRows(accessor, { directories })) {
|
|
15
|
+
const counts = await getResourceFileCountsByPageIds(accessor, chunk.map((row) => row.pageId));
|
|
16
|
+
for (const row of chunk) {
|
|
17
|
+
const resources = counts.get(row.pageId) ?? { total: 0, exists: 0 };
|
|
18
|
+
pages.push({
|
|
19
|
+
title: row.title,
|
|
20
|
+
url: row.url,
|
|
21
|
+
status: row.status,
|
|
22
|
+
redirectChain: [...(redirectFrom.get(row.pageId) ?? [])].toSorted((left, right) => left.localeCompare(right)),
|
|
23
|
+
metaDescription: row.description,
|
|
24
|
+
resourceFilesExists: resources.exists,
|
|
25
|
+
resourceFilesTotal: resources.total,
|
|
26
|
+
consoleErrorCount: row.consoleErrorCount,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return pages;
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the interactive directory prompt is dismissed (Ctrl+C), so
|
|
3
|
+
* `report()` can unwind `await using` archive disposal instead of calling
|
|
4
|
+
* `process.exit` from inside the library.
|
|
5
|
+
*
|
|
6
|
+
* `report-google-sheets` still exits immediately to dodge an enquirer
|
|
7
|
+
* readline double-close; HTML reporting prefers a clean archive close, and
|
|
8
|
+
* the CLI maps this error to exit code 0.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* throw new HtmlReportCancelledError();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class HtmlReportCancelledError extends Error {
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the interactive directory prompt is dismissed (Ctrl+C), so
|
|
3
|
+
* `report()` can unwind `await using` archive disposal instead of calling
|
|
4
|
+
* `process.exit` from inside the library.
|
|
5
|
+
*
|
|
6
|
+
* `report-google-sheets` still exits immediately to dodge an enquirer
|
|
7
|
+
* readline double-close; HTML reporting prefers a clean archive close, and
|
|
8
|
+
* the CLI maps this error to exit code 0.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* throw new HtmlReportCancelledError();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class HtmlReportCancelledError extends Error {
|
|
15
|
+
constructor() {
|
|
16
|
+
super('HTML report cancelled');
|
|
17
|
+
this.name = 'HtmlReportCancelledError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
|
+
interface HtmlReportArchiveHandle extends AsyncDisposable {
|
|
3
|
+
readonly accessor: ArchiveAccessor;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Opens a completed archive through the shared read-only tar cache.
|
|
7
|
+
* @param filePath - Completed `.nitpicker` archive path.
|
|
8
|
+
* @param onExtractProgress - Optional extraction progress callback.
|
|
9
|
+
* @returns A disposable read-only archive handle.
|
|
10
|
+
*/
|
|
11
|
+
export declare function openReportArchive(filePath: string, onExtractProgress?: (readBytes: number, totalBytes: number) => void): Promise<HtmlReportArchiveHandle>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ArchiveManager } from '@nitpicker/query';
|
|
2
|
+
/**
|
|
3
|
+
* Opens a completed archive through the shared read-only tar cache.
|
|
4
|
+
* @param filePath - Completed `.nitpicker` archive path.
|
|
5
|
+
* @param onExtractProgress - Optional extraction progress callback.
|
|
6
|
+
* @returns A disposable read-only archive handle.
|
|
7
|
+
*/
|
|
8
|
+
export async function openReportArchive(filePath, onExtractProgress) {
|
|
9
|
+
const manager = new ArchiveManager({ onExtractProgress });
|
|
10
|
+
const { accessor, mode } = await manager.open(filePath);
|
|
11
|
+
if (mode !== 'archive') {
|
|
12
|
+
await manager.closeAll();
|
|
13
|
+
throw new Error(`report: "${filePath}" is not a completed .nitpicker archive (detected mode: "${mode}").`);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
accessor,
|
|
17
|
+
async [Symbol.asyncDispose]() {
|
|
18
|
+
await manager.closeAll();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HtmlReportDirectoryPrefix } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses comma-separated full URLs or absolute pathnames for report filtering.
|
|
4
|
+
*
|
|
5
|
+
* Normalization is {@link parsePageDirectoryPrefix} (full URLs go through
|
|
6
|
+
* `@d-zero/shared/parse-url`). This wrapper only rejects relative tokens such
|
|
7
|
+
* as `docs`, which the query parser would treat as `/docs`.
|
|
8
|
+
*
|
|
9
|
+
* Pathnames are not fed to `new URL(..., base)`: a leading `//` is a
|
|
10
|
+
* protocol-relative URL there, so `//blog` would collapse to the site root.
|
|
11
|
+
* @param input - User-provided comma-separated value.
|
|
12
|
+
* @returns Deduplicated normalized directory prefixes.
|
|
13
|
+
* @throws {Error} If any token is empty, relative, or non-HTTP.
|
|
14
|
+
* @example
|
|
15
|
+
* parseDirectoryInput('/docs,https://example.com/help')
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseDirectoryInput(input: string): HtmlReportDirectoryPrefix[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { parsePageDirectoryPrefix } from '@nitpicker/query';
|
|
2
|
+
/**
|
|
3
|
+
* Matches a token written as an absolute URL. Pathname-only input is the
|
|
4
|
+
* remainder: it must start with `/` (including `//blog`, which is a path
|
|
5
|
+
* with repeated slashes — not a protocol-relative URL).
|
|
6
|
+
*/
|
|
7
|
+
const ABSOLUTE_URL = /^[a-z][a-z\d+.-]*:\/\//iu;
|
|
8
|
+
/**
|
|
9
|
+
* Turns query's host+pathname parse into the CLI prefix shape: pathname-only
|
|
10
|
+
* root is shown as `/`, and a host filter is rebuilt as `https://{host}{path}`
|
|
11
|
+
* because `parsePageDirectoryPrefix` ignores scheme and port.
|
|
12
|
+
* @param parsed - Output of {@link parsePageDirectoryPrefix}.
|
|
13
|
+
* @returns The corresponding HTML-report prefix.
|
|
14
|
+
*/
|
|
15
|
+
function toHtmlReportDirectoryPrefix(parsed) {
|
|
16
|
+
if (parsed.hostname == null) {
|
|
17
|
+
const pathname = parsed.pathname === '' ? '/' : parsed.pathname;
|
|
18
|
+
return { origin: null, pathname, display: pathname };
|
|
19
|
+
}
|
|
20
|
+
const pathname = parsed.pathname === '' ? '/' : parsed.pathname;
|
|
21
|
+
const display = `https://${parsed.hostname}${parsed.pathname}`;
|
|
22
|
+
return {
|
|
23
|
+
origin: `https://${parsed.hostname}`,
|
|
24
|
+
pathname,
|
|
25
|
+
display,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses comma-separated full URLs or absolute pathnames for report filtering.
|
|
30
|
+
*
|
|
31
|
+
* Normalization is {@link parsePageDirectoryPrefix} (full URLs go through
|
|
32
|
+
* `@d-zero/shared/parse-url`). This wrapper only rejects relative tokens such
|
|
33
|
+
* as `docs`, which the query parser would treat as `/docs`.
|
|
34
|
+
*
|
|
35
|
+
* Pathnames are not fed to `new URL(..., base)`: a leading `//` is a
|
|
36
|
+
* protocol-relative URL there, so `//blog` would collapse to the site root.
|
|
37
|
+
* @param input - User-provided comma-separated value.
|
|
38
|
+
* @returns Deduplicated normalized directory prefixes.
|
|
39
|
+
* @throws {Error} If any token is empty, relative, or non-HTTP.
|
|
40
|
+
* @example
|
|
41
|
+
* parseDirectoryInput('/docs,https://example.com/help')
|
|
42
|
+
*/
|
|
43
|
+
export function parseDirectoryInput(input) {
|
|
44
|
+
const rawTokens = input.split(',').map((token) => token.trim());
|
|
45
|
+
if (rawTokens.length === 0 || rawTokens.some((token) => token.length === 0)) {
|
|
46
|
+
throw new Error('Enter one or more comma-separated directory prefixes.');
|
|
47
|
+
}
|
|
48
|
+
const prefixes = rawTokens.map((token) => {
|
|
49
|
+
if (!token.startsWith('/') && !ABSOLUTE_URL.test(token)) {
|
|
50
|
+
throw new Error(`Directory prefix must be a full URL or start with "/": ${token}`);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return toHtmlReportDirectoryPrefix(parsePageDirectoryPrefix(token));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(`Directory URL must use http or https: ${token}`, { cause: error });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return [
|
|
60
|
+
...new Map(prefixes.map((prefix) => [`${prefix.origin ?? ''}\0${prefix.pathname}`, prefix])).values(),
|
|
61
|
+
];
|
|
62
|
+
}
|
package/lib/report.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HtmlReportParams } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a self-contained static HTML report from a completed archive.
|
|
4
|
+
*
|
|
5
|
+
* Google credentials are never consulted. The summary is always archive-wide;
|
|
6
|
+
* only the page table is narrowed when directory prefixes are required to
|
|
7
|
+
* stay at or below 10,000 inner pages.
|
|
8
|
+
* @param params - Archive path, optional output path, and directory input.
|
|
9
|
+
* @returns Resolves when the HTML file has been written.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* await report({
|
|
13
|
+
* filePath: './site.nitpicker',
|
|
14
|
+
* outputPath: './site.html',
|
|
15
|
+
* interactive: false,
|
|
16
|
+
* directoryInput: '/docs',
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function report(params: HtmlReportParams): Promise<void>;
|
package/lib/report.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { TaskList } from '@d-zero/dealer';
|
|
3
|
+
import { getViewerSummary, requireViewerReadModel } from '@nitpicker/query';
|
|
4
|
+
import { renderHtmlReport } from '@nitpicker/viewer/report-ui';
|
|
5
|
+
import { collectHtmlReportPages } from './collect-html-report-pages.js';
|
|
6
|
+
import { openReportArchive } from './open-report-archive.js';
|
|
7
|
+
import { resolveDirectoryPrefixes } from './resolve-directory-prefixes.js';
|
|
8
|
+
import { resolveOutputPath } from './resolve-output-path.js';
|
|
9
|
+
/** A `write()`-only sink that renders nothing, for `params.silent`. */
|
|
10
|
+
const NULL_STREAM = {
|
|
11
|
+
write: () => true,
|
|
12
|
+
on: () => NULL_STREAM,
|
|
13
|
+
off: () => NULL_STREAM,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Generates a self-contained static HTML report from a completed archive.
|
|
17
|
+
*
|
|
18
|
+
* Google credentials are never consulted. The summary is always archive-wide;
|
|
19
|
+
* only the page table is narrowed when directory prefixes are required to
|
|
20
|
+
* stay at or below 10,000 inner pages.
|
|
21
|
+
* @param params - Archive path, optional output path, and directory input.
|
|
22
|
+
* @returns Resolves when the HTML file has been written.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* await report({
|
|
26
|
+
* filePath: './site.nitpicker',
|
|
27
|
+
* outputPath: './site.html',
|
|
28
|
+
* interactive: false,
|
|
29
|
+
* directoryInput: '/docs',
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export async function report(params) {
|
|
34
|
+
await using archive = await openReportArchive(params.filePath, params.onExtractProgress);
|
|
35
|
+
await requireViewerReadModel(archive.accessor);
|
|
36
|
+
const prefixes = await resolveDirectoryPrefixes({
|
|
37
|
+
accessor: archive.accessor,
|
|
38
|
+
initialInput: params.directoryInput,
|
|
39
|
+
interactive: params.interactive === true,
|
|
40
|
+
onWarn: params.silent
|
|
41
|
+
? () => { }
|
|
42
|
+
: (message) => {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.warn(message);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const directoryPrefixes = prefixes.map((prefix) => prefix.display);
|
|
48
|
+
const outputPath = resolveOutputPath(params.filePath, params.outputPath);
|
|
49
|
+
let html = '';
|
|
50
|
+
let pipeline = TaskList.from(0);
|
|
51
|
+
pipeline = pipeline.pipe('Collect pages', async (input, ctx) => {
|
|
52
|
+
ctx.progress('reading inner pages...');
|
|
53
|
+
const pages = await collectHtmlReportPages(archive.accessor, directoryPrefixes);
|
|
54
|
+
const summary = await getViewerSummary(archive.accessor);
|
|
55
|
+
ctx.progress(`${pages.length.toLocaleString()} pages`);
|
|
56
|
+
html = renderHtmlReport({
|
|
57
|
+
summary,
|
|
58
|
+
pages,
|
|
59
|
+
locale: 'ja',
|
|
60
|
+
generatedAt: new Date().toISOString(),
|
|
61
|
+
directoryPrefixes,
|
|
62
|
+
});
|
|
63
|
+
return input;
|
|
64
|
+
});
|
|
65
|
+
pipeline = pipeline.pipe('Write HTML', async (input, ctx) => {
|
|
66
|
+
ctx.progress('writing...');
|
|
67
|
+
await writeFile(outputPath, html, 'utf8');
|
|
68
|
+
ctx.progress(outputPath);
|
|
69
|
+
return input;
|
|
70
|
+
});
|
|
71
|
+
await pipeline.run({
|
|
72
|
+
stream: params.silent ? NULL_STREAM : process.stderr,
|
|
73
|
+
verbose: !process.stdout.isTTY,
|
|
74
|
+
keepElapsed: true,
|
|
75
|
+
});
|
|
76
|
+
if (!params.silent) {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.log(`Wrote ${outputPath}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HtmlReportDirectoryPrefix } from './types.js';
|
|
2
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
3
|
+
interface ResolveDirectoryPrefixesOptions {
|
|
4
|
+
readonly accessor: ArchiveAccessor;
|
|
5
|
+
readonly initialInput?: string;
|
|
6
|
+
readonly interactive: boolean;
|
|
7
|
+
readonly onWarn: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolves and validates the directory prefixes needed to keep a report bounded.
|
|
11
|
+
* @param options - Archive, initial non-interactive value, and warning sink.
|
|
12
|
+
* @returns Valid prefixes whose union contains at most 10,000 pages.
|
|
13
|
+
* @example
|
|
14
|
+
* const prefixes = await resolveDirectoryPrefixes({
|
|
15
|
+
* accessor,
|
|
16
|
+
* interactive: process.stdout.isTTY === true,
|
|
17
|
+
* onWarn: console.warn,
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveDirectoryPrefixes(options: ResolveDirectoryPrefixesOptions): Promise<HtmlReportDirectoryPrefix[]>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { countPageListHostnames, countPageListRows } from '@nitpicker/query';
|
|
2
|
+
import enquirer from 'enquirer';
|
|
3
|
+
import { HtmlReportCancelledError } from './html-report-cancelled-error.js';
|
|
4
|
+
import { parseDirectoryInput } from './parse-directory-input.js';
|
|
5
|
+
const PAGE_LIMIT = 10_000;
|
|
6
|
+
/**
|
|
7
|
+
* Asks for comma-separated directory prefixes on a TTY.
|
|
8
|
+
* @returns The raw input string.
|
|
9
|
+
* @throws {HtmlReportCancelledError} If the prompt is dismissed.
|
|
10
|
+
*/
|
|
11
|
+
async function promptForInput() {
|
|
12
|
+
try {
|
|
13
|
+
const answer = await enquirer.prompt({
|
|
14
|
+
type: 'input',
|
|
15
|
+
name: 'directories',
|
|
16
|
+
message: 'Filter inner pages by directory (comma-separated full URLs or /pathnames):',
|
|
17
|
+
});
|
|
18
|
+
return answer.directories;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Why not `process.exit(0)` here (the Sheets reporter does that for
|
|
22
|
+
// enquirer Ctrl+C): this prompt runs under `report()`'s `await using`
|
|
23
|
+
// archive, and exiting the process would skip dispose. Throw so the
|
|
24
|
+
// archive closes; the CLI maps the error to exit code 0.
|
|
25
|
+
throw new HtmlReportCancelledError();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Resolves and validates the directory prefixes needed to keep a report bounded.
|
|
30
|
+
* @param options - Archive, initial non-interactive value, and warning sink.
|
|
31
|
+
* @returns Valid prefixes whose union contains at most 10,000 pages.
|
|
32
|
+
* @example
|
|
33
|
+
* const prefixes = await resolveDirectoryPrefixes({
|
|
34
|
+
* accessor,
|
|
35
|
+
* interactive: process.stdout.isTTY === true,
|
|
36
|
+
* onWarn: console.warn,
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
export async function resolveDirectoryPrefixes(options) {
|
|
40
|
+
const unfilteredTotal = await countPageListRows(options.accessor);
|
|
41
|
+
const hostnameCount = await countPageListHostnames(options.accessor);
|
|
42
|
+
let input = options.initialInput;
|
|
43
|
+
if (unfilteredTotal <= PAGE_LIMIT && input == null) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
for (;;) {
|
|
47
|
+
if (input == null) {
|
|
48
|
+
if (!options.interactive) {
|
|
49
|
+
throw new Error(`HTML report has ${unfilteredTotal.toLocaleString()} inner pages; ` +
|
|
50
|
+
'use --html-dirs with comma-separated directory prefixes to reduce it to 10,000 or fewer.');
|
|
51
|
+
}
|
|
52
|
+
options.onWarn(`HTML report has ${unfilteredTotal.toLocaleString()} inner pages; select directories containing 10,000 or fewer pages.`);
|
|
53
|
+
input = await promptForInput();
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const prefixes = parseDirectoryInput(input);
|
|
57
|
+
if (hostnameCount > 1 && prefixes.some((prefix) => prefix.origin === null)) {
|
|
58
|
+
throw new Error('This archive contains multiple hosts; every directory prefix must be a full URL.');
|
|
59
|
+
}
|
|
60
|
+
for (const prefix of prefixes) {
|
|
61
|
+
const count = await countPageListRows(options.accessor, {
|
|
62
|
+
directories: [prefix.display],
|
|
63
|
+
});
|
|
64
|
+
if (count === 0) {
|
|
65
|
+
throw new Error(`No inner page matches directory prefix: ${prefix.display}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const selectedTotal = await countPageListRows(options.accessor, {
|
|
69
|
+
directories: prefixes.map((prefix) => prefix.display),
|
|
70
|
+
});
|
|
71
|
+
if (selectedTotal > PAGE_LIMIT) {
|
|
72
|
+
throw new Error(`The selected directories contain ${selectedTotal.toLocaleString()} inner pages; narrow them to 10,000 or fewer.`);
|
|
73
|
+
}
|
|
74
|
+
return prefixes;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
78
|
+
if (!options.interactive) {
|
|
79
|
+
throw new Error(`Invalid --html-dirs: ${message}`, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
options.onWarn(`Warning: ${message}`);
|
|
82
|
+
input = await promptForInput();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the HTML destination, defaulting to the archive basename in CWD.
|
|
3
|
+
* @param filePath - Source archive path.
|
|
4
|
+
* @param outputPath - Explicit destination, when supplied.
|
|
5
|
+
* @returns Absolute output path.
|
|
6
|
+
* @example
|
|
7
|
+
* resolveOutputPath('/tmp/site.nitpicker', undefined) // `${process.cwd()}/site.html`
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveOutputPath(filePath: string, outputPath?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the HTML destination, defaulting to the archive basename in CWD.
|
|
4
|
+
* @param filePath - Source archive path.
|
|
5
|
+
* @param outputPath - Explicit destination, when supplied.
|
|
6
|
+
* @returns Absolute output path.
|
|
7
|
+
* @example
|
|
8
|
+
* resolveOutputPath('/tmp/site.nitpicker', undefined) // `${process.cwd()}/site.html`
|
|
9
|
+
*/
|
|
10
|
+
export function resolveOutputPath(filePath, outputPath) {
|
|
11
|
+
if (outputPath) {
|
|
12
|
+
return path.resolve(process.cwd(), outputPath);
|
|
13
|
+
}
|
|
14
|
+
const parsed = path.parse(filePath);
|
|
15
|
+
return path.resolve(process.cwd(), `${parsed.name}.html`);
|
|
16
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Parameters accepted by the static HTML reporter. */
|
|
2
|
+
export interface HtmlReportParams {
|
|
3
|
+
/** Path to a completed `.nitpicker` archive. */
|
|
4
|
+
readonly filePath: string;
|
|
5
|
+
/** Destination path, or omitted for `<archive-name>.html` in the current directory. */
|
|
6
|
+
readonly outputPath?: string;
|
|
7
|
+
/** Comma-separated directory prefixes used for non-interactive large reports. */
|
|
8
|
+
readonly directoryInput?: string;
|
|
9
|
+
/** Whether the reporter may prompt for directory prefixes. */
|
|
10
|
+
readonly interactive?: boolean;
|
|
11
|
+
/** Suppresses completion and warning output. */
|
|
12
|
+
readonly silent?: boolean;
|
|
13
|
+
/** Receives archive extraction byte progress. */
|
|
14
|
+
readonly onExtractProgress?: (readBytes: number, totalBytes: number) => void;
|
|
15
|
+
}
|
|
16
|
+
/** Normalized directory prefix used to constrain inner-page rows. */
|
|
17
|
+
export interface HtmlReportDirectoryPrefix {
|
|
18
|
+
/**
|
|
19
|
+
* Reconstructed `https://{hostname}` for a full-URL input (scheme and
|
|
20
|
+
* port dropped, matching `parsePageDirectoryPrefix`), or `null` for
|
|
21
|
+
* pathname-only input.
|
|
22
|
+
*/
|
|
23
|
+
readonly origin: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Normalized absolute pathname without a trailing slash. The site root
|
|
26
|
+
* is `/` here so the CLI can show it; query matching treats `/` as no
|
|
27
|
+
* path restriction.
|
|
28
|
+
*/
|
|
29
|
+
readonly pathname: string;
|
|
30
|
+
/** User-facing normalized representation passed to query directory filters. */
|
|
31
|
+
readonly display: string;
|
|
32
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nitpicker/report-html",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Self-contained static HTML reports for Nitpicker archives",
|
|
5
|
+
"author": "D-ZERO",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24.11.0"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/d-zero-dev/nitpicker.git",
|
|
13
|
+
"directory": "packages/@nitpicker/report-html"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./lib/report-html.js",
|
|
25
|
+
"types": "./lib/report-html.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc",
|
|
30
|
+
"clean": "tsc --build --clean"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@d-zero/dealer": "1.13.1",
|
|
34
|
+
"@nitpicker/crawler": "0.20.0",
|
|
35
|
+
"@nitpicker/query": "0.20.0",
|
|
36
|
+
"@nitpicker/viewer": "0.20.0",
|
|
37
|
+
"enquirer": "2.4.1",
|
|
38
|
+
"react": "19.2.8",
|
|
39
|
+
"react-dom": "19.2.8"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@d-zero/shared": "0.23.0",
|
|
43
|
+
"vitest": "4.1.11"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "c322c99bbaca356646d06130cb6eec2706c0ddc5"
|
|
46
|
+
}
|