Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoullier committed Dec 1, 2023
0 parents commit 08d519b
Show file tree
Hide file tree
Showing 19 changed files with 385 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Node.js",
// Image definition
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"github.vscode-github-actions",
"oven.bun-vscode"
]
}
},
"postCreateCommand": "curl -fsSL https://bun.sh/install | bash"
}

10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
Empty file added .gitattributes
Empty file.
10 changes: 10 additions & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Build

runs:
using: "composite"
steps:
- uses: ./.github/actions/cache
with:
scope: build
- run: bun --bun run build
shell: bash
29 changes: 29 additions & 0 deletions .github/actions/cache/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Cache

inputs:
scope:
required: true
description: Scope of files to cache
Example => 'dependencies,build'
Possible values for the scope => [dependencies, build]

runs:
using: composite
steps:
- name: Store dependencies cache
id: dependencies
if: ${{ contains(inputs.scope, 'dependencies') }}
uses: actions/cache@v3
with:
key: dependencies-${{ hashFiles('./bun.lockb') }}
path: |
./node_modules/**
- name: Store build cache
id: build
if: ${{ contains(inputs.scope, 'build') }}
uses: actions/cache@v3
with:
key: build-${{ hashFiles('./src/**') }}
path: |
./dist/**
13 changes: 13 additions & 0 deletions .github/actions/prevent-uncommit-changes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Prevent uncommit changes

runs:
using: "composite"
steps:
- shell: bash
run: |
if [ "$(git status --porcelain | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git status --porcelain
exit 1
fi
13 changes: 13 additions & 0 deletions .github/actions/setup-bun/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Setup Bun

runs:
using: "composite"
steps:
- uses: ./.github/actions/cache
with:
scope: dependencies
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun install
shell: bash
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
groups:
eslint:
patterns:
- "@typescript-eslint/*"
- "eslint"
schedule:
interval: "daily"
labels: ["dependencies"]
commit-message:
prefix: "chore"
include: "scope"
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened, labeled ]

name: CI

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read # to fetch code (actions/checkout)
packages: write # to publish packages (npm publish)

jobs:
ci-setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- uses: ./.github/actions/build
- uses: ./.github/actions/prevent-uncommit-changes
- run: bun test
- run: bun run lint

ci-canary-release:
runs-on: ubuntu-latest
needs: [ci-setup]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-bun
- uses: actions/setup-node@v3
with:
registry-url: "https://npm.pkg.github.com"
- uses: ./.github/actions/cache
with:
scope: build
- run: npm version prerelease --preid=canary.$(git rev-parse --short HEAD) --no-git-tag-version
- run: npm publish --tag canary
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
66 changes: 66 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
on: pull_request_target

name: Dependabot

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
pull-requests: write

jobs:
dependabot-update-lockfile:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: ./.github/actions/setup-bun
- name: Set @github-actions[bot] as committer
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- run: git status
- run: git add -A
- run: |
git commit -m "chore(deps-dev): bump bun lockfile"
- run: git push
dependabot-build:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
needs: [dependabot-update-lockfile]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: ./.github/actions/setup-bun
- uses: ./.github/actions/build
- uses: ./.github/actions/prevent-uncommit-changes
- run: bun test
- run: bun run lint
dependabot-automerge:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
needs: [dependabot-build]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1
- name: Approve a PR
if: ${{contains(fromJSON('["version-update:semver-patch", "version-update:semver-minor"]'), steps.metadata.outputs.update-type)}}
run: gh pr review --approve "$PR_URL" -b "**Automatically approving** pull request because **it includes a minor/patch update**"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.DEPENDABOT_AUTOMERGE_TOKEN}}
- name: Enable auto-merge for Dependabot PRs
if: ${{contains(fromJSON('["version-update:semver-patch", "version-update:semver-minor"]'), steps.metadata.outputs.update-type)}}
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.DEPENDABOT_AUTOMERGE_TOKEN}}
40 changes: 40 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
branches:
- main

name: Semantic Release

permissions:
contents: read # For Checkout

jobs:
release:
permissions:
contents: write # to create release commit (google-github-actions/release-please-action)
pull-requests: write # to create release PR (google-github-actions/release-please-action)
packages: write # to publish to GitHub Packages (actions/setup-node)

runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun install
- run: bun --bun run build
- run: bun test
- uses: actions/setup-node@v3
with:
registry-url: 'https://npm.pkg.github.com'
if: ${{ steps.release.outputs.release_created }}
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Dependency directories

node_modules/

# Generate output

dist/
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.inlayHints.variableTypes.enabled": true,
"typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName": true,
"typescript.inlayHints.parameterTypes.enabled": true,
"typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName": true,
"typescript.inlayHints.parameterNames.enabled": "all",
"typescript.preferences.preferTypeOnlyAutoImports": true,
"typescript.tsdk": "./node_modules/typescript/lib"
}
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# bun-typescript-template

Provide a modern and ready to use template to setup a typescript project

> This Project rely on [bun](https://bun.sh) toolchain
## Install project

```sh
bun install
```

## Run test

```sh
bun test
```

## Build the project

```sh
bun --bun run build
```
Binary file added bun.lockb
Binary file not shown.
60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "bun-typescript-template",
"description": "Provide a modern and ready to use template to setup a typescript project",
"version": "0.0.0",
"type": "module",
"scripts": {
"build:lib": "bun build --minify --outdir=dist src/index.ts",
"build:types": "tsc -p tsconfig.build.json",
"build": "bun build:lib && bun build:types",
"lint": "npm run lint:lib && npm run lint:exports && npm run lint:package",
"lint:lib": "eslint --ext .ts src",
"lint:exports": "attw --pack . --ignore-rules no-resolution cjs-resolves-to-esm",
"lint:package": "publint ."
},
"files": [
"dist",
"package.json"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.13.2",
"@tsconfig/strictest": "2.0.2",
"@typescript-eslint/eslint-plugin": "6.13.1",
"@typescript-eslint/parser": "6.13.1",
"bun-types": "1.0.14",
"eslint": "8.54.0",
"publint": "0.2.6",
"typescript": "5.3.2"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"eslintConfig": {
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked"
],
"plugins": [
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true,
"tsconfigRootDir": "."
},
"root": true,
"rules": {
"@typescript-eslint/no-empty-interface": "off"
}
}
}

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
5 changes: 5 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "dist", "src/*.test.ts"]
}

Loading

0 comments on commit 08d519b

Please sign in to comment.