A modern, well-configured starter template for creating TypeScript npm packages. This template provides a solid foundation with best practices and essential tooling for TypeScript package development.
git clone https://github.com/imgarylai/ts-package-starter.git my-package
cd my-package
Update the package information:
package.json
with your package name, description, author, etc.Install dependencies:
npm install
npm run dev
This is an example of how your package could be used once you publish it. Update this section with your own package's usage:
// This is just a placeholder example - replace with your own package's usage
import { YourFunction } from "your-package-name";
// Use your package
const result = YourFunction();
git clone https://github.com/imgarylai/ts-package-starter.git
cd ts-package-starter
npm install
npm run dev
npm run build
- Build the package with tsupnpm run dev
- Watch mode for developmentnpm test
- Run testsnpm run test:coverage
- Run tests with coveragenpm run lint
- Lint the codenpm run type-check
- Check typesnpm run docs
- Generate documentationnpm run docs:watch
- Generate documentation in watch modenpm run clean
- Clean build outputsnpm run prepare
- Install git hooks.
โโโ src/ # Source code
โ โโโ index.ts # Main entry point
โ โโโ index.test.ts # Tests
โโโ .github/ # GitHub configuration
โโโ .husky/ # Git hooks
โโโ dist/ # Built files (generated)
โโโ docs/ # Generated documentation
โโโ coverage/ # Test coverage reports
โโโ node_modules/ # Dependencies
src
directory*.test.ts
filesnpm test
npm run build
This package uses semantic-release for automated publishing based on conventional commit messages. The process is fully automated and will:
The release process is triggered by commits to the main branch. The version bump is determined by your commit messages:
fix: ...
- Patch release (1.0.0 โ 1.0.1)feat: ...
- Minor release (1.0.0 โ 1.1.0)BREAKING CHANGE: ...
in commit body - Major release (1.0.0 โ 2.0.0)feat!: ...
- Major release with breaking change (1.0.0 โ 2.0.0)Examples:
# Patch release
git commit -m "fix: correct network timeout issue"
# Minor release
git commit -m "feat: add new API endpoint"
# Major release
git commit -m "feat!: redesign public API
BREAKING CHANGE: The entire public API has been redesigned"
To enable automated publishing, you need to:
Create an npm account if you don't have one
Create an npm access token:
Add the npm token to your GitHub repository:
NPM_TOKEN
Note: Only commits to the main branch trigger releases. When working on features, use feature branches and pull requests.
git checkout -b feature/amazing-feature
)git commit -m 'feat: add amazing feature'
)git push origin feature/amazing-feature
)This project uses Conventional Commits. Examples:
feat: add new feature
fix: resolve bug issue
docs: update README
chore: update dependencies
The project uses tsup for building, which provides:
This project uses TypeDoc for generating API documentation. The documentation is automatically built and deployed to GitHub Pages on every push to the main branch.
To generate documentation locally:
# Generate documentation
npm run docs
# Watch mode for documentation
npm run docs:watch
The documentation will be generated in the docs
directory.
The documentation is automatically deployed to GitHub Pages at: https://imgarylai.github.io/ts-package-starter
Features of the documentation:
To set up GitHub Pages for your documentation:
The documentation will be automatically built and deployed when:
You can also manually trigger the documentation build:
The documentation is configured in typedoc.json
. Key features:
This project uses Renovate for automated dependency updates. The configuration includes:
The Renovate bot will automatically create pull requests for dependency updates according to this schedule and configuration. This helps keep your dependencies up-to-date while minimizing maintenance overhead.
This project is licensed under the MIT License - see the LICENSE file for details.
Gary Lai - @imgarylai