Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Jun 17, 2024
0 parents commit 88fe3c9
Show file tree
Hide file tree
Showing 19 changed files with 2,821 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
7 changes: 7 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
}
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2

updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
Binary file added .github/images/use-this-template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Deploy
run: pnpm run deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint -f @microsoft/eslint-formatter-sarif -o /tmp/lint.sarif
continue-on-error: true

- name: Strip suppressed results
run: pnpm dlx @ryanccn/sarif-strip-suppressed /tmp/lint.sarif

- name: Upload results
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: /tmp/lint.sarif
wait-for-processing: true
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# macOS
.DS_Store

# Node.js
node_modules/

# wrangler
.dev.vars
.wrangler/

# IDEs
.idea/
.vscode/*
!.vscode/extensions.json
tmp/
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm lint-staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm run format:check
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add files here to ignore them from prettier formatting

/dist
/coverage
tmp
/.yarn
/.nx/cache
pnpm-lock.yaml
.angular/cache

7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"printWidth": 120,
"semi": false,
"trailingComma": "all",
"arrowParens": "always"
}
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"github.vscode-github-actions"
]
}
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 Bram Borggreve https://github.com/beeman

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.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# worker-template

This is a template for building a [Cloudflare Worker](https://workers.cloudflare.com/).

It uses [**Hono**](https://hono.dev/) as the underlying framework that handles routing, body parsing, and much more. [TypeScript](https://www.typescriptlang.org/) is used for type safety, along with [TypeScript ESLint](https://typescript-eslint.io/). [Wrangler](https://developers.cloudflare.com/workers/wrangler/) is Cloudflare's official CLI that handles deployment and local development. [GitHub Actions](https://docs.github.com/en/actions) lint the codebase and deploy to Cloudflare on push. [Prettier](https://prettier.io/) is used for code formatting. The package manager is [pnpm](https://pnpm.io/).

## Getting started

1. [Use this template](https://github.com/ryanccn/worker-template/generate) on GitHub.

![Use this template](/.github/images/use-this-template.png)

2. [Create an API token](https://dash.cloudflare.com/profile/api-tokens) on Cloudflare with the default Edit Workers template and set it as a repository secret named `CLOUDFLARE_API_TOKEN`.
3. Rerun the failed deploy run.

## License

Creative Commons Zero v1.0 Universal (Public Domain)
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "worker-template",
"version": "0.0.1",
"type": "module",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"lint": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"dependencies": {
"hono": "^3.12.3"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231218.0",
"@microsoft/eslint-formatter-sarif": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"wrangler": "^3.60.3"
},
"packageManager": "[email protected]+sha256.e1f9e8d1a16607a46dd3c158b5f7a7dc7945501d1c6222d454d63d033d1d918f",
"lint-staged": {
"*.{cjs,js,json,css,scss,md,ts,tsx,html,graphql}": [
"pnpm run format"
]
}
}
Loading

0 comments on commit 88fe3c9

Please sign in to comment.