single-file-cli 2.0.64 → 2.0.66

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/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.64";
1
+ export const version = "2.0.66";
package/options.js CHANGED
@@ -65,6 +65,7 @@ const OPTIONS_INFO = {
65
65
  "browser-device-width": { description: "Width of the device viewport in pixels (default value is 360 when using --browser-mobile-emulation)", type: "number" },
66
66
  "browser-device-height": { description: "Height of the device viewport in pixels (default value is 800 when using --browser-mobile-emulation)", type: "number" },
67
67
  "browser-device-scale-factor": { description: "Scale factor of the device viewport (default value is 2 when using --browser-mobile-emulation)", type: "number" },
68
+ "console-messages-file": { description: "Path of the file where to save the console messages in JSON format", type: "string" },
68
69
  "compress-CSS": { description: "Compress CSS stylesheets", type: "boolean" },
69
70
  "compress-HTML": { description: "Compress HTML content", type: "boolean", defaultValue: true },
70
71
  "crawl-links": { description: "Crawl and save pages found via inner links", type: "boolean" },
@@ -80,8 +81,8 @@ const OPTIONS_INFO = {
80
81
  "crawl-rewrite-rule": { description: "Rewrite rule used to rewrite URLs of crawled pages", type: "string[]" },
81
82
  "dump-content": { description: "Dump the content of the processed page in the console ('true' when running in Docker)", type: "boolean" },
82
83
  "emulate-media-feature": { description: "Emulate a media feature. The syntax is <name>:<value>, e.g. \"prefers-color-scheme:dark\"", type: "string[]" },
83
- "error-file": { description: "Path of the file where to save the error messages", type: "string" },
84
- "error-traces-disabled": { description: "Remove error stack traces in the error messages", type: "boolean", defaultValue: true },
84
+ "errors-file": { description: "Path of the file where to save the error messages", type: "string", alias: "error-file" },
85
+ "errors-traces-disabled": { description: "Remove error stack traces in the error messages", type: "boolean", defaultValue: true, alias: "error-traces-disabled" },
85
86
  "filename-template": { description: "Template used to generate the output filename (see help page of the extension for more info)", type: "string", defaultValue: "%if-empty<{page-title}|No title> ({date-locale} {time-locale}).{filename-extension}" },
86
87
  "filename-conflict-action": { description: "Action when the filename is conflicting with existing one on the filesystem. The possible values are \"uniquify\" (default), \"overwrite\" and \"skip\"", type: "string", defaultValue: "uniquify" },
87
88
  "filename-replacement-character": { description: "The character used for replacing invalid characters in filenames", type: "string", defaultValue: "_" },
@@ -153,7 +154,14 @@ export default options;
153
154
 
154
155
  async function getOptions() {
155
156
  const { positionals, options } = parseArgs(Array.from(args));
156
- if ((!positionals.length && !Object.keys(options).length) || positionals.length > 2 || options.help) {
157
+ const unknownOptions = [];
158
+ positionals.forEach(positional => {
159
+ if (positional.startsWith("--")) {
160
+ unknownOptions.push(positional);
161
+ positionals.splice(positionals.indexOf(positional), 1);
162
+ }
163
+ });
164
+ if ((!positionals.length && !Object.keys(options).length) || positionals.length > 2 || options.help || unknownOptions.length) {
157
165
  console.log(USAGE_TEXT + "\n"); // eslint-disable-line no-console
158
166
  console.log("Options:"); // eslint-disable-line no-console
159
167
  Object.keys(OPTIONS_INFO).forEach(optionName => {
@@ -166,6 +174,10 @@ async function getOptions() {
166
174
  const optionDefaultValue = optionInfo.defaultValue === undefined ? "" : `(default: ${JSON.stringify(optionInfo.defaultValue)})`;
167
175
  console.log(` --${optionName}: ${optionDescription} <${optionType}> ${optionDefaultValue}`); // eslint-disable-line no-console
168
176
  });
177
+ if (unknownOptions.length) {
178
+ console.log(""); // eslint-disable-line no-console
179
+ console.log(`Error: Unknown option${unknownOptions.length > 1 ? "s" : ""} ${unknownOptions.join(", ")}`); // eslint-disable-line no-console
180
+ }
169
181
  console.log(""); // eslint-disable-line no-console
170
182
  exit(0);
171
183
  }
@@ -197,6 +209,14 @@ async function getOptions() {
197
209
  options.browserArgs = options.browserArguments;
198
210
  delete options.browserArguments;
199
211
  }
212
+ if (options.errorFile) {
213
+ options.errorsFile = options.errorFile;
214
+ delete options.errorFile;
215
+ }
216
+ if (options.errorTracesDisabled) {
217
+ options.errorsTracesDisabled = options.errorTracesDisabled;
218
+ delete options.errorTracesDisabled;
219
+ }
200
220
  delete options.acceptHeaderFont;
201
221
  delete options.acceptHeaderImage;
202
222
  delete options.acceptHeaderStylesheet;
@@ -292,7 +312,11 @@ function parseArg(arg) {
292
312
  }
293
313
 
294
314
  function getOptionInfo(optionName) {
295
- return OPTIONS_INFO[Object.keys(OPTIONS_INFO).find(keyName => keyName.toLowerCase() == optionName.toLowerCase())];
315
+ for (const keyName in OPTIONS_INFO) {
316
+ if (keyName.toLowerCase() == optionName.toLowerCase() || OPTIONS_INFO[keyName].alias == optionName.toLowerCase()) {
317
+ return OPTIONS_INFO[keyName];
318
+ }
319
+ }
296
320
  }
297
321
 
298
322
  function kebabToCamelCase(optionName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.64",
3
+ "version": "2.0.66",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -223,7 +223,7 @@ async function saveTasks() {
223
223
  }
224
224
  }
225
225
 
226
- function rewriteURL(url, crawlRemoveURLFragment, crawlRewriteRules) {
226
+ function rewriteURL(url, crawlRemoveURLFragment, crawlRewriteRules = []) {
227
227
  url = url.trim();
228
228
  if (crawlRemoveURLFragment) {
229
229
  url = url.replace(/^(.*?)#.*$/, "$1");
@@ -248,6 +248,9 @@ async function capturePage(options) {
248
248
  options.zipScript = getZipScriptSource();
249
249
  const pageData = await backend.getPageData(options);
250
250
  content = pageData.content;
251
+ if (options.consoleMessagesFile && pageData.consoleMessages) {
252
+ await writeTextFile(options.consoleMessagesFile, JSON.stringify(pageData.consoleMessages, null, 2));
253
+ }
251
254
  if (options.outputJson) {
252
255
  if (content instanceof Uint8Array) {
253
256
  const fileReader = new FileReader();
@@ -293,12 +296,12 @@ async function capturePage(options) {
293
296
  } catch (error) {
294
297
  const date = new Date();
295
298
  let message = `[${date.toISOString()}] URL: ${options.url}`;
296
- if (!options.errorTracesDisabled) {
299
+ if (!options.errorsTracesDisabled) {
297
300
  message += "\nStack: " + error.stack;
298
301
  }
299
302
  message += "\n";
300
- if (options.errorFile) {
301
- await writeTextFile(options.errorFile, message, { append: true });
303
+ if (options.errorsFile) {
304
+ await writeTextFile(options.errorsFile, message, { append: true });
302
305
  } else {
303
306
  console.error(error.message || error, message); // eslint-disable-line no-console
304
307
  }