Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
aae8ec0ee1 | |||
ec4768e1cc | |||
3308895b3b | |||
37e47fc33f | |||
b4a3a36b07 | |||
baf26dc492 | |||
30e4b4665c | |||
74a0a27fc1 | |||
59eed53644 | |||
473aaa004a | |||
ecfd4115a1 | |||
0fbbfaac7c | |||
86d2fc2c5b | |||
f97866fe82 | |||
5c0b8c4df0 | |||
8da88be5e8 | |||
4f0164965c | |||
63f4321b04 | |||
e4287e9943 | |||
337c299a5e | |||
4ac4d8d049 | |||
5e8abaa5b4 | |||
d8fd7f9956 | |||
1711aadb6b |
@ -1,5 +1,5 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -49,14 +49,14 @@ testLTS:
|
|||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -65,7 +65,7 @@ testSTABLE:
|
|||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -78,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -106,7 +98,9 @@ trigger:
|
|||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-dbase:npmci
|
||||||
|
services:
|
||||||
|
- docker:18-dind
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@
|
|||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.om",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartpdf",
|
"gitrepo": "smartpdf",
|
||||||
"shortDescription": "Create PDFs fast and smoothly",
|
"shortDescription": "Create PDFs fast and smoothly",
|
||||||
|
39
package-lock.json
generated
39
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.8",
|
"version": "1.0.20",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -248,6 +248,15 @@
|
|||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-3.0.2.tgz",
|
||||||
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
"integrity": "sha512-jmrJMUEmBCWChWK8CIcx4Vw3wv/8OgVNmkaxJrbs+WMaoRUfJtpWWJfrAwwHWt9ZXJbarJ+CwfwfYiiZXymndQ=="
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartpuppeteer": {
|
||||||
|
"version": "1.0.5",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.5.tgz",
|
||||||
|
"integrity": "sha512-7iD2mxQHXG5/6PwZY2wU6GQjNXy9dR5cLP/nvfjxXaelX/x3N1yagjPAuMYxuIqiTtVfrHC4Ehq+gnTZ4mSPow==",
|
||||||
|
"requires": {
|
||||||
|
"@types/puppeteer": "^1.12.4",
|
||||||
|
"puppeteer": "^1.17.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
"version": "1.1.14",
|
"version": "1.1.14",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartrequest/-/smartrequest-1.1.14.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartrequest/-/smartrequest-1.1.14.tgz",
|
||||||
@ -460,9 +469,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.0.3",
|
"version": "12.0.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.0.4.tgz",
|
||||||
"integrity": "sha512-zkOxCS/fA+3SsdA+9Yun0iANxzhQRiNwTvJSr6N95JhuJ/x27z9G2URx1Jpt3zYFfCGUXZGL5UDxt5eyLE7wgw=="
|
"integrity": "sha512-j8YL2C0fXq7IONwl/Ud5Kt0PeXw22zGERt+HSSnwbKOJVsAGkEz3sFCYwaF9IOuoG1HOtE0vKCj6sXF7Q0+Vaw=="
|
||||||
},
|
},
|
||||||
"@types/portscanner": {
|
"@types/portscanner": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
@ -611,7 +620,7 @@
|
|||||||
},
|
},
|
||||||
"async-limiter": {
|
"async-limiter": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/async-limiter/-/async-limiter-1.0.0.tgz",
|
||||||
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
|
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
|
||||||
},
|
},
|
||||||
"asynckit": {
|
"asynckit": {
|
||||||
@ -815,7 +824,7 @@
|
|||||||
},
|
},
|
||||||
"concat-stream": {
|
"concat-stream": {
|
||||||
"version": "1.6.2",
|
"version": "1.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/concat-stream/-/concat-stream-1.6.2.tgz",
|
||||||
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
|
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer-from": "^1.0.0",
|
"buffer-from": "^1.0.0",
|
||||||
@ -1067,7 +1076,7 @@
|
|||||||
},
|
},
|
||||||
"extract-zip": {
|
"extract-zip": {
|
||||||
"version": "1.6.7",
|
"version": "1.6.7",
|
||||||
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz",
|
"resolved": "https://verdaccio.lossless.one/extract-zip/-/extract-zip-1.6.7.tgz",
|
||||||
"integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=",
|
"integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"concat-stream": "1.6.2",
|
"concat-stream": "1.6.2",
|
||||||
@ -1078,7 +1087,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://verdaccio.lossless.one/debug/-/debug-2.6.9.tgz",
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "2.0.0"
|
"ms": "2.0.0"
|
||||||
@ -1088,7 +1097,7 @@
|
|||||||
},
|
},
|
||||||
"fd-slicer": {
|
"fd-slicer": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/fd-slicer/-/fd-slicer-1.0.1.tgz",
|
||||||
"integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=",
|
"integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"pend": "~1.2.0"
|
"pend": "~1.2.0"
|
||||||
@ -1515,7 +1524,7 @@
|
|||||||
},
|
},
|
||||||
"mkdirp": {
|
"mkdirp": {
|
||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
@ -1523,7 +1532,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
"resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz",
|
||||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1742,7 +1751,7 @@
|
|||||||
},
|
},
|
||||||
"pend": {
|
"pend": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/pend/-/pend-1.2.0.tgz",
|
||||||
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA="
|
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA="
|
||||||
},
|
},
|
||||||
"pify": {
|
"pify": {
|
||||||
@ -1786,7 +1795,7 @@
|
|||||||
},
|
},
|
||||||
"proxy-from-env": {
|
"proxy-from-env": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/proxy-from-env/-/proxy-from-env-1.0.0.tgz",
|
||||||
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4="
|
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4="
|
||||||
},
|
},
|
||||||
"pump": {
|
"pump": {
|
||||||
@ -2227,7 +2236,7 @@
|
|||||||
},
|
},
|
||||||
"typedarray": {
|
"typedarray": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
"resolved": "https://verdaccio.lossless.one/typedarray/-/typedarray-0.0.6.tgz",
|
||||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
@ -2427,7 +2436,7 @@
|
|||||||
},
|
},
|
||||||
"yauzl": {
|
"yauzl": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/yauzl/-/yauzl-2.4.1.tgz",
|
||||||
"integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=",
|
"integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"fd-slicer": "~1.0.1"
|
"fd-slicer": "~1.0.1"
|
||||||
|
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.8",
|
"version": "1.0.20",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create pdfs on the fly",
|
"description": "create pdfs on the fly",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -17,23 +17,23 @@
|
|||||||
"@gitzone/tsrun": "^1.2.6",
|
"@gitzone/tsrun": "^1.2.6",
|
||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@pushrocks/tapbundle": "^3.0.9",
|
||||||
"@types/node": "^12.0.3"
|
"@types/node": "^12.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^7.0.2",
|
"@pushrocks/smartfile": "^7.0.2",
|
||||||
"@pushrocks/smartnetwork": "^1.1.6",
|
"@pushrocks/smartnetwork": "^1.1.6",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
|
"@pushrocks/smartpuppeteer": "^1.0.5",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"@types/express": "^4.16.1",
|
"@types/express": "^4.16.1",
|
||||||
"@types/puppeteer": "^1.12.4",
|
"express": "^4.17.1"
|
||||||
"express": "^4.17.1",
|
|
||||||
"puppeteer": "^1.17.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/*",
|
||||||
"ts_web/*",
|
"ts_web/*",
|
||||||
"dist/*",
|
"dist/*",
|
||||||
"dist_web/*",
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
"assets/*",
|
"assets/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
|
10
readme.md
10
readme.md
@ -3,13 +3,13 @@ Create PDFs fast and smoothly
|
|||||||
|
|
||||||
## Availabililty and Links
|
## Availabililty and Links
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpdf)
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpdf)
|
||||||
* [gitlab.com (source)](https://gitlab.om/pushrocks/smartpdf)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpdf)
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartpdf)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartpdf)
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpdf/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpdf/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.om/pushrocks/smartpdf/commits/master)
|
[](https://gitlab.com/pushrocks/smartpdf/commits/master)
|
||||||
[](https://gitlab.om/pushrocks/smartpdf/commits/master)
|
[](https://gitlab.com/pushrocks/smartpdf/commits/master)
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartpdf)
|
[](https://www.npmjs.com/package/@pushrocks/smartpdf)
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartpdf)
|
[](https://snyk.io/test/npm/@pushrocks/smartpdf)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
@ -21,6 +21,6 @@ Create PDFs fast and smoothly
|
|||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
||||||
|
13
test/test.ts
13
test/test.ts
@ -24,6 +24,19 @@ tap.test('should create a pdf from website as single page PDF', async () => {
|
|||||||
await testSmartPdf.getFullWebsiteAsSinglePdf('https://maintainedby.lossless.com');
|
await testSmartPdf.getFullWebsiteAsSinglePdf('https://maintainedby.lossless.com');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
if (!fs.existsSync('.nogit/')) {
|
||||||
|
fs.mkdirSync('.nogit/');
|
||||||
|
}
|
||||||
|
fs.writeFileSync('.nogit/sample.pdf', pdfResult.buffer);
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should be able to close properly', async () => {
|
tap.test('should be able to close properly', async () => {
|
||||||
await testSmartPdf.stop();
|
await testSmartPdf.stop();
|
||||||
});
|
});
|
||||||
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './interface.pdfresult';
|
5
ts/interfaces/interface.pdfresult.ts
Normal file
5
ts/interfaces/interface.pdfresult.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IPdfResult {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
buffer: Buffer;
|
||||||
|
}
|
@ -5,10 +5,13 @@ import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
|
|||||||
|
|
||||||
declare const document;
|
declare const document;
|
||||||
|
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
export class SmartPdf {
|
export class SmartPdf {
|
||||||
htmlServerInstance: Server;
|
htmlServerInstance: Server;
|
||||||
serverPort: number;
|
serverPort: number;
|
||||||
headlessBrowser: plugins.puppeteer.Browser;
|
headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
||||||
|
externalBrowserBool: boolean = false;
|
||||||
private _readyDeferred: plugins.smartpromise.Deferred<void>;
|
private _readyDeferred: plugins.smartpromise.Deferred<void>;
|
||||||
private _candidates: { [key: string]: PdfCandidate } = {};
|
private _candidates: { [key: string]: PdfCandidate } = {};
|
||||||
|
|
||||||
@ -16,9 +19,15 @@ export class SmartPdf {
|
|||||||
this._readyDeferred = new plugins.smartpromise.Deferred();
|
this._readyDeferred = new plugins.smartpromise.Deferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start(headlessBrowserArg?) {
|
||||||
|
// lets set the external browser in case one is provided
|
||||||
|
this.headlessBrowser = headlessBrowserArg;
|
||||||
// setup puppeteer
|
// setup puppeteer
|
||||||
this.headlessBrowser = await plugins.puppeteer.launch();
|
if (this.headlessBrowser) {
|
||||||
|
this.externalBrowserBool = true;
|
||||||
|
} else {
|
||||||
|
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
||||||
|
}
|
||||||
|
|
||||||
// setup server
|
// setup server
|
||||||
const app = plugins.express();
|
const app = plugins.express();
|
||||||
@ -35,19 +44,24 @@ export class SmartPdf {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop
|
||||||
async stop() {
|
async stop() {
|
||||||
const done = plugins.smartpromise.defer<void>();
|
const done = plugins.smartpromise.defer<void>();
|
||||||
this.htmlServerInstance.close(() => {
|
this.htmlServerInstance.close(() => {
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
await this.headlessBrowser.close();
|
|
||||||
|
if (!this.externalBrowserBool) {
|
||||||
|
await this.headlessBrowser.close();
|
||||||
|
}
|
||||||
|
|
||||||
await done.promise;
|
await done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a pdf for a given html string;
|
* returns a pdf for a given html string;
|
||||||
*/
|
*/
|
||||||
async getPdfForHtmlString(htmlStringArg: string) {
|
async getPdfForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
|
||||||
await this._readyDeferred.promise;
|
await this._readyDeferred.promise;
|
||||||
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
||||||
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
||||||
@ -63,29 +77,37 @@ export class SmartPdf {
|
|||||||
console.log(`id security check passed for ${pdfCandidate.pdfId}`);
|
console.log(`id security check passed for ${pdfCandidate.pdfId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
path: plugins.path.join(paths.pdfDir, `${pdfCandidate.pdfId}.pdf`),
|
|
||||||
format: 'A4'
|
format: 'A4'
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
delete this._candidates[pdfCandidate.pdfId];
|
delete this._candidates[pdfCandidate.pdfId];
|
||||||
pdfCandidate.doneDeferred.resolve();
|
pdfCandidate.doneDeferred.resolve();
|
||||||
await pdfCandidate.doneDeferred.promise;
|
await pdfCandidate.doneDeferred.promise;
|
||||||
|
return {
|
||||||
|
id: pdfCandidate.pdfId,
|
||||||
|
name: `${pdfCandidate.pdfId}.js`,
|
||||||
|
buffer: pdfBuffer
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPdfForWebsite(websiteUrl: string) {
|
async getPdfForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
page.emulateMedia('screen');
|
page.emulateMedia('screen');
|
||||||
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
||||||
const pdfId = plugins.smartunique.shortId();
|
const pdfId = plugins.smartunique.shortId();
|
||||||
await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
path: plugins.path.join(paths.pdfDir, `${pdfId}.pdf`),
|
|
||||||
format: 'A4',
|
format: 'A4',
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true
|
preferCSSPageSize: true
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
|
return {
|
||||||
|
id: pdfId,
|
||||||
|
name: `${pdfId}.js`,
|
||||||
|
buffer: pdfBuffer
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFullWebsiteAsSinglePdf(websiteUrl: string) {
|
async getFullWebsiteAsSinglePdf(websiteUrl: string) {
|
||||||
@ -93,15 +115,13 @@ export class SmartPdf {
|
|||||||
page.emulateMedia('screen');
|
page.emulateMedia('screen');
|
||||||
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
||||||
const pdfId = plugins.smartunique.shortId();
|
const pdfId = plugins.smartunique.shortId();
|
||||||
const {documentHeight, documentWidth} = await page.evaluate(() => {
|
const { documentHeight, documentWidth } = await page.evaluate(() => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
documentHeight: document.height,
|
documentHeight: document.height,
|
||||||
documentWidth: document.width
|
documentWidth: document.width
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
path: plugins.path.join(paths.pdfDir, `${pdfId}.pdf`),
|
|
||||||
height: documentWidth,
|
height: documentWidth,
|
||||||
width: documentWidth,
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
@ -109,5 +129,10 @@ export class SmartPdf {
|
|||||||
preferCSSPageSize: true
|
preferCSSPageSize: true
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
|
return {
|
||||||
|
id: pdfId,
|
||||||
|
name: `${pdfId}.js`,
|
||||||
|
buffer: pdfBuffer
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import * as plugins from './smartpdf.plugins';
|
import * as plugins from './smartpdf.plugins';
|
||||||
|
|
||||||
export const packageDir = plugins.path.join(__dirname, '../');
|
export const packageDir = plugins.path.join(__dirname, '../');
|
||||||
export const pdfDir = plugins.path.join(packageDir, 'assets/pdfdir');
|
|
||||||
|
|
||||||
plugins.smartfile.fs.ensureDirSync(pdfDir);
|
|
||||||
|
@ -7,13 +7,13 @@ export { http, path };
|
|||||||
// @pushrocks
|
// @pushrocks
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartpuppeteer from '@pushrocks/smartpuppeteer';
|
||||||
import * as smartnetwork from '@pushrocks/smartnetwork';
|
import * as smartnetwork from '@pushrocks/smartnetwork';
|
||||||
import * as smartunique from '@pushrocks/smartunique';
|
import * as smartunique from '@pushrocks/smartunique';
|
||||||
|
|
||||||
export { smartfile, smartpromise, smartunique, smartnetwork };
|
export { smartfile, smartpromise, smartpuppeteer, smartunique, smartnetwork };
|
||||||
|
|
||||||
// thirdparty
|
// thirdparty
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import puppeteer from 'puppeteer';
|
|
||||||
|
|
||||||
export { express, puppeteer };
|
export { express };
|
||||||
|
Reference in New Issue
Block a user