A github npm package template with typescript.
Initial commit (Quickstart for GitHub Packages)
git init && \
git add . && \
git commit -m "Initial commit" && \
git branch -M main && \
git remote add origin https://github.com/sidisinsane/github-npm-package-template.git && \
git push -u origin main
Initial release (Managing releases in a repository)
gh release create v0.0.1 --title "v0.0.1 (beta)" --notes "this is a beta release" --prerelease
pnpm | npm | yarn | |
---|---|---|---|
Install dependencies | pnpm install |
npm install |
yarn |
Generate documentation | pnpm run docs |
npm run docs |
yarn run docs |
Run unit tests | pnpm run test |
npm run test |
yarn run test |
Build | pnpm run build |
npm run build |
yarn run build |
Lint | pnpm run lint[:fix] |
npm run lint[:fix] |
yarn run lint[:fix] |
Format | pnpm run format[:fix] |
npm run format[:fix] |
yarn run format[:fix] |
.github/workflows/release-package.yml
:
name: Node.js Package
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- TypeScript: TypeScript is JavaScript with syntax for types.
- tsup: Bundle your TypeScript library with no config, powered by esbuild.
Install
pnpm add -D typescript tsup
Configure
tsconfig.json
:
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
tsup.config.ts
:
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
target: "es2020",
format: ["cjs", "esm"],
splitting: false,
sourcemap: true,
clean: true,
dts: true,
});
- Prettier: Prettier is an opinionated code formatter.
- ESLint: ESLint statically analyzes your code to quickly find problems.
Install
pnpm add -D @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint eslint-config-prettier prettier
Configure
.eslintrc.cjs
:
/* eslint-env node */
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
root: true,
};
.prettierrc
(see .editorconfig
):
{}
- TypeDoc: TypeDoc converts comments in TypeScript source code into rendered HTML documentation or a JSON model.
Install
pnpm add -D typedoc @mxssfd/typedoc-theme
Configure
typedoc.config.cjs
:
/* eslint-env node */
/** @type {import('typedoc').TypeDocOptions} */
module.exports = {
entryPoints: ["./src/index.ts"],
out: "docs",
plugin: ["@mxssfd/typedoc-theme"],
theme: "my-theme",
cleanOutputDir: true,
};
- Jest: Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
- ts-jest: A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Install
pnpm add -D jest ts-jest @types/jest && \
npx ts-jest config:init
Configure
jest.config.cjs
:
/* eslint-env node */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
coverageDirectory: "coverage",
coveragePathIgnorePatterns: ["/node_modules/"],
coverageProvider: "v8",
coverageReporters: ["json", "text", "lcov", "clover"],
};