@nitpicker/cli 0.4.2
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/CHANGELOG.md +16 -0
- package/LICENSE +191 -0
- package/README.md +21 -0
- package/bin/nitpicker.js +3 -0
- package/lib/analyze/log.d.ts +12 -0
- package/lib/analyze/log.js +24 -0
- package/lib/analyze/logger.d.ts +10 -0
- package/lib/analyze/logger.js +16 -0
- package/lib/audit.d.ts +7 -0
- package/lib/audit.js +42 -0
- package/lib/bootstrap.d.ts +9 -0
- package/lib/bootstrap.js +22 -0
- package/lib/commands/analyze.d.ts +35 -0
- package/lib/commands/analyze.js +86 -0
- package/lib/commands/crawl.d.ts +125 -0
- package/lib/commands/crawl.js +249 -0
- package/lib/commands/report.d.ts +45 -0
- package/lib/commands/report.js +62 -0
- package/lib/crawl/debug.d.ts +6 -0
- package/lib/crawl/debug.js +10 -0
- package/lib/crawl/diff.d.ts +10 -0
- package/lib/crawl/diff.js +38 -0
- package/lib/crawl/event-assignments.d.ts +17 -0
- package/lib/crawl/event-assignments.js +33 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +28 -0
- package/lib/log.d.ts +8 -0
- package/lib/log.js +45 -0
- package/lib/logger.d.ts +10 -0
- package/lib/logger.js +16 -0
- package/package.json +45 -0
- package/src/analyze/log.spec.ts +88 -0
- package/src/analyze/log.ts +28 -0
- package/src/commands/analyze.ts +107 -0
- package/src/commands/crawl.ts +303 -0
- package/src/commands/report.ts +73 -0
- package/src/crawl/debug.ts +14 -0
- package/src/crawl/diff.ts +48 -0
- package/src/crawl/event-assignments.ts +48 -0
- package/src/index.ts +32 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.4.2](https://github.com/d-zero-dev/nitpicker/compare/v0.4.1...v0.4.2) (2026-02-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nitpicker/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.4.1](https://github.com/d-zero-dev/nitpicker/compare/v0.4.0...v0.4.1) (2026-02-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package nitpicker
|
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,21 @@
|
|
|
1
|
+
# @nitpicker/cli
|
|
2
|
+
|
|
3
|
+
Web サイトのクローラー・分析・レポート統合 CLI。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
ヘッドレスブラウザで Web サイトをクロールし、各ページのメタデータ・リンク構造・ネットワークリソース・HTML スナップショットを `.nitpicker` アーカイブに保存します。さらに、アーカイブに対して各種プラグインによる分析を実行し、Google Sheets にレポートを出力できます。
|
|
8
|
+
|
|
9
|
+
## 使い方
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx @nitpicker/cli crawl <URL> # Web サイトをクロール
|
|
13
|
+
npx @nitpicker/cli analyze <file> # 分析プラグインを実行
|
|
14
|
+
npx @nitpicker/cli report <file> # Google Sheets レポートを生成
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
詳細なオプションは[ルートの README](../../README.md) を参照してください。
|
|
18
|
+
|
|
19
|
+
## ライセンス
|
|
20
|
+
|
|
21
|
+
Apache-2.0
|
package/bin/nitpicker.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Nitpicker } from '@nitpicker/core';
|
|
2
|
+
/**
|
|
3
|
+
* Registers event listeners on a Nitpicker instance for analyze output,
|
|
4
|
+
* and prints the initial summary lines.
|
|
5
|
+
*
|
|
6
|
+
* Outputs the start log lines (site URL, file path), then listens for
|
|
7
|
+
* `writeFile` and `error` events to provide CLI feedback.
|
|
8
|
+
* Progress display is handled by Lanes in the calling code.
|
|
9
|
+
* @param nitpicker - The Nitpicker instance to listen on
|
|
10
|
+
* @param startLog - Lines to display at the start (URL + file path summary)
|
|
11
|
+
*/
|
|
12
|
+
export declare function log(nitpicker: Nitpicker, startLog: string[]): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers event listeners on a Nitpicker instance for analyze output,
|
|
3
|
+
* and prints the initial summary lines.
|
|
4
|
+
*
|
|
5
|
+
* Outputs the start log lines (site URL, file path), then listens for
|
|
6
|
+
* `writeFile` and `error` events to provide CLI feedback.
|
|
7
|
+
* Progress display is handled by Lanes in the calling code.
|
|
8
|
+
* @param nitpicker - The Nitpicker instance to listen on
|
|
9
|
+
* @param startLog - Lines to display at the start (URL + file path summary)
|
|
10
|
+
*/
|
|
11
|
+
export function log(nitpicker, startLog) {
|
|
12
|
+
for (const line of startLog) {
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.log(line);
|
|
15
|
+
}
|
|
16
|
+
nitpicker.on('writeFile', ({ filePath }) => {
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
console.log(` 📥 Write file: ${filePath}`);
|
|
19
|
+
});
|
|
20
|
+
nitpicker.on('error', (err) => {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.error(err.message);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default class Logger {
|
|
2
|
+
verbose = false;
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
|
+
constructor(_options) { }
|
|
5
|
+
close() { }
|
|
6
|
+
verbosely() {
|
|
7
|
+
this.verbose = true;
|
|
8
|
+
}
|
|
9
|
+
write(lines) {
|
|
10
|
+
const output = Array.isArray(lines) ? lines : [lines];
|
|
11
|
+
for (const line of output) {
|
|
12
|
+
const cleaned = line.replaceAll(/%dots%|%propeller%/g, '');
|
|
13
|
+
process.stderr.write(cleaned + '\n');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/lib/audit.d.ts
ADDED
package/lib/audit.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { Nitpicker } from '@nitpicker/core';
|
|
3
|
+
import enquirer from 'enquirer';
|
|
4
|
+
import { log } from './log.js';
|
|
5
|
+
const { prompt } = enquirer;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param filePath
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
export async function audit(filePath, options) {
|
|
12
|
+
let errStack = null;
|
|
13
|
+
const absFilePath = path.isAbsolute(filePath)
|
|
14
|
+
? filePath
|
|
15
|
+
: path.resolve(process.cwd(), filePath);
|
|
16
|
+
const nitpicker = await Nitpicker.open(absFilePath);
|
|
17
|
+
const config = await nitpicker.getConfig();
|
|
18
|
+
const audits = config.audit || [];
|
|
19
|
+
const pluginNameList = audits.map((plugin) => plugin.name);
|
|
20
|
+
let filter;
|
|
21
|
+
if (!options.all) {
|
|
22
|
+
const res = await prompt([
|
|
23
|
+
{
|
|
24
|
+
message: 'What do you audit through?',
|
|
25
|
+
name: 'filter',
|
|
26
|
+
type: 'multiselect',
|
|
27
|
+
choices: pluginNameList,
|
|
28
|
+
},
|
|
29
|
+
]);
|
|
30
|
+
filter = res.filter;
|
|
31
|
+
}
|
|
32
|
+
const siteUrl = (await nitpicker.archive.getUrl()) || '<Unknown URL 🤔 >';
|
|
33
|
+
const head = [`🥢 ${siteUrl} (${filePath})`, ` 📤 Read file: ${absFilePath}`];
|
|
34
|
+
log(nitpicker, head, !!options.verbose).catch((error) => {
|
|
35
|
+
errStack = error;
|
|
36
|
+
});
|
|
37
|
+
await nitpicker.audit(filter);
|
|
38
|
+
await nitpicker.write();
|
|
39
|
+
if (errStack) {
|
|
40
|
+
throw errStack;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/lib/bootstrap.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import meow from 'meow';
|
|
2
|
+
export const cli = meow(`
|
|
3
|
+
Usage
|
|
4
|
+
$ nitpicker <URL>
|
|
5
|
+
|
|
6
|
+
Options
|
|
7
|
+
--all Audit through all audits.
|
|
8
|
+
--verbose Output logs verbosely.
|
|
9
|
+
|
|
10
|
+
Examples
|
|
11
|
+
$ nitpicker https://www.d-zero.co.jp --output-path ./path/to/result.csv
|
|
12
|
+
`, {
|
|
13
|
+
importMeta: import.meta,
|
|
14
|
+
flags: {
|
|
15
|
+
all: {
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
},
|
|
18
|
+
verbose: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { InferFlags } from '@d-zero/roar';
|
|
2
|
+
/**
|
|
3
|
+
* Command definition for the `analyze` sub-command.
|
|
4
|
+
* @see {@link analyze} for the main entry point
|
|
5
|
+
*/
|
|
6
|
+
export declare const commandDef: {
|
|
7
|
+
readonly desc: "Analyze a .nitpicker archive";
|
|
8
|
+
readonly flags: {
|
|
9
|
+
readonly all: {
|
|
10
|
+
readonly type: "boolean";
|
|
11
|
+
readonly desc: "Run all analysis plugins";
|
|
12
|
+
};
|
|
13
|
+
readonly verbose: {
|
|
14
|
+
readonly type: "boolean";
|
|
15
|
+
readonly desc: "Output logs verbosely";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type AnalyzeFlags = InferFlags<typeof commandDef.flags>;
|
|
20
|
+
/**
|
|
21
|
+
* Main entry point for the `analyze` CLI command.
|
|
22
|
+
*
|
|
23
|
+
* Opens a `.nitpicker` archive, loads the configured analyze plugins,
|
|
24
|
+
* presents an interactive multi-select prompt (unless `--all` is specified),
|
|
25
|
+
* runs the selected plugins with per-plugin Lanes progress display, and
|
|
26
|
+
* writes results back to the archive.
|
|
27
|
+
*
|
|
28
|
+
* WHY enquirer prompt: Allows users to selectively run expensive plugins
|
|
29
|
+
* (e.g. Lighthouse) without re-running everything. The `--all` flag
|
|
30
|
+
* bypasses the prompt for CI/automation use cases.
|
|
31
|
+
* @param args - Positional arguments; first argument is the `.nitpicker` file path
|
|
32
|
+
* @param flags - Parsed CLI flags from the `analyze` command
|
|
33
|
+
*/
|
|
34
|
+
export declare function analyze(args: string[], flags: AnalyzeFlags): Promise<void>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { Lanes } from '@d-zero/dealer';
|
|
3
|
+
import { Nitpicker, readPluginLabels } from '@nitpicker/core';
|
|
4
|
+
import enquirer from 'enquirer';
|
|
5
|
+
import { log } from '../analyze/log.js';
|
|
6
|
+
const { prompt } = enquirer;
|
|
7
|
+
/**
|
|
8
|
+
* Command definition for the `analyze` sub-command.
|
|
9
|
+
* @see {@link analyze} for the main entry point
|
|
10
|
+
*/
|
|
11
|
+
export const commandDef = {
|
|
12
|
+
desc: 'Analyze a .nitpicker archive',
|
|
13
|
+
flags: {
|
|
14
|
+
all: {
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
desc: 'Run all analysis plugins',
|
|
17
|
+
},
|
|
18
|
+
verbose: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
desc: 'Output logs verbosely',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Main entry point for the `analyze` CLI command.
|
|
26
|
+
*
|
|
27
|
+
* Opens a `.nitpicker` archive, loads the configured analyze plugins,
|
|
28
|
+
* presents an interactive multi-select prompt (unless `--all` is specified),
|
|
29
|
+
* runs the selected plugins with per-plugin Lanes progress display, and
|
|
30
|
+
* writes results back to the archive.
|
|
31
|
+
*
|
|
32
|
+
* WHY enquirer prompt: Allows users to selectively run expensive plugins
|
|
33
|
+
* (e.g. Lighthouse) without re-running everything. The `--all` flag
|
|
34
|
+
* bypasses the prompt for CI/automation use cases.
|
|
35
|
+
* @param args - Positional arguments; first argument is the `.nitpicker` file path
|
|
36
|
+
* @param flags - Parsed CLI flags from the `analyze` command
|
|
37
|
+
*/
|
|
38
|
+
export async function analyze(args, flags) {
|
|
39
|
+
const filePath = args[0];
|
|
40
|
+
if (!filePath) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const isTTY = process.stdout.isTTY;
|
|
44
|
+
const absFilePath = path.isAbsolute(filePath)
|
|
45
|
+
? filePath
|
|
46
|
+
: path.resolve(process.cwd(), filePath);
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log(` 📦 Extracting archive: ${absFilePath}`);
|
|
49
|
+
const nitpicker = await Nitpicker.open(absFilePath);
|
|
50
|
+
const config = await nitpicker.getConfig();
|
|
51
|
+
const plugins = config.analyze || [];
|
|
52
|
+
const pluginNameList = plugins.map((plugin) => plugin.name);
|
|
53
|
+
if (pluginNameList.length === 0) {
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.error('No analyze plugins found. Install @nitpicker/analyze-* packages or configure them in .nitpickerrc.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let filter;
|
|
59
|
+
if (!flags.all) {
|
|
60
|
+
const labels = await readPluginLabels(plugins);
|
|
61
|
+
const choices = plugins.map((plugin) => ({
|
|
62
|
+
name: plugin.name,
|
|
63
|
+
message: labels.get(plugin.name) || plugin.name,
|
|
64
|
+
}));
|
|
65
|
+
const res = await prompt([
|
|
66
|
+
{
|
|
67
|
+
message: 'What do you analyze?',
|
|
68
|
+
name: 'filter',
|
|
69
|
+
type: 'multiselect',
|
|
70
|
+
choices,
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
filter = res.filter;
|
|
74
|
+
}
|
|
75
|
+
const siteUrl = (await nitpicker.archive.getUrl()) || '<Unknown URL>';
|
|
76
|
+
log(nitpicker, [`🥢 ${siteUrl} (${filePath})`, ` 📤 Read file: ${absFilePath}`]);
|
|
77
|
+
const lanes = new Lanes({ verbose: !isTTY, indent: ' ' });
|
|
78
|
+
try {
|
|
79
|
+
await nitpicker.analyze(filter, { lanes, verbose: !isTTY });
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
lanes.close();
|
|
83
|
+
}
|
|
84
|
+
await nitpicker.write();
|
|
85
|
+
await nitpicker.archive.close();
|
|
86
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { InferFlags } from '@d-zero/roar';
|
|
2
|
+
/**
|
|
3
|
+
* Command definition for the `crawl` sub-command.
|
|
4
|
+
* Defines all CLI flags with their types, defaults, and descriptions.
|
|
5
|
+
* @see {@link crawl} for the main entry point that dispatches to startCrawl/resumeCrawl/diff
|
|
6
|
+
*/
|
|
7
|
+
export declare const commandDef: {
|
|
8
|
+
readonly desc: "Crawl a website";
|
|
9
|
+
readonly flags: {
|
|
10
|
+
readonly resume: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly shortFlag: "R";
|
|
13
|
+
readonly desc: "Resume crawling from a stub file";
|
|
14
|
+
};
|
|
15
|
+
readonly interval: {
|
|
16
|
+
readonly type: "number";
|
|
17
|
+
readonly shortFlag: "I";
|
|
18
|
+
readonly desc: "An interval time on request when crawles";
|
|
19
|
+
};
|
|
20
|
+
readonly image: {
|
|
21
|
+
readonly type: "boolean";
|
|
22
|
+
readonly default: true;
|
|
23
|
+
readonly desc: "Getting images (use --no-image to disable)";
|
|
24
|
+
};
|
|
25
|
+
readonly fetchExternal: {
|
|
26
|
+
readonly type: "boolean";
|
|
27
|
+
readonly default: true;
|
|
28
|
+
readonly desc: "Fetch external links (use --no-fetch-external to disable)";
|
|
29
|
+
};
|
|
30
|
+
readonly parallels: {
|
|
31
|
+
readonly type: "number";
|
|
32
|
+
readonly shortFlag: "P";
|
|
33
|
+
readonly desc: "Number of parallel scraping";
|
|
34
|
+
};
|
|
35
|
+
readonly recursive: {
|
|
36
|
+
readonly type: "boolean";
|
|
37
|
+
readonly default: true;
|
|
38
|
+
readonly desc: "Recursive crawling (use --no-recursive to disable)";
|
|
39
|
+
};
|
|
40
|
+
readonly scope: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
readonly desc: "Set hosts and URLs as scope";
|
|
43
|
+
};
|
|
44
|
+
readonly exclude: {
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
readonly isMultiple: true;
|
|
47
|
+
readonly desc: "Excluding page URL path (glob pattern)";
|
|
48
|
+
};
|
|
49
|
+
readonly excludeKeyword: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
readonly isMultiple: true;
|
|
52
|
+
readonly desc: "Exclude keyword in document of page";
|
|
53
|
+
};
|
|
54
|
+
readonly excludeUrl: {
|
|
55
|
+
readonly type: "string";
|
|
56
|
+
readonly isMultiple: true;
|
|
57
|
+
readonly desc: "Exclude external URL prefix";
|
|
58
|
+
};
|
|
59
|
+
readonly disableQueries: {
|
|
60
|
+
readonly type: "boolean";
|
|
61
|
+
readonly shortFlag: "Q";
|
|
62
|
+
readonly desc: "Disable queries that the URL has";
|
|
63
|
+
};
|
|
64
|
+
readonly imageFileSizeThreshold: {
|
|
65
|
+
readonly type: "number";
|
|
66
|
+
readonly desc: "Image file size threshold";
|
|
67
|
+
};
|
|
68
|
+
readonly single: {
|
|
69
|
+
readonly type: "boolean";
|
|
70
|
+
readonly desc: "Single page mode";
|
|
71
|
+
};
|
|
72
|
+
readonly maxExcludedDepth: {
|
|
73
|
+
readonly type: "number";
|
|
74
|
+
readonly desc: "Avoid crawling depths above a set number";
|
|
75
|
+
};
|
|
76
|
+
readonly retry: {
|
|
77
|
+
readonly type: "number";
|
|
78
|
+
readonly default: 3;
|
|
79
|
+
readonly desc: "Number of retry attempts per URL on scrape failure";
|
|
80
|
+
};
|
|
81
|
+
readonly list: {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
readonly isMultiple: true;
|
|
84
|
+
readonly desc: "Running only each page from the list";
|
|
85
|
+
};
|
|
86
|
+
readonly listFile: {
|
|
87
|
+
readonly type: "string";
|
|
88
|
+
readonly desc: "Running only each page from the list file";
|
|
89
|
+
};
|
|
90
|
+
readonly userAgent: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
readonly desc: "Custom User-Agent string for HTTP requests";
|
|
93
|
+
};
|
|
94
|
+
readonly ignoreRobots: {
|
|
95
|
+
readonly type: "boolean";
|
|
96
|
+
readonly desc: "Ignore robots.txt restrictions (use responsibly)";
|
|
97
|
+
};
|
|
98
|
+
readonly verbose: {
|
|
99
|
+
readonly type: "boolean";
|
|
100
|
+
readonly desc: "Output verbose log to standard out";
|
|
101
|
+
};
|
|
102
|
+
readonly silent: {
|
|
103
|
+
readonly type: "boolean";
|
|
104
|
+
readonly desc: "No output log to standard out";
|
|
105
|
+
};
|
|
106
|
+
readonly diff: {
|
|
107
|
+
readonly type: "boolean";
|
|
108
|
+
readonly desc: "Diff mode";
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
type CrawlFlags = InferFlags<typeof commandDef.flags>;
|
|
113
|
+
/**
|
|
114
|
+
* Main entry point for the `crawl` CLI command.
|
|
115
|
+
*
|
|
116
|
+
* Dispatches to one of four modes based on the flags:
|
|
117
|
+
* 1. `--diff` mode: Compares two archive files and outputs URL lists
|
|
118
|
+
* 2. `--resume` mode: Resumes a previously interrupted crawl
|
|
119
|
+
* 3. `--list-file` / `--list` mode: Crawls a pre-defined URL list (non-recursive)
|
|
120
|
+
* 4. Default mode: Crawls from a single root URL
|
|
121
|
+
* @param args - Positional arguments (typically one or two URLs/file paths)
|
|
122
|
+
* @param flags - Parsed CLI flags from the `crawl` command
|
|
123
|
+
*/
|
|
124
|
+
export declare function crawl(args: string[], flags: CrawlFlags): Promise<void>;
|
|
125
|
+
export {};
|