Compare commits

...

4 Commits

Author SHA1 Message Date
30e4b4665c 1.0.17 2019-06-03 17:09:16 +02:00
74a0a27fc1 fix(core): update 2019-06-03 17:09:16 +02:00
59eed53644 1.0.16 2019-06-03 16:39:21 +02:00
473aaa004a fix(core): update 2019-06-03 16:39:21 +02:00
4 changed files with 11 additions and 13 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.15",
"version": "1.0.17",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.15",
"version": "1.0.17",
"private": false,
"description": "create pdfs on the fly",
"main": "dist/index.js",

View File

@ -5,13 +5,13 @@ import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
declare const document;
import { IPdfResult } from './interfaces';
import * as interfaces from './interfaces';
export class SmartPdf {
htmlServerInstance: Server;
serverPort: number;
headlessBrowser: plugins.puppeteer.Browser;
externalBrowser: boolean = false;
externalBrowserBool: boolean = false;
private _readyDeferred: plugins.smartpromise.Deferred<void>;
private _candidates: { [key: string]: PdfCandidate } = {};
@ -23,7 +23,9 @@ export class SmartPdf {
// lets set the external browser in case one is provided
this.headlessBrowser = headlessBrowserArg
// setup puppeteer
if (!this.headlessBrowser) {
if (this.headlessBrowser) {
this.externalBrowserBool = true;
} else {
let chromeArgs: string[] = [];
if(process.env.CI) {
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox'])
@ -31,8 +33,6 @@ export class SmartPdf {
this.headlessBrowser = await plugins.puppeteer.launch({
args: chromeArgs
});
} else {
this.externalBrowser = true;
}
// setup server
@ -50,13 +50,14 @@ export class SmartPdf {
});
}
// stop
async stop() {
const done = plugins.smartpromise.defer<void>();
this.htmlServerInstance.close(() => {
done.resolve();
});
if (!this.externalBrowser) {
if (!this.externalBrowserBool) {
await this.headlessBrowser.close();
}
@ -66,7 +67,7 @@ export class SmartPdf {
/**
* returns a pdf for a given html string;
*/
async getPdfForHtmlString(htmlStringArg: string): Promise<IPdfResult> {
async getPdfForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
await this._readyDeferred.promise;
const pdfCandidate = new PdfCandidate(htmlStringArg);
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
@ -96,7 +97,7 @@ export class SmartPdf {
};
}
async getPdfForWebsite(websiteUrl: string): Promise<IPdfResult> {
async getPdfForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
const page = await this.headlessBrowser.newPage();
page.emulateMedia('screen');
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });

View File

@ -1,6 +1,3 @@
import * as plugins from './smartpdf.plugins';
export const packageDir = plugins.path.join(__dirname, '../');
export const pdfDir = plugins.path.join(packageDir, 'assets/pdfdir');
plugins.smartfile.fs.ensureDirSync(pdfDir);