Development
This module is a C++ wrapper around the Zint barcode library. The version of zint that will be used will be determined by the git reference stored in the zintVersion
field of package.json
.
Source code management
Upon installation of dependencies (yarn install
), a copy of the Zint source repo will be cloned in the Git-ignored .zint
directory, and its relevant C source files are referenced in binding.gyp
, along with src/binding/main.cpp
. The compiled .node
module is then available for use by the JavaScript source, in src/index.js
.
Once .zint
is created, the same install script will then apply a small number of patches to some Zint source files to adapt it to the following needs:
- Add
rendered_data
as a char array to be populated with raw string output. - Update
svg.c
andps.c
to write to therendered_data
buffer instead ofstdout
. - Replace
malloc.h
references withstdlib.h
for cross-compatibility.
See scripts/install.js
and scripts/patches.js
for more info.
Utilization of Nan
This project utilizes Nan to make the project backwards-compatible and make bindings future-proof.
Building the project
Builds are created using node-pre-gyp
.
Upon installation of dependencies, node-pre-gyp build
will be run, which will compile the project from source.
Building on Windows
If you're using Windows (excluding WSL), then you'll need to install windows-build-tools to compile the native Node module.
npm install --global --production windows-build-tools --vs2017
npm config set msvs_version 2017 –global
This install takes a while, but once it's complete, you can move on to Creating a build below.
Creating a build
To create a packaged build, run:
yarn package:binary
Running tests
Tests are written as *.test.js
and utilize Jest.
Both unit and e2e tests are written for this project. To run all tests:
yarn test
Unit tests
Unit tests are specified in the __tests__
subdirectories under src
.
To run unit tests:
yarn test:unit
Test coverage results are sent to Codecov.
e2e tests
e2e tests are specified in the test/e2e
directory. They utilize jest-image-snapshot for comparisons of barcode images in tandem with the helper test method, createImageFile
.
To run e2e tests:
yarn test:e2e
Committing
Commit message standards abide by standard-changelog
. This module utilizes commitizen
as a devDependency to help developers write their commits, and commit messages are enforced using commitlint
.
Versioning
This package abides by the semver standard. standard-version
will automatically update CHANGELOG.md
and bump the version.
Automated builds and CI
GitHub Actions will automatically build and test pull requests. At least one admin PR approval and all status checks are required to merge a PR.
The following status checks are implemented:
- Successful Windows builds (AppVeyor)
- Successful Linux and macOS builds (Travis)
- Sufficient code coverage (threshold >90%)
Upon the successful merge of a PR, CI will create an automated release of the binaries on GitHub (via node-pre-gyp-github
), publish to npm, and push the updated changelog and version bump changes to GitHub.
Important
The package version is automatically updated. Do not change any version references in this project.
Contributing
All constructive feedback and pull request changes are welcome. For more information on contributing to this project, please see the Contributing Guidelines.