@aashari/boilerplate-npm-package
v1.8.2
Published
A simple Node.js package that prints 'Hello World'
Readme
@aashari/boilerplate-npm-package
A simple TypeScript npm package boilerplate with automated publishing to npm using GitHub Actions.
Installation
npm install @aashari/boilerplate-npm-packageTypeScript Support
This package is written in TypeScript and includes type definitions. When using it in a TypeScript project, you'll get full type checking and autocompletion:
import { greet } from '@aashari/boilerplate-npm-package';
// Type checking works as expected
greet(); // OK
greet('Alice'); // OK
greet(123); // Type error: Argument of type 'number' is not assignable to parameter of type 'string | undefined'Usage
As a Library
// ES Modules
import { greet } from '@aashari/boilerplate-npm-package';
// CommonJS
const { greet } = require('@aashari/boilerplate-npm-package');
// Call the function with default greeting
greet(); // Outputs "Hello World"
// Call the function with custom name
greet('Alice'); // Outputs "Hello Alice"Command Line Interface (CLI)
This package also provides a CLI that can be used after installation:
# Basic usage (prints "Hello World")
my-node-package
# Specific greeting command
my-node-package greet
# Greeting with custom name
my-node-package greet --name Alice
# OR
my-node-package greet -n Alice
# Display version
my-node-package --version
# Display help
my-node-package --helpTesting
This package includes comprehensive testing with Jest.
To run tests:
# Run all tests
npm test
# Run tests with coverage report
npm run test:coverageCurrent test coverage is 100% across all metrics.
Development
- Clone this repository
- Install dependencies:
npm install - Make your changes
- Run linting:
npm run lint - Format code:
npm run format - Build the package:
npm run build - Run tests:
npm test
Available Scripts
npm run build- Compile TypeScript filesnpm test- Run testsnpm run test:coverage- Run tests with coverage reportnpm run lint- Check code for linting errorsnpm run format- Format code with Prettiernpm run update:version- Update version numbers in source filesnpm run update:check- Check for outdated dependenciesnpm run update:deps- Update all dependenciesnpm run publish:npm- Publish to npm registry
Version Management
The package includes a versatile version management script that syncs versions between package.json and source files:
# Use version from package.json
npm run update:version
# Specify a custom version
npm run update:version 1.2.3
# Preview changes without applying them
npm run update:version --dry-run
# Show detailed information
npm run update:version --verboseRelease Process
The project uses semantic-release to automate the release process. When commits are pushed to the main branch:
- Semantic release determines if a new version should be published (based on commit messages)
- If a release is needed:
- Version is automatically incremented (patch, minor, or major)
- Changelog is updated
- Release notes are generated
- Package is published to npm registry
- GitHub release is created with release notes
Note: Automated publishing to npm requires an
NPM_TOKENsecret to be configured in your GitHub repository settings. See the CI/CD Workflows section for details.
To trigger a release, push a commit with a message following the Conventional Commits format:
fix: ...- for a patch release (e.g., 1.0.1)feat: ...- for a minor release (e.g., 1.1.0)feat!: ...orfix!: ...orfeat: ...BREAKING CHANGE...- for a major release (e.g., 2.0.0)
Other common prefixes that don't trigger releases:
docs:- Documentation changes onlystyle:- Changes that don't affect code functionalityrefactor:- Code changes that neither fix bugs nor add featurestest:- Adding or updating testschore:- Maintenance tasksci:- Changes to CI configurationbuild:- Changes to build processperf:- Performance improvements
Manual Release
If you need to publish manually:
npm run publish:npm # Publish to npmContributing
- Fork the repository
- Create a new branch:
git checkout -b feature/your-feature-name - Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature/your-feature-name - Submit a pull request
CI/CD Workflows
This project uses GitHub Actions for continuous integration and delivery:
- Semantic Release - Automatically determines version bumps based on commit messages, creates releases, and publishes to npm.
- Dependency Checks - Scheduled workflow that checks for outdated dependencies.
- Dependabot Auto-merge - Automatically tests and merges minor and patch Dependabot PRs if they pass tests.
All workflows use Node.js 22 with dependency caching for optimal performance.
Required Repository Secrets
For the CI/CD pipeline to work correctly, you need to configure the following secrets in your GitHub repository settings:
NPM_TOKEN- An npm authentication token with publish permissions. You can create one at https://www.npmjs.com/settings/[your-username]/tokens.
To add these secrets:
- Go to your repository on GitHub
- Navigate to Settings > Secrets and variables > Actions
- Click "New repository secret"
- Add your NPM_TOKEN with the appropriate value
License
MIT
