A template repository allows you to start a new github project with all of the boilerplate already laid out. Check here for more info about using a template repository.
# Transpiles the typescript and generates the JSONSchema
npm run build
# Runs the tests with Jest
npm run test
# Runs the tests with Jest, watching for changes
npm run test:watch
# Generates the developer documentation
npm run build:docs
The build and document generation process happens automatically during the build process managed by GitHub actions.
The Typescript code in this package is exposed as an NPM package, @ensomata/package-template
. If you need to use the code in other codebases, you can install that package from the GitHub Packages registry.
- Navigate to the github developer settings page
- Create a new token with
repo
andwrite:packages
permissions - Copy the token to a safe place
- Export an environment variable
GH_NPM_TOKEN
in your.zshrc
or.bashrc
with the personal access token as the value
Run the command below, using the GitHub token as the password
npm login --scope=@ensomata --registry=https://npm.pkg.github.com
Inside a project that will be installing this package, create a file named .npmrc
with the following content:
@ensomata:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GH_NPM_TOKEN}
- Create personal access token (PAT) with
read:packages
permissions - Register token in AWS Secrets Manager
- Authenticate to GitHub Packages using the PAT
- Export the PAT in the CodeBuild environment variables (e.g. $GH_PERSONAL_ACCESS_TOKEN)
npm config set @ensomata:registry https://npm.pkg.github.com
npm config set //npm.pkg.github.com/:_authToken $GH_PERSONAL_ACCESS_TOKEN
https://typicode.github.io/husky/#/
Husky allows you to configure hooks that run in the git lifecycle. The following hooks are configured:
pre-commit
- Runs lint-staged- Command to ensure consistent code formatting
prepare-commit-msg
- Runs Commitizen- Command to assist in formatting standardized commit messages
commit-msg
- Runs commitlint- Command to enforce standardized commit messages
This repository is configured with GitHub actions to handle automated tasks related to publishing the NPM package. With the tooling above (e.g. Husky/conventional-commits/commitizen) we have enabled automated versioning with Semver, based on the commit messages included in any given push (or merge) to the main
branch.
- Check out latest commit on main branch
- Set up Nodejs execution environment (v 14)
- Install NPM dependencies
- Run automated tests
- Check out latest commit on main branch
- Set up Nodejs execution environment (v 14)
- Bump package.json version and .cz.toml if necessary
- Create a new GitHub release
- Push to
prod
branch
- Check if there was a bump
- Check out latest commit on main branch
- Save the bumped version number in an environment variable
- Set up the Nodejs execution environment (v 14)
- Install NPM dependencies
- Run the
build:docs
script - Commit the generated documentation
- Simply set a variable to allow future jobs to know if the version was actually bumped or not (e.g. if the latest change was simply a
ci:
ordocs:
commit message)
- Check out latest commit on main branch
- Install NPM dependencies
- Transpile and build code
- Prune development-only npm dependencies
- Set up the Nodejs execution environment (v 14)
- Specify GitHub as the registry
- Publish the package