@nitpicker/report-google-sheets 0.4.3 → 0.5.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 CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Archive } from '@nitpicker/crawler';
2
2
  /**
3
- *
4
- * @param filePath
3
+ * Opens a `.nitpicker` archive file and registers process signal handlers
4
+ * to ensure the archive is closed gracefully on unexpected termination.
5
+ * @param filePath - Path to the `.nitpicker` archive file
6
+ * @returns The opened `Archive` instance with plugin data loaded
5
7
  */
6
8
  export declare function getArchive(filePath: string): Promise<Archive>;
package/lib/archive.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Archive } from '@nitpicker/crawler';
2
2
  import { archiveLog } from './debug.js';
3
3
  /**
4
- *
5
- * @param filePath
4
+ * Opens a `.nitpicker` archive file and registers process signal handlers
5
+ * to ensure the archive is closed gracefully on unexpected termination.
6
+ * @param filePath - Path to the `.nitpicker` archive file
7
+ * @returns The opened `Archive` instance with plugin data loaded
6
8
  */
7
9
  export async function getArchive(filePath) {
8
10
  archiveLog('Open file: %s', filePath);
@@ -24,6 +24,6 @@ import type { CreateSheet } from '../sheets/types.js';
24
24
  * - Error-like titles and non-success status codes
25
25
  *
26
26
  * Unused path columns (beyond the deepest URL) are hidden automatically.
27
- * @param reports
27
+ * @param reports - Analyze plugin reports to extract per-page data columns from
28
28
  */
29
29
  export declare const createPageList: CreateSheet;
@@ -32,7 +32,7 @@ const indexRefs = new Map();
32
32
  * - Error-like titles and non-success status codes
33
33
  *
34
34
  * Unused path columns (beyond the deepest URL) are hidden automatically.
35
- * @param reports
35
+ * @param reports - Analyze plugin reports to extract per-page data columns from
36
36
  */
37
37
  export const createPageList = (reports) => {
38
38
  const reportPageData = reports
@@ -1,6 +1,8 @@
1
1
  import type { ConfigJSON } from '@nitpicker/types';
2
2
  /**
3
- *
4
- * @param filePath
3
+ * Loads a nitpicker configuration JSON file from the given path.
4
+ * Returns an empty object when no path is provided.
5
+ * @param filePath - Absolute or relative path to the configuration file, or `null` to skip loading
6
+ * @returns The parsed configuration object
5
7
  */
6
8
  export declare function loadConfig(filePath: string | null): Promise<ConfigJSON>;
@@ -1,8 +1,10 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  /**
4
- *
5
- * @param filePath
4
+ * Loads a nitpicker configuration JSON file from the given path.
5
+ * Returns an empty object when no path is provided.
6
+ * @param filePath - Absolute or relative path to the configuration file, or `null` to skip loading
7
+ * @returns The parsed configuration object
6
8
  */
7
9
  export async function loadConfig(filePath) {
8
10
  if (!filePath) {
@@ -0,0 +1 @@
1
+ export { report } from './report.js';
@@ -0,0 +1 @@
1
+ export { report } from './report.js';
package/lib/report.d.ts CHANGED
@@ -12,6 +12,10 @@ export interface ReportParams {
12
12
  readonly configPath: string | null;
13
13
  /** Batch size for `getPagesWithRefs()` pagination (default: 100,000). */
14
14
  readonly limit: number;
15
+ /** When `true`, generate all sheets without interactive prompt. */
16
+ readonly all?: boolean;
17
+ /** When `true`, suppress progress display output. */
18
+ readonly silent?: boolean;
15
19
  }
16
20
  /**
17
21
  * Generates a Google Sheets report from a `.nitpicker` archive file.
package/lib/report.js CHANGED
@@ -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 } = params;
49
+ const { filePath, sheetUrl, credentialFilePath, configPath, limit, all, silent } = params;
50
50
  log('Initialization');
51
51
  const SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];
52
52
  log('Authenticating');
@@ -80,80 +80,94 @@ export async function report(params) {
80
80
  'Referrers Relational Table',
81
81
  'Resources Relational Table',
82
82
  ];
83
- log('Choice creating data');
84
- const chosenSheets = await enquirer
85
- .prompt([
86
- {
87
- message: 'What do you report?',
88
- name: 'sheetName',
89
- type: 'multiselect',
90
- choices: sheetNames,
91
- },
92
- ])
93
- .catch(() => {
94
- // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
95
- // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
96
- // 即座に終了して回避する
97
- process.exit(0);
98
- });
99
- if (!chosenSheets) {
83
+ let selectedSheetNames;
84
+ if (all) {
85
+ log('All sheets selected (--all or non-TTY)');
86
+ selectedSheetNames = sheetNames;
87
+ }
88
+ else {
100
89
  log('Choice creating data');
101
- archiveLog('Closes file');
102
- await archive.close();
103
- return;
90
+ const chosenSheets = await enquirer
91
+ .prompt([
92
+ {
93
+ message: 'What do you report?',
94
+ name: 'sheetName',
95
+ type: 'multiselect',
96
+ choices: sheetNames,
97
+ },
98
+ ])
99
+ .catch(() => {
100
+ // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
101
+ // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
102
+ // 即座に終了して回避する
103
+ process.exit(0);
104
+ });
105
+ if (!chosenSheets) {
106
+ log('Choice creating data');
107
+ archiveLog('Closes file');
108
+ await archive.close();
109
+ return;
110
+ }
111
+ selectedSheetNames = chosenSheets.sheetName;
104
112
  }
105
- log('Chosen sheets: %O', chosenSheets.sheetName);
113
+ log('Chosen sheets: %O', selectedSheetNames);
106
114
  const createSheetList = [];
107
- if (chosenSheets.sheetName.includes('Page List')) {
115
+ if (selectedSheetNames.includes('Page List')) {
108
116
  createSheetList.push(createPageList);
109
117
  }
110
- if (chosenSheets.sheetName.includes('Links')) {
118
+ if (selectedSheetNames.includes('Links')) {
111
119
  createSheetList.push(createLinks);
112
120
  }
113
- if (chosenSheets.sheetName.includes('Discrepancies')) {
121
+ if (selectedSheetNames.includes('Discrepancies')) {
114
122
  createSheetList.push(createDiscrepancies);
115
123
  }
116
- if (chosenSheets.sheetName.includes('Violations')) {
124
+ if (selectedSheetNames.includes('Violations')) {
117
125
  createSheetList.push(createViolations);
118
126
  }
119
- if (chosenSheets.sheetName.includes('Referrers Relational Table')) {
127
+ if (selectedSheetNames.includes('Referrers Relational Table')) {
120
128
  createSheetList.push(createReferrersRelationalTable);
121
129
  }
122
- if (chosenSheets.sheetName.includes('Resources Relational Table')) {
130
+ if (selectedSheetNames.includes('Resources Relational Table')) {
123
131
  createSheetList.push(createResourcesRelationalTable);
124
132
  }
125
- if (chosenSheets.sheetName.includes('Resources')) {
133
+ if (selectedSheetNames.includes('Resources')) {
126
134
  createSheetList.push(createResources);
127
135
  }
128
- if (chosenSheets.sheetName.includes('Images')) {
136
+ if (selectedSheetNames.includes('Images')) {
129
137
  createSheetList.push(createImageList);
130
138
  }
131
- // eslint-disable-next-line no-console
132
- console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
133
- const lanes = new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
134
- log('Lanes created (verbose: %s)', !process.stdout.isTTY);
139
+ if (!silent) {
140
+ // eslint-disable-next-line no-console
141
+ console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
142
+ }
143
+ const lanes = silent
144
+ ? null
145
+ : new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
146
+ log('Lanes created (verbose: %s, silent: %s)', !process.stdout.isTTY, !!silent);
135
147
  const RATE_LIMIT_LANE = 10_000;
136
148
  let countdownSeq = 0;
137
149
  let waitingCount = 0;
138
- sheets.onLog = (message) => {
139
- if (message.waiting && message.waitTime) {
140
- waitingCount++;
141
- const id = `rateLimit_${countdownSeq++}`;
142
- const label = message.message === 'TooManyRequestError'
143
- ? 'Too Many Requests (429)'
144
- : message.message === 'UserRateLimitExceededError'
145
- ? 'Rate Limit Exceeded (403)'
146
- : 'Connection Reset';
147
- lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
148
- }
149
- else {
150
- waitingCount--;
151
- if (waitingCount <= 0) {
152
- waitingCount = 0;
153
- lanes.delete(RATE_LIMIT_LANE);
150
+ if (lanes) {
151
+ sheets.onLog = (message) => {
152
+ if (message.waiting && message.waitTime) {
153
+ waitingCount++;
154
+ const id = `rateLimit_${countdownSeq++}`;
155
+ const label = message.message === 'TooManyRequestError'
156
+ ? 'Too Many Requests (429)'
157
+ : message.message === 'UserRateLimitExceededError'
158
+ ? 'Rate Limit Exceeded (403)'
159
+ : 'Connection Reset';
160
+ lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
154
161
  }
155
- }
156
- };
162
+ else {
163
+ waitingCount--;
164
+ if (waitingCount <= 0) {
165
+ waitingCount = 0;
166
+ lanes.delete(RATE_LIMIT_LANE);
167
+ }
168
+ }
169
+ };
170
+ }
157
171
  log('Reporting starts (limit: %d)', limit);
158
172
  try {
159
173
  await createSheets({
@@ -162,16 +176,18 @@ export async function report(params) {
162
176
  reports,
163
177
  limit,
164
178
  createSheetList,
165
- options: { lanes },
179
+ options: lanes ? { lanes } : undefined,
166
180
  });
167
181
  }
168
182
  finally {
169
- lanes.close();
183
+ lanes?.close();
170
184
  }
171
185
  log('Reporting done');
172
- // eslint-disable-next-line no-console
173
- console.log('\nReport complete.');
174
- if (chosenSheets.sheetName.includes('Summary')) {
186
+ if (!silent) {
187
+ // eslint-disable-next-line no-console
188
+ console.log('\nReport complete.');
189
+ }
190
+ if (selectedSheetNames.includes('Summary')) {
175
191
  await addToSummary( /*sheets, archive, reports*/);
176
192
  }
177
193
  archiveLog('Closes file');
@@ -1,7 +1,9 @@
1
1
  import type { Archive } from '@nitpicker/crawler';
2
2
  import type { Report } from '@nitpicker/types';
3
3
  /**
4
- *
5
- * @param archive
4
+ * Retrieves analyze plugin reports stored in the archive.
5
+ * Returns an empty array if no reports are found.
6
+ * @param archive - The opened archive to read plugin reports from
7
+ * @returns An array of plugin report data
6
8
  */
7
9
  export declare function getPluginReports(archive: Archive): Promise<Report[]>;
@@ -1,7 +1,9 @@
1
1
  import { reportLog } from '../debug.js';
2
2
  /**
3
- *
4
- * @param archive
3
+ * Retrieves analyze plugin reports stored in the archive.
4
+ * Returns an empty array if no reports are found.
5
+ * @param archive - The opened archive to read plugin reports from
6
+ * @returns An array of plugin report data
5
7
  */
6
8
  export async function getPluginReports(archive) {
7
9
  const reports = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitpicker/report-google-sheets",
3
- "version": "0.4.3",
3
+ "version": "0.5.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",
@@ -18,8 +18,8 @@
18
18
  "type": "module",
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./lib/index.js",
22
- "types": "./lib/index.d.ts"
21
+ "import": "./lib/report-google-sheets.js",
22
+ "types": "./lib/report-google-sheets.d.ts"
23
23
  }
24
24
  },
25
25
  "scripts": {
@@ -27,12 +27,12 @@
27
27
  "clean": "tsc --build --clean"
28
28
  },
29
29
  "dependencies": {
30
- "@d-zero/dealer": "1.6.3",
30
+ "@d-zero/dealer": "1.7.0",
31
31
  "@d-zero/google-auth": "0.5.6",
32
32
  "@d-zero/google-sheets": "0.6.0",
33
- "@d-zero/shared": "0.20.0",
34
- "@nitpicker/crawler": "0.4.3",
35
- "@nitpicker/types": "0.4.3",
33
+ "@d-zero/shared": "0.20.1",
34
+ "@nitpicker/crawler": "0.5.0",
35
+ "@nitpicker/types": "0.5.0",
36
36
  "ansi-colors": "4.1.3",
37
37
  "debug": "4.4.3",
38
38
  "enquirer": "2.4.1",
@@ -44,5 +44,5 @@
44
44
  "googleapis": "171.4.0",
45
45
  "vitest": "4.0.18"
46
46
  },
47
- "gitHead": "0f4ca55751be2f83dd5b6622c3502503fc7dfb41"
47
+ "gitHead": "607d06bd596a0270d7088f32373d7367eb47ea94"
48
48
  }