bits-to-dead-trees 0.0.11 → 1.0.0
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/ci.yml +3 -0
- package/CHANGELOG.md +17 -0
- package/Dockerfile +5 -9
- package/README.md +1 -2
- package/{src/index.ts → index.js} +28 -6
- package/nodemon.json +2 -3
- package/package.json +11 -18
- package/{src/schemas → schemas}/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
|
}
|
package/.github/workflows/ci.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# bits-to-dead-trees
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- eccf614: Remove TypeScript, use vanilla JS with JSDoc types.
|
|
8
|
+
|
|
9
|
+
This actually improves DX by not having that extra build step, while still having
|
|
10
|
+
good support in your IDE, since we still have the types as JSDoc.
|
|
11
|
+
|
|
12
|
+
This is the v1.0. This has been very stable and it's unlikely that the API will change
|
|
13
|
+
a lot. Nothing should break for users with this release.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 7ef95e5: Update playwright to 1.21.1
|
|
18
|
+
- d651f7a: Update playwright to 1.21.0
|
|
19
|
+
|
|
3
20
|
## 0.0.11
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
FROM mcr.microsoft.com/playwright:v1.
|
|
1
|
+
FROM mcr.microsoft.com/playwright:v1.21.1-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 --production
|
|
16
|
+
RUN npm install --production --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", "schemas", "./"]
|
|
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
|
|
|
@@ -1,7 +1,18 @@
|
|
|
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("./schemas/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";
|
|
@@ -18,7 +29,13 @@ const server = fastify({
|
|
|
18
29
|
},
|
|
19
30
|
});
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param {string} url
|
|
35
|
+
* @param {PdfOptions} options
|
|
36
|
+
* @returns Buffer
|
|
37
|
+
*/
|
|
38
|
+
const createPDF = async (url, options = {}) => {
|
|
22
39
|
const browser = await playwright.chromium.launch();
|
|
23
40
|
const context = await browser.newContext({ ignoreHTTPSErrors: true });
|
|
24
41
|
const page = await context.newPage();
|
|
@@ -31,9 +48,14 @@ const createPDF = async (url: string, options?: PdfOptions) => {
|
|
|
31
48
|
return pdf;
|
|
32
49
|
};
|
|
33
50
|
|
|
34
|
-
server.post
|
|
51
|
+
server.post(
|
|
35
52
|
"/pdf",
|
|
36
53
|
{ schema: { body: PdfRequestBodySchema }, attachValidation: true },
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {import('fastify').FastifyRequest<{Body: PdfRequestBody}>} request
|
|
57
|
+
* @param {import('fastify').FastifyReply} response
|
|
58
|
+
*/
|
|
37
59
|
async (request, response) => {
|
|
38
60
|
if (request.validationError) {
|
|
39
61
|
response.code(400);
|
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": "0.0
|
|
4
|
+
"version": "1.0.0",
|
|
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,31 @@
|
|
|
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 schemas/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
31
|
"fastify": "^3.28.0",
|
|
33
|
-
"playwright-core": "^1.
|
|
32
|
+
"playwright-core": "^1.21.1"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@changesets/cli": "^2.22.0",
|
|
37
|
-
"@types/node": "^16",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
39
|
-
"@typescript-eslint/parser": "^5.18.0",
|
|
40
|
-
"concurrently": "^7.1.0",
|
|
41
36
|
"eslint": "^8.13.0",
|
|
42
37
|
"eslint-config-prettier": "^8.5.0",
|
|
43
38
|
"nodemon": "^2.0.15",
|
|
44
39
|
"pino-pretty": "^7.6.1",
|
|
45
40
|
"prettier": "^2.6.2",
|
|
46
|
-
"rimraf": "^3.0.2",
|
|
47
|
-
"typescript": "^4.6.3",
|
|
48
41
|
"typescript-json-schema": "^0.53.0"
|
|
49
42
|
}
|
|
50
43
|
}
|
|
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
|