bits-to-dead-trees 0.0.6 → 0.0.9

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.
@@ -0,0 +1,30 @@
1
+ name: Build and Push Docker Image
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ concurrency: ${{ github.workflow }}-${{ github.ref }}
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout Repo
14
+ uses: actions/checkout@v3
15
+ ref: ${{ github.ref_name }}
16
+
17
+ - name: Login to GitHub Container Registry
18
+ uses: docker/login-action@v1
19
+ with:
20
+ registry: ghcr.io
21
+ username: ${{ github.repository_owner }}
22
+ password: ${{ secrets.GITHUB_TOKEN }}
23
+
24
+ - name: Build and push builder image
25
+ uses: docker/build-push-action@v2
26
+ with:
27
+ file: Dockerfile
28
+ push: true
29
+ tags: |
30
+ ghcr.io/${{ github.repository }}:${{ github.ref_name }}
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on: push
4
+
5
+ concurrency:
6
+ group: ${{ github.ref }}
7
+ cancel-in-progress: true
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout Repo
14
+ uses: actions/checkout@v3
15
+
16
+ - name: Set up Node
17
+ uses: actions/setup-node@v3
18
+ with:
19
+ node-version: lts/*
20
+ cache: npm
21
+
22
+ - name: Run eslint
23
+ run: npm run lint
24
+
25
+ - name: Run prettier
26
+ run: npm run check-format
@@ -0,0 +1,30 @@
1
+ {
2
+ "[javascriptreact]": {
3
+ "editor.formatOnSave": true,
4
+ "editor.formatOnPaste": true
5
+ },
6
+ "[html]": {
7
+ "editor.formatOnType": true,
8
+ "editor.formatOnSave": true
9
+ },
10
+ "[javascript]": {
11
+ "editor.formatOnSave": true,
12
+ "editor.formatOnPaste": true
13
+ },
14
+ "[json]": {
15
+ "editor.formatOnSave": true,
16
+ "editor.formatOnPaste": true
17
+ },
18
+ "[typescript]": {
19
+ "editor.formatOnSave": true,
20
+ "editor.formatOnPaste": true
21
+ },
22
+ "[css]": {
23
+ "editor.formatOnSave": true,
24
+ "editor.formatOnPaste": true
25
+ },
26
+ "[scss]": {
27
+ "editor.formatOnSave": true,
28
+ "editor.formatOnPaste": true
29
+ }
30
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # bits-to-dead-trees
2
2
 
3
+ ## 0.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - ddb70f5: Update eslint
8
+ - 5176013: Add CI setup
9
+
10
+ ## 0.0.8
11
+
12
+ ### Patch Changes
13
+
14
+ - 67dc4a4: Manual release process for now
15
+ - e37239b: Add repository to package.json
16
+
17
+ ## 0.0.7
18
+
19
+ ### Patch Changes
20
+
21
+ - e272ea9: 🤡
22
+
3
23
  ## 0.0.6
4
24
 
5
25
  ### Patch Changes
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fastify_1 = __importDefault(require("fastify"));
7
+ const playwright_core_1 = __importDefault(require("playwright-core"));
8
+ const pdf_request_body_json_1 = __importDefault(require("./schemas/pdf_request_body.json"));
9
+ const SERVER_PORT = process.env["SERVER_PORT"] ?? 8000;
10
+ const server = (0, fastify_1.default)({
11
+ logger: {
12
+ prettyPrint: process.env["NODE_ENV"] !== "production"
13
+ ? {
14
+ translateTime: "HH:MM:ss Z",
15
+ ignore: "pid,hostname",
16
+ }
17
+ : false,
18
+ },
19
+ });
20
+ const createPDF = async (url, options) => {
21
+ const browser = await playwright_core_1.default.chromium.launch();
22
+ const context = await browser.newContext({ ignoreHTTPSErrors: true });
23
+ const page = await context.newPage();
24
+ await page.goto(url);
25
+ const pdf = await page.pdf(options);
26
+ await browser.close();
27
+ return pdf;
28
+ };
29
+ server.post("/pdf", { schema: { body: pdf_request_body_json_1.default }, attachValidation: true }, async (request, response) => {
30
+ if (request.validationError) {
31
+ response.code(400);
32
+ return {
33
+ error: true,
34
+ message: request.validationError.message,
35
+ };
36
+ }
37
+ try {
38
+ return createPDF(request.body.url, request.body.options);
39
+ }
40
+ catch (error) {
41
+ response.code(500);
42
+ return {
43
+ error,
44
+ };
45
+ }
46
+ });
47
+ server.get("/health", async (_, response) => response.code(200).send());
48
+ const startServer = async () => {
49
+ try {
50
+ await server.listen(+SERVER_PORT, "0.0.0.0");
51
+ }
52
+ catch (error) {
53
+ console.error(error);
54
+ process.exit(1);
55
+ }
56
+ };
57
+ startServer();
@@ -0,0 +1,84 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "options": {
5
+ "properties": {
6
+ "displayHeaderFooter": {
7
+ "description": "Display header and footer. Defaults to `false`.",
8
+ "type": "boolean"
9
+ },
10
+ "footerTemplate": {
11
+ "description": "HTML template for the print footer. Should use the same format as the `headerTemplate`.",
12
+ "type": "string"
13
+ },
14
+ "format": {
15
+ "description": "Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.",
16
+ "type": "string"
17
+ },
18
+ "headerTemplate": {
19
+ "description": "HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values\ninto them:\n- `'date'` formatted print date\n- `'title'` document title\n- `'url'` document location\n- `'pageNumber'` current page number\n- `'totalPages'` total pages in the document",
20
+ "type": "string"
21
+ },
22
+ "height": {
23
+ "description": "Paper height, accepts values labeled with units.",
24
+ "type": ["string", "number"]
25
+ },
26
+ "landscape": {
27
+ "description": "Paper orientation. Defaults to `false`.",
28
+ "type": "boolean"
29
+ },
30
+ "margin": {
31
+ "description": "Paper margins, defaults to none.",
32
+ "properties": {
33
+ "bottom": {
34
+ "description": "Bottom margin, accepts values labeled with units. Defaults to `0`.",
35
+ "type": ["string", "number"]
36
+ },
37
+ "left": {
38
+ "description": "Left margin, accepts values labeled with units. Defaults to `0`.",
39
+ "type": ["string", "number"]
40
+ },
41
+ "right": {
42
+ "description": "Right margin, accepts values labeled with units. Defaults to `0`.",
43
+ "type": ["string", "number"]
44
+ },
45
+ "top": {
46
+ "description": "Top margin, accepts values labeled with units. Defaults to `0`.",
47
+ "type": ["string", "number"]
48
+ }
49
+ },
50
+ "type": "object"
51
+ },
52
+ "pageRanges": {
53
+ "description": "Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.",
54
+ "type": "string"
55
+ },
56
+ "path": {
57
+ "description": "The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to the current working\ndirectory. If no path is provided, the PDF won't be saved to the disk.",
58
+ "type": "string"
59
+ },
60
+ "preferCSSPageSize": {
61
+ "description": "Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format`\noptions. Defaults to `false`, which will scale the content to fit the paper size.",
62
+ "type": "boolean"
63
+ },
64
+ "printBackground": {
65
+ "description": "Print background graphics. Defaults to `false`.",
66
+ "type": "boolean"
67
+ },
68
+ "scale": {
69
+ "description": "Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.",
70
+ "type": "number"
71
+ },
72
+ "width": {
73
+ "description": "Paper width, accepts values labeled with units.",
74
+ "type": ["string", "number"]
75
+ }
76
+ },
77
+ "type": "object"
78
+ },
79
+ "url": {
80
+ "type": "string"
81
+ }
82
+ },
83
+ "type": "object"
84
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "bits-to-dead-trees",
3
3
  "author": "Robin Mehner <robin@coding-robin.de>",
4
- "version": "0.0.6",
4
+ "version": "0.0.9",
5
5
  "description": "Turn HTML into PDF files",
6
+ "repository": "github:rmehner/bits-to-dead-trees",
6
7
  "license": "Apache-2.0",
7
8
  "keywords": [
8
9
  "html",
@@ -14,6 +15,7 @@
14
15
  },
15
16
  "main": "dist/index.js",
16
17
  "scripts": {
18
+ "check-format": "prettier --check 'src/**/*.ts'",
17
19
  "clean": "rimraf dist",
18
20
  "lint": "eslint src/*.ts",
19
21
  "format": "prettier --write src/**/*.{ts,json}",
@@ -24,7 +26,8 @@
24
26
  "update-schemas": "npm run dump-schemas && npm run format",
25
27
  "postinstall": "npx playwright install chromium",
26
28
  "add-changeset": "changeset",
27
- "release": "changeset publish"
29
+ "release": "changeset publish",
30
+ "version": "changeset version"
28
31
  },
29
32
  "dependencies": {
30
33
  "fastify": "^3.28.0",
@@ -36,7 +39,7 @@
36
39
  "@typescript-eslint/eslint-plugin": "^5.18.0",
37
40
  "@typescript-eslint/parser": "^5.18.0",
38
41
  "concurrently": "^7.1.0",
39
- "eslint": "^8.12.0",
42
+ "eslint": "^8.13.0",
40
43
  "eslint-config-prettier": "^8.5.0",
41
44
  "nodemon": "^2.0.15",
42
45
  "pino-pretty": "^7.6.1",
@@ -1,74 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- concurrency: ${{ github.workflow }}-${{ github.ref }}
9
-
10
- jobs:
11
- release:
12
- name: Release
13
- runs-on: ubuntu-latest
14
- steps:
15
- - name: Checkout Repo
16
- uses: actions/checkout@v3
17
- with:
18
- # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
19
- fetch-depth: 0
20
-
21
- - name: Setup Node.js
22
- uses: actions/setup-node@v3
23
- with:
24
- cache: npm
25
- node-version: lts/*
26
-
27
- - name: Install Dependencies
28
- run: npm install
29
-
30
- - name: Create Release Pull Request or Publish to npm
31
- id: changesets
32
- uses: changesets/action@v1
33
- with:
34
- publish: npm run release
35
- title: Release new version 🚀
36
- env:
37
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
39
- build-docker:
40
- name: Build and push docker image
41
- runs-on: ubuntu-latest
42
- needs: ["release"]
43
- # https://github.com/actions/runner/issues/491#issuecomment-850884422 ¯\_(ツ)_/¯
44
- if: |
45
- always() &&
46
- needs.release.result == 'success' &&
47
- needs.release.changesets.outputs.published == 'true'
48
- steps:
49
- - name: Checkout Repo
50
- uses: actions/checkout@v3
51
-
52
- - name: Determine version
53
- run: |
54
- echo "VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
55
-
56
- - name: Checkout tag
57
- run: |
58
- git fetch --tags
59
- git checkout "v${{ env.VERSION }}"
60
-
61
- - name: Login to GitHub Container Registry
62
- uses: docker/login-action@v1
63
- with:
64
- registry: ghcr.io
65
- username: ${{ github.repository_owner }}
66
- password: ${{ secrets.GITHUB_TOKEN }}
67
-
68
- - name: Build and push builder image
69
- uses: docker/build-push-action@v2
70
- with:
71
- file: Dockerfile
72
- push: true
73
- tags: |
74
- ghcr.io/${{ github.repository }}:${{ env.VERSION }}