single-file-cli 2.0.47 → 2.0.49

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.47";
1
+ export const version = "2.0.49";
package/options.js CHANGED
@@ -131,7 +131,8 @@ const OPTIONS_INFO = {
131
131
  "prevent-appended-data": { description: "Prevent appending data after the compressed data when creating self-extracting HTML files", type: "boolean" },
132
132
  "embed-screenshot": { description: "Embed a screenshot of the page as a PNG file in the compressed file (self-extracting HTML or ZIP file). When enabled, the resulting file can be read as a ZIP file or a PNG image.", type: "boolean" },
133
133
  "output-directory": { description: "Path to where to save files, this path must exist.", type: "string" },
134
- "version": { description: "Print the version number and exit.", type: "boolean" }
134
+ "version": { description: "Print the version number and exit.", type: "boolean" },
135
+ "output-json": { description: "Output the result as a JSON string containing the page and network info", type: "boolean" },
135
136
  };
136
137
 
137
138
  const { args, exit } = Deno;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.47",
3
+ "version": "2.0.49",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -21,7 +21,7 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global URL */
24
+ /* global URL, Blob, FileReader */
25
25
 
26
26
  import * as backend from "./lib/cdp-client.js";
27
27
  import { getZipScriptSource } from "./lib/single-file-script.js";
@@ -244,29 +244,48 @@ function getHostURL(url) {
244
244
 
245
245
  async function capturePage(options) {
246
246
  try {
247
- let filename;
247
+ let filename, content;
248
248
  options.zipScript = getZipScriptSource();
249
249
  const pageData = await backend.getPageData(options);
250
+ filename = pageData.filename;
251
+ content = pageData.content;
252
+ if (options.outputJson) {
253
+ if (content instanceof Uint8Array) {
254
+ const fileReader = new FileReader();
255
+ fileReader.readAsDataURL(new Blob([content]));
256
+ content = await new Promise(resolve => {
257
+ fileReader.onload = () => resolve(fileReader.result);
258
+ });
259
+ content = content.replace(/^data:.*?;base64,/, "");
260
+ pageData.content = undefined;
261
+ pageData.binaryContent = content;
262
+ }
263
+ pageData.doctype = undefined;
264
+ pageData.viewport = undefined;
265
+ pageData.comment = undefined;
266
+ filename += filename.endsWith(".json") ? "" : ".json";
267
+ content = JSON.stringify(pageData, null, 2);
268
+ }
250
269
  if (options.output) {
251
270
  filename = await getFilename(options.output, options);
252
271
  } else if (options.dumpContent) {
253
272
  if (options.compressContent) {
254
- await stdout.write(pageData.content);
273
+ await stdout.write(content);
255
274
  } else {
256
- console.log(pageData.content || ""); // eslint-disable-line no-console
275
+ console.log(content || ""); // eslint-disable-line no-console
257
276
  }
258
277
  } else {
259
- filename = await getFilename(pageData.filename, options);
278
+ filename = await getFilename(filename, options);
260
279
  }
261
- if (filename) {
280
+ if (filename && !options.dumpContent) {
262
281
  const directoryName = await path.dirname(filename);
263
282
  if (directoryName !== ".") {
264
283
  await mkdir(directoryName, { recursive: true });
265
284
  }
266
- if (pageData.content instanceof Uint8Array) {
267
- await writeFile(filename, pageData.content);
285
+ if (content instanceof Uint8Array) {
286
+ await writeFile(filename, content);
268
287
  } else {
269
- await writeTextFile(filename, pageData.content);
288
+ await writeTextFile(filename, content);
270
289
  }
271
290
  }
272
291
  return pageData;