init repo

This commit is contained in:
b1ek 2024-05-11 18:38:18 +10:00
commit 964184851f
Signed by: blek
GPG Key ID: 14546221E3595D0C
12 changed files with 1490 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

2
.prettierignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}

11
README.md Normal file
View File

@ -0,0 +1,11 @@
# fastify-ts-template
A template for fasitify with TypeScript, eslint and prettier built with esbuild.
## Using this template
`git clone` this repo, then delete the `.git` directory and initalize it again, and change `name` and `author` in `package.json`.
## License
The template itself is `GPL-3.0-only`, and it is a default recommended license for all projects created with this template, but projects are free to choose any other license.

24
eslint.config.js Normal file
View File

@ -0,0 +1,24 @@
// @ts-check
import tse from 'typescript-eslint';
export default tse.config(...tse.configs.recommended, {
rules: {
'no-unused-vars': [
'error',
{
argsIgnorePattern: '_',
args: 'after-used',
caughtErrors: 'none',
},
],
'no-invalid-regexp': 'error',
'no-var': 'error',
eqeqeq: 'error',
'no-useless-concat': 'error',
'no-useless-rename': 'error',
'no-useless-assignment': 'error',
'default-case': 'error',
'prefer-const': 'error',
},
});

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "fastify-ts-template",
"license": "GPL-3.0-only",
"author": "blek! <me@blek.codes>",
"type": "module",
"main": "dist/index.js",
"dependencies": {
"fastify": "^4.27.0",
"typescript-eslint": "^7.8.0"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@types/node": "^20.12.11",
"esbuild": "^0.21.1",
"eslint": "^9.2.0",
"prettier": "3.2.5",
"typescript": "^5.4.5"
},
"scripts": {
"build": "node scripts/build.js",
"lint": "eslint",
"format": "prettier"
}
}

11
prettier.config.js Normal file
View File

@ -0,0 +1,11 @@
/**
* @type { import("prettier").Config }
*/
export default {
trailingComma: 'all',
tabWidth: 4,
semi: true,
singleQuote: true,
endOfLine: 'lf'
}

18
scripts/build.js Normal file
View File

@ -0,0 +1,18 @@
import esbuild from 'esbuild';
import fs from 'node:fs';
const entryPoints = fs
.readdirSync('src', { recursive: true })
.filter((x) => x.endsWith('.ts'))
.map((x) => 'src/' + x);
if (fs.existsSync('dist')) fs.rmSync('dist', { recursive: true, force: true });
try {
fs.mkdirSync('dist');
} catch (_) {}
await esbuild.build({
entryPoints,
outdir: 'dist',
});

14
src/index.ts Normal file
View File

@ -0,0 +1,14 @@
import Fastify from 'fastify';
import routes from './routes/index.js';
const fastify = Fastify();
// register any plugins here, i.e.
// fastify.register(middie);
fastify.register(routes);
fastify.listen({
port: parseInt(process.env.PORT ?? '80'),
host: process.env.HOST ?? 'localhost',
});

6
src/routes/index.ts Normal file
View File

@ -0,0 +1,6 @@
import { FastifyPluginAsync } from 'fastify';
import ping from './ping.js';
export default (async function (fastify) {
await fastify.register(ping);
} as FastifyPluginAsync);

7
src/routes/ping.ts Normal file
View File

@ -0,0 +1,7 @@
import { FastifyPluginAsync } from 'fastify';
export default (async function (fastify) {
fastify.get('/ping', async () => {
return 'Pong!';
});
} as FastifyPluginAsync);

1367
yarn.lock Normal file

File diff suppressed because it is too large Load Diff