Skip to content

Commit f74da26

Browse files
authored
Initial commit
0 parents  commit f74da26

17 files changed

Lines changed: 2594 additions & 0 deletions

.devcontainer/devcontainer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
3+
{
4+
"name": "Node.js & TypeScript",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "devcontainer",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
"customizations": {
9+
"vscode": {
10+
"extensions": ["biomejs.biome", "ms-azuretools.vscode-docker"]
11+
}
12+
},
13+
//
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
// "features": {},
16+
//
17+
"forwardPorts": [8082],
18+
"portsAttributes": {
19+
"8082": {
20+
"label": "pgweb"
21+
}
22+
},
23+
//
24+
// Use 'postCreateCommand' to run commands after the container is created.
25+
"postCreateCommand": "pnpm install"
26+
//
27+
// Configure tool-specific properties.
28+
// "customizations": {},
29+
//
30+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
31+
// "remoteUser": "root"
32+
}

.devcontainer/docker-compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '3.8'
2+
services:
3+
devcontainer:
4+
image: mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm
5+
volumes:
6+
- ../..:/workspaces:cached
7+
network_mode: service:db
8+
command: sleep infinity
9+
10+
db:
11+
image: postgres:latest
12+
restart: unless-stopped
13+
volumes:
14+
- postgres-data:/var/lib/postgresql/data
15+
environment:
16+
POSTGRES_PASSWORD: postgres
17+
POSTGRES_USER: postgres
18+
POSTGRES_DB: postgres
19+
20+
pgweb:
21+
image: sosedoff/pgweb:0.15.0
22+
restart: unless-stopped
23+
ports:
24+
- "8082:8081"
25+
links:
26+
- db:postgres
27+
environment:
28+
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
29+
depends_on:
30+
- db
31+
32+
volumes:
33+
postgres-data:

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

.gitignore

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"biome.enabled": true,
3+
"editor.defaultFormatter": "biomejs.biome",
4+
"editor.formatOnSave": true,
5+
"editor.codeActionsOnSave": {
6+
"source.fixAll": "explicit",
7+
"quickfix.biome": "explicit",
8+
"source.organizeImports.biome": "explicit"
9+
}
10+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Pontus Öwre
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# owre/node-typescript-postgres-template
2+
3+
Project template to kick off your Node.js TypeScript application. Biome for formatting and linting, vitest for speedy testing, and Postgres together with pgweb included.
4+
5+
## Features
6+
7+
* [DevContainer](https://containers.dev/overview): For a consistent and stable development environment.
8+
* [TypeScript](https://www.typescriptlang.org/): Leverage static types and modern JavaScript features. Aliased paths are set up for easy imports of your modules and properly rewritten during build thanks to [typescript-transform-paths](https://github.com/LeDDGroup/typescript-transform-paths).
9+
* [ESM](https://nodejs.org/api/esm.html#introduction): Utilize ECMAScript modules for better interoperability.
10+
* [Biome](https://biomejs.dev/): Format, lint, and more in a fraction of a second. No more wasting your time (and sanity) getting ESLint to work.
11+
* [Vitest](https://vitest.dev/): A next generation, Jest compatible, testing framework. Enables speedy and efficient testing.
12+
* [Postgres](https://www.postgresql.org/) with [pgweb](https://sosedoff.github.io/pgweb/): The World's Most Advanced Open Source Relational Database included together with pgweb for seamless database management. Access the web interface at port 8082.
13+
* [Lefthook] Fast, powerful and simple git hooks manager
14+
15+
## Prepared npm scripts
16+
17+
* **start** - run `src/main.ts` with tsx
18+
* **start:dist** - run built project at `dist/src/main.js` with node,
19+
* **clean** - deletes `dist` and `coverage` directories,
20+
* **prebuild** - automatically runs `clean`, `lint` and `test` scripts when running `build`
21+
* **build** - builds project using release configuration
22+
* **lint** - uses `biome` to lint the project
23+
* **prepare** - automatically runs when dependencies are installed
24+
* **test** - runs test files,
25+
* **test:coverage** - gather test coverage
26+
* **test:watch** - runs test files in watch mode
27+
* **typecheck** - convenient helper to check the type integrity in the project

biome.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
3+
"organizeImports": { "enabled": true },
4+
"files": {
5+
"ignore": ["**/dist/**", "**/coverage/**", "**/node_modules/**"]
6+
},
7+
"formatter": {
8+
"indentWidth": 2,
9+
"indentStyle": "space"
10+
},
11+
"javascript": {
12+
"formatter": { "quoteStyle": "single", "semicolons": "asNeeded" }
13+
}
14+
}

lefthook.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Refer to the documentation for more information:
3+
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
4+
#
5+
pre-commit:
6+
commands:
7+
biome:
8+
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
9+
run: pnpm biome check --no-errors-on-unmatched --files-ignore-unknown=true {staged_files}
10+
tests:
11+
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx}"
12+
run: pnpm vitest related --run {staged_files}

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"author": "Pontus Öwre <pontus@owre.se>",
3+
"name": "node-typescript-postgres-template",
4+
"description": "Project template to kick off your Node.js TypeScript application. Biome for formatting and linting, vitest for speedy testing, and Postgres together with pgweb included.",
5+
"version": "0.0.0",
6+
"type": "module",
7+
"license": "MIT",
8+
"scripts": {
9+
"start": "tsx src/main.ts",
10+
"start:dist": "node dist/src/main.js",
11+
"clean": "rimraf dist coverage",
12+
"prebuild": "pnpm run \"/^clean|lint|test$/\"",
13+
"build": "tsc -p tsconfig.release.json",
14+
"lint": "biome check .",
15+
"prepare": "lefthook install && ts-patch install",
16+
"test": "vitest --run",
17+
"test:coverage": "vitest --coverage",
18+
"test:watch": "vitest",
19+
"typecheck": "tspc --noEmit"
20+
},
21+
"devDependencies": {
22+
"@biomejs/biome": "1.8.1",
23+
"@types/node": "^20.14.2",
24+
"@vitest/coverage-v8": "^1.6.0",
25+
"lefthook": "1.6.15",
26+
"rimraf": "^5.0.7",
27+
"ts-patch": "^3.2.0",
28+
"tsx": "^4.15.2",
29+
"typescript": "^5.4.5",
30+
"typescript-transform-paths": "^3.4.7",
31+
"vite-tsconfig-paths": "^4.3.2",
32+
"vitest": "^1.6.0"
33+
}
34+
}

0 commit comments

Comments
 (0)