Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde authored Jun 17, 2024
0 parents commit 58846c1
Show file tree
Hide file tree
Showing 26 changed files with 8,358 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,snap}]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eslint.config.mjs linguist-vendored
fix-ext.sh linguist-vendored
4 changes: 4 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>2bad/renovate-config:default"]
}
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build

on:
push:
paths-ignore:
- 'docs/**'
- '*.md'

jobs:
build:
name: build on node@${{ matrix.node-version }}
runs-on: ubuntu-latest

strategy:
matrix:
node-version:
- 20
- 21
- 22

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
persist-credentials: false
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: ${{ matrix.node-version }}

- run: npm ci
- run: npm run check
- run: npm run build
34 changes: 34 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CodeQL

on:
schedule:
- cron: 0 4 * * 1

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language:
- javascript-typescript

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
persist-credentials: false

# Initializes the CodeQL tools for scanning.
- uses: github/codeql-action/init@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality

- uses: github/codeql-action/analyze@23acc5c183826b7a8a97bce3cecc52db901f8251 # v3
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish

on:
release:
types: [published]

jobs:
publish:
name: publish
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
persist-credentials: false
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version-file: package.json
registry-url: https://registry.npmjs.org

- run: npm ci
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
62 changes: 62 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test

on:
push:
paths-ignore:
- 'docs/**'
- '*.md'
# schedule:
# - cron: 0 20 * * *

jobs:
test:
name: test on ${{ matrix.os-release }} node@${{ matrix.node-version }}
runs-on: ${{ matrix.os-release }}

strategy:
matrix:
node-version:
- 20
- 21
- 22
os-release:
- ubuntu-latest
- windows-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
persist-credentials: false
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: ${{ matrix.node-version }}

- run: npm ci
- run: npm run test

coverage:
name: collect coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
persist-credentials: false
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version-file: package.json

- run: npm ci

- run: npm run test:unit
- uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unit

# - run: rm -rf coverage

# - run: npm run test:integration
# - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# flags: integration
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Windows
Thumbs.db
Desktop.ini
$RECYCLE.BIN/

## OS X
.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.Spotlight-V100
.Trashes

## Editors and IDE
*.sublime*
*.code-workspace

## Node.js
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp
pids
logs
results
tmp
node_modules
npm-debug.log

## Build
build

## Coverage reports
coverage

## API keys and secrets
.env
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
19 changes: 19 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"test": ".*\\.ts$",
"exclude": [".*\\.test.ts$"],
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2022",
"baseUrl": "./source",
"paths": {
"~/*": ["./*"]
}
},
"module": {
"type": "es6"
}
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"vitest.explorer"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"eslint.workingDirectories": [{ "mode": "auto" }]
}
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Breaking Changes

### Added

### Fixed

### Changed

### Removed
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 2BAD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# TS Lib Starter

A lightweight and customizable starter kit for building TypeScript libraries. It comes with ESM support, flexible configuration options, extensive ESLint rules, and built-in Github Actions integration to automate the build checks, tests, and package publishing process. With TypeScript path aliases and speedy test capabilities, developers can easily create high-quality, performant libraries using this starter kit.

# ✨ Features

- 🔥 **ESM First**
- 📝 **Extensive ESLint Rules**
- :octocat: **Github Actions**
- 🪢 **Typescript Path Aliases**
- 🏎️ **Super Fast Tests**

# Using this template

- Search `ts-lib-starter` and replace it with your custom package name.
- Search `2BAD` and replace it with your name. (be careful not to replace `@2bad/tsconfig` references)

# Package Choices

The packages chosen for this project include some of the most popular and widely used tools for TypeScript development:

- **typescript**: a superset of JavaScript that adds type annotations to improve code quality, readability, and maintainability.
- **eslint**: a tool for identifying and reporting on patterns found in code. It's highly configurable and can be customized according to different coding standards. Comes preconfigured with plugins for linting tests, jsdoc blocks, and TypeScript itself.
- **prettier**: an opinionated code formatter that ensures consistent formatting across the entire codebase.
- **npm-run-all**: a CLI tool that allows you to run multiple npm scripts sequentially or in parallel.
- **tsc-alias**: a TypeScript plugin that provides easy-to-use aliases for import statements without requiring complex configurations in Webpack or other build tools.
- **vitest**: a testing framework that includes functionality for both unit and integration tests.

# NPM Scripts

Here are the npm scripts included in this project:

- **build**: cleans the ./build directory, compiles TypeScript code to JavaScript, and applies aliases.
- **format:check**: checks if TypeScript files are formatted according to Prettier standards.
- **format:fix**: automatically fixes formatting issues using Prettier.
- **lint**: lints TypeScript files with eslint (including tests and jsdoc blocks).
- **lint:fix**: automatically fixes linting errors found by eslint.
- **prepublishOnly**: prepares for publishing by running the build scripts.
- **preversion**: runs clean, lint, test, and build scripts before publishing a new version.
19 changes: 19 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
"files": {
"include": ["*.js", "*.mjs", "*.jsx", "*.ts", "*.tsx"]
},
"formatter": {
// should be removed once this issue is fixed: https://github.com/biomejs/biome/issues/1724
"indentStyle": "space",
"lineWidth": 120
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "single",
"quoteStyle": "single",
"semicolons": "asNeeded",
"trailingCommas": "none"
}
}
}
Loading

0 comments on commit 58846c1

Please sign in to comment.