args.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright 2010-2020 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * The code in this file is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Affero General Public License
  9. * (GNU AGPL) as published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * The code in this file is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  15. * General Public License for more details.
  16. *
  17. * As additional permission under GNU AGPL version 3 section 7, you may
  18. * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
  19. * AGPL normally required by section 4, provided you include this license
  20. * notice and a URL through which recipients can access the Corresponding
  21. * Source.
  22. */
  23. /* global require, module */
  24. const args = require("yargs")
  25. .wrap(null)
  26. .command("$0 [url] [output]", "Save a page into a single HTML file.", yargs => {
  27. yargs.positional("url", { description: "URL or path on the filesystem of the page to save", type: "string" });
  28. yargs.positional("output", { description: "Output filename", type: "string" });
  29. })
  30. .default({
  31. "back-end": "puppeteer",
  32. "browser-headless": true,
  33. "browser-executable-path": "",
  34. "browser-width": 1280,
  35. "browser-height": 720,
  36. "browser-load-max-time": 60000,
  37. "browser-wait-until": "networkidle0",
  38. "browser-wait-until-fallback": true,
  39. "browser-debug": false,
  40. "browser-extensions": [],
  41. "browser-scripts": [],
  42. "browser-args": "",
  43. "compress-CSS": false,
  44. "compress-HTML": true,
  45. "filename-template": "{page-title} ({date-iso} {time-locale}).html",
  46. "filename-replacement-character": "_",
  47. "group-duplicate-images": true,
  48. "include-infobar": false,
  49. "load-deferred-images": true,
  50. "load-deferred-images-max-idle-time": 1500,
  51. "maxParallelWorkers": 8,
  52. "max-resource-size-enabled": false,
  53. "max-resource-size": 10,
  54. "remove-hidden-elements": true,
  55. "remove-unused-styles": true,
  56. "remove-unused-fonts": true,
  57. "remove-frames": false,
  58. "remove-imports": true,
  59. "remove-scripts": true,
  60. "remove-audio-src": true,
  61. "remove-video-src": true,
  62. "remove-alternative-fonts": true,
  63. "remove-alternative-medias": true,
  64. "remove-alternative-images": true,
  65. "save-raw-page": false,
  66. "web-driver-executable-path": "",
  67. "user-script-enabled": true,
  68. "include-BOM": false,
  69. "crawl-links": false,
  70. "crawl-inner-links-only": true,
  71. "crawl-max-depth": 1,
  72. "crawl-replace-urls": false,
  73. "crawl-rewrite-rules": []
  74. })
  75. .options("back-end", { description: "Back-end to use" })
  76. .choices("back-end", ["jsdom", "puppeteer", "webdriver-chromium", "webdriver-gecko"])
  77. .options("browser-headless", { description: "Run the browser in headless mode (puppeteer, webdriver-gecko, webdriver-chromium)" })
  78. .boolean("browser-headless")
  79. .options("browser-executable-path", { description: "Path to chrome/chromium executable (puppeteer, webdriver-gecko, webdriver-chromium)" })
  80. .string("browser-executable-path")
  81. .options("browser-width", { description: "Width of the browser viewport in pixels" })
  82. .number("browser-width")
  83. .options("browser-height", { description: "Height of the browser viewport in pixels" })
  84. .number("browser-height")
  85. .options("browser-load-max-time", { description: "Maximum delay of time to wait for page loading in ms (puppeteer, webdriver-gecko, webdriver-chromium)" })
  86. .number("browser-load-max-time")
  87. .options("browser-wait-until", { description: "When to consider the page is loaded (puppeteer, webdriver-gecko, webdriver-chromium)" })
  88. .choices("browser-wait-until", ["networkidle0", "networkidle2", "load", "domcontentloaded"])
  89. .options("browser-wait-until-fallback", { description: "Retry with the next value of --browser-wait-until when a timeout error is thrown" })
  90. .boolean("browser-wait-until-fallback")
  91. .options("browser-debug", { description: "Enable debug mode (puppeteer, webdriver-gecko, webdriver-chromium)" })
  92. .boolean("browser-debug")
  93. .options("browser-extensions", { description: "List of extension paths separated by a space and relative to the 'cli' folder (webdriver-gecko, webdriver-chromium)" })
  94. .array("browser-extensions")
  95. .options("browser-scripts", { description: "List of script paths separated by a space and relative to the 'cli' folder. They will be executed in all the frames." })
  96. .array("browser-scripts")
  97. .options("browser-args", { description: "Arguments provided as a JSON array and passed to the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
  98. .string("browser-args")
  99. .options("compress-CSS", { description: "Compress CSS stylesheets" })
  100. .boolean("compress-CSS")
  101. .options("compress-HTML", { description: "Compress HTML content" })
  102. .boolean("compress-HTML")
  103. .options("crawl-links", { description: "Crawl and save pages found via inner links" })
  104. .boolean("crawl-links")
  105. .options("crawl-inner-links-only", { description: "Crawl pages found via inner links only if they are hosted on the same domain" })
  106. .boolean("crawl-inner-links-only")
  107. .options("crawl-max-depth", { description: "Max depth when crawling pages found in internal and external links (0: infinite)" })
  108. .number("crawl-max-depth")
  109. .options("crawl-external-links-max-depth", { description: "Max depth when crawling pages found in external links (0: infinite)" })
  110. .number("crawl-external-links-max-depth")
  111. .options("crawl-replace-urls", { description: "Replace URLs of saved pages with relative paths of saved pages on the filesystem" })
  112. .boolean("crawl-replace-urls")
  113. .options("crawl-rewrite-rules", { description: "List of rewrite rules used to rewrite URLs of internal and external links" })
  114. .array("crawl-rewrite-rules")
  115. .options("error-file")
  116. .string("error-file")
  117. .options("filename-template", { description: "Template used to generate the output filename (see help page of the extension for more info)" })
  118. .string("filename-template")
  119. .options("filename-replacement-character", { description: "The character used for replacing invalid characters in filenames" })
  120. .string("filename-replacement-character")
  121. .string("filename-template")
  122. .options("group-duplicate-images", { description: "Group duplicate images into CSS custom properties" })
  123. .boolean("group-duplicate-images")
  124. .options("include-BOM", { description: "Include the UTF-8 BOM into the HTML page" })
  125. .boolean("include-BOM")
  126. .options("include-infobar", { description: "Include the infobar" })
  127. .boolean("include-infobar")
  128. .options("load-deferred-images", { description: "Load deferred (a.k.a. lazy-loaded) images (puppeteer, webdriver-gecko, webdriver-chromium)" })
  129. .boolean("load-deferred-images")
  130. .options("load-deferred-images-max-idle-time", { description: "Maximum delay of time to wait for deferred images in ms (puppeteer, webdriver-gecko, webdriver-chromium)" })
  131. .number("load-deferred-images-max-idle-time")
  132. .options("max-parallel-workers", { description: "Maximum number of browsers launched in parallel when processing a list of URLs (cf --urls-file)" })
  133. .number("max-parallel-workers")
  134. .options("max-resource-size-enabled", { description: "Enable removal of embedded resources exceeding a given size" })
  135. .boolean("max-resource-size-enabled")
  136. .options("max-resource-size", { description: "Maximum size of embedded resources in MB (i.e. images, stylesheets, scripts and iframes)" })
  137. .number("max-resource-size")
  138. .options("remove-frames", { description: "Remove frames (puppeteer, webdriver-gecko, webdriver-chromium)" })
  139. .boolean("remove-frames")
  140. .options("remove-hidden-elements", { description: "Remove HTML elements which are not displayed" })
  141. .boolean("remove-hidden-elements")
  142. .options("remove-unused-styles", { description: "Remove unused CSS rules and unneeded declarations" })
  143. .boolean("remove-unused-styles")
  144. .options("remove-unused-fonts", { description: "Remove unused CSS font rules" })
  145. .boolean("remove-unused-fonts")
  146. .options("remove-imports", { description: "Remove HTML imports" })
  147. .boolean("remove-imports")
  148. .options("remove-scripts", { description: "Remove JavaScript scripts" })
  149. .boolean("remove-scripts")
  150. .options("remove-audio-src", { description: "Remove source of audio elements" })
  151. .boolean("remove-audio-src")
  152. .options("remove-video-src", { description: "Remove source of video elements" })
  153. .boolean("remove-video-src")
  154. .options("remove-alternative-fonts", { description: "Remove alternative fonts to the ones displayed" })
  155. .boolean("remove-alternative-fonts")
  156. .options("remove-alternative-medias", { description: "Remove alternative CSS stylesheets" })
  157. .boolean("remove-alternative-medias")
  158. .options("remove-alternative-images", { description: "Remove images for alternative sizes of screen" })
  159. .boolean("remove-alternative-images")
  160. .options("save-raw-page", { description: "Save the original page without interpreting it into the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
  161. .boolean("save-raw-page")
  162. .options("urls-file", { description: "Path to a text file containing a list of URLs (separated by a newline) to save" })
  163. .string("urls-file")
  164. .options("user-agent", { description: "User-agent of the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
  165. .string("user-agent")
  166. .options("user-script-enabled", { description: "Enable the event API allowing to execute scripts before the page is saved" })
  167. .boolean("user-script-enabled")
  168. .options("web-driver-executable-path", { description: "Path to Selenium WebDriver executable (webdriver-gecko, webdriver-chromium)" })
  169. .string("web-driver-executable-path")
  170. .argv;
  171. args.compressCSS = args.compressCss;
  172. args.compressHTML = args.compressHtml;
  173. args.includeBOM = args.includeBom;
  174. args.crawlReplaceURLs = args.crawlReplaceUrls;
  175. module.exports = args;