|
|
@@ -24,6 +24,7 @@
|
|
|
/* global require, module, URL */
|
|
|
|
|
|
const fs = require("fs");
|
|
|
+const path = require("path");
|
|
|
const VALID_URL_TEST = /^(https?|file):\/\//;
|
|
|
|
|
|
const STATE_PROCESSING = "processing";
|
|
|
@@ -201,19 +202,21 @@ function getHostURL(url) {
|
|
|
|
|
|
async function capturePage(options) {
|
|
|
try {
|
|
|
+ let filename;
|
|
|
const pageData = await backend.getPageData(options);
|
|
|
if (options.output) {
|
|
|
- const filename = getFilename(options.output, options);
|
|
|
- if (filename) {
|
|
|
- fs.writeFileSync(filename, pageData.content);
|
|
|
- }
|
|
|
+ filename = getFilename(options.output, options);
|
|
|
+ } else if (options.dumpContent) {
|
|
|
+ console.log(pageData.content); // eslint-disable-line no-console
|
|
|
} else {
|
|
|
- const filename = getFilename(pageData.filename, options);
|
|
|
- if (options.dumpContent) {
|
|
|
- console.log(pageData.content); // eslint-disable-line no-console
|
|
|
- } else if (filename) {
|
|
|
- fs.writeFileSync(filename, pageData.content);
|
|
|
+ filename = getFilename(pageData.filename, options);
|
|
|
+ }
|
|
|
+ if (filename) {
|
|
|
+ const dirname = path.dirname(filename);
|
|
|
+ if (dirname) {
|
|
|
+ fs.mkdirSync(dirname, { recursive: true });
|
|
|
}
|
|
|
+ fs.writeFileSync(filename, pageData.content);
|
|
|
}
|
|
|
return pageData;
|
|
|
} catch (error) {
|