@nitpicker/report-google-sheets 0.18.1 → 0.19.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/lib/archive.d.ts +13 -4
- package/lib/archive.js +19 -4
- package/lib/data/create-page-list.js +2 -0
- package/lib/report.d.ts +9 -0
- package/lib/report.js +100 -110
- package/package.json +12 -9
package/lib/archive.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Archive } from '@nitpicker/crawler';
|
|
2
2
|
/**
|
|
3
3
|
* Result of opening an archive with signal handlers registered.
|
|
4
|
+
*
|
|
5
|
+
* Implements `Symbol.asyncDispose` so callers can obtain one via
|
|
6
|
+
* `await using` instead of remembering to call both
|
|
7
|
+
* `removeSignalHandlers()` and `archive.close()` by hand.
|
|
4
8
|
*/
|
|
5
|
-
export interface ArchiveHandle {
|
|
9
|
+
export interface ArchiveHandle extends AsyncDisposable {
|
|
6
10
|
/** The opened archive instance. */
|
|
7
11
|
readonly archive: Archive;
|
|
8
12
|
/** Removes the registered signal handlers. Call this when the archive is no longer in use. */
|
|
@@ -12,9 +16,14 @@ export interface ArchiveHandle {
|
|
|
12
16
|
* Opens a `.nitpicker` archive file and registers process signal handlers
|
|
13
17
|
* to ensure the archive is closed gracefully on unexpected termination.
|
|
14
18
|
*
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
19
|
+
* The returned handle's `Symbol.asyncDispose` removes the signal handlers
|
|
20
|
+
* and closes the archive together — prefer `await using` over calling
|
|
21
|
+
* `removeSignalHandlers()` / `archive.close()` separately.
|
|
17
22
|
* @param filePath - Path to the `.nitpicker` archive file
|
|
23
|
+
* @param onExtractProgress - Forwarded to `Archive.open` — called during the
|
|
24
|
+
* untar step with bytes read so far and the archive's total size (issue
|
|
25
|
+
* #294: a large archive's extraction can take tens of seconds with no
|
|
26
|
+
* other signal it isn't hung).
|
|
18
27
|
* @returns An {@link ArchiveHandle} containing the archive and a cleanup function.
|
|
19
28
|
*/
|
|
20
|
-
export declare function getArchive(filePath: string): Promise<ArchiveHandle>;
|
|
29
|
+
export declare function getArchive(filePath: string, onExtractProgress?: (readBytes: number, totalBytes: number) => void): Promise<ArchiveHandle>;
|
package/lib/archive.js
CHANGED
|
@@ -4,16 +4,22 @@ import { archiveLog } from './debug.js';
|
|
|
4
4
|
* Opens a `.nitpicker` archive file and registers process signal handlers
|
|
5
5
|
* to ensure the archive is closed gracefully on unexpected termination.
|
|
6
6
|
*
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
7
|
+
* The returned handle's `Symbol.asyncDispose` removes the signal handlers
|
|
8
|
+
* and closes the archive together — prefer `await using` over calling
|
|
9
|
+
* `removeSignalHandlers()` / `archive.close()` separately.
|
|
9
10
|
* @param filePath - Path to the `.nitpicker` archive file
|
|
11
|
+
* @param onExtractProgress - Forwarded to `Archive.open` — called during the
|
|
12
|
+
* untar step with bytes read so far and the archive's total size (issue
|
|
13
|
+
* #294: a large archive's extraction can take tens of seconds with no
|
|
14
|
+
* other signal it isn't hung).
|
|
10
15
|
* @returns An {@link ArchiveHandle} containing the archive and a cleanup function.
|
|
11
16
|
*/
|
|
12
|
-
export async function getArchive(filePath) {
|
|
17
|
+
export async function getArchive(filePath, onExtractProgress) {
|
|
13
18
|
archiveLog('Open file: %s', filePath);
|
|
14
19
|
const archive = await Archive.open({
|
|
15
20
|
filePath,
|
|
16
21
|
openPluginData: true,
|
|
22
|
+
onExtractProgress,
|
|
17
23
|
});
|
|
18
24
|
archiveLog('File open succeeded');
|
|
19
25
|
const signals = ['SIGINT', 'SIGBREAK', 'SIGHUP', 'SIGABRT'];
|
|
@@ -30,5 +36,14 @@ export async function getArchive(filePath) {
|
|
|
30
36
|
process.removeListener(signal, close);
|
|
31
37
|
}
|
|
32
38
|
};
|
|
33
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
archive,
|
|
41
|
+
removeSignalHandlers,
|
|
42
|
+
async [Symbol.asyncDispose]() {
|
|
43
|
+
archiveLog('Closes file');
|
|
44
|
+
removeSignalHandlers();
|
|
45
|
+
await archive.close();
|
|
46
|
+
archiveLog('Closed');
|
|
47
|
+
},
|
|
48
|
+
};
|
|
34
49
|
}
|
|
@@ -122,6 +122,7 @@ export const createPageList = (reports) => {
|
|
|
122
122
|
'main_content_video_count',
|
|
123
123
|
'main_content_audio_count',
|
|
124
124
|
'main_content_canvas_count',
|
|
125
|
+
'main_content_custom_element_count',
|
|
125
126
|
'scroll_height_desktop',
|
|
126
127
|
'scroll_height_mobile',
|
|
127
128
|
];
|
|
@@ -286,6 +287,7 @@ export const createPageList = (reports) => {
|
|
|
286
287
|
createCellData({ value: page.mainContentVideoCount }, defaultCellFormat),
|
|
287
288
|
createCellData({ value: page.mainContentAudioCount }, defaultCellFormat),
|
|
288
289
|
createCellData({ value: page.mainContentCanvasCount }, defaultCellFormat),
|
|
290
|
+
createCellData({ value: page.mainContentCustomElementCount }, defaultCellFormat),
|
|
289
291
|
createCellData({ value: page.scrollHeightDesktop }, defaultCellFormat),
|
|
290
292
|
createCellData({ value: page.scrollHeightMobile }, defaultCellFormat),
|
|
291
293
|
];
|
package/lib/report.d.ts
CHANGED
|
@@ -26,6 +26,15 @@ export interface ReportParams {
|
|
|
26
26
|
* to `false` (raw mode).
|
|
27
27
|
*/
|
|
28
28
|
readonly dedupeResources?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Called during the archive-open untar step with bytes read so far and
|
|
31
|
+
* the archive's total size (issue #294: a large archive's extraction can
|
|
32
|
+
* take tens of seconds with no other signal it isn't hung). This
|
|
33
|
+
* package stays UI-agnostic — the caller (the CLI's `report` command)
|
|
34
|
+
* owns turning this into a `Lanes` display, the same way `Sheets.onLog`
|
|
35
|
+
* lets the caller own the rate-limit countdown display below.
|
|
36
|
+
*/
|
|
37
|
+
readonly onExtractProgress?: (readBytes: number, totalBytes: number) => void;
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
40
|
* Generates a Google Sheets report from a `.nitpicker` archive file.
|
package/lib/report.js
CHANGED
|
@@ -13,7 +13,7 @@ import { createReferrersRelationalTable } from './data/create-referrers-relation
|
|
|
13
13
|
import { createResourcesRelationalTable } from './data/create-resources-relational-table.js';
|
|
14
14
|
import { createResources } from './data/create-resources.js';
|
|
15
15
|
import { createViolations } from './data/create-violations.js';
|
|
16
|
-
import {
|
|
16
|
+
import { log } from './debug.js';
|
|
17
17
|
import { loadConfig } from './load-config.js';
|
|
18
18
|
import { getPluginReports } from './reports/get-plugin-reports.js';
|
|
19
19
|
import { createSheets } from './sheets/create-sheets.js';
|
|
@@ -46,7 +46,7 @@ import { createSheets } from './sheets/create-sheets.js';
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export async function report(params) {
|
|
49
|
-
const { filePath, sheetUrl, credentialFilePath, configPath, limit, all, silent, dedupeResources, } = params;
|
|
49
|
+
const { filePath, sheetUrl, credentialFilePath, configPath, limit, all, silent, dedupeResources, onExtractProgress, } = params;
|
|
50
50
|
log('Initialization');
|
|
51
51
|
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
|
|
52
52
|
log('Authenticating');
|
|
@@ -55,91 +55,92 @@ export async function report(params) {
|
|
|
55
55
|
});
|
|
56
56
|
log('Authentication succeeded');
|
|
57
57
|
log('Opening archive: %s', filePath);
|
|
58
|
-
|
|
58
|
+
await using archiveHandle = await getArchive(filePath, onExtractProgress);
|
|
59
|
+
const { archive } = archiveHandle;
|
|
59
60
|
log('Archive opened');
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
61
|
+
log('Loading config');
|
|
62
|
+
const config = await loadConfig(configPath);
|
|
63
|
+
log('Config loaded');
|
|
64
|
+
const plugins = config.plugins?.analyze
|
|
65
|
+
? Object.keys(config.plugins.analyze)
|
|
66
|
+
: undefined;
|
|
67
|
+
log('Loaded plugins: %O', plugins);
|
|
68
|
+
log('Loading plugin reports');
|
|
69
|
+
const reports = await getPluginReports(archive /*plugins*/);
|
|
70
|
+
log('Plugin reports loaded: %d', reports.length);
|
|
71
|
+
const sheets = new Sheets(sheetUrl, auth);
|
|
72
|
+
log('Reporting starts');
|
|
73
|
+
const sheetNames = [
|
|
74
|
+
'Page List',
|
|
75
|
+
'Links',
|
|
76
|
+
'Resources',
|
|
77
|
+
'Images',
|
|
78
|
+
'Violations',
|
|
79
|
+
'Discrepancies',
|
|
80
|
+
'Summary',
|
|
81
|
+
'Referrers Relational Table',
|
|
82
|
+
'Resources Relational Table',
|
|
83
|
+
];
|
|
84
|
+
let selectedSheetNames;
|
|
85
|
+
if (all) {
|
|
86
|
+
log('All sheets selected (--all or non-TTY)');
|
|
87
|
+
selectedSheetNames = sheetNames;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
log('Choice creating data');
|
|
91
|
+
const chosenSheets = await enquirer
|
|
92
|
+
.prompt([
|
|
93
|
+
{
|
|
94
|
+
message: 'What do you report?',
|
|
95
|
+
name: 'sheetName',
|
|
96
|
+
type: 'multiselect',
|
|
97
|
+
choices: sheetNames,
|
|
98
|
+
},
|
|
99
|
+
])
|
|
100
|
+
.catch(() => {
|
|
101
|
+
// enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
|
|
102
|
+
// ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
|
|
103
|
+
// 即座に終了して回避する
|
|
104
|
+
process.exit(0);
|
|
105
|
+
});
|
|
106
|
+
if (!chosenSheets) {
|
|
90
107
|
log('Choice creating data');
|
|
91
|
-
|
|
92
|
-
.prompt([
|
|
93
|
-
{
|
|
94
|
-
message: 'What do you report?',
|
|
95
|
-
name: 'sheetName',
|
|
96
|
-
type: 'multiselect',
|
|
97
|
-
choices: sheetNames,
|
|
98
|
-
},
|
|
99
|
-
])
|
|
100
|
-
.catch(() => {
|
|
101
|
-
// enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
|
|
102
|
-
// ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
|
|
103
|
-
// 即座に終了して回避する
|
|
104
|
-
process.exit(0);
|
|
105
|
-
});
|
|
106
|
-
if (!chosenSheets) {
|
|
107
|
-
log('Choice creating data');
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
selectedSheetNames = chosenSheets.sheetName;
|
|
111
|
-
}
|
|
112
|
-
log('Chosen sheets: %O', selectedSheetNames);
|
|
113
|
-
const createSheetList = [];
|
|
114
|
-
if (selectedSheetNames.includes('Page List')) {
|
|
115
|
-
createSheetList.push(createPageList);
|
|
116
|
-
}
|
|
117
|
-
if (selectedSheetNames.includes('Links')) {
|
|
118
|
-
createSheetList.push(createLinks);
|
|
119
|
-
}
|
|
120
|
-
if (selectedSheetNames.includes('Discrepancies')) {
|
|
121
|
-
createSheetList.push(createDiscrepancies);
|
|
122
|
-
}
|
|
123
|
-
if (selectedSheetNames.includes('Violations')) {
|
|
124
|
-
createSheetList.push(createViolations);
|
|
125
|
-
}
|
|
126
|
-
if (selectedSheetNames.includes('Referrers Relational Table')) {
|
|
127
|
-
createSheetList.push(createReferrersRelationalTable);
|
|
108
|
+
return;
|
|
128
109
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
110
|
+
selectedSheetNames = chosenSheets.sheetName;
|
|
111
|
+
}
|
|
112
|
+
log('Chosen sheets: %O', selectedSheetNames);
|
|
113
|
+
const createSheetList = [];
|
|
114
|
+
if (selectedSheetNames.includes('Page List')) {
|
|
115
|
+
createSheetList.push(createPageList);
|
|
116
|
+
}
|
|
117
|
+
if (selectedSheetNames.includes('Links')) {
|
|
118
|
+
createSheetList.push(createLinks);
|
|
119
|
+
}
|
|
120
|
+
if (selectedSheetNames.includes('Discrepancies')) {
|
|
121
|
+
createSheetList.push(createDiscrepancies);
|
|
122
|
+
}
|
|
123
|
+
if (selectedSheetNames.includes('Violations')) {
|
|
124
|
+
createSheetList.push(createViolations);
|
|
125
|
+
}
|
|
126
|
+
if (selectedSheetNames.includes('Referrers Relational Table')) {
|
|
127
|
+
createSheetList.push(createReferrersRelationalTable);
|
|
128
|
+
}
|
|
129
|
+
if (selectedSheetNames.includes('Resources Relational Table')) {
|
|
130
|
+
createSheetList.push(createResourcesRelationalTable);
|
|
131
|
+
}
|
|
132
|
+
if (selectedSheetNames.includes('Resources')) {
|
|
133
|
+
createSheetList.push(createResources({ dedupe: dedupeResources }));
|
|
134
|
+
}
|
|
135
|
+
if (selectedSheetNames.includes('Images')) {
|
|
136
|
+
createSheetList.push(createImageList);
|
|
137
|
+
}
|
|
138
|
+
if (!silent) {
|
|
139
|
+
// eslint-disable-next-line no-console
|
|
140
|
+
console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
|
|
141
|
+
}
|
|
142
|
+
{
|
|
143
|
+
using lanes = silent
|
|
143
144
|
? null
|
|
144
145
|
: new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
|
|
145
146
|
log('Lanes created (verbose: %s, silent: %s)', !process.stdout.isTTY, !!silent);
|
|
@@ -170,32 +171,21 @@ export async function report(params) {
|
|
|
170
171
|
};
|
|
171
172
|
}
|
|
172
173
|
log('Reporting starts (limit: %d)', limit);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
log('Reporting done');
|
|
187
|
-
if (!silent) {
|
|
188
|
-
// eslint-disable-next-line no-console
|
|
189
|
-
console.log('\nReport complete.');
|
|
190
|
-
}
|
|
191
|
-
if (selectedSheetNames.includes('Summary')) {
|
|
192
|
-
await addToSummary( /*sheets, archive, reports*/);
|
|
193
|
-
}
|
|
174
|
+
await createSheets({
|
|
175
|
+
sheets,
|
|
176
|
+
archive,
|
|
177
|
+
reports,
|
|
178
|
+
limit,
|
|
179
|
+
createSheetList,
|
|
180
|
+
options: lanes ? { lanes } : undefined,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
log('Reporting done');
|
|
184
|
+
if (!silent) {
|
|
185
|
+
// eslint-disable-next-line no-console
|
|
186
|
+
console.log('\nReport complete.');
|
|
194
187
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
removeSignalHandlers();
|
|
198
|
-
await archive.close();
|
|
199
|
-
log('Done');
|
|
188
|
+
if (selectedSheetNames.includes('Summary')) {
|
|
189
|
+
await addToSummary( /*sheets, archive, reports*/);
|
|
200
190
|
}
|
|
201
191
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitpicker/report-google-sheets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Nitpicker reporter that outputs crawl and analysis results to Google Sheets",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24.11.0"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "https://github.com/d-zero-dev/nitpicker.git",
|
|
@@ -27,13 +30,13 @@
|
|
|
27
30
|
"clean": "tsc --build --clean"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@d-zero/dealer": "1.
|
|
31
|
-
"@d-zero/google-auth": "0.7.
|
|
32
|
-
"@d-zero/google-sheets": "0.
|
|
33
|
-
"@d-zero/shared": "0.
|
|
34
|
-
"@nitpicker/crawler": "0.
|
|
35
|
-
"@nitpicker/query": "0.
|
|
36
|
-
"@nitpicker/types": "0.
|
|
33
|
+
"@d-zero/dealer": "1.12.0",
|
|
34
|
+
"@d-zero/google-auth": "0.7.6",
|
|
35
|
+
"@d-zero/google-sheets": "0.10.0",
|
|
36
|
+
"@d-zero/shared": "0.23.0",
|
|
37
|
+
"@nitpicker/crawler": "0.19.0",
|
|
38
|
+
"@nitpicker/query": "0.19.0",
|
|
39
|
+
"@nitpicker/types": "0.19.0",
|
|
37
40
|
"ansi-colors": "4.1.3",
|
|
38
41
|
"debug": "4.4.3",
|
|
39
42
|
"enquirer": "2.4.1",
|
|
@@ -45,5 +48,5 @@
|
|
|
45
48
|
"googleapis": "173.0.0",
|
|
46
49
|
"vitest": "4.1.10"
|
|
47
50
|
},
|
|
48
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b79b5c304820d924168a139e7148e0593c29fe1c"
|
|
49
52
|
}
|