@ewizardjs/blocks-renderer
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -35,1 +35,5 @@ import { PuppeteerNode } from 'puppeteer-core'; | ||
} | ||
export interface IStaticServer { | ||
port: string | number; | ||
stop(): void; | ||
} |
@@ -10,2 +10,6 @@ import { ScreenshotOptions, Page, WaitForOptions, BrowserLaunchArgumentOptions, BrowserContext, Browser } from 'puppeteer-core'; | ||
createPage(url: string, requirePuppeteerCb: requirePuppeteerCb, waitForOptions: WaitForOptions, rendererOptions?: BrowserLaunchArgumentOptions, browserUrl?: string): Promise<void>; | ||
hostContent(url: string): Promise<{ | ||
pageUrl: string; | ||
server: import("../../interfaces").IStaticServer; | ||
}>; | ||
exposeClone(): Promise<void>; | ||
@@ -12,0 +16,0 @@ addScriptsToPage(scripts: string[]): Promise<void>; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const fs_extra_1 = require("fs-extra"); | ||
const server_1 = require("../server"); | ||
class FacadePuppeteer { | ||
@@ -16,10 +17,32 @@ constructor() { } | ||
async createPage(url, requirePuppeteerCb, waitForOptions, rendererOptions = {}, browserUrl) { | ||
const { pageUrl, server } = await this.hostContent(url); | ||
const puppeteer = await requirePuppeteerCb(); | ||
const { browser, closeBrowser } = await browser_1.createBrowser(puppeteer, rendererOptions, browserUrl); | ||
this.browser = browser; | ||
this.closeBrowser = closeBrowser; | ||
this.closeBrowser = async () => { | ||
await closeBrowser(); | ||
server && server.stop(); | ||
}; | ||
this.page = await this.browser.newPage(); | ||
await this.exposeClone(); | ||
await this.page.goto(url, waitForOptions); | ||
console.log("Block renderer"); | ||
console.log("this.page.gotoageUrl", pageUrl); | ||
await this.page.goto(pageUrl, waitForOptions); | ||
} | ||
async hostContent(url) { | ||
const { pathname, protocol } = new URL(url); | ||
console.log("Host content\n"); | ||
console.log("URL: ", url); | ||
console.log("Conetnt pathname: " + pathname); | ||
console.log("Conetnt protocol: " + protocol); | ||
if (protocol === 'file:') { | ||
const server = await server_1.createServer(pathname.replace('/index.html', '')); | ||
const pageUrl = `http://localhost:${server.port}`; | ||
console.log("Static server: ", server); | ||
console.log("pageUrl: ", pageUrl); | ||
return { pageUrl, server }; | ||
} | ||
console.log("pageUrl: ", url); | ||
return { pageUrl: url, server: undefined }; | ||
} | ||
async exposeClone() { | ||
@@ -26,0 +49,0 @@ try { |
{ | ||
"name": "@ewizardjs/blocks-renderer", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -35,5 +35,7 @@ "main": "dist/index.js", | ||
"clone": "^2.1.2", | ||
"find-free-port": "^2.0.0", | ||
"fs-extra": "^9.0.0", | ||
"qs": "^6.10.3" | ||
"qs": "^6.10.3", | ||
"static-server": "^2.2.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24698
26
359
5
+ Addedfind-free-port@^2.0.0
+ Addedstatic-server@^2.2.1
+ Addedansi-regex@0.2.1(transitive)
+ Addedansi-styles@1.1.0(transitive)
+ Addedchalk@0.5.1(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfile-size@0.0.5(transitive)
+ Addedfind-free-port@2.0.0(transitive)
+ Addedhas-ansi@0.1.0(transitive)
+ Addedis-wsl@1.1.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedopn@5.5.0(transitive)
+ Addedstatic-server@2.2.1(transitive)
+ Addedstrip-ansi@0.3.0(transitive)
+ Addedsupports-color@0.2.0(transitive)