fix(core): update

This commit is contained in:
Philipp Kunz 2021-10-14 10:59:45 +02:00
parent 56fa53b701
commit 8a308fa9e3
6 changed files with 18022 additions and 2453 deletions

20400
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,22 +12,23 @@
"build": "(tsbuild --web)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.52",
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.59",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^15.0.1",
"@types/node": "^16.10.5",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smartfile": "^8.0.10",
"@pushrocks/smartnetwork": "^2.0.10",
"@pushrocks/smartpromise": "^3.1.5",
"@pushrocks/smartpuppeteer": "^1.0.21",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartpuppeteer": "^1.0.27",
"@pushrocks/smartunique": "^3.0.3",
"@types/express": "^4.17.11",
"express": "^4.17.1"
"@types/express": "^4.17.13",
"express": "^4.17.1",
"pdf-merger-js": "^3.2.1"
},
"files": [
"ts/**/*",

View File

@ -25,18 +25,28 @@ tap.test('should create a pdf from website as single page PDF', async () => {
});
tap.test('should create a valid PDFResult', async () => {
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(
'https://maintainedby.lossless.com'
);
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
const fs = await import('fs');
const writePDfToDisk = async (urlArg: string, fileName: string) => {
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(urlArg);
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
const fs = await import('fs');
if (!fs.existsSync('.nogit/')) {
fs.mkdirSync('.nogit/');
}
fs.writeFileSync('.nogit/sample.pdf', pdfResult.buffer);
if (!fs.existsSync('.nogit/')) {
fs.mkdirSync('.nogit/');
}
fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer);
};
await writePDfToDisk('https://maintainedby.lossless.com/', '1.pdf')
await writePDfToDisk('https://lossless.com/', '2.pdf')
});
tap.test('should combine pdfs', async () => {
const fs = await import('fs');
const buffer1 = fs.readFileSync('.nogit/1.pdf');
const buffer2 = fs.readFileSync('.nogit/2.pdf');
fs.writeFileSync(`.nogit/combined.pdf`, await testSmartPdf.mergePdfBuffers([buffer1, buffer2]));
})
tap.test('should be able to close properly', async () => {
await testSmartPdf.stop();
});

View File

@ -1,8 +1,11 @@
import * as plugins from './smartpdf.plugins';
export class PdfCandidate {
pdfId = plugins.smartunique.shortId();
doneDeferred = plugins.smartpromise.defer();
public htmlString: string;
public pdfId = plugins.smartunique.shortId();
public doneDeferred = plugins.smartpromise.defer();
constructor(public htmlString) {}
constructor(htmlStringArg: string) {
this.htmlString = htmlStringArg;
}
}

View File

@ -3,7 +3,7 @@ import * as paths from './smartpdf.paths';
import { Server } from 'http';
import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
declare const document;
declare const document: any;
import * as interfaces from './interfaces';
@ -19,7 +19,7 @@ export class SmartPdf {
this._readyDeferred = new plugins.smartpromise.Deferred();
}
async start(headlessBrowserArg?) {
async start(headlessBrowserArg?: plugins.smartpuppeteer.puppeteer.Browser) {
// lets set the external browser in case one is provided
this.headlessBrowser = headlessBrowserArg;
// setup puppeteer
@ -80,7 +80,7 @@ export class SmartPdf {
}
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: true,
@ -108,7 +108,7 @@ export class SmartPdf {
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
height: documentWidth,
width: documentWidth,
printBackground: true,
@ -135,7 +135,7 @@ export class SmartPdf {
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
height: documentWidth,
width: documentWidth,
printBackground: true,
@ -149,4 +149,12 @@ export class SmartPdf {
buffer: pdfBuffer,
};
}
public async mergePdfBuffers(pdfBuffers: Buffer[]): Promise<Buffer> {
const merger = new plugins.pdfMerger();
for (const buffer of pdfBuffers) {
merger.add(buffer);
}
return merger.saveAsBuffer();
}
}

View File

@ -14,6 +14,7 @@ import * as smartunique from '@pushrocks/smartunique';
export { smartfile, smartpromise, smartpuppeteer, smartunique, smartnetwork };
// thirdparty
import pdfMerger from 'pdf-merger-js';
import express from 'express';
export { express };
export { pdfMerger, express };