@jzetlen/zenit
v0.1.0
Published
spy on global javascript
Readme
Node.JS TypeScript Library Template
This is a template repository meant to be used as a starting point for new
Node.JS projects written in
TypeScript.
As this is a highly opinionated template, many tools are included and pre-configured with sane and strict defaults to enforce a standard level of code quality and a consistent style across projects.
With this in mind, feel free to edit the various config files to your liking.
Prerequisites
To view static documentation and coverage reports,
http-server is recommended; it is included as a
development dependency for the serve:* commands, but for manual CLI
usage, install it with npm i -g http-server.
Setup
pnpm is used as the package manager; install it with
npm i -g pnpm if you do not already have it.
Then, to get started, simply install dependencies with pnpm i.
Building Sources and Documentation
Three npm scripts are provided to build
TypeScript sources and generate documentation with
TypeDoc:
build-- runs bothbuild:tsandbuild:docs.build:ts-- buildsTypeScriptsources from./srcto native JavaScript files in./dist.build:docs-- builds documentation withTypeDocin./docs. BothLICENSE.mdandCHANGELOG.mdare copied into./docs.
Viewing Documentation Site
After building the static HTML documentation with build:docs,
run pnpm serve:docs or http-server docs and navigate to
localhost:8080.
Deploy Documentation On GitHub Pages
To enable GitHub Pages, access the repository settings and configure the Pages
settings to use the main (or master) branch and the ./docs folder.
Testing
Testing is done with mocha and chai.
nyc is used to generate coverage reports. The following npm
scripts are provided:
test-- runs mocha on all TypeScript sourcestest:coverage-- liketestbut runsnycto generate an HTML coverage report in/coverage.test:watch-- runsnycandmochacontinuously, re-running tests when any sources change.
Viewing Test Coverage Report
After generating an HTML coverage report with test:coverage, view it by
running either serve:coverage or http-server ./coverage and navigating
to localhost:8080.
Linting
Linting is provided by ESLint and
markdownlint. The following npm scripts are provided:
lint:eslint-- runsESLinton./package.jsonand./src/**/*and prints any errors.lint:markdownlint-- runsmarkdownlintonREADME.mdand prints any errors.lint:eslint:fix-- likelint:eslintbut automatically fixes linter errors where possible.lint:markdownlint:fix-- likelint:markdownlintbut automatically fixes linter errors where possible.lint-- runs bothlint:eslintandlint:markdownlint.lint:fix-- runs bothlint:eslint:fixandlint:markdownlint:fix
ESLint Config & Plugins
A strict ESLint config is provided with many
plugins, the full list is below:
eslint-plugin-chai-expect--ESLintplugin that checks for common chai.js expect() mistakes.eslint-plugin-eslint-comments--ESLintrules for JavaScript comments.eslint-plugin-github-- An opinionated collection ofESLintrules used by GitHub.eslint-plugin-immutable-- This is anESLintplugin to disable all mutation in JavaScript.eslint-plugin-json-format--ESLintplugin for JSON files.eslint-plugin-jsonc-- ThisESLintplugin provides linting rules relate to better ways to help you avoid problems when usingJSON,JSONCandJSON5.eslint-plugin-lodash-- Lodash-specific linting rules forESLint.eslint-plugin-mocha--ESLintrules for mocha.eslint-plugin-no-secrets-- AnESLintrule that searches for potential secrets/keys in code and JSON files.eslint-plugin-optimize-regex-- Optimize regex literals.eslint-plugin-promise-- Enforce best practices for JavaScript promises.eslint-plugin-pure-- Enforce rules to make your code purely functional by disallowing some language constructs.eslint-plugin-regexp-- AnESLintplugin for finding RegExp mistakes and RegExp style guide violations.eslint-plugin-sonarjs--SonarJSrules forESLintto help developers produceClean Codeby detecting bugs and suspicious patterns.eslint-plugin-switch-case-- Switch-case-specific linting rules forESLint.eslint-plugin-tsdoc-- ThisESLintplugin provides a rule for validating that TypeScript doc comments conform to theTSDocspecification.eslint-plugin-unicorn-- More than 100 powerfulESLintruleseslint-plugin-write-good-comments-- Enforce good writing style in your comments.
Formatting
Prettier is included to automatically format sources to
enforce a consistent and standardized code style. It automatically verifies
that sources conform to the standard style as part of the
Husky pre-commit hook.
Two scripts are provided:
format-- runsPrettierand formats files in-place.format:check-- runsPrettierin check mode, reporting any files that do not match the standard style. To fix any reported issues, use theformatscript.
Husky
Huskyhooks are automatically installed whenpnpm iis run.
Husky is included and configured
with two commit hooks:
- pre-commit: runs
lint-staged, which runsmarkdownlintandESLinton README.md and project sources insrc/**. - commit-msg: runs
commitlinton commit messages to enforce theconventional commitstandard.
Creating A New Project
To start a new project with this repository as a template, clone it and delete
the .git folder, then run git init . to start a new git project and
commit history.
Then, configure package.json with your project name,
description, keywords, repository URL, version number, and any other details
you wish to change.
Add code to ./src, and it will be built to ./dist.
./src/index.ts will be built as the project entry point
at ./dist/index.js as defined in the
manifest.
CI
After each push to the main branch, the
CI GitHub Action runs to ensure all checks
pass.
Releasing
To release a new version of your package, the release npm script is
provided. It does the following:
- runs
pnpm format:check - runs
pnpm lint - runs
pnpm test - runs
pnpm build, - runs
git add docs - Updates the
package.jsonversion appropriately based on the commits made since the last release. - Updates the
CHANGELOG.md. - Commits all changes and tags the commit with the new version number.
- Pushes
mainwith the new tag to origin. - Triggers the
NPM Publishworkflow to automatically publish the new version on the NPM Registry.
Available scripts are:
pnpm docs: generate HTML documentation in./docstest: run mocha on all tests in./src/teststest:coverage: run mocha and generate a coverage report in./coveragebuild: build to JS in./distlint: runeslinton all files in./srcupdate-deps: update all dependenciesupdate-version: updates the CHANGELOG.md, bumps the version, commits & tagsrelease: lints, tests, builds, generates docs, runsupdate-versionand pushes.
Publishing
Publishing to the NPM Registry is done automatically
with a NPM Publish GitHub Action
that runs when a new tag is pushed. For this to work, you must add a secret
named NPM_TOKEN to the repository settings.
Release History
See CHANGELOG.md for more information.
License
Distributed under the MIT license. See LICENSE.md
for more information.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
