diff --git a/.docs/arm.md b/.docs/arm.md index 3335dc0..d45f4be 100644 --- a/.docs/arm.md +++ b/.docs/arm.md @@ -2,8 +2,9 @@ This example is for Macbook Pro M1. -## Steps +Run installation of these tools in your terminal. +You have to use brew. -1. [Install tooling for Rosseta](https://support.apple.com/en-gb/HT211861) -2. [Open iTerm / Terminal with Rosseta](https://apple.stackexchange.com/a/428769) -3. Run package and projects depending on that from this terminal +``` +arch -arm64 brew install pkg-config cairo pango jpeg giflib librsvg +``` diff --git a/.github/workflows/pull-request-created.yml b/.github/workflows/pull-request-created.yml index 10a8f1e..9634b1c 100644 --- a/.github/workflows/pull-request-created.yml +++ b/.github/workflows/pull-request-created.yml @@ -31,6 +31,9 @@ jobs: - name: 'Build' run: npm run build + - name: 'Tests' + run: npm run test + - name: 'The job has failed' if: ${{ failure() }} uses: marocchino/sticky-pull-request-comment@v1 diff --git a/.gitignore b/.gitignore index ecb2f04..e29c525 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ node_modules .vscode dist/ + +tmp/* diff --git a/package-lock.json b/package-lock.json index 28188e8..0d3320d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@trisbee/qr-image-nodejs", - "version": "1.2.3", + "version": "1.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@trisbee/qr-image-nodejs", - "version": "1.2.3", + "version": "1.2.4", "dependencies": { - "canvas": "^2.7.0", - "qrcode": "^1.4.4" + "canvas": "^2.9.0", + "qrcode": "^1.5.0" }, "devDependencies": { "@types/node": "^14.0.27", @@ -37,9 +37,9 @@ } }, "node_modules/@types/node": { - "version": "14.18.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.5.tgz", - "integrity": "sha512-LMy+vDDcQR48EZdEx5wRX1q/sEl6NdGuHXPnfeL8ixkwCOSZ2qnIyIZmcCbdX0MeRqHhAcHmX+haCbrS8Run+A==", + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==", "dev": true }, "node_modules/@types/qrcode": { @@ -129,13 +129,13 @@ } }, "node_modules/canvas": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.8.0.tgz", - "integrity": "sha512-gLTi17X8WY9Cf5GZ2Yns8T5lfBOcGgFehDFb+JQwDqdOoBOcECS9ZWMEAqMSVcMYwXD659J8NyzjRY/2aE+C2Q==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.9.0.tgz", + "integrity": "sha512-0l93g7uxp7rMyr7H+XRQ28A3ud0dKIUTIEkUe1Dxh4rjUYN7B93+SjC3r1PDKA18xcQN87OFGgUnyw7LSgNLSQ==", "hasInstallScript": true, "dependencies": { "@mapbox/node-pre-gyp": "^1.0.0", - "nan": "^2.14.0", + "nan": "^2.15.0", "simple-get": "^3.0.3" }, "engines": { @@ -429,9 +429,9 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -484,14 +484,22 @@ "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==" }, "node_modules/node-fetch": { - "version": "2.6.6", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz", - "integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==", + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "dependencies": { "whatwg-url": "^5.0.0" }, "engines": { "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } } }, "node_modules/nopt": { @@ -688,9 +696,9 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "node_modules/signal-exit": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz", - "integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==" + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "node_modules/simple-concat": { "version": "1.0.1", @@ -712,9 +720,9 @@ ] }, "node_modules/simple-get": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz", - "integrity": "sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz", + "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==", "dependencies": { "decompress-response": "^4.2.0", "once": "^1.3.1", @@ -899,9 +907,9 @@ } }, "@types/node": { - "version": "14.18.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.5.tgz", - "integrity": "sha512-LMy+vDDcQR48EZdEx5wRX1q/sEl6NdGuHXPnfeL8ixkwCOSZ2qnIyIZmcCbdX0MeRqHhAcHmX+haCbrS8Run+A==", + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==", "dev": true }, "@types/qrcode": { @@ -973,12 +981,12 @@ "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" }, "canvas": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.8.0.tgz", - "integrity": "sha512-gLTi17X8WY9Cf5GZ2Yns8T5lfBOcGgFehDFb+JQwDqdOoBOcECS9ZWMEAqMSVcMYwXD659J8NyzjRY/2aE+C2Q==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/canvas/-/canvas-2.9.0.tgz", + "integrity": "sha512-0l93g7uxp7rMyr7H+XRQ28A3ud0dKIUTIEkUe1Dxh4rjUYN7B93+SjC3r1PDKA18xcQN87OFGgUnyw7LSgNLSQ==", "requires": { "@mapbox/node-pre-gyp": "^1.0.0", - "nan": "^2.14.0", + "nan": "^2.15.0", "simple-get": "^3.0.3" } }, @@ -1197,9 +1205,9 @@ "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==" }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "requires": { "brace-expansion": "^1.1.7" } @@ -1237,9 +1245,9 @@ "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==" }, "node-fetch": { - "version": "2.6.6", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz", - "integrity": "sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==", + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "requires": { "whatwg-url": "^5.0.0" } @@ -1370,9 +1378,9 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "signal-exit": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz", - "integrity": "sha512-sDl4qMFpijcGw22U5w63KmD3cZJfBuFlVNbVMKje2keoKML7X2UzWbc4XrmEbDwg0NXJc3yv4/ox7b+JWb57kQ==" + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "simple-concat": { "version": "1.0.1", @@ -1380,9 +1388,9 @@ "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==" }, "simple-get": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz", - "integrity": "sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.1.tgz", + "integrity": "sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==", "requires": { "decompress-response": "^4.2.0", "once": "^1.3.1", diff --git a/package.json b/package.json index cb390ee..aaae18e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@trisbee/qr-image-nodejs", - "version": "1.2.3", + "version": "1.2.4", "types": "dist/index.d.ts", "description": "Allows you to generate image in middle of QR code", "main": "dist/index.js", @@ -9,11 +9,12 @@ "url": "git+https://github.com/trisbee/qr-image-nodejs.git" }, "scripts": { - "build": "tsc" + "build": "tsc --removeComments", + "test": "node ./test/qr-code-without-img.js" }, "dependencies": { - "canvas": "^2.7.0", - "qrcode": "^1.4.4" + "canvas": "^2.9.0", + "qrcode": "^1.5.0" }, "devDependencies": { "@types/node": "^14.0.27", diff --git a/src/index.ts b/src/index.ts index bd2b0e1..f5f3644 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import QRCOde = require('qrcode'); -import {QRCodeToBufferOptions} from "qrcode"; -import {createCanvas, loadImage} from "canvas"; +import { QRCodeToBufferOptions } from "qrcode"; +import { createCanvas, loadImage } from "canvas"; interface QRResponse { buffer: Buffer, diff --git a/test/qr-code-without-img.js b/test/qr-code-without-img.js new file mode 100644 index 0000000..26a7384 --- /dev/null +++ b/test/qr-code-without-img.js @@ -0,0 +1,20 @@ +const { generateQRWithImage } = require('../dist/index'); +const { printToTerminal } = require("./tools"); + +async function TestQRCodeWithoutImage() +{ + console.debug(`⏳ QR code start ...`); + + const data = await generateQRWithImage( + "https://www.trisbee.com/en/careers", + 256, + 256, + null + ); + + console.info(`👍 QR code generated ...`); + + printToTerminal(data.buffer); +} + +TestQRCodeWithoutImage(); diff --git a/test/tools.js b/test/tools.js new file mode 100644 index 0000000..4cfd676 --- /dev/null +++ b/test/tools.js @@ -0,0 +1,48 @@ +const fs = require('fs'); +const path = require('path'); +const resolve = require('path').resolve + +/** + * convert buffer data to file on disk + */ +async function imageToFile(body) { + + const suffix = Math.floor(new Date().getTime() / 1000); + const fileName = `image-${suffix}.png`; + const folder = '/../tmp/'; + + let fileAbsolutePath = path.join(__dirname, folder, fileName); + + ensureDirectoryExistence(fileAbsolutePath); + + fs.writeFile(fileAbsolutePath, body, function(err) { + if (err) throw err; + console.log("✅ File saved to:", 'file://' + fileAbsolutePath); + }); +} + +/** + * check if directory path exist + * if not, create it + */ +function ensureDirectoryExistence(filePath) +{ + const dirname = path.dirname(filePath); + if (fs.existsSync(dirname)) { + return true; + } + ensureDirectoryExistence(dirname); + + fs.mkdirSync(dirname); +} + + +/** + * get buffer and print QR code to terminal + */ +async function printToTerminal(buffer) { + await imageToFile(buffer); +} + + +module.exports.printToTerminal = printToTerminal;