Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
add manual test, upgrade deps, doc (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
landsman authored Mar 8, 2022
1 parent 0d10f19 commit 0ec92b7
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 52 deletions.
9 changes: 5 additions & 4 deletions .docs/arm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
3 changes: 3 additions & 0 deletions .github/workflows/pull-request-created.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ node_modules
.vscode

dist/

tmp/*
92 changes: 50 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
20 changes: 20 additions & 0 deletions test/qr-code-without-img.js
Original file line number Diff line number Diff line change
@@ -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();
48 changes: 48 additions & 0 deletions test/tools.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0ec92b7

Please sign in to comment.