-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
138 lines (134 loc) · 4.63 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const commandLineUsage = require("command-line-usage")
const fs = require("fs");
const optionDefinitions = [
{ name: "abppath", alias: "p", type: String },
{ name: "urllist", alias: "u", type: String },
{ name: "output", alias: "o", type: String },
{ name: "screenshots", alias: "s", type: Boolean },
{ name: "screenshots-delay", alias: "y", type: Number },
{ name: "depth", alias: "d", type: Number },
{ name: "postProcessing", alias: "c", type: String },
{ name: "settings", alias: "t", type: String },
{ name: "userDataDir", alias: "e", type: String },
{ name: "concurrency", alias: "r", type: Number },
{ name: "single-page", alias: "i", type: String }
];
function loadFromSettingsFile(options) {
try {
let settingsPath = options.settings;
if (typeof settingsPath == "undefined")
settingsPath = "settings/settings.json"
let settings = JSON.parse(fs.readFileSync(settingsPath));
if (typeof options.urllist == "undefined") {
options.urllist = settings.urllist;
}
if (typeof options.abppath == "undefined") {
options.abppath = settings.abppath;
}
if (typeof options.output == "undefined") {
options.output = settings.output;
}
if (typeof options.screenshots == "undefined") {
options.screenshots = settings.screenshots;
}
if (typeof options.screenshotsDelay == "undefined") {
options.screenshotsDelay = settings.screenshotsDelay;
}
if (typeof options.depth == "undefined") {
options.depth = settings.depth;
}
if (typeof options.postProcessing == "undefined") {
options.postProcessing = settings.postProcessing;
}
if (typeof options.userDataDir == "undefined") {
options.userDataDir = settings.userDataDir;
}
if (typeof options.concurrency == "undefined") {
options.concurrency = settings.concurrency;
}
if (typeof options.singlePage == "undefined") {
options.singlePage = settings.singlePage;
}
}
catch (e) {
console.log("Settings file not found. Proceding with command line arguments.");
}
return options;
}
function areOptionsCorrect(options) {
if (!options.abppath || !options.urllist) {
return false;
}
return true;
}
function printUsage() {
const sections = [
{
header: "Adblock Plus Headless Chrome Crawler",
content: "Crawls the web and stores the filter hit statistics, along with the requests made."
},
{
header: "Options",
optionList: [
{
name: "abppath -p",
typeLabel: "{underline directory}",
description: "Path to unpacked ABP for Chrome."
},
{
name: "urllist -u",
typeLabel: "{underline file}",
description: "A CSV list of URLs to crawl. URL to crawl is a second parameter. https://moz.com/top500/domains/csv is a good start"
},
{
name: "output -o",
typeLabel: "{underline directory}",
description: "Path to an output folder."
},
{
name: "screenshots -o",
typeLabel: "{underline Boolean}",
description: "Enable taking a screenshot."
},
{
name: "screenshotsDelay -y",
typeLabel: "{underline Number}",
description: "Milliseconds to wait before making a screenshot."
},
{
name: "depth -d",
typeLabel: "{underline integer}",
description: "A crawl depth"
},
{
name: "postProcessing -c",
typeLabel: "{underline String}",
description: "A command to run on every page as a post processing step."
},
{
name: "settings -t",
typeLabel: "{underline String}",
description: "Path to settings file. Default `settings/settings.json`."
},
{
name: "concurrency -r",
typeLabel: "{underline integer}",
description: "Maximum concurrency of requests. NOTE: if taking screenshots is enabled it is best to set concurrency to 1. See: https://github.com/GoogleChrome/puppeteer/issues/1479"
},
]
},
{
header: "Settings file",
content: "Alternatively settings can be set using file (by default in `settings/settings.json`). Command line parameters have higher priority."
}
]
const usage = commandLineUsage(sections)
console.log(usage)
return;
}
module.exports = {
optionDefinitions: optionDefinitions,
loadFromSettingsFile: loadFromSettingsFile,
areOptionsCorrect: areOptionsCorrect,
printUsage: printUsage
}