sg-paynow-qr
v1.1.3
Published
Generates qr string for making sg paynow payments
Downloads
19
Maintainers
Readme
Developer Documentation
Basic Gitlab NPM package
This is a test module for learning basics to publishing a Javascript/Typescript module to NPM registry to share and reuse cide.
This is initially based on the article from snyk.
It's reference code can be found here.
Changes:
- Use Jest for testing instead of Mocha
- Use Gitlab CI instead of Github Actions.
- Use nodejs-scan and semgrep SAST provided by Gitlab
Prerequisites to setup:
- Gitlab account with 2FA
- Gitlab personal access token with API, read_repository and write_repository permissions
- NPM token for publishing to npmjs registry.
Quick start
This section outlines the overall steps to configure up your name project. Details of individual steps could be found on next section.
On Gitlab CI web console.
- Create empty Gitlab project with your desired namespace and project name.
- Add the following environment variables.
- GL_TOKEN = ******
- NPM_TOKEN = ******
- DRYRUN = true
- COMMIT_LINT_DEPTH = 1
On your local repository clone.
- Update references to kaikokchew namespace with your own.
- Update references to sg-paynow-qr project name with your own.
- Update NPM cache to local folder.
- Perform an NPM install.
- Perform a docker build of runner container image.
- Push container image of runner into the Gitlab CI registry.
- Update origin of this repo with your Gitlab project.
- Push this baseline into your Gitlab repo.
The pipeline should trigger from this push into the Gitlab repository.
Detailed Steps
Set npm cache to local
Docker build will rely on this to speed up
npm config set cache .npmInstall all dependencies and setup commit hook
npm installRunning linters
To perform a check
npm run lintTo Auto fix as much as possible.
npm run lint-fixCheck on commit message format
npx commitlint --from=HEADRunning unit tests
For local run.
npm run testFor running tests in Gitlab CI.
npm run test:ciDocker image for test and publish in Gitlab CI/CD
Building and updating image on Gitlab registry.
docker login registry.gitlab.com
docker build -t registry.gitlab.com/kaikokchew/sg-paynow-qr/runner:latest --build-arg GL_PROJ_GROUP=kaikokchew --build-arg GL_PROJ_NAME=sg-paynow-qr --progress=plain .
docker push registry.gitlab.com/kaikokchew/sg-paynow-qr/runner:latestRunning and testing image on local.
docker run -it -v $(pwd):/builds/kaikokchew/sg-paynow-qr --rm registry.gitlab.com/kaikokchew/sg-paynow-qr/runner shConfiguring pre-commit hooks
Typically this is already done as part of first time npm installation.
npm install --save-dev husky
npm pkg set scripts.commitlint="commitlint --edit"
echo "npm run commitlint \${1}" > .husky/commit-msg
npm pkg set scripts.pre-commit="npm run lint"
echo "npm run pre-commit \${1}" > .husky/pre-commitBuilding your package
npm run build