bits-to-dead-trees 0.0.11 → 1.0.2
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/.eslintrc.json +1 -7
- package/.github/workflows/build-docker-image-of-release.yml +2 -2
- package/.github/workflows/ci.yml +4 -1
- package/.github/workflows/release.yml +2 -2
- package/.tool-versions +1 -1
- package/CHANGELOG.md +30 -0
- package/Dockerfile +5 -9
- package/README.md +15 -2
- package/{src/index.ts → index.js} +36 -11
- package/nodemon.json +2 -3
- package/package.json +19 -25
- package/{src/schemas/pdf_request_body.json → pdf_request_body.json} +0 -0
- package/tsconfig.json +8 -11
- /package/{src/types → types}/schemas.ts +0 -0
package/.eslintrc.json
CHANGED
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
"es2021": true,
|
|
4
4
|
"node": true
|
|
5
5
|
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"eslint:recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended",
|
|
9
|
-
"prettier"
|
|
10
|
-
],
|
|
11
|
-
"parser": "@typescript-eslint/parser",
|
|
6
|
+
"extends": ["eslint:recommended", "prettier"],
|
|
12
7
|
"parserOptions": {
|
|
13
8
|
"ecmaVersion": "latest",
|
|
14
9
|
"sourceType": "module"
|
|
15
10
|
},
|
|
16
|
-
"plugins": ["@typescript-eslint"],
|
|
17
11
|
"rules": {}
|
|
18
12
|
}
|
|
@@ -16,14 +16,14 @@ jobs:
|
|
|
16
16
|
ref: ${{ github.ref_name }}
|
|
17
17
|
|
|
18
18
|
- name: Login to GitHub Container Registry
|
|
19
|
-
uses: docker/login-action@
|
|
19
|
+
uses: docker/login-action@v2
|
|
20
20
|
with:
|
|
21
21
|
registry: ghcr.io
|
|
22
22
|
username: ${{ github.repository_owner }}
|
|
23
23
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
24
24
|
|
|
25
25
|
- name: Build and push builder image
|
|
26
|
-
uses: docker/build-push-action@
|
|
26
|
+
uses: docker/build-push-action@v3
|
|
27
27
|
with:
|
|
28
28
|
file: Dockerfile
|
|
29
29
|
push: true
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
- name: Set up Node
|
|
17
17
|
uses: actions/setup-node@v3
|
|
18
18
|
with:
|
|
19
|
-
node-version:
|
|
19
|
+
node-version-file: .tool-versions
|
|
20
20
|
cache: npm
|
|
21
21
|
|
|
22
22
|
- name: Install npm dependencies
|
|
@@ -27,3 +27,6 @@ jobs:
|
|
|
27
27
|
|
|
28
28
|
- name: Run prettier
|
|
29
29
|
run: npm run check-format
|
|
30
|
+
|
|
31
|
+
- name: Run typecheck
|
|
32
|
+
run: npm run ts-check
|
|
@@ -18,11 +18,11 @@ jobs:
|
|
|
18
18
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
19
19
|
fetch-depth: 0
|
|
20
20
|
|
|
21
|
-
- name:
|
|
21
|
+
- name: Set up Node
|
|
22
22
|
uses: actions/setup-node@v3
|
|
23
23
|
with:
|
|
24
|
+
node-version-file: .tool-versions
|
|
24
25
|
cache: npm
|
|
25
|
-
node-version: lts/*
|
|
26
26
|
|
|
27
27
|
- name: Install Dependencies
|
|
28
28
|
run: npm install
|
package/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
nodejs 16.
|
|
1
|
+
nodejs 16.16.0
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# bits-to-dead-trees
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 86a275d: Fix server crash due to missing schema
|
|
8
|
+
- 029ce39: Fix server crash due to pretty print on development
|
|
9
|
+
|
|
10
|
+
## 1.0.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- cd71c2f: Update playwright to 1.23.2 (new browser versions)
|
|
15
|
+
|
|
16
|
+
## 1.0.0
|
|
17
|
+
|
|
18
|
+
### Major Changes
|
|
19
|
+
|
|
20
|
+
- eccf614: Remove TypeScript, use vanilla JS with JSDoc types.
|
|
21
|
+
|
|
22
|
+
This actually improves DX by not having that extra build step, while still having
|
|
23
|
+
good support in your IDE, since we still have the types as JSDoc.
|
|
24
|
+
|
|
25
|
+
This is the v1.0. This has been very stable and it's unlikely that the API will change
|
|
26
|
+
a lot. Nothing should break for users with this release.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 7ef95e5: Update playwright to 1.21.1
|
|
31
|
+
- d651f7a: Update playwright to 1.21.0
|
|
32
|
+
|
|
3
33
|
## 0.0.11
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
FROM mcr.microsoft.com/playwright:v1.
|
|
1
|
+
FROM mcr.microsoft.com/playwright:v1.23.2-focal
|
|
2
2
|
|
|
3
3
|
ENV NODE_ENV=production
|
|
4
4
|
ENV SERVER_PORT=8000
|
|
@@ -11,15 +11,11 @@ RUN apt-get update -yqq && \
|
|
|
11
11
|
apt-get clean && \
|
|
12
12
|
rm -rf /var/lib/apt/lists/*
|
|
13
13
|
|
|
14
|
-
COPY ["package.json", "package-lock.json*", "
|
|
14
|
+
COPY ["package.json", "package-lock.json*", "./"]
|
|
15
15
|
|
|
16
|
-
RUN npm install --
|
|
16
|
+
RUN npm install --omit=dev --ignore-scripts
|
|
17
17
|
|
|
18
|
-
COPY
|
|
19
|
-
|
|
20
|
-
RUN npm run build && \
|
|
21
|
-
rm -Rf src && \
|
|
22
|
-
npm install --production --ignore-scripts
|
|
18
|
+
COPY ["index.js", "pdf_request_body.json", "./"]
|
|
23
19
|
|
|
24
20
|
ENTRYPOINT ["tini", "-v", "--"]
|
|
25
|
-
CMD ["node", "
|
|
21
|
+
CMD ["node", "index.js"]
|
package/README.md
CHANGED
|
@@ -19,8 +19,7 @@ of that. It's using [Playwright](https://playwright.dev) in the background for t
|
|
|
19
19
|
1. `git checkout https://github.com/rmehner/bits-to-dead-trees`
|
|
20
20
|
2. `cd bits-to-dead-trees`
|
|
21
21
|
3. `npm install`
|
|
22
|
-
4. `npm
|
|
23
|
-
5. `npm start` to start the server. It'll listen to port 8000 on localhost by default.
|
|
22
|
+
4. `npm start` to start the server. It'll listen to port 8000 on localhost by default.
|
|
24
23
|
|
|
25
24
|
### Development
|
|
26
25
|
|
|
@@ -42,3 +41,17 @@ The server exposes the `/pdf` endpoint that listens to a POST request and expect
|
|
|
42
41
|
`options` are the options Playwright knows about PDF: https://playwright.dev/docs/api/class-page#page-pdf. We pass them to Playwright directly, so please refer to their docs.
|
|
43
42
|
|
|
44
43
|
The response is the PDF file.
|
|
44
|
+
|
|
45
|
+
## Docker
|
|
46
|
+
|
|
47
|
+
Versions are automatically build as Docker images and are available on [GitHub's package registry](https://github.com/rmehner/bits-to-dead-trees/pkgs/container/bits-to-dead-trees)
|
|
48
|
+
|
|
49
|
+
If you want to use it internally with docker-compose, this should give you a good idea to start:
|
|
50
|
+
|
|
51
|
+
```yml
|
|
52
|
+
services:
|
|
53
|
+
pdf:
|
|
54
|
+
image: ghcr.io/rmehner/bits-to-dead-trees:v1.0.0
|
|
55
|
+
ports:
|
|
56
|
+
- 8000:8000
|
|
57
|
+
```
|
|
@@ -1,24 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Parameters<import("playwright-core").Page["pdf"]>[0]} PdfOptions
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Object} PdfRequestBody
|
|
9
|
+
* @property {string} url
|
|
10
|
+
* @property {PdfOptions} options
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { fastify } = require("fastify");
|
|
14
|
+
const playwright = require("playwright-core");
|
|
15
|
+
const PdfRequestBodySchema = require("./pdf_request_body.json");
|
|
5
16
|
|
|
6
17
|
const SERVER_PORT = process.env["SERVER_PORT"] ?? 8000;
|
|
7
18
|
const SERVER_ADDRESS = process.env["SERVER_ADDRESS"] ?? "localhost";
|
|
8
19
|
|
|
9
20
|
const server = fastify({
|
|
10
21
|
logger: {
|
|
11
|
-
|
|
22
|
+
transport:
|
|
12
23
|
process.env["NODE_ENV"] !== "production"
|
|
13
24
|
? {
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
target: "pino-pretty",
|
|
26
|
+
options: {
|
|
27
|
+
translateTime: "HH:MM:ss Z",
|
|
28
|
+
ignore: "pid,hostname",
|
|
29
|
+
},
|
|
16
30
|
}
|
|
17
|
-
:
|
|
31
|
+
: undefined,
|
|
18
32
|
},
|
|
19
33
|
});
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {string} url
|
|
38
|
+
* @param {PdfOptions} options
|
|
39
|
+
* @returns Buffer
|
|
40
|
+
*/
|
|
41
|
+
const createPDF = async (url, options = {}) => {
|
|
22
42
|
const browser = await playwright.chromium.launch();
|
|
23
43
|
const context = await browser.newContext({ ignoreHTTPSErrors: true });
|
|
24
44
|
const page = await context.newPage();
|
|
@@ -31,9 +51,14 @@ const createPDF = async (url: string, options?: PdfOptions) => {
|
|
|
31
51
|
return pdf;
|
|
32
52
|
};
|
|
33
53
|
|
|
34
|
-
server.post
|
|
54
|
+
server.post(
|
|
35
55
|
"/pdf",
|
|
36
56
|
{ schema: { body: PdfRequestBodySchema }, attachValidation: true },
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {import('fastify').FastifyRequest<{Body: PdfRequestBody}>} request
|
|
60
|
+
* @param {import('fastify').FastifyReply} response
|
|
61
|
+
*/
|
|
37
62
|
async (request, response) => {
|
|
38
63
|
if (request.validationError) {
|
|
39
64
|
response.code(400);
|
|
@@ -60,7 +85,7 @@ server.get("/health", async (_, response) => response.code(200).send());
|
|
|
60
85
|
|
|
61
86
|
const startServer = async () => {
|
|
62
87
|
try {
|
|
63
|
-
await server.listen(+SERVER_PORT, SERVER_ADDRESS);
|
|
88
|
+
await server.listen({ port: +SERVER_PORT, host: SERVER_ADDRESS });
|
|
64
89
|
} catch (error) {
|
|
65
90
|
console.error(error);
|
|
66
91
|
process.exit(1);
|
package/nodemon.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bits-to-dead-trees",
|
|
3
3
|
"author": "Robin Mehner <robin@coding-robin.de>",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Turn HTML into PDF files",
|
|
6
6
|
"repository": "github:rmehner/bits-to-dead-trees",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -13,38 +13,32 @@
|
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">= 16"
|
|
15
15
|
},
|
|
16
|
-
"main": "
|
|
16
|
+
"main": "index.js",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"check-format": "prettier --check
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"start:dev": "concurrently --kill-others \"npm run build -- --watch\" \"nodemon --inspect dist/index.js\" ",
|
|
25
|
-
"dump-schemas": "typescript-json-schema src/types/schemas.ts PdfRequestBody --out src/schemas/pdf_request_body.json",
|
|
18
|
+
"check-format": "prettier --check **/*.{js,ts,json,md}",
|
|
19
|
+
"lint": "eslint *.js",
|
|
20
|
+
"format": "prettier --write **/*.{js,ts,json,md}",
|
|
21
|
+
"start": "node index.js",
|
|
22
|
+
"start:dev": "nodemon --inspect index.js",
|
|
23
|
+
"dump-schemas": "typescript-json-schema types/schemas.ts PdfRequestBody --out pdf_request_body.json",
|
|
26
24
|
"update-schemas": "npm run dump-schemas && npm run format",
|
|
27
25
|
"postinstall": "npx playwright install chromium",
|
|
28
26
|
"add-changeset": "changeset",
|
|
29
|
-
"release": "changeset publish"
|
|
27
|
+
"release": "changeset publish",
|
|
28
|
+
"ts-check": "npx tsc --noEmit"
|
|
30
29
|
},
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"fastify": "^
|
|
33
|
-
"playwright-core": "^1.
|
|
31
|
+
"fastify": "^4.2.1",
|
|
32
|
+
"playwright-core": "^1.23.2"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@changesets/cli": "^2.
|
|
37
|
-
"
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
39
|
-
"@typescript-eslint/parser": "^5.18.0",
|
|
40
|
-
"concurrently": "^7.1.0",
|
|
41
|
-
"eslint": "^8.13.0",
|
|
35
|
+
"@changesets/cli": "^2.23.1",
|
|
36
|
+
"eslint": "^8.19.0",
|
|
42
37
|
"eslint-config-prettier": "^8.5.0",
|
|
43
|
-
"nodemon": "^2.0.
|
|
44
|
-
"pino-pretty": "^
|
|
45
|
-
"prettier": "^2.
|
|
46
|
-
"
|
|
47
|
-
"typescript": "^
|
|
48
|
-
"typescript-json-schema": "^0.53.0"
|
|
38
|
+
"nodemon": "^2.0.19",
|
|
39
|
+
"pino-pretty": "^8.1.0",
|
|
40
|
+
"prettier": "^2.7.1",
|
|
41
|
+
"tslib": "^2.4.0",
|
|
42
|
+
"typescript-json-schema": "^0.54.0"
|
|
49
43
|
}
|
|
50
44
|
}
|
|
File without changes
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"module": "CommonJS",
|
|
7
|
-
"rootDir": "./src",
|
|
3
|
+
"lib": ["es2021"],
|
|
4
|
+
|
|
5
|
+
"strict": true,
|
|
8
6
|
"moduleResolution": "node",
|
|
9
|
-
"
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"esModuleInterop": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
12
8
|
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
|
|
11
|
+
"checkJs": true
|
|
12
|
+
}
|
|
16
13
|
}
|
|
File without changes
|